From f498f2e891907854a78439867b5306d05db2a107 Mon Sep 17 00:00:00 2001 From: DarkKronicle Date: Fri, 14 Oct 2022 11:43:46 -0600 Subject: [PATCH] Fixing bugs and having player model centered in flight! --- .../kronhud/gui/hud/PlayerHud.java | 34 ++++++++++++++++++- .../kronhud/gui/hud/simple/ComboHud.java | 3 ++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PlayerHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PlayerHud.java index 85261f4..9365bf1 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PlayerHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/PlayerHud.java @@ -12,7 +12,9 @@ import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Quaternion; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3f; import java.util.List; @@ -26,6 +28,9 @@ public class PlayerHud extends BoxHudEntry { private float lastYawOffset = 0; private float yawOffset = 0; + private float lastYOffset = 0; + private float yOffset = 0; + public PlayerHud() { super(62, 94, true); @@ -47,9 +52,11 @@ public void renderPlayer(double x, double y, float delta) { return; } + float lerpY = (lastYOffset + ((yOffset - lastYOffset) * delta)); + MatrixStack matrixStack = RenderSystem.getModelViewStack(); matrixStack.push(); - matrixStack.translate(x, y, 1050); + matrixStack.translate(x, y - lerpY, 1050); matrixStack.scale(1, 1, -1); RenderSystem.applyModelViewMatrix(); @@ -104,6 +111,31 @@ public boolean tickable() { public void tick() { lastYawOffset = yawOffset; yawOffset *= .93f; + lastYOffset = yOffset; + if (client.player != null && client.player.isInSwimmingPose()) { + float rawPitch = client.player.isTouchingWater() ? -90.0F - client.player.getPitch() : -90.0F; + float pitch = MathHelper.lerp(client.player.getLeaningPitch(1), 0.0F, rawPitch); + float height = client.player.getHeight(); + // sin = opposite / hypotenuse + float offset = (float) (Math.sin(Math.toRadians(pitch)) * height); + yOffset = Math.abs(offset) + 35; + } else if (client.player != null && client.player.isFallFlying()) { + // Elytra! + + float j = (float)client.player.getRoll() + 1; + float k = MathHelper.clamp(j * j / 100.0F, 0.0F, 1.0F); + + float pitch = k * (-90.0F - client.player.getPitch()) + 90; + float height = client.player.getHeight(); + // sin = opposite / hypotenuse + float offset = (float) (Math.sin(Math.toRadians(pitch)) * height) * 50; + yOffset = 35 - offset; + if (pitch < 0) { + yOffset -= ((1 / (1 + Math.exp(-pitch / 4))) - .5) * 20; + } + } else { + yOffset *= .8; + } } @Override diff --git a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/simple/ComboHud.java b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/simple/ComboHud.java index f7123de..b15c700 100644 --- a/src/main/java/io/github/darkkronicle/kronhud/gui/hud/simple/ComboHud.java +++ b/src/main/java/io/github/darkkronicle/kronhud/gui/hud/simple/ComboHud.java @@ -43,6 +43,9 @@ public void onEntityAttack(Entity attacked) { } public void onEntityDamage(Entity entity) { + if (client.player == null) { + return; + } if (entity.getId() == client.player.getId()) { target = -1; count = 0;