AutoWeb module

AutoWeb: 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/AutoWeb.javaJava · 212 lines · 10.1 KB

Puts cobweb at the target's feet

SettingsRangeWallRangePlaceTimingBlock/TickDelay/PlaceInteractPlaceModeRotateSelectionHeadLeggsSurroundUpperSurroundRenderRender ModeRender Fill ColorRender Line ColorRender Line WidthEffect Duration (MS)
AutoWeb.javaJava · Minecraft 26.2 · 212 lines · 10.1 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.core.Direction;
6
import net.minecraft.world.entity.player.Player;
7
import net.minecraft.world.item.BlockItem;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.level.ClipContext;
10
import net.minecraft.world.level.block.Block;
11
import net.minecraft.world.level.block.Blocks;
12
import net.minecraft.world.phys.AABB;
13
import net.minecraft.world.phys.BlockHitResult;
14
import net.minecraft.world.phys.HitResult;
15
import thunder.hack.core.Managers;
16
import thunder.hack.events.impl.EventTick;
17
import thunder.hack.features.modules.Module;
18
import thunder.hack.features.modules.client.HudEditor;
19
import thunder.hack.setting.Setting;
20
import thunder.hack.setting.impl.ColorSetting;
21
import thunder.hack.setting.impl.SettingGroup;
22
import thunder.hack.utility.Timer;
23
import thunder.hack.utility.player.InteractionUtility;
24
import thunder.hack.utility.player.InventoryUtility;
25
import thunder.hack.utility.render.Render2DEngine;
26
import thunder.hack.utility.render.Render3DEngine;
27
28
import java.util.ArrayList;
29
import java.util.List;
30
import java.util.Map;
31
import java.util.concurrent.ConcurrentHashMap;
32
33
import static thunder.hack.utility.player.InteractionUtility.squaredDistanceFromEyes;
34
35
import com.mojang.blaze3d.vertex.PoseStack;
36
37
public final class AutoWeb extends Module {
38
    private final Setting<Integer> range = new Setting<>("Range", 5, 1, 7);
39
    private final Setting<Integer> placeWallRange = new Setting<>("WallRange", 5, 1, 7);
40
    private final Setting<PlaceTiming> placeTiming = new Setting<>("PlaceTiming", PlaceTiming.Default);
41
    private final Setting<Integer> blocksPerTick = new Setting<>("Block/Tick", 8, 1, 12, v -> placeTiming.getValue() == PlaceTiming.Default);
42
    private final Setting<Integer> placeDelay = new Setting<>("Delay/Place", 3, 0, 10);
43
    private final Setting<InteractionUtility.Interact> interact = new Setting<>("Interact", InteractionUtility.Interact.Strict);
44
    private final Setting<InteractionUtility.PlaceMode> placeMode = new Setting<>("PlaceMode", InteractionUtility.PlaceMode.Normal);
45
    private final Setting<InteractionUtility.Rotate> rotate = new Setting<>("Rotate", InteractionUtility.Rotate.None);
46
    private final Setting<SettingGroup> selection = new Setting<>("Selection", new SettingGroup(false, 0));
47
    private final Setting<Boolean> head = new Setting<>("Head", true).addToGroup(selection);
48
    private final Setting<Boolean> leggs = new Setting<>("Leggs", true).addToGroup(selection);
49
    private final Setting<Boolean> surround = new Setting<>("Surround", true).addToGroup(selection);
50
    private final Setting<Boolean> upperSurround = new Setting<>("UpperSurround", false).addToGroup(selection);
51
    private final Setting<SettingGroup> renderCategory = new Setting<>("Render", new SettingGroup(false, 0));
52
    private final Setting<RenderMode> renderMode = new Setting<>("Render Mode", RenderMode.Fade).addToGroup(renderCategory);
53
    private final Setting<ColorSetting> renderFillColor = new Setting<>("Render Fill Color", new ColorSetting(HudEditor.getColor(0))).addToGroup(renderCategory);
54
    private final Setting<ColorSetting> renderLineColor = new Setting<>("Render Line Color", new ColorSetting(HudEditor.getColor(0))).addToGroup(renderCategory);
55
    private final Setting<Integer> renderLineWidth = new Setting<>("Render Line Width", 2, 1, 5).addToGroup(renderCategory);
56
    private final Setting<Integer> effectDurationMs = new Setting<>("Effect Duration (MS)", 500, 0, 10000).addToGroup(renderCategory);
57
58
    private final ArrayList<BlockPos> sequentialBlocks = new ArrayList<>();
59
    public static Timer inactivityTimer = new Timer();
60
61
    private final Map<BlockPos, Long> renderPoses = new ConcurrentHashMap<>();
62
63
    private int delay = 0;
64
65
    public AutoWeb() {
66
        super("AutoWeb", Category.COMBAT);
67
    }
68
69
    public void onRender3D(PoseStack stack) {
70
        renderPoses.forEach((pos, time) -> {
71
            if (System.currentTimeMillis() - time > effectDurationMs.getValue()) {
72
                renderPoses.remove(pos);
73
            } else {
74
                switch (renderMode.getValue()) {
75
                    case Fade -> {
76
                        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(new AABB(pos), Render2DEngine.injectAlpha(renderFillColor.getValue().getColorObject(), (int) (100f * (1f - ((System.currentTimeMillis() - time) / 500f))))));
77
                        Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(new AABB(pos), Render2DEngine.injectAlpha(renderLineColor.getValue().getColorObject(), (int) (100f * (1f - ((System.currentTimeMillis() - time) / 500f)))), renderLineWidth.getValue()));
78
                    }
79
                    case Decrease -> {
80
                        float scale = 1 - (float) (System.currentTimeMillis() - time) / 500;
81
                        AABB box = new AABB(pos.getX(), pos.getY(), pos.getZ(), pos.getX(), pos.getY(), pos.getZ());
82
                        AABB scaledBox = box.contract(scale, scale, scale).move(0.5 + scale * 0.5, 0.5 + scale * 0.5, 0.5 + scale * 0.5);
83
84
                        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(scaledBox, Render2DEngine.injectAlpha(renderFillColor.getValue().getColorObject(), (int) (100f * (1f - ((System.currentTimeMillis() - time) / 500f))))));
85
                        Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(scaledBox, renderLineColor.getValue().getColorObject(), renderLineWidth.getValue()));
86
                    }
87
                }
88
            }
89
        });
90
    }
91
92
93
    @Override
94
    public void onEnable() {
95
        sequentialBlocks.clear();
96
        renderPoses.clear();
97
    }
98
99
    @EventHandler
100
    public void onTick(EventTick e) {
101
        BlockPos targetBlock1 = getSequentialPos();
102
        if (targetBlock1 == null) return;
103
104
        if (delay > 0) {
105
            delay--;
106
            return;
107
        }
108
109
        InventoryUtility.saveSlot();
110
        if (placeTiming.getValue() == PlaceTiming.Default) {
111
            int placed = 0;
112
            while (placed < blocksPerTick.getValue()) {
113
                BlockPos targetBlock = getSequentialPos();
114
                if (targetBlock == null)
115
                    break;
116
117
                if (InteractionUtility.placeBlock(targetBlock, rotate.getValue(), interact.getValue(), placeMode.getValue(), getSlot(), false, true)) {
118
                    placed++;
119
                    renderPoses.put(targetBlock, System.currentTimeMillis());
120
                    delay = placeDelay.getValue();
121
                    inactivityTimer.reset();
122
                } else break;
123
            }
124
        } else if (placeTiming.getValue() == PlaceTiming.Vanilla) {
125
            BlockPos targetBlock = getSequentialPos();
126
            if (targetBlock == null) return;
127
128
            if (InteractionUtility.placeBlock(targetBlock, rotate.getValue(), interact.getValue(), placeMode.getValue(), getSlot(), false, true)) {
129
                sequentialBlocks.add(targetBlock);
130
                renderPoses.put(targetBlock, System.currentTimeMillis());
131
                delay = placeDelay.getValue();
132
                inactivityTimer.reset();
133
            }
134
        }
135
        InventoryUtility.returnSlot();
136
    }
137
138
    private BlockPos getSequentialPos() {
139
        Player target = Managers.COMBAT.getNearestTarget(range.getValue());
140
        if (target != null) {
141
142
            BlockPos targetBp = BlockPos.containing(target.position());
143
144
            ArrayList<BlockPos> positions = new ArrayList<>();
145
            if (leggs.getValue())
146
                positions.add(targetBp);
147
148
            if (head.getValue())
149
                positions.add(targetBp.above());
150
151
            if (surround.getValue()) {
152
                positions.add(targetBp.east());
153
                positions.add(targetBp.west());
154
                positions.add(targetBp.south());
155
                positions.add(targetBp.north());
156
            }
157
158
            if (upperSurround.getValue()) {
159
                positions.add(targetBp.east().above());
160
                positions.add(targetBp.west().above());
161
                positions.add(targetBp.south().above());
162
                positions.add(targetBp.north().above());
163
            }
164
165
            for (BlockPos bp : positions) {
166
                BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), net.minecraft.world.phys.Vec3.atBottomCenterOf(bp).relative(Direction.UP, 0.5f), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
167
                if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != bp)
168
                    if (squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(bp)) > placeWallRange.getPow2Value()) continue;
169
                if (InteractionUtility.canPlaceBlock(bp, interact.getValue(), true) && mc.level.getBlockState(bp).canBeReplaced()) {
170
                    return bp;
171
                }
172
            }
173
        }
174
175
        return null;
176
    }
177
178
179
    private int getSlot() {
180
        List<Block> canUseBlocks = new ArrayList<>();
181
        canUseBlocks.add(Blocks.COBWEB);
182
        int slot = -1;
183
        final ItemStack mainhandStack = mc.player.getMainHandItem();
184
        if (mainhandStack != ItemStack.EMPTY && mainhandStack.getItem() instanceof BlockItem) {
185
            final Block blockFromMainhandItem = ((BlockItem) mainhandStack.getItem()).getBlock();
186
            if (canUseBlocks.contains(blockFromMainhandItem)) {
187
                slot = mc.player.getInventory().getSelectedSlot();
188
            }
189
        }
190
        if (slot == -1) {
191
            for (int i = 0; i < 9; i++) {
192
                final ItemStack stack = mc.player.getInventory().getItem(i);
193
                if (stack != ItemStack.EMPTY && stack.getItem() instanceof BlockItem) {
194
                    final Block blockFromItem = ((BlockItem) stack.getItem()).getBlock();
195
                    if (canUseBlocks.contains(blockFromItem)) {
196
                        slot = i;
197
                        break;
198
                    }
199
                }
200
            }
201
        }
202
        return slot;
203
    }
204
205
    private enum PlaceTiming {
206
        Default, Vanilla
207
    }
208
209
    private enum RenderMode {
210
        Fade, Decrease
211
    }
212
}
OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/AutoWeb.javaJava · 204 lines · 7.6 KB

Throws cobwebs at an enemy to lock them in place.

SettingsTarget rangeRangeWalls rangeWebs per tickDelayPredictLeadCoverUpper bodyRotateShow webs
AutoWeb.javaJava · Minecraft 26.2 · 204 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.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.render.BoxStyle;
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.ColorUtil;
14
import com.jellypudding.offlineclient.util.EntityUtil;
15
import com.jellypudding.offlineclient.util.InventoryUtil;
16
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
17
import com.jellypudding.offlineclient.util.TargetPriority;
18
import net.minecraft.core.BlockPos;
19
import net.minecraft.world.entity.player.Player;
20
import net.minecraft.world.item.Items;
21
import net.minecraft.world.level.block.Blocks;
22
import net.minecraft.world.phys.Vec3;
23
24
import java.util.ArrayList;
25
import java.util.LinkedHashSet;
26
import java.util.List;
27
import java.util.Set;
28
29
// A runner moves about a third of a block a tick. Webs are laid along
30
// their predicted path from ahead back to their feet and then around them.
31
public final class AutoWeb extends Module {
32
33
    // How much of the colour a spot already webbed keeps.
34
    private static final float DONE_FADE = 0.4f;
35
36
    private final NumberSetting targetRange = new NumberSetting("Target range",
37
        "How far away enemies are considered.", 8, 1, 16, 0.5, " blocks");
38
    private final EnumSetting<TargetPriority> priority = TargetPriority.setting("Webs",
39
        TargetPriority.NEAREST);
40
    private final NumberSetting range = new NumberSetting("Range",
41
        "How far you can reach to place.", 4.5, 1, 6, 0.1, " blocks");
42
    private final NumberSetting wallsRange = new NumberSetting("Walls range",
43
        "Shorter reach for a spot you cannot see.", 4, 0, 6, 0.1, " blocks");
44
    private final NumberSetting perTick = new NumberSetting("Webs per tick",
45
        "How many webs go down in one tick.", 2, 1, 4, 1);
46
    private final NumberSetting delay = new NumberSetting("Delay",
47
        "Ticks to wait between rounds.", 1, 0, 20, 1, " ticks");
48
    private final BoolSetting predict = new BoolSetting("Predict",
49
        "Lays the webs along the way a moving target is heading.", true);
50
    private final NumberSetting lead = new NumberSetting("Lead",
51
        "How many ticks ahead of a runner the furthest web goes.", 6, 1, 15, 1, " ticks")
52
        .under(predict);
53
    private final NumberSetting cover = new NumberSetting("Cover",
54
        "Blocks to web on every side of the target as well. Zero webs only their feet.",
55
        0, 0, 2, 1, " blocks");
56
    private final BoolSetting doubles = new BoolSetting("Upper body",
57
        "Also web the block their head is in.", false);
58
    private final BoolSetting rotate = new BoolSetting("Rotate",
59
        "Send a look packet towards each web.", true);
60
    private final BoolSetting render = new BoolSetting("Show webs",
61
        "Outline the spots being webbed. Done ones fade.", true);
62
    private final BoxStyle style = new BoxStyle(BoxStyle.Shape.BOTH, 270f).under(render);
63
64
    // Spots still to web then spots already webbed. The outline lasts the whole tick.
65
    private final List<BlockPos> pending = new ArrayList<>();
66
    private final List<BlockPos> done = new ArrayList<>();
67
    private final SlotSwap slots = new SlotSwap();
68
    private int timer;
69
    private String targetName;
70
71
    public AutoWeb() {
72
        super("AutoWeb", "Throws cobwebs at an enemy to lock them in place.", Category.COMBAT);
73
        addSettings(targetRange, priority, range, wallsRange, perTick, delay, predict, lead, cover,
74
            doubles, rotate, render);
75
        addSettings(style.settings());
76
        searchTags("cobweb", "web", "trap");
77
    }
78
79
    @Override
80
    public String getSuffix() {
81
        return targetName;
82
    }
83
84
    @Override
85
    protected void onEnable() {
86
        timer = 0;
87
        targetName = null;
88
        pending.clear();
89
        done.clear();
90
    }
91
92
    @Override
93
    protected void onDisable() {
94
        targetName = null;
95
        pending.clear();
96
        done.clear();
97
    }
98
99
    @Subscribe
100
    private void onTick(TickEvent event) {
101
        pending.clear();
102
        done.clear();
103
        if (!inGame() || mc.player.isSpectator()) {
104
            targetName = null;
105
            return;
106
        }
107
        if (timer > 0) {
108
            timer--;
109
        }
110
        Player target = EntityUtil.bestEnemy(targetRange.getValue(), priority.getValue());
111
        targetName = EntityUtil.nameOf(target);
112
        if (target == null) {
113
            return;
114
        }
115
116
        for (BlockPos spot : spotsFor(target)) {
117
            if (BlockUtil.state(spot).getBlock() == Blocks.COBWEB) {
118
                done.add(spot);
119
            } else if (webbable(spot) && inReach(spot)) {
120
                pending.add(spot);
121
            }
122
        }
123
        if (timer > 0 || pending.isEmpty()) {
124
            return;
125
        }
126
127
        int placed = 0;
128
        for (BlockPos spot : pending) {
129
            if (placed >= perTick.getInt()) {
130
                break;
131
            }
132
            if (placeWeb(spot, rotate.isOn(), slots)) {
133
                placed++;
134
            }
135
        }
136
        if (placed > 0) {
137
            timer = delay.getInt();
138
        }
139
    }
140
141
    // Furthest ahead first. A web behind a runner is wasted.
142
    private Set<BlockPos> spotsFor(Player target) {
143
        Set<BlockPos> spots = new LinkedHashSet<>();
144
        Vec3 feet = target.position();
145
        Vec3 pace = predict.isOn() ? EntityUtil.velocityOf(target) : Vec3.ZERO;
146
        // Vertical movement is a jump. The web wants the block they land in.
147
        pace = new Vec3(pace.x, 0, pace.z);
148
        int ahead = pace.horizontalDistanceSqr() > 0.0004 ? lead.getInt() : 0;
149
        for (int tick = ahead; tick >= 0; tick--) {
150
            addColumn(spots, BlockPos.containing(feet.add(pace.scale(tick))));
151
        }
152
        int ring = cover.getInt();
153
        BlockPos centre = BlockPos.containing(feet);
154
        for (int dx = -ring; dx <= ring; dx++) {
155
            for (int dz = -ring; dz <= ring; dz++) {
156
                addColumn(spots, centre.offset(dx, 0, dz));
157
            }
158
        }
159
        return spots;
160
    }
161
162
    private void addColumn(Set<BlockPos> spots, BlockPos feet) {
163
        spots.add(feet.immutable());
164
        if (doubles.isOn()) {
165
            spots.add(feet.above());
166
        }
167
    }
168
169
    private boolean inReach(BlockPos pos) {
170
        double reach = BlockUtil.canSee(Vec3.atCenterOf(pos)) ? range.getValue() : wallsRange.getValue();
171
        return BlockUtil.distanceTo(pos) <= reach;
172
    }
173
174
    static boolean webbable(BlockPos pos) {
175
        return BlockUtil.isReplaceable(pos) && BlockUtil.state(pos).getBlock() != Blocks.COBWEB;
176
    }
177
178
    static boolean placeWeb(BlockPos pos, boolean rotate, SlotSwap slots) {
179
        if (!webbable(pos)) {
180
            return false;
181
        }
182
        int slot = InventoryUtil.hotbarSlot(stack -> stack.is(Items.COBWEB));
183
        if (slot == -1) {
184
            return false;
185
        }
186
        slots.select(slot);
187
        boolean placed = BlockUtil.placeAny(pos, rotate, true);
188
        slots.restore();
189
        return placed;
190
    }
191
192
    @Subscribe
193
    private void onRender3D(Render3DEvent event) {
194
        if (!render.isOn()) {
195
            return;
196
        }
197
        style.drawAll(event.getBatch(), pending, false);
198
        int faded = ColorUtil.fade(style.lineColor(), DONE_FADE);
199
        for (BlockPos spot : done) {
200
            style.draw(event.getBatch(), spot, faded, false);
201
        }
202
    }
203
}
204