3030import io .github .axolotlclient .modules .hud .gui .entry .BoxHudEntry ;
3131import io .github .axolotlclient .util .Hooks ;
3232import lombok .Getter ;
33+ import net .minecraft .block .Blocks ;
34+ import net .minecraft .block .material .Material ;
35+ import net .minecraft .client .render .Camera ;
3336import net .minecraft .client .render .DiffuseLighting ;
3437import net .minecraft .client .render .entity .EntityRenderDispatcher ;
38+ import net .minecraft .entity .player .ClientPlayerEntity ;
3539import net .minecraft .util .Identifier ;
40+ import net .minecraft .util .math .BlockPos ;
3641
3742import java .util .List ;
3843
@@ -48,12 +53,15 @@ public class PlayerHud extends BoxHudEntry {
4853
4954 private final DoubleOption rotation = new DoubleOption ("axolotlclient.rotation" , 0 , 0 , 360 );
5055 private final BooleanOption dynamicRotation = new BooleanOption ("axolotlclient.dynamicrotation" , true );
56+ private final BooleanOption autoHide = new BooleanOption ("axolotlclient.autoHide" , false );
5157
5258 private float lastYawOffset = 0 ;
5359 private float yawOffset = 0 ;
5460 private float lastYOffset = 0 ;
5561 private float yOffset = 0 ;
5662
63+ private long hide ;
64+
5765 @ Getter
5866 private static boolean currentlyRendering = false ;
5967
@@ -64,19 +72,31 @@ public PlayerHud() {
6472
6573 @ Override
6674 public void renderComponent (float delta ) {
67- renderPlayer (getTruePos ().x () + 31 * getScale (), getTruePos ().y () + 86 * getScale (), delta );
75+ renderPlayer (false , getTruePos ().x () + 31 * getScale (), getTruePos ().y () + 86 * getScale (), delta );
6876 }
6977
7078 @ Override
7179 public void renderPlaceholderComponent (float delta ) {
72- renderPlayer (getTruePos ().x () + 31 * getScale (), getTruePos ().y () + 86 * getScale (), 0 ); // If delta was delta, it would start jittering
80+ renderPlayer (true , getTruePos ().x () + 31 * getScale (), getTruePos ().y () + 86 * getScale (), 0 ); // If delta was delta, it would start jittering
7381 }
7482
75- public void renderPlayer (double x , double y , float delta ) {
83+ public void renderPlayer (boolean placeholder , double x , double y , float delta ) {
7684 if (client .player == null ) {
7785 return ;
7886 }
7987
88+ if (!placeholder && autoHide .get ()) {
89+ if (isPerformingAction ()) {
90+ hide = -1 ;
91+ } else if (hide == -1 ) {
92+ hide = System .currentTimeMillis ();
93+ }
94+
95+ if (hide != -1 && System .currentTimeMillis () - hide > 500 ) {
96+ return ;
97+ }
98+ }
99+
80100 float lerpY = (lastYOffset + ((yOffset - lastYOffset ) * delta ));
81101
82102 GlStateManager .color4f (1 , 1 , 1 , 1 );
@@ -138,6 +158,14 @@ public void renderPlayer(double x, double y, float delta) {
138158 //DiffuseLighting.setup3DGuiLighting();
139159 }
140160
161+ private boolean isPerformingAction () {
162+ // inspired by tr7zw's mod
163+ ClientPlayerEntity player = client .player ;
164+ return player .isSneaking () || player .isSprinting () || player .abilities .flying
165+ || client .player .isSubmergedIn (Material .WATER ) || player .hasVehicle () || player .isUsingItem ()
166+ || player .handSwinging || player .hurtTime > 0 || player .isOnFire ();
167+ }
168+
141169 public void onPlayerDirectionChange (float prevPitch , float prevYaw , float pitch , float yaw ) {
142170 yawOffset += (yaw - prevYaw ) / 2 ;
143171 }
@@ -170,6 +198,7 @@ public List<Option<?>> getConfigurationOptions() {
170198 List <Option <?>> options = super .getConfigurationOptions ();
171199 options .add (dynamicRotation );
172200 options .add (rotation );
201+ options .add (autoHide );
173202 return options ;
174203 }
175204}
0 commit comments