Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -34,7 +34,7 @@ processResources {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}

Expand Down
13 changes: 7 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/versions.html
# After making changes
# gradlew --refresh-dependencies
# To remap the mixin locations:
# gradlew migrateMappings --mappings "1.16.1+build.9"
# gradlew migrateMappings --mappings "1.19.3+build.5"

minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.7
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.1
loader_version=0.14.18

#Fabric api
fabric_version=0.55.3+1.19
fabric_version=0.76.0+1.19.4

# Mod Properties
mod_version = 1.19-fabric-1
mod_version = 1.19.4-fabric-2
maven_group = net.torocraft
archives_base_name = flighthud
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.3.1-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-7.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
65 changes: 28 additions & 37 deletions src/main/java/net/torocraft/flighthud/FlightComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.joml.Matrix3f;

public class FlightComputer {
private static final float TICKS_PER_SECOND = 20;
Expand All @@ -28,12 +29,13 @@ public class FlightComputer {
public Float distanceFromGround;
public Float elytraHealth;

public void update(MinecraftClient client, float partial) {
public void update(MinecraftClient client, Matrix3f normalMatrix) {
heading = computeHeading(client, normalMatrix);
pitch = computePitch(client, normalMatrix);
roll = computeRoll(client, normalMatrix);

velocity = client.player.getVelocity();
pitch = computePitch(client, partial);
speed = computeSpeed(client);
roll = computeRoll(client, partial);
heading = computeHeading(client);
altitude = computeAltitude(client);
groundLevel = computeGroundLevel(client);
distanceFromGround = computeDistanceFromGround(client, altitude, groundLevel);
Expand Down Expand Up @@ -66,43 +68,36 @@ private float computeFlightHeading(Vec3d velocity, float heading) {
return toHeading((float) Math.toDegrees(-Math.atan2(velocity.x, velocity.z)));
}

/**
* Roll logic is from:
* https://github.com/Jorbon/cool_elytra/blob/main/src/main/java/edu/jorbonism/cool_elytra/mixin/GameRendererMixin.java
* to enable both mods will sync up when used together.
*/
private float computeRoll(MinecraftClient client, float partial) {
//region Camera Angles

private float computeRoll(MinecraftClient client, Matrix3f normalMatrix) {
if (!FlightHud.CONFIG_SETTINGS.calculateRoll) {
return 0;
return 0.0f;
}

float wingPower = FlightHud.CONFIG_SETTINGS.rollTurningForce;
float rollSmoothing = FlightHud.CONFIG_SETTINGS.rollSmoothing;
Vec3d facing = client.player.getRotationVecClient();
Vec3d velocity = client.player.getVelocity();
double horizontalFacing2 = facing.horizontalLengthSquared();
double horizontalSpeed2 = velocity.horizontalLengthSquared();

float rollAngle = 0.0f;

if (horizontalFacing2 > 0.0D && horizontalSpeed2 > 0.0D) {
double dot = (velocity.x * facing.x + velocity.z * facing.z) / Math.sqrt(horizontalFacing2 * horizontalSpeed2);
dot = MathHelper.clamp(dot, -1, 1);
double direction = Math.signum(velocity.x * facing.z - velocity.z * facing.x);
rollAngle = (float) (Math.atan(Math.sqrt(horizontalSpeed2) * Math.acos(dot) * wingPower) * direction
* 57.29577951308);
}
float y = normalMatrix.getRowColumn(0, 1);
float x = normalMatrix.getRowColumn(1, 1);
return (float) Math.toDegrees(Math.atan2(y, x));
}

rollAngle = (float) ((1.0 - rollSmoothing) * rollAngle + rollSmoothing * previousRollAngle);
previousRollAngle = rollAngle;
private float computePitch(MinecraftClient client, Matrix3f normalMatrix) {
if (client.player == null) {
return 0.0f;
}

return rollAngle;
return -client.player.getPitch();
}

private float computePitch(MinecraftClient client, float parital) {
return client.player.getPitch(parital) * -1;
private float computeHeading(MinecraftClient client, Matrix3f normalMatrix) {
if (client.player == null) {
return 0.0f;
}

return toHeading(client.player.getYaw());
}

//endregion

private boolean isGround(BlockPos pos, MinecraftClient client) {
BlockState block = client.world.getBlockState(pos);
return !block.isAir();
Expand Down Expand Up @@ -136,10 +131,6 @@ private float computeAltitude(MinecraftClient client) {
return (float) client.player.getPos().y - 1;
}

private float computeHeading(MinecraftClient client) {
return toHeading(client.player.getYaw());
}

private float computeSpeed(MinecraftClient client) {
float speed = 0;
var player = client.player;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/torocraft/flighthud/FlightHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class FlightHud implements ClientModInitializer {

private static KeyBinding keyBinding;

public static final FlightComputer computer = new FlightComputer();

@Override
public void onInitializeClient() {
CONFIG_LOADER_SETTINGS.load();
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/net/torocraft/flighthud/HudComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.RotationAxis;
import net.torocraft.flighthud.config.HudConfig;
import org.joml.Matrix4f;

public abstract class HudComponent extends DrawableHelper {

Expand All @@ -27,7 +22,8 @@ protected int i(double d) {
protected void drawPointer(MatrixStack m, float x, float y, float rot) {
m.push();
m.translate(x, y, 0);
m.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(rot + 45));
m.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(rot + 45));
// m.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(rot + 45));
drawVerticalLine(m, 0, 0, 5, CONFIG.color);
drawHorizontalLine(m, 0, 5, 0, CONFIG.color);
m.pop();
Expand Down Expand Up @@ -129,16 +125,14 @@ private static void fill(Matrix4f matrix, float x1, float y1, float x2, float y2
float b = (float) (color & 255) / 255.0F;
BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer();
RenderSystem.enableBlend();
RenderSystem.disableTexture();
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(matrix, x1, y2, 0.0F).color(r, g, b, alpha).next();
bufferBuilder.vertex(matrix, x2, y2, 0.0F).color(r, g, b, alpha).next();
bufferBuilder.vertex(matrix, x2, y1, 0.0F).color(r, g, b, alpha).next();
bufferBuilder.vertex(matrix, x1, y1, 0.0F).color(r, g, b, alpha).next();
BufferRenderer.drawWithShader(bufferBuilder.end());
RenderSystem.enableTexture();
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
RenderSystem.disableBlend();
}
}
5 changes: 3 additions & 2 deletions src/main/java/net/torocraft/flighthud/HudRenderer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.torocraft.flighthud;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import net.torocraft.flighthud.components.AltitudeIndicator;
Expand All @@ -11,10 +12,11 @@
import net.torocraft.flighthud.components.SpeedIndicator;
import net.torocraft.flighthud.config.SettingsConfig.DisplayMode;

import static net.torocraft.flighthud.FlightHud.computer;

public class HudRenderer extends HudComponent {

private final Dimensions dim = new Dimensions();
private final FlightComputer computer = new FlightComputer();
private static final String FULL = DisplayMode.FULL.toString();
private static final String MIN = DisplayMode.MIN.toString();

Expand Down Expand Up @@ -57,7 +59,6 @@ public void render(MatrixStack m, float partial, MinecraftClient client) {
m.scale(scale, scale, scale);
}

computer.update(client, partial);
dim.update(client);

for (HudComponent component : components) {
Expand Down
Loading