SelfAnvil module

SelfAnvil: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

1 implementationCOMBAT

Clients with this module

Full module source: 1 implementation

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

OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/SelfAnvil.javaJava · 77 lines · 2.7 KB

Places an anvil above you to keep others out of your hole.

SettingsRotate
SelfAnvil.javaJava · Minecraft 26.2 · 77 lines · 2.7 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.TickEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.Module;
8
import com.jellypudding.offlineclient.setting.BoolSetting;
9
import com.jellypudding.offlineclient.util.BlockUtil;
10
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
11
import net.minecraft.core.BlockPos;
12
import net.minecraft.network.protocol.game.ClientboundOpenScreenPacket;
13
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
14
import net.minecraft.world.inventory.MenuType;
15
import net.minecraft.world.level.block.AnvilBlock;
16
17
// Drops an anvil onto your own head. Nobody can walk into a hole with an anvil in it.
18
public final class SelfAnvil extends Module {
19
20
    private final BoolSetting rotate = new BoolSetting("Rotate",
21
        "Send a look packet towards the spot.", true);
22
23
    private final SlotSwap slots = new SlotSwap();
24
25
    public SelfAnvil() {
26
        super("SelfAnvil", "Places an anvil above you to keep others out of your hole.",
27
            Category.COMBAT);
28
        addSettings(rotate);
29
        searchTags("anvil", "hole");
30
    }
31
32
    @Override
33
    protected void onEnable() {
34
        slots.forget();
35
    }
36
37
    @Override
38
    protected void onDisable() {
39
        slots.restore();
40
    }
41
42
    @Subscribe
43
    private void onTick(TickEvent event) {
44
        if (!inGame() || mc.player.isSpectator()) {
45
            return;
46
        }
47
        BlockPos target = mc.player.blockPosition().above(2);
48
        if (!BlockUtil.isReplaceable(target)) {
49
            slots.restore();
50
            setEnabled(false);
51
            return;
52
        }
53
        int slot = BlockUtil.findBlockSlot(block -> block instanceof AnvilBlock);
54
        if (slot == -1) {
55
            slots.restore();
56
            return;
57
        }
58
        slots.select(slot);
59
        boolean placed = BlockUtil.placeAny(target, rotate.isOn(), true);
60
        slots.restore();
61
        if (placed) {
62
            setEnabled(false);
63
        }
64
    }
65
66
    // The server opens the repair menu for a click that lands on an anvil already down.
67
    // The menu is closed on the server too. The next click is then not swallowed.
68
    @Subscribe
69
    private void onPacketReceive(PacketReceiveEvent event) {
70
        if (event.getPacket() instanceof ClientboundOpenScreenPacket packet
71
            && packet.getType() == MenuType.ANVIL && mc.player != null) {
72
            event.cancel();
73
            mc.player.connection.send(new ServerboundContainerClosePacket(packet.getContainerId()));
74
        }
75
    }
76
}
77