AutoCity module

AutoCity: 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/AutoCity.javaJava · 268 lines · 9.9 KB

Mines the block guarding an enemy in a hole.

SettingsTarget rangeBreak rangePlace rangeModeSwitch toolSupportChat infoRotateToggle off when doneShow target
AutoCity.javaJava · Minecraft 26.2 · 268 lines · 9.9 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.ExclusivityGroup;
8
import com.jellypudding.offlineclient.module.Module;
9
import com.jellypudding.offlineclient.render.BoxStyle;
10
import com.jellypudding.offlineclient.setting.BoolSetting;
11
import com.jellypudding.offlineclient.setting.EnumSetting;
12
import com.jellypudding.offlineclient.setting.NumberSetting;
13
import com.jellypudding.offlineclient.util.BlockMiner;
14
import com.jellypudding.offlineclient.util.BlockUtil;
15
import com.jellypudding.offlineclient.util.ChatUtil;
16
import com.jellypudding.offlineclient.util.EntityUtil;
17
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
18
import com.jellypudding.offlineclient.util.ItemUtil;
19
import com.jellypudding.offlineclient.util.SwingMode;
20
import com.jellypudding.offlineclient.util.TargetPriority;
21
import net.minecraft.core.BlockPos;
22
import net.minecraft.core.Direction;
23
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
24
import net.minecraft.world.entity.player.Player;
25
import net.minecraft.world.item.ItemStack;
26
import net.minecraft.world.level.block.state.BlockState;
27
28
// Strips the blast proof cover from an enemy standing in a hole.
29
public final class AutoCity extends Module {
30
31
    public enum Mode { HOLD, PACKET, SILENT }
32
33
    private final NumberSetting targetRange = new NumberSetting("Target range",
34
        "How far away enemies are considered.", 6, 1, 10, 0.5, " blocks");
35
    private final EnumSetting<TargetPriority> priority = TargetPriority.setting("Cities",
36
        TargetPriority.NEAREST);
37
    private final NumberSetting breakRange = new NumberSetting("Break range",
38
        "How far you can reach to mine.", 4.5, 1, 6, 0.1, " blocks");
39
    private final NumberSetting placeRange = new NumberSetting("Place range",
40
        "How far you can reach to place the support block.", 4.5, 1, 6, 0.1, " blocks");
41
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
42
        "How the block is mined.", Mode.HOLD)
43
        .describe(Mode.HOLD, "Mine it like a held left click with the tool in hand throughout.")
44
        .describe(Mode.PACKET, "Send the start and stop at once and keep the tool out whilst the server counts.")
45
        .describe(Mode.SILENT, "Send the start and stop at once and put the tool away until the last packet.");
46
    private final BoolSetting switchTool = new BoolSetting("Switch tool",
47
        "Swap to your fastest hotbar tool first.", true);
48
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
49
    private final BoolSetting support = new BoolSetting("Support",
50
        "Fill the empty block under the city block to give a crystal a base.", true);
51
    private final BoolSetting chatInfo = new BoolSetting("Chat info",
52
        "Say why the module stopped.", true);
53
    private final BoolSetting rotate = new BoolSetting("Rotate",
54
        "Turn towards the block on the server side.", true);
55
    private final BoolSetting toggleOff = new BoolSetting("Toggle off when done",
56
        "Turn off once the block is gone.", true);
57
    private final BoolSetting render = new BoolSetting("Show target",
58
        "Outline the block being mined.", true);
59
    private final BoxStyle style = new BoxStyle(BoxStyle.Shape.BOTH, 0f).under(render);
60
61
    private final SlotSwap slots = new SlotSwap();
62
    private BlockPos current;
63
    private String targetName;
64
    // How far along the server should be with the packet pair it was sent.
65
    private float progress;
66
    private boolean sent;
67
68
    public AutoCity() {
69
        super("AutoCity", "Mines the block guarding an enemy in a hole.", Category.COMBAT);
70
        addSettings(targetRange, priority, breakRange, placeRange, mode, switchTool, swing, support,
71
            chatInfo, rotate, toggleOff, render);
72
        addSettings(style.settings());
73
        searchTags("city", "surround", "obsidian");
74
    }
75
76
    @Override
77
    public String getSuffix() {
78
        return targetName;
79
    }
80
81
    @Override
82
    public ExclusivityGroup getExclusivityGroup() {
83
        return ExclusivityGroup.MINING;
84
    }
85
86
    @Override
87
    protected void onEnable() {
88
        current = null;
89
        slots.forget();
90
        targetName = null;
91
        progress = 0;
92
        sent = false;
93
    }
94
95
    @Override
96
    protected void onDisable() {
97
        stopMining();
98
        targetName = null;
99
    }
100
101
    @Subscribe
102
    private void onTick(TickEvent event) {
103
        if (!inGame() || mc.player.isSpectator()) {
104
            return;
105
        }
106
107
        Player target = EntityUtil.bestEnemy(targetRange.getValue(), priority.getValue());
108
        targetName = EntityUtil.nameOf(target);
109
        if (target == null) {
110
            stopMining();
111
            return;
112
        }
113
114
        if (current != null && BlockUtil.state(current).isAir()) {
115
            forgetBlock();
116
            if (toggleOff.isOn()) {
117
                if (chatInfo.isOn()) {
118
                    ChatUtil.message("§bAutoCity §7took the block down.");
119
                }
120
                setEnabled(false);
121
                return;
122
            }
123
        }
124
        if (current != null && BlockUtil.distanceTo(current) > breakRange.getValue()) {
125
            stopMining();
126
        }
127
        if (current == null) {
128
            current = cityBlock(target);
129
        }
130
        if (current == null) {
131
            return;
132
        }
133
        // A crystal needs a base under the gap the city leaves behind.
134
        if (support.isOn() && placeSupport()) {
135
            return;
136
        }
137
        if (mode.is(Mode.HOLD)) {
138
            holdMine();
139
        } else {
140
            packetMine();
141
        }
142
    }
143
144
    private void holdMine() {
145
        if (switchTool.isOn()) {
146
            ItemUtil.selectBestTool(BlockUtil.state(current), slots);
147
        }
148
        if (!BlockMiner.mine(current, rotate.isOn())) {
149
            stopMining();
150
        }
151
    }
152
153
    // The pair goes out once with the tool in hand. The server counts from there.
154
    // The final stop only has to arrive once the client reckons the count is done.
155
    private void packetMine() {
156
        BlockState state = BlockUtil.state(current);
157
        int tool = switchTool.isOn() ? ItemUtil.bestToolSlot(state) : -1;
158
        ItemStack toolStack = tool == -1
159
            ? mc.player.getMainHandItem() : mc.player.getInventory().getItem(tool);
160
        if (!sent) {
161
            withTool(tool, () -> {
162
                BlockMiner.breakInstantly(current);
163
                swing.getValue().swing();
164
            });
165
            sent = true;
166
            progress = 0;
167
            return;
168
        }
169
        progress += BlockUtil.breakDelta(toolStack, current);
170
        if (progress < 1) {
171
            return;
172
        }
173
        withTool(tool, () -> {
174
            Direction side = BlockUtil.facingSide(current);
175
            mc.player.connection.send(new ServerboundPlayerActionPacket(
176
                ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, current, side));
177
            swing.getValue().swing();
178
        });
179
        // A miss keeps the count going and tries again next tick.
180
        progress = 0.5f;
181
    }
182
183
    // Runs the action with the tool in hand. Silent mode hands the slot back after.
184
    private void withTool(int tool, Runnable action) {
185
        if (rotate.isOn()) {
186
            BlockUtil.faceVector(BlockUtil.hitPoint(current, BlockUtil.facingSide(current)));
187
        }
188
        if (tool != -1) {
189
            slots.select(tool);
190
        }
191
        action.run();
192
        if (mode.is(Mode.SILENT)) {
193
            slots.restore();
194
        }
195
    }
196
197
    // Fills the hole under the block about to fall.
198
    // True when a block went down this tick and mining should wait.
199
    private boolean placeSupport() {
200
        BlockPos below = current.below();
201
        if (!BlockUtil.isReplaceable(below) || BlockUtil.intersectsPlayer(below)) {
202
            return false;
203
        }
204
        if (BlockUtil.distanceTo(below) > placeRange.getValue()) {
205
            return false;
206
        }
207
        int slot = BlockUtil.findBlockSlot();
208
        if (slot == -1) {
209
            return false;
210
        }
211
        slots.select(slot);
212
        boolean placed = BlockUtil.placeAny(below, rotate.isOn(), true);
213
        slots.restore();
214
        return placed;
215
    }
216
217
    private BlockPos cityBlock(Player target) {
218
        return cityBlock(target, breakRange.getValue());
219
    }
220
221
    // The blast proof block beside the target's feet that is closest to the player.
222
    public static BlockPos cityBlock(Player target, double reach) {
223
        BlockPos feet = target.blockPosition();
224
        BlockPos best = null;
225
        double bestDistance = reach;
226
        for (Direction side : Direction.Plane.HORIZONTAL) {
227
            BlockPos pos = feet.relative(side);
228
            BlockState state = BlockUtil.state(pos);
229
            if (state.isAir() || !BlockUtil.isBreakable(pos)
230
                || state.getBlock().getExplosionResistance() < BlockUtil.BLAST_PROOF) {
231
                continue;
232
            }
233
            double distance = BlockUtil.distanceTo(pos);
234
            if (distance <= bestDistance) {
235
                bestDistance = distance;
236
                best = pos;
237
            }
238
        }
239
        return best;
240
    }
241
242
    private void forgetBlock() {
243
        slots.restore();
244
        current = null;
245
        progress = 0;
246
        sent = false;
247
    }
248
249
    private void stopMining() {
250
        if (current != null && mode.is(Mode.HOLD)) {
251
            BlockMiner.release();
252
        }
253
        if (current != null && sent) {
254
            mc.player.connection.send(new ServerboundPlayerActionPacket(
255
                ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, current, Direction.DOWN));
256
        }
257
        forgetBlock();
258
    }
259
260
    @Subscribe
261
    private void onRender3D(Render3DEvent event) {
262
        if (!render.isOn() || current == null || BlockUtil.state(current).isAir()) {
263
            return;
264
        }
265
        style.draw(event.getBatch(), current, false);
266
    }
267
}
268