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);