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).
This commit is contained in:
froslanz
2026-10-30 11:56:03 -04:00
parent 0d86808824
commit 0f8f5d3f3d
5 changed files with 117 additions and 0 deletions
@@ -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));
}
}
@@ -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));
}
}
@@ -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));
}
}
@@ -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());
@@ -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);