From 0f8f5d3f3d0f6717d58c5d80fc1ffbb35947db9a Mon Sep 17 00:00:00 2001 From: froslanz Date: Fri, 30 Oct 2026 11:56:03 -0400 Subject: [PATCH] hud: port Totem/Crystal/XP counters from Sydney Three separate draggable HUD modules, one per Sydney element (TotemCounter, CrystalCounter, XPCounter), each rendering the item icon with its stacked count. Hidden while the count is zero, matching Sydney; the editor box keeps its nominal 16x16 size so the element stays draggable. Adds InventoryUtil.count(Item) covering storage, hotbar and offhand (an offhand totem must count). --- .../modules/hud/CrystalHudModule.java | 33 +++++++++++++++++++ .../features/modules/hud/TotemHudModule.java | 33 +++++++++++++++++++ .../features/modules/hud/XpHudModule.java | 33 +++++++++++++++++++ .../java/cc/fros/manager/ModuleManager.java | 6 ++++ .../cc/fros/util/inventory/InventoryUtil.java | 12 +++++++ 5 files changed, 117 insertions(+) create mode 100644 src/main/java/cc/fros/features/modules/hud/CrystalHudModule.java create mode 100644 src/main/java/cc/fros/features/modules/hud/TotemHudModule.java create mode 100644 src/main/java/cc/fros/features/modules/hud/XpHudModule.java diff --git a/src/main/java/cc/fros/features/modules/hud/CrystalHudModule.java b/src/main/java/cc/fros/features/modules/hud/CrystalHudModule.java new file mode 100644 index 0000000..462f33b --- /dev/null +++ b/src/main/java/cc/fros/features/modules/hud/CrystalHudModule.java @@ -0,0 +1,33 @@ +package cc.fros.features.modules.hud; + +import cc.fros.event.impl.render.Render2DEvent; +import cc.fros.features.modules.client.HudModule; +import cc.fros.util.inventory.InventoryUtil; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +public class CrystalHudModule extends HudModule { + + public CrystalHudModule() { + super("Crystal", "Display how many end crystals you are carrying", 16, 16); + } + + @Override + protected void render(Render2DEvent e) { + super.render(e); + + if (nullCheck()) return; + + int count = InventoryUtil.count(Items.END_CRYSTAL); + setWidth(16); + setHeight(16); + if (count == 0) return; + + ItemStack stack = new ItemStack(Items.END_CRYSTAL); + int x = (int) getX(); + int y = (int) getY(); + + e.getContext().renderItem(stack, x, y); + e.getContext().renderItemDecorations(mc.font, stack, x, y, String.valueOf(count)); + } +} diff --git a/src/main/java/cc/fros/features/modules/hud/TotemHudModule.java b/src/main/java/cc/fros/features/modules/hud/TotemHudModule.java new file mode 100644 index 0000000..fe0e247 --- /dev/null +++ b/src/main/java/cc/fros/features/modules/hud/TotemHudModule.java @@ -0,0 +1,33 @@ +package cc.fros.features.modules.hud; + +import cc.fros.event.impl.render.Render2DEvent; +import cc.fros.features.modules.client.HudModule; +import cc.fros.util.inventory.InventoryUtil; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +public class TotemHudModule extends HudModule { + + public TotemHudModule() { + super("Totem", "Display how many totems you are carrying", 16, 16); + } + + @Override + protected void render(Render2DEvent e) { + super.render(e); + + if (nullCheck()) return; + + int count = InventoryUtil.count(Items.TOTEM_OF_UNDYING); + setWidth(16); + setHeight(16); + if (count == 0) return; + + ItemStack stack = new ItemStack(Items.TOTEM_OF_UNDYING); + int x = (int) getX(); + int y = (int) getY(); + + e.getContext().renderItem(stack, x, y); + e.getContext().renderItemDecorations(mc.font, stack, x, y, String.valueOf(count)); + } +} diff --git a/src/main/java/cc/fros/features/modules/hud/XpHudModule.java b/src/main/java/cc/fros/features/modules/hud/XpHudModule.java new file mode 100644 index 0000000..b9db3e6 --- /dev/null +++ b/src/main/java/cc/fros/features/modules/hud/XpHudModule.java @@ -0,0 +1,33 @@ +package cc.fros.features.modules.hud; + +import cc.fros.event.impl.render.Render2DEvent; +import cc.fros.features.modules.client.HudModule; +import cc.fros.util.inventory.InventoryUtil; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +public class XpHudModule extends HudModule { + + public XpHudModule() { + super("XP", "Display how many experience bottles you are carrying", 16, 16); + } + + @Override + protected void render(Render2DEvent e) { + super.render(e); + + if (nullCheck()) return; + + int count = InventoryUtil.count(Items.EXPERIENCE_BOTTLE); + setWidth(16); + setHeight(16); + if (count == 0) return; + + ItemStack stack = new ItemStack(Items.EXPERIENCE_BOTTLE); + int x = (int) getX(); + int y = (int) getY(); + + e.getContext().renderItem(stack, x, y); + e.getContext().renderItemDecorations(mc.font, stack, x, y, String.valueOf(count)); + } +} diff --git a/src/main/java/cc/fros/manager/ModuleManager.java b/src/main/java/cc/fros/manager/ModuleManager.java index c269ff9..54abe92 100644 --- a/src/main/java/cc/fros/manager/ModuleManager.java +++ b/src/main/java/cc/fros/manager/ModuleManager.java @@ -21,8 +21,11 @@ import cc.fros.features.modules.combat.KeyPearlModule; import cc.fros.features.modules.combat.SurroundModule; import cc.fros.features.modules.hud.ArrayListHudModule; import cc.fros.features.modules.hud.ArmorHudModule; +import cc.fros.features.modules.hud.CrystalHudModule; import cc.fros.features.modules.hud.ServerHudModule; +import cc.fros.features.modules.hud.TotemHudModule; import cc.fros.features.modules.hud.TpsHudModule; +import cc.fros.features.modules.hud.XpHudModule; import cc.fros.features.modules.hud.CoordinatesHudModule; import cc.fros.features.modules.hud.FpsHudModule; import cc.fros.features.modules.hud.PingHudModule; @@ -69,6 +72,9 @@ public class ModuleManager implements Jsonable, Util { register(new ArmorHudModule()); register(new TpsHudModule()); register(new ServerHudModule()); + register(new TotemHudModule()); + register(new CrystalHudModule()); + register(new XpHudModule()); register(new HudEditorModule()); register(new ClickGuiModule()); register(new NotificationsModule()); diff --git a/src/main/java/cc/fros/util/inventory/InventoryUtil.java b/src/main/java/cc/fros/util/inventory/InventoryUtil.java index a5b8c8a..ec0b1a0 100644 --- a/src/main/java/cc/fros/util/inventory/InventoryUtil.java +++ b/src/main/java/cc/fros/util/inventory/InventoryUtil.java @@ -41,6 +41,18 @@ public final class InventoryUtil implements Util { return mc.player.getInventory().getSelectedSlot(); } + /** how many of {@code target} the player is carrying (storage, hotbar and offhand) */ + public static int count(Item target) { + int count = 0; + for (int i = 0; i < 36; i++) { + ItemStack stack = mc.player.getInventory().getItem(i); + if (stack.is(target)) count += stack.getCount(); + } + ItemStack offhand = mc.player.getOffhandItem(); + if (offhand.is(target)) count += offhand.getCount(); + return count; + } + public static void click(int slot, int button, ClickType type) { int id = mc.player.containerMenu.containerId; mc.gameMode.handleInventoryMouseClick(id, slot, button, type, mc.player);