diff --git a/src/client/java/autumnvn/autumn/Options.java b/src/client/java/autumnvn/autumn/Options.java index 4a44e76..a273184 100644 --- a/src/client/java/autumnvn/autumn/Options.java +++ b/src/client/java/autumnvn/autumn/Options.java @@ -37,6 +37,7 @@ public class Options { public SimpleOption noMineDelay; public SimpleOption noToast; public SimpleOption noUseDelay; + public SimpleOption pingNumber; public SimpleOption rightClickHarvest; public SimpleOption thirdPersonNoClip; public SimpleOption visibleBarrier; @@ -75,6 +76,8 @@ public Options() { options.put("noToast", noToast); noUseDelay = SimpleOption.ofBoolean("No Use Delay", value -> Tooltip.of(Text.of("Remove 4-tick delay when using items")), false); options.put("noUseDelay", noUseDelay); + pingNumber = SimpleOption.ofBoolean("Ping Number", value -> Tooltip.of(Text.of("Show ping number on tab list")), true); + options.put("pingNumber", pingNumber); rightClickHarvest = SimpleOption.ofBoolean("Right Click Harvest", value -> Tooltip.of(Text.of("Right click to harvest fully-grown crop & netherwart")), true); options.put("rightClickHarvest", rightClickHarvest); thirdPersonNoClip = SimpleOption.ofBoolean("Third Person No Clip", value -> Tooltip.of(Text.of("Let third-person camera clip through blocks")), true); diff --git a/src/client/java/autumnvn/autumn/SettingsScreen.java b/src/client/java/autumnvn/autumn/SettingsScreen.java index 41c25bf..5974fde 100644 --- a/src/client/java/autumnvn/autumn/SettingsScreen.java +++ b/src/client/java/autumnvn/autumn/SettingsScreen.java @@ -26,6 +26,7 @@ public class SettingsScreen extends Screen { AutumnClient.options.noMineDelay, AutumnClient.options.noToast, AutumnClient.options.noUseDelay, + AutumnClient.options.pingNumber, AutumnClient.options.rightClickHarvest, AutumnClient.options.thirdPersonNoClip, AutumnClient.options.visibleBarrier diff --git a/src/client/java/autumnvn/autumn/mixin/client/PlayerListHudMixin.java b/src/client/java/autumnvn/autumn/mixin/client/PlayerListHudMixin.java new file mode 100644 index 0000000..8caeb17 --- /dev/null +++ b/src/client/java/autumnvn/autumn/mixin/client/PlayerListHudMixin.java @@ -0,0 +1,35 @@ +package autumnvn.autumn.mixin.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import autumnvn.autumn.AutumnClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.PlayerListHud; +import net.minecraft.client.network.PlayerListEntry; + +@Mixin(PlayerListHud.class) +public class PlayerListHudMixin { + + // PingNumber + @Inject(method = "renderLatencyIcon", at = @At("HEAD"), cancellable = true) + private void renderLatencyIcon(DrawContext context, int width, int x, int y, PlayerListEntry entry, CallbackInfo ci) { + if (AutumnClient.options.pingNumber.getValue()) { + int ping = entry.getLatency(); + context.drawTextWithShadow(AutumnClient.client.textRenderer, ping + "ms", x + width - AutumnClient.client.textRenderer.getWidth(ping + "ms"), y, + ping > 1000 ? 0xaa0000 + : ping > 600 ? 0xff5555 + : ping > 300 ? 0xffaa00 + : ping > 150 ? 0xffff55 + : 0x55ff55); + ci.cancel(); + } + } + + @ModifyVariable(method = "render", at = @At(value = "STORE"), ordinal = 7) + private int q(int original) { + return AutumnClient.options.pingNumber.getValue() ? original + AutumnClient.client.textRenderer.getWidth("9999ms") : original; + } +} diff --git a/src/client/resources/autumn.client.mixins.json b/src/client/resources/autumn.client.mixins.json index 1e31693..d58dc7e 100644 --- a/src/client/resources/autumn.client.mixins.json +++ b/src/client/resources/autumn.client.mixins.json @@ -18,6 +18,7 @@ "LivingEntityMixin", "MinecraftClientMixin", "OptionsScreenMixin", + "PlayerListHudMixin", "SplashOverlayMixin", "TitleScreenMixin", "ToastManagerMixin"