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

Commit 28d5584

Browse files
authored
Merge pull request #46 from TheKodeToad/autohide
Add player hud autohide (1.19)
2 parents 1190acd + 6199f4a commit 28d5584

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/main/java/io/github/axolotlclient/modules/hud/gui/hud/PlayerHud.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.github.axolotlclient.util.Hooks;
3232
import lombok.Getter;
3333
import net.minecraft.client.MinecraftClient;
34+
import net.minecraft.client.network.ClientPlayerEntity;
3435
import net.minecraft.client.render.VertexConsumerProvider;
3536
import net.minecraft.client.render.entity.EntityRenderDispatcher;
3637
import 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
}

src/main/resources/assets/axolotlclient/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
"playerhud": "Player HUD",
239239
"tpshud": "TPS HUD",
240240
"dynamicrotation": "Dynamic Rotation",
241+
"autoHide": "Auto-hide",
241242
"rotation": "Rotation",
242243

243244
"hud.snapping": "Snapping",

0 commit comments

Comments
 (0)