Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit f498f2e

Browse files
committed
Fixing bugs and having player model centered in flight!
1 parent 8f4062c commit f498f2e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/main/java/io/github/darkkronicle/kronhud/gui/hud/PlayerHud.java

+33-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import net.minecraft.client.render.entity.EntityRenderDispatcher;
1313
import net.minecraft.client.util.math.MatrixStack;
1414
import net.minecraft.util.Identifier;
15+
import net.minecraft.util.math.MathHelper;
1516
import net.minecraft.util.math.Quaternion;
17+
import net.minecraft.util.math.Vec3d;
1618
import net.minecraft.util.math.Vec3f;
1719

1820
import java.util.List;
@@ -26,6 +28,9 @@ public class PlayerHud extends BoxHudEntry {
2628

2729
private float lastYawOffset = 0;
2830
private float yawOffset = 0;
31+
private float lastYOffset = 0;
32+
private float yOffset = 0;
33+
2934

3035
public PlayerHud() {
3136
super(62, 94, true);
@@ -47,9 +52,11 @@ public void renderPlayer(double x, double y, float delta) {
4752
return;
4853
}
4954

55+
float lerpY = (lastYOffset + ((yOffset - lastYOffset) * delta));
56+
5057
MatrixStack matrixStack = RenderSystem.getModelViewStack();
5158
matrixStack.push();
52-
matrixStack.translate(x, y, 1050);
59+
matrixStack.translate(x, y - lerpY, 1050);
5360
matrixStack.scale(1, 1, -1);
5461

5562
RenderSystem.applyModelViewMatrix();
@@ -104,6 +111,31 @@ public boolean tickable() {
104111
public void tick() {
105112
lastYawOffset = yawOffset;
106113
yawOffset *= .93f;
114+
lastYOffset = yOffset;
115+
if (client.player != null && client.player.isInSwimmingPose()) {
116+
float rawPitch = client.player.isTouchingWater() ? -90.0F - client.player.getPitch() : -90.0F;
117+
float pitch = MathHelper.lerp(client.player.getLeaningPitch(1), 0.0F, rawPitch);
118+
float height = client.player.getHeight();
119+
// sin = opposite / hypotenuse
120+
float offset = (float) (Math.sin(Math.toRadians(pitch)) * height);
121+
yOffset = Math.abs(offset) + 35;
122+
} else if (client.player != null && client.player.isFallFlying()) {
123+
// Elytra!
124+
125+
float j = (float)client.player.getRoll() + 1;
126+
float k = MathHelper.clamp(j * j / 100.0F, 0.0F, 1.0F);
127+
128+
float pitch = k * (-90.0F - client.player.getPitch()) + 90;
129+
float height = client.player.getHeight();
130+
// sin = opposite / hypotenuse
131+
float offset = (float) (Math.sin(Math.toRadians(pitch)) * height) * 50;
132+
yOffset = 35 - offset;
133+
if (pitch < 0) {
134+
yOffset -= ((1 / (1 + Math.exp(-pitch / 4))) - .5) * 20;
135+
}
136+
} else {
137+
yOffset *= .8;
138+
}
107139
}
108140

109141
@Override

src/main/java/io/github/darkkronicle/kronhud/gui/hud/simple/ComboHud.java

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public void onEntityAttack(Entity attacked) {
4343
}
4444

4545
public void onEntityDamage(Entity entity) {
46+
if (client.player == null) {
47+
return;
48+
}
4649
if (entity.getId() == client.player.getId()) {
4750
target = -1;
4851
count = 0;

0 commit comments

Comments
 (0)