AntiAnvil module

AntiAnvil: 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/AntiAnvil.javaJava · 137 lines · 4.8 KB

Puts a block over your head when an anvil is dropped on you.

SettingsRotateShow roof
AntiAnvil.javaJava · Minecraft 26.2 · 137 lines · 4.8 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.Render3DEvent;
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.setting.EnumSetting;
10
import com.jellypudding.offlineclient.util.BlockUtil;
11
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
12
import com.jellypudding.offlineclient.util.SwingMode;
13
import net.minecraft.core.BlockPos;
14
import net.minecraft.world.entity.Entity;
15
import net.minecraft.world.entity.item.FallingBlockEntity;
16
import net.minecraft.world.level.block.AnvilBlock;
17
import net.minecraft.world.phys.AABB;
18
19
// A dropped anvil is a falling entity until it lands.
20
// AntiAnvil places a block overhead while it is still falling.
21
public final class AntiAnvil extends Module {
22
23
    // How far above the head an anvil is worth catching. Higher ones take a while yet.
24
    private static final int WATCH_HEIGHT = 12;
25
26
    // Two blocks over the feet is the first block clear of the player's own body.
27
    private static final int ROOF_OFFSET = 2;
28
29
    // A placed anvil sits as a block for a moment before it starts to fall.
30
    // Anything lower than this would already be touching the roof.
31
    private static final int FIRST_PLACED = 3;
32
33
    private static final int ROOF_COLOR = 0xFFFF9040;
34
35
    private final BoolSetting rotate = new BoolSetting("Rotate",
36
        "Send a look packet towards the block.", true);
37
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
38
    private final BoolSetting render = new BoolSetting("Show roof",
39
        "Outline the block being placed.", true);
40
41
    private final SlotSwap slots = new SlotSwap();
42
    private BlockPos roof;
43
44
    public AntiAnvil() {
45
        super("AntiAnvil", "Puts a block over your head when an anvil is dropped on you.", Category.COMBAT);
46
        addSettings(rotate, swing, render);
47
        searchTags("anvil");
48
    }
49
50
    @Override
51
    public String getSuffix() {
52
        return roof == null ? null : "covering";
53
    }
54
55
    @Override
56
    protected void onEnable() {
57
        slots.forget();
58
        roof = null;
59
    }
60
61
    @Override
62
    protected void onDisable() {
63
        slots.restore();
64
        roof = null;
65
    }
66
67
    @Subscribe
68
    private void onTick(TickEvent event) {
69
        roof = null;
70
        if (!inGame() || mc.player.isSpectator()) {
71
            return;
72
        }
73
        BlockPos feet = mc.player.blockPosition();
74
        if (!anvilOverhead() && !anvilPlacedOverhead(feet)) {
75
            slots.restore();
76
            return;
77
        }
78
        BlockPos target = feet.above(ROOF_OFFSET);
79
        // Somebody has already placed the roof or the anvil is stuck on a block in between.
80
        if (!BlockUtil.state(target).isAir() && !BlockUtil.isReplaceable(target)) {
81
            return;
82
        }
83
        roof = target;
84
        cover(target);
85
    }
86
87
    // True whilst an anvil entity is falling through the column over the player.
88
    private boolean anvilOverhead() {
89
        AABB column = mc.player.getBoundingBox();
90
        column = new AABB(column.minX, column.maxY, column.minZ,
91
            column.maxX, column.maxY + WATCH_HEIGHT, column.maxZ);
92
        for (Entity entity : mc.level.getEntities((Entity) null, column,
93
            e -> e instanceof FallingBlockEntity falling
94
                && falling.getBlockState().getBlock() instanceof AnvilBlock)) {
95
            if (entity.getDeltaMovement().y <= 0) {
96
                return true;
97
            }
98
        }
99
        return false;
100
    }
101
102
    // True whilst an anvil block with nothing under it sits in the column within reach.
103
    private boolean anvilPlacedOverhead(BlockPos feet) {
104
        int top = FIRST_PLACED + (int) mc.player.blockInteractionRange();
105
        for (int i = FIRST_PLACED; i <= top; i++) {
106
            BlockPos pos = feet.above(i);
107
            if (BlockUtil.state(pos).getBlock() instanceof AnvilBlock
108
                && BlockUtil.state(pos.below()).isAir()) {
109
                return true;
110
            }
111
        }
112
        return false;
113
    }
114
115
    private void cover(BlockPos target) {
116
        int slot = BlockUtil.findBlastProofSlot();
117
        if (slot == -1) {
118
            slot = BlockUtil.findBlockSlot(block -> true);
119
        }
120
        if (slot == -1) {
121
            return;
122
        }
123
        slots.select(slot);
124
        if (BlockUtil.placeAny(target, rotate.isOn(), false)) {
125
            swing.getValue().swing();
126
        }
127
        slots.restore();
128
    }
129
130
    @Subscribe
131
    private void onRender3D(Render3DEvent event) {
132
        if (render.isOn() && roof != null) {
133
            event.getBatch().outlineBlock(roof, ROOF_COLOR, false);
134
        }
135
    }
136
}
137