From 0a8957b4775bbffc09539482fd9b12eafff4c7f0 Mon Sep 17 00:00:00 2001 From: froslanz Date: Fri, 30 Oct 2026 15:38:12 -0400 Subject: [PATCH] add AutoTotem module Ported from Sydney-Legacy AutoTotemModule: - offhand modes Totem/Crystal/Gapple with health, elytra, fall, gapple, lethal-override, tick-abort, smart-mine and anti-mace checks - own-totem pop resets the tick-abort interval via entity event 35 - three-click pickup move into offhand container slot 45 - ServerManager.getPingDelay() added for lag-scaled action pacing Substitutions: no Suicide/SpeedMine modules in fros, so those branches are dropped; SmartMine uses vanilla isDestroying() as the mining proxy; sword/axe check via ItemTags.SWORDS/AXES (no SwordItem/AxeItem classes) --- .../modules/combat/AutoTotemModule.java | 158 ++++++++++++++++++ .../java/cc/fros/manager/ModuleManager.java | 2 + .../java/cc/fros/manager/ServerManager.java | 5 + 3 files changed, 165 insertions(+) create mode 100644 src/main/java/cc/fros/features/modules/combat/AutoTotemModule.java diff --git a/src/main/java/cc/fros/features/modules/combat/AutoTotemModule.java b/src/main/java/cc/fros/features/modules/combat/AutoTotemModule.java new file mode 100644 index 0000000..f21d7dd --- /dev/null +++ b/src/main/java/cc/fros/features/modules/combat/AutoTotemModule.java @@ -0,0 +1,158 @@ +package cc.fros.features.modules.combat; + +import cc.fros.Fros; +import cc.fros.event.impl.network.PacketEvent; +import cc.fros.event.system.Subscribe; +import cc.fros.features.modules.Module; +import cc.fros.features.settings.Setting; +import cc.fros.util.inventory.InventoryUtil; +import cc.fros.util.inventory.Result; +import cc.fros.util.inventory.ResultType; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.gui.screens.inventory.InventoryScreen; +import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; +import net.minecraft.tags.ItemTags; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +import java.util.EnumSet; + +/** + * AutoTotem — keeps a chosen item (totem, crystal or enchanted golden apple) in your offhand, + * swapping one in whenever safety conditions are met. + * Ported from Sydney's {@code AutoTotemModule}. + */ +public class AutoTotemModule extends Module { + private static final byte TOTEM_POP_EVENT_ID = 35; + private static final int OFFHAND_SLOT = 45; + + private final Setting item = mode("Item", Mode.Totem); + private final Setting health = num("Health", 16, 0, 36); + private final Setting elytraCheck = bool("ElytraCheck", true); + private final Setting fallDistance = num("FallDistance", 20f, 0f, 80f); + private final Setting useGapple = bool("UseGapple", true); + private final Setting lethalOverride = bool("LethalOverride", false); + private final Setting tickAbort = bool("TickAbort", true); + private final Setting smartMine = bool("SmartMine", false); + private final Setting antiMace = bool("AntiMace", false); + private final Setting maceRange = num("MaceRange", 12f, 0f, 24f); + + private int totemCount; + private int ticks; + + public AutoTotemModule() { + super("AutoTotem", "Automatically puts a specified item in your offhand slot.", Category.COMBAT); + health.setVisibility(v -> item.getValue() != Mode.Totem); + smartMine.setVisibility(v -> item.getValue() == Mode.Crystal); + lethalOverride.setVisibility(v -> useGapple.getValue()); + maceRange.setVisibility(v -> antiMace.getValue()); + } + + @Override + public void onTick() { + if (nullCheck()) return; + totemCount = InventoryUtil.count(Items.TOTEM_OF_UNDYING); + + if (ticks > 0 && tickAbort.getValue()) { + ticks--; + return; + } + + // don't shuffle items around while some other container screen is open + if (!(mc.screen instanceof InventoryScreen) && mc.screen instanceof AbstractContainerScreen) return; + + Item target = getItem(); + if (mc.player.getOffhandItem().is(target)) return; + + Result slot = InventoryUtil.find(target, EnumSet.of(ResultType.INVENTORY)); + if (!slot.found()) slot = InventoryUtil.find(target, EnumSet.of(ResultType.HOTBAR, ResultType.INVENTORY)); + if (!slot.found() && target == Items.TOTEM_OF_UNDYING) { + // no spare totem anywhere: move an empty slot over the offhand to clear it + slot = InventoryUtil.find(ItemStack::isEmpty, EnumSet.of(ResultType.HOTBAR, ResultType.INVENTORY)); + } + if (!slot.found()) return; + + // three-click "pick up, place, put back" move into the offhand + int src = containerSlot(slot); + InventoryUtil.click(src, 0, ClickType.PICKUP); + InventoryUtil.click(OFFHAND_SLOT, 0, ClickType.PICKUP); + InventoryUtil.click(src, 0, ClickType.PICKUP); + ticks = 2 + Fros.serverManager.getPingDelay(); + } + + @Subscribe + public void onPacketReceive(PacketEvent.Receive event) { + // popping your own totem restarts the tick-abort interval; runs on the network thread + if (!(event.getPacket() instanceof ClientboundEntityEventPacket packet)) return; + if (packet.getEventId() != TOTEM_POP_EVENT_ID) return; + if (mc.level == null) return; + if (packet.getEntity(mc.level) == mc.player) ticks = 0; + } + + private Item getItem() { + ItemStack mainhand = mc.player.getMainHandItem(); + + if (useGapple.getValue() && mc.options.keyUse.isDown() + && (lethalOverride.getValue() || !needsTotem()) + && (mainhand.is(ItemTags.SWORDS) || mainhand.is(ItemTags.AXES)) + && hasItem(Items.ENCHANTED_GOLDEN_APPLE)) { + return Items.ENCHANTED_GOLDEN_APPLE; + } + + if (hasItem(Items.TOTEM_OF_UNDYING)) { + if (needsTotem()) return Items.TOTEM_OF_UNDYING; + + // crystal mode: hold the totem unless a block is actually being mined + if (item.getValue() == Mode.Crystal && smartMine.getValue() && !mc.gameMode.isDestroying()) { + return Items.TOTEM_OF_UNDYING; + } + } + + return switch (item.getValue()) { + case Crystal -> hasItem(Items.END_CRYSTAL) ? Items.END_CRYSTAL : Items.TOTEM_OF_UNDYING; + case Gapple -> hasItem(Items.ENCHANTED_GOLDEN_APPLE) ? Items.ENCHANTED_GOLDEN_APPLE : Items.TOTEM_OF_UNDYING; + default -> Items.TOTEM_OF_UNDYING; + }; + } + + private boolean needsTotem() { + if (mc.player.getHealth() + mc.player.getAbsorptionAmount() <= health.getValue()) return true; + if (mc.player.fallDistance > fallDistance.getValue()) return true; + if (elytraCheck.getValue() && mc.player.getItemBySlot(EquipmentSlot.CHEST).is(Items.ELYTRA)) return true; + return antiMace.getValue() && maceThreat(); + } + + private boolean maceThreat() { + float range = maceRange.getValue(); + for (Player player : mc.level.players()) { + if (player == mc.player) continue; + if (Fros.friendManager.isFriend(player)) continue; + if (mc.player.distanceToSqr(player) > range * range) continue; + if (player.fallDistance >= 1.5f && player.getMainHandItem().is(Items.MACE)) return true; + } + return false; + } + + private boolean hasItem(Item target) { + return InventoryUtil.find(target, EnumSet.of(ResultType.HOTBAR, ResultType.INVENTORY)).found() + || mc.player.getOffhandItem().is(target); + } + + /** Container-menu slot id for an inventory result (hotbar indices 0-8 live at 36-44). */ + private static int containerSlot(Result result) { + return result.type() == ResultType.HOTBAR ? result.slot() + 36 : result.slot(); + } + + @Override + public String getDisplayInfo() { + return String.valueOf(totemCount); + } + + private enum Mode { + Totem, Crystal, Gapple + } +} diff --git a/src/main/java/cc/fros/manager/ModuleManager.java b/src/main/java/cc/fros/manager/ModuleManager.java index 41910b1..454e700 100644 --- a/src/main/java/cc/fros/manager/ModuleManager.java +++ b/src/main/java/cc/fros/manager/ModuleManager.java @@ -14,6 +14,7 @@ import cc.fros.features.modules.Module; import cc.fros.features.modules.client.ClickGuiModule; import cc.fros.features.modules.client.HudEditorModule; import cc.fros.features.modules.client.NotificationsModule; +import cc.fros.features.modules.combat.AutoTotemModule; import cc.fros.features.modules.combat.KillAuraModule; import cc.fros.features.modules.combat.CrystalAuraModule; import cc.fros.features.modules.combat.CriticalsModule; @@ -108,6 +109,7 @@ public class ModuleManager implements Jsonable, Util { register(new KillAuraModule()); register(new CrystalAuraModule()); register(new SurroundModule()); + register(new AutoTotemModule()); register(new ExpThrowerModule()); register(new FastAccelModule()); diff --git a/src/main/java/cc/fros/manager/ServerManager.java b/src/main/java/cc/fros/manager/ServerManager.java index befe460..8de7190 100644 --- a/src/main/java/cc/fros/manager/ServerManager.java +++ b/src/main/java/cc/fros/manager/ServerManager.java @@ -85,4 +85,9 @@ public class ServerManager return 0; } } + + /** Ticks to wait after an inventory action so the server can catch up, scaled by ping. */ + public int getPingDelay() { + return (int) (getPing() / 25.0f); + } } \ No newline at end of file