12
12
import net .minecraft .client .render .entity .EntityRenderDispatcher ;
13
13
import net .minecraft .client .util .math .MatrixStack ;
14
14
import net .minecraft .util .Identifier ;
15
+ import net .minecraft .util .math .MathHelper ;
15
16
import net .minecraft .util .math .Quaternion ;
17
+ import net .minecraft .util .math .Vec3d ;
16
18
import net .minecraft .util .math .Vec3f ;
17
19
18
20
import java .util .List ;
@@ -26,6 +28,9 @@ public class PlayerHud extends BoxHudEntry {
26
28
27
29
private float lastYawOffset = 0 ;
28
30
private float yawOffset = 0 ;
31
+ private float lastYOffset = 0 ;
32
+ private float yOffset = 0 ;
33
+
29
34
30
35
public PlayerHud () {
31
36
super (62 , 94 , true );
@@ -47,9 +52,11 @@ public void renderPlayer(double x, double y, float delta) {
47
52
return ;
48
53
}
49
54
55
+ float lerpY = (lastYOffset + ((yOffset - lastYOffset ) * delta ));
56
+
50
57
MatrixStack matrixStack = RenderSystem .getModelViewStack ();
51
58
matrixStack .push ();
52
- matrixStack .translate (x , y , 1050 );
59
+ matrixStack .translate (x , y - lerpY , 1050 );
53
60
matrixStack .scale (1 , 1 , -1 );
54
61
55
62
RenderSystem .applyModelViewMatrix ();
@@ -104,6 +111,31 @@ public boolean tickable() {
104
111
public void tick () {
105
112
lastYawOffset = yawOffset ;
106
113
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
+ }
107
139
}
108
140
109
141
@ Override
0 commit comments