AutoTotem module

AutoTotem: Minecraft 26.3 cheat module, full source for every implementation (4 clients: MelaHack (ThunderHack fork), OfflineClient, Combatant, …).

4 implementationsCOMBATPLAYERCombat

Full module source: 4 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

MelaHack (ThunderHack fork)COMBATsrc/main/java/thunder/hack/features/modules/combat/AutoTotem.javaJava · 443 lines · 22.5 KB

Automatically places totems and other items in your offhand.

SettingsModeItemDoNotSwapBackBindSwapSwapButtonSwapNCPStrictHPShieldGappleHpCalcAbsorptionStopMotionResetAttackCooldownSafetyHotbarFallbackFallBackCalcOnElytraOnFallOnCrystalOnObsidianPlaceOnCrystalInHandOnMinecartTNTOnCreeperOnAnchorOnTNTRightClickGappleCrappleSpoof
AutoTotem.javaJava · Minecraft 26.2 · 443 lines · 22.5 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.world.level.block.*;
5
import net.minecraft.world.phys.BlockHitResult;
6
import net.minecraft.world.phys.HitResult;
7
import net.minecraft.world.phys.Vec3;
8
import net.minecraft.world.InteractionHand;
9
import net.minecraft.world.effect.MobEffects;
10
import net.minecraft.world.entity.Entity;
11
import net.minecraft.world.entity.EntityType;
12
import net.minecraft.world.entity.EntityTypes;
13
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
14
import net.minecraft.world.entity.item.PrimedTnt;
15
import net.minecraft.world.entity.monster.Creeper;
16
import net.minecraft.world.entity.player.Player;
17
import net.minecraft.world.entity.vehicle.minecart.MinecartTNT;
18
import net.minecraft.world.inventory.ContainerInput;
19
import net.minecraft.world.item.*;
20
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
21
import net.minecraft.client.player.LocalPlayer;
22
import net.minecraft.core.BlockPos;
23
import net.minecraft.core.Direction;
24
import net.minecraft.network.protocol.game.*;
25
import net.minecraft.tags.ItemTags;
26
import org.jetbrains.annotations.NotNull;
27
import org.lwjgl.glfw.GLFW;
28
import thunder.hack.core.Managers;
29
import thunder.hack.core.manager.client.ModuleManager;
30
import thunder.hack.events.impl.PacketEvent;
31
import thunder.hack.features.modules.Module;
32
import thunder.hack.features.modules.movement.Blink;
33
import thunder.hack.injection.accesors.IMinecraftClient;
34
import thunder.hack.setting.Setting;
35
import thunder.hack.setting.impl.Bind;
36
import thunder.hack.setting.impl.BooleanSettingGroup;
37
import thunder.hack.setting.impl.SettingGroup;
38
import thunder.hack.utility.Timer;
39
import thunder.hack.utility.math.PredictUtility;
40
import thunder.hack.utility.player.InventoryUtility;
41
import thunder.hack.utility.player.SearchInvResult;
42
import thunder.hack.utility.world.ExplosionUtility;
43
44
public final class AutoTotem extends Module {
45
    private final Setting<Mode> mode = new Setting<>("Mode", Mode.Matrix);
46
    private final Setting<OffHand> offhand = new Setting<>("Item", OffHand.Totem);
47
    private final Setting<Boolean> pomoyka = new Setting<>("DoNotSwapBack", false, v -> offhand.is(OffHand.Totem));
48
    private final Setting<BooleanSettingGroup> bindSwap = new Setting<>("BindSwap", new BooleanSettingGroup(false), v -> offhand.is(OffHand.Totem));
49
    private final Setting<Bind> swapButton = new Setting<>("SwapButton", new Bind(GLFW.GLFW_KEY_CAPS_LOCK, false, false)).addToGroup(bindSwap);
50
    private final Setting<Swap> swapMode = new Setting<>("Swap", Swap.GappleShield).addToGroup(bindSwap);
51
    private final Setting<Boolean> ncpStrict = new Setting<>("NCPStrict", false);
52
    private final Setting<Float> healthF = new Setting<>("HP", 16f, 0f, 36f);
53
    private final Setting<Float> healthS = new Setting<>("ShieldGappleHp", 16f, 0f, 20f, v -> offhand.getValue() == OffHand.Shield);
54
    private final Setting<Boolean> calcAbsorption = new Setting<>("CalcAbsorption", true);
55
    private final Setting<Boolean> stopMotion = new Setting<>("StopMotion", false);
56
    private final Setting<Boolean> resetAttackCooldown = new Setting<>("ResetAttackCooldown", false);
57
    private final Setting<SettingGroup> safety = new Setting<>("Safety", new SettingGroup(false, 0));
58
    private final Setting<Boolean> hotbarFallBack = new Setting<>("HotbarFallback", false).addToGroup(safety);
59
    private final Setting<Boolean> fallBackCalc = new Setting<>("FallBackCalc", true, v -> hotbarFallBack.getValue()).addToGroup(safety);
60
    private final Setting<Boolean> onElytra = new Setting<>("OnElytra", true).addToGroup(safety);
61
    private final Setting<Boolean> onFall = new Setting<>("OnFall", true).addToGroup(safety);
62
    private final Setting<Boolean> onCrystal = new Setting<>("OnCrystal", true).addToGroup(safety);
63
    private final Setting<Boolean> onObsidianPlace = new Setting<>("OnObsidianPlace", false).addToGroup(safety);
64
    private final Setting<Boolean> onCrystalInHand = new Setting<>("OnCrystalInHand", false).addToGroup(safety);
65
    private final Setting<Boolean> onMinecartTnt = new Setting<>("OnMinecartTNT", true).addToGroup(safety);
66
    private final Setting<Boolean> onCreeper = new Setting<>("OnCreeper", true).addToGroup(safety);
67
    private final Setting<Boolean> onAnchor = new Setting<>("OnAnchor", true).addToGroup(safety);
68
    private final Setting<Boolean> onTnt = new Setting<>("OnTNT", true).addToGroup(safety);
69
    public final Setting<RCGap> rcGap = new Setting<>("RightClickGapple", RCGap.Off);
70
    private final Setting<Boolean> crappleSpoof = new Setting<>("CrappleSpoof", true, v -> offhand.getValue() == OffHand.GApple);
71
72
    private enum OffHand {Totem, Crystal, GApple, Shield}
73
74
    private enum Mode {Default, Alternative, Matrix, MatrixPick, NewVersion}
75
76
    private enum Swap {GappleShield, BallShield, GappleBall, BallTotem}
77
78
    public enum RCGap {Off, Always, OnlySafe}
79
80
81
    private int delay;
82
83
    private Timer bindDelay = new Timer();
84
85
    private Item prevItem;
86
87
    public AutoTotem() {
88
        super("AutoTotem", Category.COMBAT);
89
    }
90
91
    @Override
92
    protected void onSync() {
93
        swapTo(getItemSlot());
94
        HitResult crosshairTarget = mc.hitResult;
95
        if (crosshairTarget instanceof BlockHitResult blockHitResult) {
96
            BlockPos pos = blockHitResult.getBlockPos();
97
            if (rcGap.not(RCGap.Off)) {
98
                LocalPlayer clientPlayer = mc.player;
99
                if (clientPlayer != null && clientPlayer.getMainHandItem().is(ItemTags.SWORDS) && mc.options.keyUse.isDown() && !clientPlayer.isUsingItem() && !pomoyka.getValue()) {
100
                    assert mc.level != null;
101
                    if (!(mc.level.getBlockState(pos).getBlock() instanceof DoorBlock ||
102
                            mc.level.getBlockState(pos).getBlock() instanceof BedBlock ||
103
                            mc.level.getBlockState(pos).getBlock() instanceof TrapDoorBlock ||
104
                            mc.level.getBlockState(pos).getBlock() instanceof CampfireBlock ||
105
                            mc.level.getBlockState(pos).getBlock() instanceof CakeBlock ||
106
                            mc.level.getBlockState(pos).getBlock() instanceof LeverBlock ||
107
                            mc.level.getBlockState(pos).getBlock() instanceof ButtonBlock
108
                    )) {
109
                        ((IMinecraftClient) mc).idoItemUse();
110
                    }
111
                }
112
            }
113
        }
114
        delay--;
115
    }
116
117
    @EventHandler
118
    public void onPacketReceive(PacketEvent.@NotNull Receive e) {
119
        if (e.getPacket() instanceof ClientboundAddEntityPacket spawn)
120
            if (spawn.getType() == EntityTypes.END_CRYSTAL)
121
                if (getPlayerPos().distanceToSqr(spawn.getX(), spawn.getY(), spawn.getZ()) < 36) {
122
                    if (hotbarFallBack.getValue()) {
123
                        if (fallBackCalc.getValue() && ExplosionUtility.getExplosionDamageWPredict(new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()), mc.player, PredictUtility.createBox(getPlayerPos(), mc.player), false) < getTriggerHealth() + 4f)
124
                            return;
125
                        runInstant();
126
                    }
127
128
                    if (onCrystal.getValue()) {
129
                        if (getTriggerHealth() - ExplosionUtility.getExplosionDamageWPredict(new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()), mc.player, PredictUtility.createBox(getPlayerPos(), mc.player), false) < 0.5) {
130
                            int slot = -1;
131
                            for (int i = 9; i < 45; i++) {
132
                                if (mc.player.getInventory().getItem(i >= 36 ? i - 36 : i).getItem().equals(Items.TOTEM_OF_UNDYING)) {
133
                                    slot = i >= 36 ? i - 36 : i;
134
                                    break;
135
                                }
136
                            }
137
138
                            swapTo(slot);
139
                            debug("spawn switch");
140
                        }
141
                    }
142
                }
143
144
145
        if (e.getPacket() instanceof ClientboundBlockUpdatePacket blockUpdate)
146
            if (blockUpdate.getBlockState().getBlock() == Blocks.OBSIDIAN && onObsidianPlace.getValue())
147
                if (getPlayerPos().distanceToSqr(net.minecraft.world.phys.Vec3.atBottomCenterOf(blockUpdate.getPos())) < 36 && delay <= 0)
148
                    runInstant();
149
    }
150
151
    private float getTriggerHealth() {
152
        return mc.player.getHealth() + (calcAbsorption.getValue() ? mc.player.getAbsorptionAmount() : 0f);
153
    }
154
155
    private void runInstant() {
156
        SearchInvResult hotbarResult = InventoryUtility.findItemInHotBar(Items.TOTEM_OF_UNDYING);
157
        SearchInvResult invResult = InventoryUtility.findItemInInventory(Items.TOTEM_OF_UNDYING);
158
        if (hotbarResult.found()) {
159
            hotbarResult.switchTo();
160
            delay = 20;
161
        } else if (invResult.found()) {
162
            int slot = invResult.slot() >= 36 ? invResult.slot() - 36 : invResult.slot();
163
            if (!hotbarFallBack.getValue()) swapTo(slot);
164
            else mc.gameMode.handleCreativeModeItemAdd(mc.player.getInventory().getItem(slot), slot);
165
            delay = 20;
166
        }
167
    }
168
169
    public void swapTo(int slot) {
170
        if (slot != -1 && delay <= 0) {
171
            if (mc.gui.screen() instanceof ContainerScreen) return;
172
173
            if (stopMotion.getValue()) mc.player.setDeltaMovement(0, mc.player.getDeltaMovement().y(), 0);
174
175
            int nearestSlot = findNearestCurrentItem();
176
            int prevCurrentItem = mc.player.getInventory().getSelectedSlot();
177
            if (slot >= 9) {
178
                switch (mode.getValue()) {
179
                    case Default -> {
180
                        if (ncpStrict.getValue())
181
                            sendPacket(new ServerboundPlayerCommandPacket(mc.player, ServerboundPlayerCommandPacket.Action.STOP_SPRINTING));
182
                        clickSlot(slot);
183
                        clickSlot(45);
184
                        clickSlot(slot);
185
                        sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
186
                    }
187
                    case Alternative -> {
188
                        if (ncpStrict.getValue())
189
                            sendPacket(new ServerboundPlayerCommandPacket(mc.player, ServerboundPlayerCommandPacket.Action.STOP_SPRINTING));
190
                        clickSlot(slot, nearestSlot, ContainerInput.SWAP);
191
                        clickSlot(45, nearestSlot, ContainerInput.SWAP);
192
                        clickSlot(slot, nearestSlot, ContainerInput.SWAP);
193
                        sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
194
                    }
195
                    case Matrix -> {
196
                        if (ncpStrict.getValue())
197
                            sendPacket(new ServerboundPlayerCommandPacket(mc.player, ServerboundPlayerCommandPacket.Action.STOP_SPRINTING));
198
199
                        mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, slot, nearestSlot, ContainerInput.SWAP, mc.player);
200
                        debug(slot + " " + nearestSlot);
201
202
                        sendPacket(new ServerboundSetCarriedItemPacket(nearestSlot));
203
                        mc.player.getInventory().setSelectedSlot(nearestSlot);
204
205
                        ItemStack itemstack = mc.player.getOffhandItem();
206
                        mc.player.setItemInHand(InteractionHand.OFF_HAND, mc.player.getMainHandItem());
207
                        mc.player.setItemInHand(InteractionHand.MAIN_HAND, itemstack);
208
                        sendPacket(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ZERO, Direction.DOWN));
209
210
                        sendPacket(new ServerboundSetCarriedItemPacket(prevCurrentItem));
211
                        mc.player.getInventory().setSelectedSlot(prevCurrentItem);
212
213
                        mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, slot, nearestSlot, ContainerInput.SWAP, mc.player);
214
215
                        sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
216
                        if (resetAttackCooldown.getValue())
217
                            mc.player.resetAttackStrengthTicker();
218
                    }
219
                    case MatrixPick -> {
220
                        debug(slot + " pick");
221
                        mc.gameMode.handleCreativeModeItemAdd(mc.player.getInventory().getItem(slot), slot);
222
                        sendPacket(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ZERO, Direction.DOWN));
223
                        int prevSlot = mc.player.getInventory().getSelectedSlot();
224
                        Managers.ASYNC.run(() -> mc.player.getInventory().setSelectedSlot(prevSlot), 300);
225
                    }
226
                    case NewVersion -> {
227
                        debug(slot + " swap");
228
                        mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, slot, 40, ContainerInput.SWAP, mc.player);
229
                        sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
230
                    }
231
                }
232
            } else {
233
                sendPacket(new ServerboundSetCarriedItemPacket(slot));
234
                mc.player.getInventory().setSelectedSlot(slot);
235
                debug(slot + " select");
236
                sendPacket(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ZERO, Direction.DOWN));
237
                sendPacket(new ServerboundSetCarriedItemPacket(prevCurrentItem));
238
                mc.player.getInventory().setSelectedSlot(prevCurrentItem);
239
                if (resetAttackCooldown.getValue())
240
                    mc.player.resetAttackStrengthTicker();
241
            }
242
            delay = (int) (2 + (Managers.SERVER.getPing() / 25f));
243
        }
244
    }
245
246
    public static int findNearestCurrentItem() {
247
        int i = mc.player.getInventory().getSelectedSlot();
248
        if (i == 8) return 7;
249
        if (i == 0) return 1;
250
        return i - 1;
251
    }
252
253
    public int getItemSlot() {
254
        if (mc.player == null || mc.level == null) return -1;
255
256
        SearchInvResult gapple = InventoryUtility.findItemInInventory(Items.ENCHANTED_GOLDEN_APPLE);
257
        SearchInvResult crapple = InventoryUtility.findItemInInventory(Items.GOLDEN_APPLE);
258
        SearchInvResult shield = InventoryUtility.findItemInInventory(Items.SHIELD);
259
        Item offHandItem = mc.player.getOffhandItem().getItem();
260
261
        int itemSlot = -1;
262
        Item item = null;
263
        switch (offhand.getValue()) {
264
            case Totem -> {
265
                if (offHandItem != Items.TOTEM_OF_UNDYING && !mc.player.getOffhandItem().isEmpty())
266
                    prevItem = offHandItem;
267
268
                if (!pomoyka.getValue())
269
                    item = prevItem;
270
271
                if (bindSwap.getValue().isEnabled())
272
                    if (isKeyPressed(swapButton) && bindDelay.every(250)) {
273
                        switch (swapMode.getValue()) {
274
                            case BallShield -> {
275
                                if (mc.player.getOffhandItem().isEmpty() || offHandItem == Items.SHIELD)
276
                                    item = Items.PLAYER_HEAD;
277
                                else item = Items.SHIELD;
278
                            }
279
                            case GappleBall -> {
280
                                if (mc.player.getOffhandItem().isEmpty() || offHandItem == Items.GOLDEN_APPLE)
281
                                    item = Items.PLAYER_HEAD;
282
                                else item = Items.GOLDEN_APPLE;
283
                            }
284
                            case GappleShield -> {
285
                                if (mc.player.getOffhandItem().isEmpty() || offHandItem == Items.SHIELD)
286
                                    item = Items.GOLDEN_APPLE;
287
                                else item = Items.SHIELD;
288
                            }
289
                            case BallTotem -> {
290
                                if (mc.player.getOffhandItem().isEmpty() || offHandItem == Items.TOTEM_OF_UNDYING)
291
                                    item = Items.PLAYER_HEAD;
292
                                else item = Items.TOTEM_OF_UNDYING;
293
                            }
294
                        }
295
296
                            prevItem = item;
297
298
                    }
299
            }
300
301
            case Crystal -> item = Items.END_CRYSTAL;
302
303
            case GApple -> {
304
                if (crappleSpoof.getValue()) {
305
                    if (mc.player.hasEffect(MobEffects.ABSORPTION) && mc.player.getEffect(MobEffects.ABSORPTION).getAmplifier() > 2) {
306
                        if (crapple.found() || offHandItem == Items.GOLDEN_APPLE)
307
                            item = Items.GOLDEN_APPLE;
308
                        else if (gapple.found() || offHandItem == Items.ENCHANTED_GOLDEN_APPLE)
309
                            item = Items.ENCHANTED_GOLDEN_APPLE;
310
                    } else {
311
                        if (gapple.found() || offHandItem == Items.ENCHANTED_GOLDEN_APPLE)
312
                            item = Items.ENCHANTED_GOLDEN_APPLE;
313
                        else if (crapple.found() || offHandItem == Items.GOLDEN_APPLE)
314
                            item = Items.GOLDEN_APPLE;
315
                    }
316
                } else {
317
                    if (crapple.found() || offHandItem == Items.GOLDEN_APPLE)
318
                        item = Items.GOLDEN_APPLE;
319
                    else if (gapple.found() || offHandItem == Items.ENCHANTED_GOLDEN_APPLE)
320
                        item = Items.ENCHANTED_GOLDEN_APPLE;
321
                }
322
            }
323
324
            case Shield -> {
325
                if (shield.found() || offHandItem == Items.SHIELD) {
326
                    if (getTriggerHealth() <= healthS.getValue()) {
327
                        if (crapple.found() || offHandItem == Items.GOLDEN_APPLE)
328
                            item = Items.GOLDEN_APPLE;
329
                        else if (gapple.found() || offHandItem == Items.ENCHANTED_GOLDEN_APPLE)
330
                            item = Items.ENCHANTED_GOLDEN_APPLE;
331
                    } else {
332
                        if (!mc.player.getCooldowns().isOnCooldown(new ItemStack(Items.SHIELD))) item = Items.SHIELD;
333
                        else {
334
                            if (crapple.found() || offHandItem == Items.GOLDEN_APPLE)
335
                                item = Items.GOLDEN_APPLE;
336
                            else if (gapple.found() || offHandItem == Items.ENCHANTED_GOLDEN_APPLE)
337
                                item = Items.ENCHANTED_GOLDEN_APPLE;
338
                        }
339
                    }
340
                } else if (crapple.found() || offHandItem == Items.GOLDEN_APPLE)
341
                    item = Items.GOLDEN_APPLE;
342
            }
343
        }
344
345
346
        if (getTriggerHealth() <= healthF.getValue() && (InventoryUtility.findItemInInventory(Items.TOTEM_OF_UNDYING).found() || offHandItem == Items.TOTEM_OF_UNDYING))
347
            item = Items.TOTEM_OF_UNDYING;
348
349
        if (!rcGap.is(RCGap.Off) && mc.player.getMainHandItem().is(ItemTags.SWORDS) && mc.options.keyUse.isDown() && !(offHandItem instanceof ShieldItem)) {
350
            if (rcGap.is(RCGap.Always) || (rcGap.is(RCGap.OnlySafe) && getTriggerHealth() > healthF.getValue())) {
351
                if (crapple.found() || offHandItem == Items.GOLDEN_APPLE)
352
                    item = Items.GOLDEN_APPLE;
353
                if (gapple.found() || offHandItem == Items.ENCHANTED_GOLDEN_APPLE)
354
                    item = Items.ENCHANTED_GOLDEN_APPLE;
355
            }
356
        }
357
358
        if (onFall.getValue() && (getTriggerHealth()) - (((mc.player.fallDistance - 3) / 2F) + 3.5F) < 0.5)
359
            item = Items.TOTEM_OF_UNDYING;
360
361
        if (onElytra.getValue() && mc.player.isFallFlying())
362
            item = Items.TOTEM_OF_UNDYING;
363
364
        if (onCrystalInHand.getValue()) {
365
            for (Player pl : Managers.ASYNC.getAsyncPlayers()) {
366
                if (Managers.FRIEND.isFriend(pl)) continue;
367
                if (pl == mc.player) continue;
368
                if (getPlayerPos().distanceToSqr(pl.position()) < 36) {
369
                    if (pl.getMainHandItem().getItem() == Items.OBSIDIAN
370
                            || pl.getMainHandItem().getItem() == Items.END_CRYSTAL
371
                            || pl.getOffhandItem().getItem() == Items.OBSIDIAN
372
                            || pl.getOffhandItem().getItem() == Items.END_CRYSTAL)
373
                        item = Items.TOTEM_OF_UNDYING;
374
                }
375
            }
376
        }
377
378
        for (Entity entity : mc.level.entitiesForRendering()) {
379
            if (entity == null || !entity.isAlive()) continue;
380
            if (getPlayerPos().distanceToSqr(entity.position()) > 36) continue;
381
382
            if (onCrystal.getValue()) {
383
                if (entity instanceof EndCrystal) {
384
                    if (getTriggerHealth() - ExplosionUtility.getExplosionDamageWPredict(entity.position(), mc.player, PredictUtility.createBox(getPlayerPos(), mc.player), false) < 0.5) {
385
                        item = Items.TOTEM_OF_UNDYING;
386
                        break;
387
                    }
388
                }
389
            }
390
391
            if (onTnt.getValue()) {
392
                if (entity instanceof PrimedTnt) {
393
                    item = Items.TOTEM_OF_UNDYING;
394
                    break;
395
                }
396
            }
397
398
            if (onMinecartTnt.getValue()) {
399
                if (entity instanceof MinecartTNT) {
400
                    item = Items.TOTEM_OF_UNDYING;
401
                    break;
402
                }
403
            }
404
405
            if (onCreeper.getValue()) {
406
                if (entity instanceof Creeper) {
407
                    item = Items.TOTEM_OF_UNDYING;
408
                    break;
409
                }
410
            }
411
        }
412
413
        if (onAnchor.getValue()) {
414
            for (int x = -6; x <= 6; x++)
415
                for (int y = -6; y <= 6; y++)
416
                    for (int z = -6; z <= 6; z++) {
417
                        BlockPos bp = new BlockPos(x, y, z);
418
                        if (mc.level.getBlockState(bp).getBlock() == Blocks.RESPAWN_ANCHOR) {
419
                            item = Items.TOTEM_OF_UNDYING;
420
                            break;
421
                        }
422
                    }
423
        }
424
425
        for (int i = 9; i < 45; i++) {
426
            if (item != null && mc.player.getOffhandItem().getItem() == item) return -1;
427
            if (mc.player.getInventory().getItem(i >= 36 ? i - 36 : i).getItem().equals(item)) {
428
                itemSlot = i >= 36 ? i - 36 : i;
429
                break;
430
            }
431
        }
432
433
        if (item == mc.player.getMainHandItem().getItem() && mc.options.keyUse.isDown()) return -1;
434
435
436
        return itemSlot;
437
    }
438
439
    private Vec3 getPlayerPos() {
440
        return ModuleManager.blink.isEnabled() ? Blink.lastPos : mc.player.position();
441
    }
442
}
443
OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/AutoTotem.javaJava · 147 lines · 5.4 KB

Keeps a totem of undying in your offhand.

SettingsHealthDelayExplosionsBlast rangeMeleeFallElytraTotem counter
AutoTotem.javaJava · Minecraft 26.2 · 147 lines · 5.4 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.combat;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.TickEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.setting.BoolSetting;
8
import com.jellypudding.offlineclient.setting.NumberSetting;
9
import com.jellypudding.offlineclient.util.DamageUtil;
10
import com.jellypudding.offlineclient.util.EntityUtil;
11
import com.jellypudding.offlineclient.util.InventoryUtil;
12
import com.jellypudding.offlineclient.util.InventoryUtil.Swap;
13
import net.minecraft.world.item.Items;
14
15
public final class AutoTotem extends Module {
16
17
    // Gliding into a wall kills outright. A totem is always worth holding.
18
    private static final double ELYTRA_TRIGGER_SPEED = 0.5;
19
20
    // Health points in one heart.
21
    private static final float HEART = 2;
22
23
    private final NumberSetting health = new NumberSetting("Health",
24
        "Puts a totem in your offhand once you drop to this many hearts. Zero keeps one there at all times.",
25
        0, 0, 10, 0.5, " hearts");
26
    private final NumberSetting delay = new NumberSetting("Delay",
27
        "Ticks to wait before equipping the next totem.", 0, 0, 20, 1, " ticks");
28
    private final BoolSetting explosions = new BoolSetting("Explosions",
29
        "Equip early when a nearby crystal or bed or anchor could drop you to the health line.", true);
30
    private final NumberSetting blastRange = new NumberSetting("Blast range",
31
        "How far away a charge is counted as a threat.", 8, 2, 16, 0.5, " blocks")
32
        .under(explosions);
33
    private final BoolSetting melee = new BoolSetting("Melee",
34
        "Equip early when an enemy within five blocks holds a weapon that could do it.", true);
35
    private final BoolSetting fall = new BoolSetting("Fall",
36
        "Equip early when the fall you are in would do it.", true);
37
    private final BoolSetting elytra = new BoolSetting("Elytra",
38
        "Always hold a totem whilst gliding at speed.", true);
39
40
    private final InventoryUtil.StrandedStack cursor = new InventoryUtil.StrandedStack();
41
    private int totems;
42
    private int timer;
43
    private boolean hadTotem;
44
    private boolean locked;
45
46
    private final BoolSetting counter = new BoolSetting("Totem counter",
47
        "Show how many totems you have left next to the name.", true);
48
49
    public AutoTotem() {
50
        super("AutoTotem", "Keeps a totem of undying in your offhand.", Category.COMBAT);
51
        addSettings(health, delay, explosions, blastRange, melee, fall, elytra, counter);
52
        searchTags("totem", "pop");
53
    }
54
55
    @Override
56
    public String getSuffix() {
57
        return counter.isOn() ? totems + " left" : null;
58
    }
59
60
    // True whilst the offhand is claimed for a totem. Offhand steps aside for it.
61
    public boolean isLocked() {
62
        return isEnabled() && locked;
63
    }
64
65
    @Override
66
    protected void onEnable() {
67
        timer = 0;
68
        hadTotem = false;
69
        locked = false;
70
    }
71
72
    @Override
73
    protected void onDisable() {
74
        if (inGame()) {
75
            cursor.giveBack();
76
        }
77
    }
78
79
    @Subscribe
80
    private void onTick(TickEvent event) {
81
        if (!inGame() || mc.player.isSpectator()) {
82
            return;
83
        }
84
        if (!cursor.recover()) {
85
            return;
86
        }
87
        totems = countTotems();
88
        float minHealth = health.getFloat();
89
        locked = totems > 0 && (minHealth <= 0 || threatened(minHealth));
90
91
        if (mc.player.getOffhandItem().is(Items.TOTEM_OF_UNDYING)) {
92
            hadTotem = true;
93
            return;
94
        }
95
        if (hadTotem) {
96
            timer = delay.getInt();
97
            hadTotem = false;
98
        }
99
        int totemSlot = findTotem();
100
        if (totemSlot == -1 || !locked) {
101
            return;
102
        }
103
104
        if (!InventoryUtil.canClick()) {
105
            return;
106
        }
107
        if (!InventoryUtil.carried().isEmpty()) {
108
            return;
109
        }
110
111
        if (timer > 0) {
112
            timer--;
113
            return;
114
        }
115
116
        if (InventoryUtil.swap(totemSlot, InventoryUtil.OFFHAND_SLOT) == Swap.STRANDED) {
117
            // The item the totem replaced had nowhere to go.
118
            cursor.hold(totemSlot);
119
        }
120
    }
121
122
    // True when the health line is already crossed or something already in the world
123
    // would push the player under it before the next tick could react.
124
    private boolean threatened(float minHealth) {
125
        if (elytra.isOn() && mc.player.isFallFlying()
126
            && mc.player.getDeltaMovement().length() > ELYTRA_TRIGGER_SPEED) {
127
            return true;
128
        }
129
        float incoming = DamageUtil.possibleIncoming(blastRange.getValue(),
130
            explosions.isOn(), melee.isOn(), fall.isOn());
131
        return EntityUtil.totalHealth(mc.player) - incoming <= minHealth * HEART;
132
    }
133
134
    // Every totem the player owns. The one already equipped counts.
135
    private int countTotems() {
136
        int offhand = mc.player.getOffhandItem().is(Items.TOTEM_OF_UNDYING)
137
            ? mc.player.getOffhandItem().getCount() : 0;
138
        return offhand + InventoryUtil.count(Items.TOTEM_OF_UNDYING, InventoryUtil.WHOLE_INVENTORY);
139
    }
140
141
    // Network slot of the first totem in the inventory. Minus one when there is none.
142
    private int findTotem() {
143
        int slot = InventoryUtil.findSlot(Items.TOTEM_OF_UNDYING, InventoryUtil.WHOLE_INVENTORY);
144
        return slot == -1 ? -1 : InventoryUtil.networkSlot(slot);
145
    }
146
}
147
CombatantPLAYERsrc/main/java/combatant/client/features/module/modules/player/AutoTotem.javaJava · 340 lines · 10.2 KB
Settingsautototem_thresholdautototem_elytra_healthautototem_crystal_distanceautototem_fall_checkautototem_save_taliksautototem_return_item
AutoTotem.javaJava · Minecraft 26.2 · 340 lines · 10.2 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.player;
9
10
import net.minecraft.client.Minecraft;
11
import net.minecraft.client.player.LocalPlayer;
12
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
13
import net.minecraft.world.item.Item;
14
import net.minecraft.world.item.ItemStack;
15
import net.minecraft.world.item.Items;
16
import combatant.client.config.common.CommonSettingSchemas;
17
import combatant.client.config.values.BooleanValue;
18
import combatant.client.config.values.NumberValue;
19
import combatant.client.features.gui.hud.draggable.impl.Itemizer;
20
import combatant.client.features.module.Module;
21
import combatant.client.features.module.ModuleCategory;
22
import combatant.client.features.module.ModuleInfo;
23
import combatant.client.util.player.inventory.InventorySwap;
24
25
import java.util.function.Predicate;
26
27
//todo Description
28
@ModuleInfo(
29
        id = "autototem",
30
        displayName = "AutoTotem",
31
        category = ModuleCategory.PLAYER
32
)
33
public class AutoTotem extends Module {
34
    private final Minecraft mc = Minecraft.getInstance();
35
36
    private final NumberValue<Float> healthThreshold =
37
            numCommon(
38
                    "autototem_threshold",
39
                    "health_threshold",
40
                    CommonSettingSchemas.PLAYER_HEALTH_THRESHOLD,
41
                    10.0f,
42
                    1.0f,
43
                    40.0f
44
            );
45
46
    private final NumberValue<Float> elytraHealth =
47
            numCommon(
48
                    "autototem_elytra_health",
49
                    "elytra_health",
50
                    CommonSettingSchemas.PLAYER_ELYTRA_HEALTH,
51
                    8.5f,
52
                    1.0f,
53
                    40.0f
54
            );
55
56
    private final NumberValue<Float> crystalDistance =
57
            numCommon(
58
                    "autototem_crystal_distance",
59
                    "crystal_distance",
60
                    CommonSettingSchemas.COMBAT_CRYSTAL_DISTANCE,
61
                    4.0f,
62
                    1.0f,
63
                    6.0f
64
            );
65
66
    private final BooleanValue fallCheck =
67
            boolCommon(
68
                    "autototem_fall_check",
69
                    "fall_check",
70
                    CommonSettingSchemas.PLAYER_FALL_CHECK,
71
                    true
72
            );
73
74
    private final BooleanValue saveTaliks =
75
            boolCommon(
76
                    "autototem_save_taliks",
77
                    "save_taliks",
78
                    CommonSettingSchemas.ITEMS_SAVE_UNENCHANTED,
79
                    true
80
            );
81
82
    private final BooleanValue returnItem =
83
            boolCommon(
84
                    "autototem_return_item",
85
                    "return_item",
86
                    CommonSettingSchemas.INVENTORY_RESTORE_ITEM,
87
                    true
88
            );
89
90
    private ItemStack previousOffhand = ItemStack.EMPTY;
91
    private int previousOffhandSlot = -1;
92
    private boolean usingTotem = false;
93
    private boolean offhandSwapPending = false;
94
95
    @Override
96
    public void onTick() {
97
        if (!isEnabled()) return;
98
99
        if (mc.player == null || mc.level == null || mc.isPaused()) {
100
            offhandSwapPending = false;
101
            return;
102
        }
103
104
        if (offhandSwapPending) {
105
            return;
106
        }
107
108
        LocalPlayer player = mc.player;
109
110
        float health = player.getHealth() + player.getAbsorptionAmount();
111
112
        boolean shouldHoldTotem = shouldHoldTotem(player, health);
113
        if (shouldHoldTotem) {
114
            equipTotem(player);
115
            return;
116
        }
117
118
        if (usingTotem && returnItem.get()) {
119
            restorePrevious(player);
120
        }
121
    }
122
123
    @Override
124
    public void onDisable() {
125
        offhandSwapPending = false;
126
        clearRestoreState();
127
    }
128
129
    private boolean shouldHoldTotem(LocalPlayer player, float health) {
130
        if (player.isFallFlying() && health <= elytraHealth.get()) {
131
            return true;
132
        }
133
134
        if (health <= healthThreshold.get()) {
135
            return true;
136
        }
137
138
        if (fallCheck.get() && player.fallDistance > 10.0f) {
139
            return true;
140
        }
141
142
        return getClosestCrystalDistance(player) <= crystalDistance.get();
143
    }
144
145
    public boolean shouldHoldTotemNow(LocalPlayer player) {
146
        if (!isEnabled() || player == null) return false;
147
        return shouldHoldTotem(player, player.getHealth() + player.getAbsorptionAmount());
148
    }
149
150
    public boolean canProvideTotemNow(LocalPlayer player) {
151
        if (!isEnabled()) return false;
152
        if (player == null || mc.gameMode == null) return false;
153
        if (isTotemInOffhand(player)) return true;
154
        if (offhandSwapPending) return false;
155
        return findTotemSlot(player) != -1;
156
    }
157
158
    public boolean ensureTotemForDanger(LocalPlayer player) {
159
        if (!canProvideTotemNow(player)) return false;
160
        if (isTotemInOffhand(player)) return true;
161
162
        int slot = findTotemSlot(player);
163
        if (slot == -1) return false;
164
165
        rememberPreviousOffhand(player, slot);
166
        return swapTotemToOffhand(player, slot);
167
    }
168
169
170
    public boolean isTotemSwapPending() {
171
        return offhandSwapPending;
172
    }
173
174
    private void equipTotem(LocalPlayer player) {
175
        if (player == null || mc.gameMode == null) return;
176
        if (isTotemInOffhand(player)) return;
177
        int slot = findTotemSlot(player);
178
        if (slot == -1) return;
179
180
        rememberPreviousOffhand(player, slot);
181
        swapTotemToOffhand(player, slot);
182
    }
183
184
    private boolean swapTotemToOffhand(LocalPlayer player, int slot) {
185
        if (player == null || mc.gameMode == null || offhandSwapPending) return false;
186
187
        offhandSwapPending = true;
188
        ItemStack displayStack = player.getInventory().getItem(slot).copy();
189
        boolean accepted = InventorySwap.INSTANCE.swapInventoryToOffhand(slot, () -> {
190
            usingTotem = true;
191
            offhandSwapPending = false;
192
            Itemizer.showAutoTotem(displayStack);
193
        });
194
        if (!accepted) {
195
            offhandSwapPending = false;
196
        }
197
        return accepted;
198
    }
199
200
    private void restorePrevious(LocalPlayer player) {
201
        if (player == null || mc.gameMode == null) return;
202
203
        if (previousOffhand.isEmpty()) {
204
            clearRestoreState();
205
            return;
206
        }
207
208
        if (!player.getOffhandItem().is(Items.TOTEM_OF_UNDYING)) {
209
            clearRestoreState();
210
            return;
211
        }
212
213
        int restoreSlot = resolveRestoreSlot(player);
214
        if (restoreSlot == -1) {
215
            clearRestoreState();
216
            return;
217
        }
218
219
        requestOffhandSwap(restoreSlot, this::clearRestoreState);
220
    }
221
222
    private void rememberPreviousOffhand(LocalPlayer player, int totemSlot) {
223
        if (player == null) return;
224
        if (usingTotem) return;
225
226
        ItemStack offhand = player.getOffhandItem();
227
        if (offhand.isEmpty()) {
228
            previousOffhand = ItemStack.EMPTY;
229
            previousOffhandSlot = -1;
230
            return;
231
        }
232
233
        previousOffhand = offhand.copy();
234
        previousOffhandSlot = totemSlot;
235
    }
236
237
    private boolean requestOffhandSwap(int slot, Runnable afterSwap) {
238
        if (offhandSwapPending) return false;
239
240
        offhandSwapPending = true;
241
        boolean accepted = InventorySwap.INSTANCE.swapInventoryToOffhand(slot, () -> {
242
            if (afterSwap != null) {
243
                afterSwap.run();
244
            }
245
            offhandSwapPending = false;
246
        });
247
        if (!accepted) {
248
            offhandSwapPending = false;
249
        }
250
        return accepted;
251
    }
252
253
    private int findTotemSlot(LocalPlayer player) {
254
        if (saveTaliks.get()) {
255
            int nonEnchanted = find(player, stack ->
256
                    stack.is(Items.TOTEM_OF_UNDYING) && !stack.isEnchanted()
257
            );
258
259
            if (nonEnchanted != -1) {
260
                return nonEnchanted;
261
            }
262
        }
263
264
        return find(player, Items.TOTEM_OF_UNDYING);
265
    }
266
267
    private int find(LocalPlayer player, Item item) {
268
        return find(player, stack -> stack.is(item));
269
    }
270
271
    private int find(LocalPlayer player, Predicate<ItemStack> predicate) {
272
        if (player == null || predicate == null) return -1;
273
274
        for (int i = 0; i < 36; i++) {
275
            ItemStack stack = player.getInventory().getItem(i);
276
            if (!stack.isEmpty() && predicate.test(stack)) {
277
                return i;
278
            }
279
        }
280
281
        return -1;
282
    }
283
284
    private int findItem(LocalPlayer player, ItemStack target) {
285
        if (player == null || target == null || target.isEmpty()) return -1;
286
287
        for (int i = 0; i < 36; i++) {
288
            ItemStack stack = player.getInventory().getItem(i);
289
            if (!stack.isEmpty() && ItemStack.isSameItemSameComponents(stack, target)) {
290
                return i;
291
            }
292
        }
293
294
        return -1;
295
    }
296
297
    private int resolveRestoreSlot(LocalPlayer player) {
298
        if (previousOffhandSlot >= 0 && previousOffhandSlot < 36) {
299
            ItemStack stack = player.getInventory().getItem(previousOffhandSlot);
300
            if (!stack.isEmpty() && ItemStack.isSameItemSameComponents(stack, previousOffhand)) {
301
                return previousOffhandSlot;
302
            }
303
        }
304
305
        return findItem(player, previousOffhand);
306
    }
307
308
    private double getClosestCrystalDistance(LocalPlayer player) {
309
        if (player == null || mc.level == null) {
310
            return Double.MAX_VALUE;
311
        }
312
313
        double minDist = Double.MAX_VALUE;
314
        double range = crystalDistance.get();
315
316
        for (EndCrystal crystal : mc.level.getEntitiesOfClass(
317
                EndCrystal.class,
318
                player.getBoundingBox().inflate(range),
319
                crystal -> crystal != null && !crystal.isRemoved()
320
        )) {
321
            double dist = player.position().distanceTo(crystal.position());
322
            if (dist < minDist) {
323
                minDist = dist;
324
            }
325
        }
326
327
        return minDist;
328
    }
329
330
    private boolean isTotemInOffhand(LocalPlayer player) {
331
        return player != null && player.getOffhandItem().is(Items.TOTEM_OF_UNDYING);
332
    }
333
334
    private void clearRestoreState() {
335
        previousOffhand = ItemStack.EMPTY;
336
        previousOffhandSlot = -1;
337
        usingTotem = false;
338
    }
339
}
340
NicotineCombatsrc/client/java/nicotine/mod/mods/combat/AutoTotem.javaJava · 36 lines · 943 B
AutoTotem.javaJava · Minecraft 26.3 · 36 lines · 943 B · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.combat;
2
3
import net.minecraft.world.item.Items;
4
import nicotine.events.ClientLevelTickEvent;
5
import nicotine.mod.Mod;
6
import nicotine.mod.ModCategory;
7
import nicotine.util.EventBus;
8
import nicotine.util.Inventory;
9
10
11
import static nicotine.util.Common.mc;
12
13
public class AutoTotem extends Mod {
14
15
    public AutoTotem() {
16
        super(ModCategory.Combat,"AutoTotem");
17
    }
18
19
    @Override
20
    protected void init() {
21
        EventBus.register(ClientLevelTickEvent.class, event -> {
22
            if (!this.enabled || !mc.player.getOffhandItem().isEmpty() || Inventory.isContainerOpen())
23
                return true;
24
25
            for (int i = 0; i <= 35; i++) {
26
                if (mc.player.getInventory().getItem(i).getItem() == Items.TOTEM_OF_UNDYING) {
27
                    Inventory.move(i < 9 ? 36 + i : i, 45);
28
                    break;
29
                }
30
            }
31
32
            return true;
33
        });
34
    }
35
}
36