3131import io .github .axolotlclient .util .Hooks ;
3232import lombok .Getter ;
3333import net .minecraft .client .MinecraftClient ;
34+ import net .minecraft .client .network .ClientPlayerEntity ;
3435import net .minecraft .client .render .VertexConsumerProvider ;
3536import net .minecraft .client .render .entity .EntityRenderDispatcher ;
3637import net .minecraft .client .util .math .MatrixStack ;
@@ -53,12 +54,15 @@ public class PlayerHud extends BoxHudEntry {
5354
5455 private final DoubleOption rotation = new DoubleOption ("rotation" , 0 , 0 , 360 );
5556 private final BooleanOption dynamicRotation = new BooleanOption ("dynamicrotation" , true );
57+ private final BooleanOption autoHide = new BooleanOption ("autoHide" , false );
5658
5759 private float lastYawOffset = 0 ;
5860 private float yawOffset = 0 ;
5961 private float lastYOffset = 0 ;
6062 private float yOffset = 0 ;
6163
64+ private long hide ;
65+
6266 @ Getter
6367 private static boolean currentlyRendering ;
6468
@@ -69,19 +73,31 @@ public PlayerHud() {
6973
7074 @ Override
7175 public void renderComponent (MatrixStack matrices , float delta ) {
72- renderPlayer (getTruePos ().x () + 31 * getScale (), getTruePos ().y () + 86 * getScale (), delta );
76+ renderPlayer (false , getTruePos ().x () + 31 * getScale (), getTruePos ().y () + 86 * getScale (), delta );
7377 }
7478
7579 @ Override
7680 public void renderPlaceholderComponent (MatrixStack matrices , float delta ) {
77- renderPlayer (getTruePos ().x () + 31 * getScale (), getTruePos ().y () + 86 * getScale (), 0 ); // If delta was delta, it would start jittering
81+ renderPlayer (true , getTruePos ().x () + 31 * getScale (), getTruePos ().y () + 86 * getScale (), 0 ); // If delta was delta, it would start jittering
7882 }
7983
80- public void renderPlayer (double x , double y , float delta ) {
84+ public void renderPlayer (boolean placeholder , double x , double y , float delta ) {
8185 if (client .player == null ) {
8286 return ;
8387 }
8488
89+ if (!placeholder && autoHide .get ()) {
90+ if (isPerformingAction ()) {
91+ hide = -1 ;
92+ } else if (hide == -1 ) {
93+ hide = System .currentTimeMillis ();
94+ }
95+
96+ if (hide != -1 && System .currentTimeMillis () - hide > 500 ) {
97+ return ;
98+ }
99+ }
100+
85101 float lerpY = (lastYOffset + ((yOffset - lastYOffset ) * delta ));
86102
87103 MatrixStack matrixStack = RenderSystem .getModelViewStack ();
@@ -131,6 +147,14 @@ public void renderPlayer(double x, double y, float delta) {
131147 DiffuseLighting .setup3DGuiLighting ();
132148 }
133149
150+ private boolean isPerformingAction () {
151+ // inspired by tr7zw's mod
152+ ClientPlayerEntity player = client .player ;
153+ return player .isSneaking () || player .isSprinting () || player .isFallFlying () || player .getAbilities ().flying
154+ || player .isSubmergedInWater () || player .isInSwimmingPose () || player .hasVehicle ()
155+ || player .isUsingItem () || player .handSwinging || player .hurtTime > 0 || player .isOnFire ();
156+ }
157+
134158 public void onPlayerDirectionChange (float prevPitch , float prevYaw , float pitch , float yaw ) {
135159 yawOffset += (yaw - prevYaw ) / 2 ;
136160 }
@@ -186,6 +210,7 @@ public List<Option<?>> getConfigurationOptions() {
186210 List <Option <?>> options = super .getConfigurationOptions ();
187211 options .add (dynamicRotation );
188212 options .add (rotation );
213+ options .add (autoHide );
189214 return options ;
190215 }
191216}
0 commit comments