PistonPush module

PistonPush: Minecraft 26.3 cheat module, full source for every implementation (1 client: MelaHack (ThunderHack fork)).

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.

MelaHack (ThunderHack fork)COMBATsrc/main/java/thunder/hack/features/modules/combat/PistonPush.javaJava · 299 lines · 11.4 KB

Pushes players from safe holes using pistons.

SettingsTarget RangeBlocks/TickDelay/PlacePlace ModeInteractRotateCharge TypePiston TypeAuto SwapSwingRenderFill ColorLine ColorLine Width
PistonPush.javaJava · Minecraft 26.2 · 299 lines · 11.4 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.network.protocol.game.ServerboundMovePlayerPacket;
6
import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket;
7
import net.minecraft.world.InteractionHand;
8
import net.minecraft.world.entity.player.Player;
9
import net.minecraft.world.level.block.Blocks;
10
import net.minecraft.world.phys.AABB;
11
import thunder.hack.core.Managers;
12
import thunder.hack.events.impl.EventPostSync;
13
import thunder.hack.events.impl.EventSync;
14
import thunder.hack.injection.accesors.IClientPlayerEntity;
15
import thunder.hack.injection.accesors.IEntity;
16
import thunder.hack.features.modules.Module;
17
import thunder.hack.setting.Setting;
18
import thunder.hack.setting.impl.ColorSetting;
19
import thunder.hack.setting.impl.SettingGroup;
20
import thunder.hack.utility.player.InteractionUtility;
21
import thunder.hack.utility.player.InventoryUtility;
22
import thunder.hack.utility.player.SearchInvResult;
23
import thunder.hack.utility.render.Render2DEngine;
24
import thunder.hack.utility.render.Render3DEngine;
25
import thunder.hack.utility.world.HoleUtility;
26
import com.mojang.blaze3d.vertex.PoseStack;
27
import java.awt.*;
28
import java.util.concurrent.ConcurrentHashMap;
29
30
public final class PistonPush extends Module {
31
    private final Setting<Float> range = new Setting<>("Target Range", 5.f, 1.5f, 7.f);
32
    private final Setting<Integer> blocksPerTick = new Setting<>("Blocks/Tick", 2, 1, 2);
33
    private final Setting<Integer> delayPerPlace = new Setting<>("Delay/Place", 0, 0, 5);
34
    private final Setting<InteractionUtility.PlaceMode> placeMode = new Setting<>("Place Mode", InteractionUtility.PlaceMode.Normal);
35
    private final Setting<InteractionUtility.Interact> interact = new Setting<>("Interact", InteractionUtility.Interact.Strict);
36
37
    private final Setting<Boolean> rotate = new Setting<>("Rotate", false);
38
    private final Setting<ChargeType> chargeType = new Setting<>("Charge Type", ChargeType.All);
39
    private final Setting<PistonType> pistonType = new Setting<>("Piston Type", PistonType.All);
40
    private final Setting<Boolean> autoSwap = new Setting<>("Auto Swap", true);
41
    private final Setting<Boolean> swing = new Setting<>("Swing", true);
42
43
    private final Setting<SettingGroup> render = new Setting<>("Render", new SettingGroup(false, 0));
44
    private final Setting<ColorSetting> fillColor = new Setting<>("Fill Color", new ColorSetting(new Color(255, 0, 0, 50))).addToGroup(render);
45
    private final Setting<ColorSetting> lineColor = new Setting<>("Line Color", new ColorSetting(new Color(255, 0, 0, 200))).addToGroup(render);
46
    private final Setting<Integer> lineWidth = new Setting<>("Line Width", 2, 1, 5).addToGroup(render);
47
48
    private Player target;
49
    private BlockPos pistonPos;
50
    private BlockPos chargePos;
51
    private boolean firstPlace;
52
    private int delay;
53
54
    private final ConcurrentHashMap<BlockPos, Long> renderPoses = new ConcurrentHashMap<>();
55
56
    public PistonPush() {
57
        super("PistonPush", Category.COMBAT);
58
    }
59
60
    @Override
61
    public void onEnable() {
62
        target = null;
63
        pistonPos = null;
64
        chargePos = null;
65
        placeRunnable = null;
66
        delay = 0;
67
        firstPlace = true;
68
    }
69
70
    private Runnable placeRunnable = null;
71
72
    @EventHandler
73
    public void onSync(EventSync event) {
74
        if (!isPlayerTargetCorrect(target)) {
75
            findTarget();
76
            return;
77
        }
78
79
        if (pistonPos == null || chargePos == null) {
80
            findPlacePoses();
81
            return;
82
        }
83
84
        if (delay < delayPerPlace.getValue()) {
85
            delay++;
86
            return;
87
        }
88
89
        handlePistonPush(false);
90
    }
91
92
    @EventHandler
93
    public void onPostSync(EventPostSync event) {
94
        int blocksPlaced = 0;
95
        while (blocksPlaced < blocksPerTick.getValue()) {
96
            handlePistonPush(true);
97
            if (placeRunnable != null) {
98
                placeRunnable.run();
99
                placeRunnable = null;
100
            } else {
101
                return;
102
            }
103
            blocksPlaced++;
104
        }
105
        delay = 0;
106
    }
107
108
    public void handlePistonPush(boolean onSync) {
109
        if (firstPlace) placePiston(onSync);
110
        else placeCharge(onSync);
111
    }
112
113
    public void onRender3D(PoseStack stack) {
114
        renderPoses.forEach((pos, time) -> {
115
            if (System.currentTimeMillis() - time > 500) {
116
                renderPoses.remove(pos);
117
            } else {
118
                Render3DEngine.FILLED_QUEUE.add(
119
                        new Render3DEngine.FillAction(new AABB(pos), Render2DEngine.injectAlpha(fillColor.getValue().getColorObject(), (int) (fillColor.getValue().getAlpha() * (1f - ((System.currentTimeMillis() - time) / 500f)))))
120
                );
121
                Render3DEngine.OUTLINE_QUEUE.add(
122
                        new Render3DEngine.OutlineAction(new AABB(pos), lineColor.getValue().getColorObject(), lineWidth.getValue())
123
                );
124
            }
125
        });
126
    }
127
128
    private void placeCharge(boolean onSync) {
129
        if (!getChargeSlot().found() || (!autoSwap.getValue() && !getChargeSlot().isHolding()))
130
            return;
131
132
        if (chargePos == null)
133
            return;
134
135
136
        if (rotate.getValue()) {
137
            final float[] angle = InteractionUtility.getPlaceAngle(chargePos, interact.getValue(), false);
138
            if (angle == null) {
139
                return;
140
            }
141
            if (onSync) {
142
                sendPacket(new ServerboundMovePlayerPacket.Rot(angle[0], angle[1], mc.player.onGround(), mc.player.horizontalCollision));
143
            } else {
144
                mc.player.setYRot(angle[0]);
145
                mc.player.setXRot(angle[1]);
146
            }
147
        }
148
149
        placeRunnable = () -> {
150
            int prevSlot = mc.player.getInventory().getSelectedSlot();
151
            InteractionUtility.placeBlock(chargePos, InteractionUtility.Rotate.None, interact.getValue(), placeMode.getValue(), getChargeSlot(), true, false);
152
            sendPacket(new ServerboundSetCarriedItemPacket(prevSlot));
153
            mc.player.getInventory().setSelectedSlot(prevSlot);
154
            firstPlace = true;
155
            if (swing.getValue())
156
                mc.player.swing(InteractionHand.MAIN_HAND);
157
            renderPoses.put(chargePos, System.currentTimeMillis());
158
        };
159
    }
160
161
    private void placePiston(boolean extra) {
162
        if (pistonPos == null)
163
            return;
164
165
        if (!getPistonSlot().found() || (!autoSwap.getValue() && !getPistonSlot().isHolding()))
166
            return;
167
168
        if (rotate.getValue()) {
169
            final float[] angle = InteractionUtility.getPlaceAngle(pistonPos, interact.getValue(), false);
170
            if (angle == null)
171
                return;
172
173
            if (extra) sendPacket(new ServerboundMovePlayerPacket.Rot(angle[0], angle[1], mc.player.onGround(), mc.player.horizontalCollision));
174
            else {
175
                mc.player.setYRot(angle[0]);
176
                mc.player.setXRot(angle[1]);
177
            }
178
        }
179
180
        placeRunnable = () -> {
181
            final float angle = InteractionUtility.calculateAngle(target.getEyePosition(), net.minecraft.world.phys.Vec3.atBottomCenterOf(pistonPos))[0];
182
            sendPacket(new ServerboundMovePlayerPacket.Rot(angle, 0, mc.player.onGround(), mc.player.horizontalCollision));
183
            float prevYaw = mc.player.getYRot();
184
            mc.player.setYRot(angle);
185
            ((thunder.hack.injection.accesors.IEntity) mc.player).setLastYaw(angle);
186
            ((IEntity) mc.player).setLastYaw(angle);
187
            int prevSlot = mc.player.getInventory().getSelectedSlot();
188
            InteractionUtility.placeBlock(pistonPos, InteractionUtility.Rotate.None, interact.getValue(), placeMode.getValue(), getPistonSlot(), true, false);
189
            sendPacket(new ServerboundSetCarriedItemPacket(prevSlot));
190
            mc.player.getInventory().setSelectedSlot(prevSlot);
191
            mc.player.setYRot(prevYaw);
192
            firstPlace = false;
193
            if (swing.getValue())
194
                mc.player.swing(InteractionHand.MAIN_HAND);
195
            renderPoses.put(pistonPos, System.currentTimeMillis());
196
        };
197
    }
198
199
    private SearchInvResult getPistonSlot() {
200
        final SearchInvResult stickyPistonSlot = InventoryUtility.findBlockInHotBar(Blocks.STICKY_PISTON);
201
        final SearchInvResult pistonSlot = InventoryUtility.findBlockInHotBar(Blocks.PISTON);
202
        SearchInvResult finalResult = null;
203
204
        switch (pistonType.getValue()) {
205
            case Normal -> finalResult = pistonSlot;
206
            case Sticky -> finalResult = stickyPistonSlot;
207
            case All -> finalResult = pistonSlot.found() ? pistonSlot : stickyPistonSlot;
208
        }
209
210
        return finalResult;
211
    }
212
213
    private SearchInvResult getChargeSlot() {
214
        final SearchInvResult redstoneTorchSlot = InventoryUtility.findBlockInHotBar(Blocks.REDSTONE_TORCH);
215
        final SearchInvResult redstoneBlockSlot = InventoryUtility.findBlockInHotBar(Blocks.REDSTONE_BLOCK);
216
        SearchInvResult finalResult = null;
217
218
        switch (chargeType.getValue()) {
219
            case Block -> finalResult = redstoneBlockSlot;
220
            case Torch -> finalResult = redstoneTorchSlot;
221
            case All -> finalResult = redstoneTorchSlot.found() ? redstoneTorchSlot : redstoneBlockSlot;
222
        }
223
224
        return finalResult;
225
    }
226
227
    private void findPlacePoses() {
228
        BlockPos targetBP = BlockPos.containing(target.position());
229
230
        BlockPos[] surroundPoses = {
231
                targetBP.offset(1, 1, 0),
232
                targetBP.offset(-1, 1, 0),
233
                targetBP.offset(0, 1, 1),
234
                targetBP.offset(0, 1, -1)
235
        };
236
237
        for (BlockPos pos : surroundPoses) {
238
            if (!InteractionUtility.canPlaceBlock(pos, interact.getValue(), false)) continue;
239
240
            BlockPos[] chargePoses = {
241
                    pos.offset(0, 1, 0),
242
                    pos.offset(0, -1, 0),
243
                    pos.offset(1, 0, 0),
244
                    pos.offset(-1, 0, 0),
245
                    pos.offset(0, 0, 1),
246
                    pos.offset(0, 0, -1)
247
            };
248
249
            for (BlockPos chPos : chargePoses) {
250
                if (chPos == targetBP) continue;
251
                if (mc.level.getBlockState(chPos).canBeReplaced()) {
252
                    if (chargeType.getValue() == ChargeType.Torch && chPos.equals(pos.above())) {
253
                        continue;
254
                    }
255
                    if (InteractionUtility.canPlaceBlock(chPos, interact.getValue(), false)) {
256
                        chargePos = chPos;
257
                        break;
258
                    }
259
                }
260
            }
261
262
            pistonPos = pos;
263
        }
264
    }
265
266
    @SuppressWarnings("BooleanMethodIsAlwaysInverted")
267
    private boolean isPlayerTargetCorrect(Player player) {
268
        if (player == null) return false;
269
270
        return !Managers.FRIEND.isFriend(player)
271
                && player != mc.player
272
                && player.distanceTo(((mc.player))) <= range.getValue()
273
                && !player.isDeadOrDying()
274
                && player.getHealth() + player.getAbsorptionAmount() > 0
275
                && HoleUtility.isHole(player.blockPosition());
276
    }
277
278
    private void findTarget() {
279
        for (Player player : Managers.ASYNC.getAsyncPlayers()) {
280
            if (!isPlayerTargetCorrect(player)) continue;
281
282
            target = player;
283
            break;
284
        }
285
    }
286
287
    private enum ChargeType {
288
        Block,
289
        Torch,
290
        All
291
    }
292
293
    private enum PistonType {
294
        Sticky,
295
        Normal,
296
        All
297
    }
298
}
299