AutoAnvil module

AutoAnvil: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), OfflineClient).

2 implementationsCOMBAT

Full module source: 2 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/AutoAnvil.javaJava · 117 lines · 5.6 KB

Places anvils above the enemy's head (also requires pressure plates).

SettingsRangeOncePlacePlatesPlace ModeInteract ModeRotateTargetBySandGravelСoncreteAnvils
AutoAnvil.javaJava · Minecraft 26.2 · 117 lines · 5.6 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.world.entity.player.Player;
6
import net.minecraft.world.item.BlockItem;
7
import net.minecraft.world.item.Items;
8
import net.minecraft.world.level.block.Block;
9
import net.minecraft.world.level.block.Blocks;
10
import net.minecraft.world.level.block.ConcretePowderBlock;
11
import net.minecraft.world.level.block.PressurePlateBlock;
12
import thunder.hack.core.Managers;
13
import thunder.hack.core.manager.player.CombatManager;
14
import thunder.hack.events.impl.EventTick;
15
import thunder.hack.features.modules.Module;
16
import thunder.hack.setting.Setting;
17
import thunder.hack.utility.player.InteractionUtility;
18
import thunder.hack.utility.player.InventoryUtility;
19
import thunder.hack.utility.player.SearchInvResult;
20
import thunder.hack.utility.world.HoleUtility;
21
22
import java.util.ArrayList;
23
import java.util.Arrays;
24
import java.util.List;
25
26
import static thunder.hack.features.modules.client.ClientSettings.isRu;
27
28
public class AutoAnvil extends Module {
29
    private final Setting<Float> range = new Setting<>("Range", 5f, 1f, 7f);
30
    private final Setting<Boolean> once = new Setting<>("Once", false);
31
    private final Setting<Boolean> placePlates = new Setting<>("PlacePlates", false);
32
    private final Setting<InteractionUtility.PlaceMode> placeMode = new Setting<>("Place Mode", InteractionUtility.PlaceMode.Normal);
33
    private final Setting<InteractionUtility.Interact> interact = new Setting<>("Interact Mode", InteractionUtility.Interact.Vanilla);
34
    private final Setting<InteractionUtility.Rotate> rotate = new Setting<>("Rotate", InteractionUtility.Rotate.None);
35
    private final Setting<CombatManager.TargetBy> targetBy = new Setting<>("TargetBy", CombatManager.TargetBy.Distance);
36
    private final Setting<Boolean> sand = new Setting<>("Sand", false);
37
    private final Setting<Boolean> gravel = new Setting<>("Gravel", false);
38
    private final Setting<Boolean> concrete = new Setting<>("Сoncrete", false);
39
    private final Setting<Boolean> anvils = new Setting<>("Anvils", true);
40
41
    private Player target;
42
43
    public AutoAnvil() {
44
        super("AutoAnvil", Category.COMBAT);
45
    }
46
47
    @EventHandler
48
    private void onTick(EventTick event) {
49
        if (mc.player == null) return;
50
        if (target == null || target.isDeadOrDying()) {
51
            target = Managers.COMBAT.getTarget(range.getValue(), targetBy.getValue());
52
            return;
53
        }
54
55
        final SearchInvResult result = getBlockResult();
56
        final SearchInvResult plateResult = InventoryUtility.findItemInHotBar(Items.STONE_PRESSURE_PLATE, Items.BIRCH_PRESSURE_PLATE, Items.HEAVY_WEIGHTED_PRESSURE_PLATE, Items.LIGHT_WEIGHTED_PRESSURE_PLATE, Items.OAK_PRESSURE_PLATE);
57
58
        final BlockPos anvilPos = BlockPos.containing(target.position()).above(2);
59
60
        if (!result.found() || (!plateResult.found() && placePlates.getValue()))
61
            return;
62
63
        Block targetBlock = mc.level.getBlockState(BlockPos.containing(target.position())).getBlock();
64
65
        if (!(targetBlock instanceof PressurePlateBlock) && targetBlock != Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE && targetBlock != Blocks.LIGHT_WEIGHTED_PRESSURE_PLATE && placePlates.getValue()) {
66
            InteractionUtility.placeBlock(BlockPos.containing(target.position()), rotate.getValue(), interact.getValue(), placeMode.getValue(), plateResult, true, true);
67
            return;
68
        }
69
70
        if (!InteractionUtility.canPlaceBlock(anvilPos, interact.getValue(), false)) {
71
            if (needObsidian(anvilPos)) {
72
                final BlockPos obsidianPos = Arrays.stream(HoleUtility.VECTOR_PATTERN).parallel()
73
                        .map(anvilPos::offset)
74
                        .filter(pos -> InteractionUtility.canPlaceBlock(pos, interact.getValue(), false))
75
                        .filter(pos -> pos.distToCenterSqr(mc.player.position()) <= range.getPow2Value())
76
                        .findFirst()
77
                        .orElse(null);
78
                final SearchInvResult obbyResult = InventoryUtility.findBlockInHotBar(Blocks.OBSIDIAN);
79
80
                if (obsidianPos != null && obbyResult.found()) {
81
                    InteractionUtility.placeBlock(obsidianPos, rotate.getValue(), interact.getValue(), placeMode.getValue(), obbyResult, true, false);
82
                    if(once.getValue())
83
                        disable(isRu() ? "Блок размещен" : "Done");
84
                }
85
            }
86
            return;
87
        }
88
89
        InteractionUtility.placeBlock(anvilPos, rotate.getValue(), interact.getValue(), placeMode.getValue(), result, true, false);
90
    }
91
92
    private boolean needObsidian(BlockPos anvilPos) {
93
        if (mc.level == null) return false;
94
95
        return Arrays.stream(HoleUtility.VECTOR_PATTERN)
96
                .map(anvilPos::offset)
97
                .filter(pos -> !mc.level.getBlockState(pos).canBeReplaced())
98
                .toList()
99
                .isEmpty();
100
    }
101
102
    protected SearchInvResult getBlockResult() {
103
        final List<Block> canUseBlocks = new ArrayList<>();
104
105
        if (mc.player == null) return SearchInvResult.notFound();
106
        if (anvils.getValue()) canUseBlocks.add(Blocks.ANVIL);
107
        if (sand.getValue()) canUseBlocks.add(Blocks.SAND);
108
        if (gravel.getValue()) canUseBlocks.add(Blocks.GRAVEL);
109
110
111
        SearchInvResult defaultResult = InventoryUtility.findBlockInHotBar(canUseBlocks);
112
        SearchInvResult concreteResult = InventoryUtility.findInHotBar(i -> (i.getItem() instanceof BlockItem bi && bi.getBlock() instanceof ConcretePowderBlock));
113
114
        return concrete.getValue() && concreteResult.found() ? concreteResult : defaultResult;
115
    }
116
}
117
OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/AutoAnvil.javaJava · 197 lines · 7.6 KB

Drops anvils on an enemy to break their helmet.

SettingsTarget rangePlace rangeHeightDelayMulti placePlace triggerRotateToggle off when doneClose menuShow spot
AutoAnvil.javaJava · Minecraft 26.2 · 197 lines · 7.6 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.PacketReceiveEvent;
5
import com.jellypudding.offlineclient.event.events.Render3DEvent;
6
import com.jellypudding.offlineclient.event.events.TickEvent;
7
import com.jellypudding.offlineclient.module.Category;
8
import com.jellypudding.offlineclient.module.Module;
9
import com.jellypudding.offlineclient.setting.BoolSetting;
10
import com.jellypudding.offlineclient.setting.EnumSetting;
11
import com.jellypudding.offlineclient.setting.NumberSetting;
12
import com.jellypudding.offlineclient.util.BlockUtil;
13
import com.jellypudding.offlineclient.util.EntityUtil;
14
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
15
import com.jellypudding.offlineclient.util.TargetPriority;
16
import net.minecraft.core.BlockPos;
17
import net.minecraft.core.Direction;
18
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
19
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
20
import net.minecraft.world.entity.EquipmentSlot;
21
import net.minecraft.world.entity.player.Player;
22
import net.minecraft.world.inventory.MenuType;
23
import net.minecraft.world.level.block.AnvilBlock;
24
import net.minecraft.world.level.block.BasePressurePlateBlock;
25
import net.minecraft.world.level.block.Blocks;
26
import net.minecraft.world.level.block.ButtonBlock;
27
import net.minecraft.world.phys.shapes.CollisionContext;
28
29
// Places anvils in the air above an enemy.
30
// A landing anvil damages the helmet of whoever is under it.
31
public final class AutoAnvil extends Module {
32
33
    private final NumberSetting targetRange = new NumberSetting("Target range",
34
        "How far away enemies are considered.", 4, 1, 10, 0.5, " blocks");
35
    private final EnumSetting<TargetPriority> priority = TargetPriority.setting("Targets",
36
        TargetPriority.LOW_HEALTH);
37
    private final NumberSetting placeRange = new NumberSetting("Place range",
38
        "How far you can reach to place.", 4.5, 1, 6, 0.1);
39
    private final NumberSetting height = new NumberSetting("Height",
40
        "How far above their feet the anvil goes.", 3, 2, 6, 1, " blocks");
41
    private final NumberSetting delay = new NumberSetting("Delay",
42
        "Ticks to wait between anvils.", 10, 0, 40, 1, " ticks");
43
    private final BoolSetting multiPlace = new BoolSetting("Multi place",
44
        "Fill every free spot from the height down to two above their head in one go.", true);
45
    private final BoolSetting trigger = new BoolSetting("Place trigger",
46
        "Put a button or a plate at their feet to break every anvil on landing.", true);
47
    private final BoolSetting rotate = new BoolSetting("Rotate",
48
        "Send a look packet towards each block.", true);
49
    private final BoolSetting toggleOff = new BoolSetting("Toggle off when done",
50
        "Turn off once the target has no helmet left.", false);
51
    private final BoolSetting closeMenu = new BoolSetting("Close menu",
52
        "Keep the repair screen shut when a click lands on a placed anvil.", true);
53
    private final BoolSetting render = new BoolSetting("Show spot",
54
        "Outline where the next anvil goes.", true);
55
56
    private final SlotSwap slots = new SlotSwap();
57
    private String targetName;
58
    private BlockPos spot;
59
    private int timer;
60
61
    public AutoAnvil() {
62
        super("AutoAnvil", "Drops anvils on an enemy to break their helmet.", Category.COMBAT);
63
        addSettings(targetRange, priority, placeRange, height, delay, multiPlace, trigger, rotate,
64
            toggleOff, closeMenu, render);
65
        searchTags("anvil", "helmet", "armour break");
66
    }
67
68
    @Override
69
    public String getSuffix() {
70
        return targetName;
71
    }
72
73
    @Override
74
    protected void onEnable() {
75
        timer = 0;
76
        slots.forget();
77
        targetName = null;
78
        spot = null;
79
    }
80
81
    @Override
82
    protected void onDisable() {
83
        slots.restore();
84
        targetName = null;
85
        spot = null;
86
    }
87
88
    @Subscribe
89
    private void onTick(TickEvent event) {
90
        spot = null;
91
        if (!inGame() || mc.player.isSpectator()) {
92
            targetName = null;
93
            return;
94
        }
95
        Player target = EntityUtil.bestEnemy(targetRange.getValue(), priority.getValue());
96
        targetName = EntityUtil.nameOf(target);
97
        if (target == null) {
98
            slots.restore();
99
            return;
100
        }
101
        if (toggleOff.isOn() && target.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) {
102
            slots.restore();
103
            setEnabled(false);
104
            return;
105
        }
106
107
        BlockPos feet = target.blockPosition();
108
        BlockPos above = feet.above(height.getInt());
109
        if (!clearPath(feet, above)) {
110
            slots.restore();
111
            return;
112
        }
113
        spot = above;
114
        if (timer > 0) {
115
            timer--;
116
            return;
117
        }
118
119
        // Only the first placement of the tick turns.
120
        boolean rotated = placeTrigger(feet);
121
122
        int anvilSlot = BlockUtil.findBlockSlot(block -> block instanceof AnvilBlock);
123
        if (anvilSlot == -1) {
124
            slots.restore();
125
            return;
126
        }
127
        slots.select(anvilSlot);
128
        boolean placed = false;
129
        // The lowest spot still leaves the anvil a block to fall through.
130
        for (int y = height.getInt(); y >= 2; y--) {
131
            BlockPos pos = feet.above(y);
132
            if (BlockUtil.distanceTo(pos) > placeRange.getValue() || !BlockUtil.isReplaceable(pos)) {
133
                continue;
134
            }
135
            boolean turn = rotate.isOn() && !rotated;
136
            if (BlockUtil.placeAny(pos, turn, true)) {
137
                placed = true;
138
                rotated |= turn;
139
                if (!multiPlace.isOn()) {
140
                    break;
141
                }
142
            }
143
        }
144
        if (placed) {
145
            timer = delay.getInt();
146
        }
147
        slots.restore();
148
    }
149
150
    // The server opens the repair menu for a click that lands on an anvil already down.
151
    // The menu is closed on the server too. The next click is then not swallowed.
152
    @Subscribe
153
    private void onPacketReceive(PacketReceiveEvent event) {
154
        if (closeMenu.isOn() && event.getPacket() instanceof ClientboundOpenScreenPacket packet
155
            && packet.getType() == MenuType.ANVIL && mc.player != null) {
156
            event.cancel();
157
            mc.player.connection.send(new ServerboundContainerClosePacket(packet.getContainerId()));
158
        }
159
    }
160
161
    private boolean placeTrigger(BlockPos feet) {
162
        if (!trigger.isOn() || !BlockUtil.isReplaceable(feet)
163
            || BlockUtil.distanceTo(feet) > placeRange.getValue()) {
164
            return false;
165
        }
166
        Direction support = BlockUtil.findPlaceSupport(feet);
167
        if (support == null) {
168
            return false;
169
        }
170
        int slot = BlockUtil.findBlockSlot(block ->
171
            block instanceof ButtonBlock || block instanceof BasePressurePlateBlock);
172
        if (slot == -1) {
173
            return false;
174
        }
175
        slots.select(slot);
176
        BlockUtil.place(feet, support, rotate.isOn(), true);
177
        return rotate.isOn();
178
    }
179
180
    // The anvil needs the whole column free to reach their head.
181
    private boolean clearPath(BlockPos feet, BlockPos above) {
182
        for (int y = feet.getY() + 1; y <= above.getY(); y++) {
183
            if (!BlockUtil.isReplaceable(new BlockPos(feet.getX(), y, feet.getZ()))) {
184
                return false;
185
            }
186
        }
187
        return mc.level.isUnobstructed(Blocks.ANVIL.defaultBlockState(), above, CollisionContext.empty());
188
    }
189
190
    @Subscribe
191
    private void onRender3D(Render3DEvent event) {
192
        if (render.isOn() && spot != null) {
193
            event.getBatch().outlineBlock(spot, 0xFFB0B0C0, false);
194
        }
195
    }
196
}
197