PistonAura module

PistonAura: 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/PistonAura.javaJava · 959 lines · 44.0 KB

Pushes end crystals into players' hitboxes with pistons.

SettingsDelay/PlaceBlock/TickPatternSupportPlaceFireBypassOldVersionTrapTarget RangePlaceRangeWallRangePlace ModeInteractRotate
PistonAura.javaJava · Minecraft 26.2 · 959 lines · 44.0 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
import meteordevelopment.orbit.EventHandler;
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
6
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
7
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
8
import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket;
9
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
10
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
11
import net.minecraft.sounds.SoundEvents;
12
import net.minecraft.sounds.SoundSource;
13
import net.minecraft.world.InteractionHand;
14
import net.minecraft.world.entity.Entity;
15
import net.minecraft.world.entity.ExperienceOrb;
16
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
17
import net.minecraft.world.entity.player.Player;
18
import net.minecraft.world.item.Items;
19
import net.minecraft.world.level.ClipContext;
20
import net.minecraft.world.level.block.*;
21
import net.minecraft.world.level.block.piston.PistonBaseBlock;
22
import net.minecraft.world.level.block.state.BlockState;
23
import net.minecraft.world.phys.AABB;
24
import net.minecraft.world.phys.BlockHitResult;
25
import net.minecraft.world.phys.HitResult;
26
import net.minecraft.world.phys.Vec3;
27
import org.jetbrains.annotations.NotNull;
28
import org.jetbrains.annotations.Nullable;
29
import thunder.hack.core.Managers;
30
import thunder.hack.events.impl.EventEntityRemoved;
31
import thunder.hack.events.impl.EventPostSync;
32
import thunder.hack.events.impl.EventSync;
33
import thunder.hack.events.impl.PacketEvent;
34
import thunder.hack.injection.accesors.IClientPlayerEntity;
35
import thunder.hack.injection.accesors.IEntity;
36
import thunder.hack.features.modules.Module;
37
import thunder.hack.setting.Setting;
38
import thunder.hack.utility.Timer;
39
import thunder.hack.utility.world.ExplosionUtility;
40
import thunder.hack.utility.math.MathUtility;
41
import thunder.hack.utility.player.InteractionUtility;
42
import thunder.hack.utility.player.InventoryUtility;
43
import thunder.hack.utility.player.PlayerUtility;
44
import thunder.hack.utility.player.SearchInvResult;
45
import thunder.hack.utility.render.Render2DEngine;
46
import thunder.hack.utility.render.Render3DEngine;
47
import java.util.List;
48
49
import java.awt.*;
50
import java.util.*;
51
52
import static thunder.hack.features.modules.client.ClientSettings.isRu;
53
54
import com.mojang.blaze3d.vertex.PoseStack;
55
56
public final class PistonAura extends Module {
57
    private final Setting<Integer> placeDelay = new Setting<>("Delay/Place", 1, 0, 25);
58
    private final Setting<Integer> blocksPerTick = new Setting<>("Block/Tick", 3, 1, 4);
59
    private final Setting<Pattern> patternsSetting = new Setting<>("Pattern", Pattern.All);
60
    private final Setting<Boolean> supportPlace = (new Setting<>("SupportPlace", false));
61
    private final Setting<Boolean> bypass = new Setting<>("FireBypass", false);
62
    private final Setting<Boolean> oldVersion = (new Setting<>("OldVersion", false));
63
    private final Setting<Boolean> trap = new Setting<>("Trap", false);
64
    private final Setting<Float> targetRange = new Setting<>("Target Range", 10.0f, 0.0f, 12.0f);
65
    private final Setting<Float> placeRange = new Setting<>("PlaceRange", 4.0f, 1.0f, 7.0f);
66
    private final Setting<Float> wallRange = new Setting<>("WallRange", 4.0f, 1.0f, 7.0f);
67
    private final Setting<InteractionUtility.PlaceMode> placeMode = new Setting<>("Place Mode", InteractionUtility.PlaceMode.Normal);
68
    private final Setting<InteractionUtility.Interact> interact = new Setting<>("Interact", InteractionUtility.Interact.Strict);
69
    private final Setting<InteractionUtility.Rotate> rotate = new Setting<>("Rotate", InteractionUtility.Rotate.None);
70
71
    public Player target;
72
    private BlockPos targetPos, pistonPos, crystalPos, redStonePos, firePos, pistonHeadPos;
73
    private boolean builtTrap, isFire;
74
75
    private final Timer trapTimer = new Timer();
76
    private final Timer attackTimer = new Timer();
77
78
    private int delay = 0;
79
    private Runnable postAction = null;
80
    private Stage stage = Stage.Searching;
81
    private EndCrystal lastCrystal;
82
    private Vec3 rotations;
83
84
    public PistonAura() {
85
        super("PistonAura", Category.COMBAT);
86
    }
87
88
    public void reset() {
89
        builtTrap = false;
90
        target = null;
91
        stage = Stage.Searching;
92
        trapTimer.reset();
93
        attackTimer.reset();
94
        rotations = Vec3.ZERO;
95
        pistonPos = null;
96
        targetPos = null;
97
        firePos = null;
98
        pistonHeadPos = null;
99
        lastCrystal = null;
100
        delay = 0;
101
        trapTimer.reset();
102
        attackTimer.reset();
103
        postAction = null;
104
    }
105
106
    @Override
107
    public void onEnable() {
108
        reset();
109
    }
110
111
    @EventHandler
112
    public void onSync(EventSync event) {
113
        if (delay < placeDelay.getValue()) delay++;
114
115
        if (stage == Stage.Break) {
116
            if (isFire) {
117
                reset();
118
                return;
119
            }
120
            breakCrystal();
121
            return;
122
        }
123
124
        if (delay < placeDelay.getValue()) return;
125
126
        handlePistonAura(false);
127
    }
128
129
    @EventHandler
130
    @SuppressWarnings("unused")
131
    private void onPostSync(EventPostSync event) {
132
        if (postAction != null) {
133
            delay = 0;
134
            postAction.run();
135
            postAction = null;
136
            int extraBlocks = 1;
137
            while (extraBlocks < blocksPerTick.getValue()) {
138
                handlePistonAura(true);
139
                if (postAction != null) {
140
                    postAction.run();
141
                    postAction = null;
142
                } else {
143
                    return;
144
                }
145
                extraBlocks++;
146
            }
147
        }
148
        postAction = null;
149
    }
150
151
152
    public void handlePistonAura(boolean extra) {
153
        if (!InventoryUtility.findBlockInHotBar(Blocks.OBSIDIAN).found() && (trap.getValue() || supportPlace.getValue())) {
154
            disable(isRu() ? "Нет обсидиана!" : "No obsidian!");
155
            return;
156
        }
157
158
        if (!InventoryUtility.findBlockInHotBar(Blocks.REDSTONE_BLOCK).found() && !InventoryUtility.findBlockInHotBar(Blocks.REDSTONE_TORCH).found()) {
159
            disable(isRu() ? "Нет редстоуна!" : "No redstone!");
160
            return;
161
        }
162
163
        if (!InventoryUtility.findItemInHotBar(Items.END_CRYSTAL).found() && mc.player.getOffhandItem().getItem() != Items.END_CRYSTAL) {
164
            disable(isRu() ? "Нет кристаллов!" : "No crystals!");
165
            return;
166
        }
167
168
        if (!(InventoryUtility.findItemInHotBar(Items.PISTON).found() || InventoryUtility.findItemInHotBar(Items.STICKY_PISTON).found())) {
169
            disable(isRu() ? "Нет поршней!" : "No pistons!");
170
            return;
171
        }
172
173
        switch (stage) {
174
            case Searching -> {
175
                findPos();
176
                stage = Stage.Trap;
177
            }
178
            case Trap -> buildTrap();
179
            case Piston -> placePiston(extra);
180
            case Fire -> placeFire(extra);
181
            case Crystal -> placeCrystal(extra);
182
            case RedStone -> placeRedStone(extra);
183
            case Break -> {
184
                if (isFire)
185
                    stage = Stage.Searching;
186
            }
187
        }
188
    }
189
190
    private void placeRedStone(boolean extra) {
191
        if (redStonePos == null) {
192
            stage = Stage.Searching;
193
            return;
194
        }
195
196
        if (mc.level.getBlockState(redStonePos).getBlock() instanceof PoweredBlock) {
197
            stage = Stage.Break;
198
        }
199
200
        if (mc.level.getBlockState(redStonePos.below()).canBeReplaced() && supportPlace.getValue()) {
201
            InteractionUtility.placeBlock(redStonePos.below(), rotate.getValue(), interact.getValue(), placeMode.getValue(), InventoryUtility.findBlockInHotBar(Blocks.OBSIDIAN), false, false);
202
            return;
203
        }
204
205
        final float[] angle = InteractionUtility.getPlaceAngle(redStonePos, interact.getValue(), false);
206
        if (angle == null) return;
207
        if (extra) {
208
            sendPacket(new ServerboundMovePlayerPacket.Rot(angle[0], angle[1], mc.player.onGround(), mc.player.horizontalCollision));
209
        } else {
210
            mc.player.setYRot(angle[0]);
211
            mc.player.setXRot(angle[1]);
212
        }
213
214
        postAction = () -> {
215
            int redstone_slot = -1;
216
217
            SearchInvResult redBlockResult = InventoryUtility.findBlockInHotBar(Blocks.REDSTONE_BLOCK);
218
            SearchInvResult redTorchResult = InventoryUtility.findBlockInHotBar(Blocks.REDSTONE_TORCH);
219
220
            if (!redBlockResult.found()) {
221
                if (!redTorchResult.found()) disable(isRu() ? "Нет редстоуна!" : "No redstone!");
222
                else redstone_slot = redTorchResult.slot();
223
            } else redstone_slot = redBlockResult.slot();
224
225
            InteractionUtility.placeBlock(redStonePos, InteractionUtility.Rotate.None, interact.getValue(), placeMode.getValue(), redstone_slot, false, false);
226
            stage = Stage.Break;
227
        };
228
    }
229
230
    private void placeCrystal(boolean extra) {
231
        if (crystalPos == null) {
232
            stage = Stage.Searching;
233
            return;
234
        }
235
236
        if (mc.level.getBlockState(crystalPos).canBeReplaced() && supportPlace.getValue()) {
237
            InteractionUtility.placeBlock(crystalPos, rotate.getValue(), interact.getValue(), placeMode.getValue(), InventoryUtility.findBlockInHotBar(Blocks.OBSIDIAN), false, false);
238
            return;
239
        }
240
241
        BlockHitResult result = getPlaceData(crystalPos);
242
        if (result == null) return;
243
        float[] angle = InteractionUtility.calculateAngle(rotations);
244
        if (extra) {
245
            sendPacket(new ServerboundMovePlayerPacket.Rot(angle[0] + MathUtility.random(-0.2f, 0.2f), angle[1], mc.player.onGround(), mc.player.horizontalCollision));
246
        } else {
247
            mc.player.setYRot(angle[0] + MathUtility.random(-0.2f, 0.2f));
248
            mc.player.setXRot(angle[1]);
249
        }
250
251
        postAction = () -> {
252
            boolean offHand = mc.player.getOffhandItem().getItem() == Items.END_CRYSTAL;
253
            int prev_slot = -1;
254
            if (!offHand) {
255
                int crystal_slot = InventoryUtility.findItemInHotBar(Items.END_CRYSTAL).slot();
256
                prev_slot = mc.player.getInventory().getSelectedSlot();
257
                if (crystal_slot != -1) {
258
                    mc.player.getInventory().setSelectedSlot(crystal_slot);
259
                    sendPacket(new ServerboundSetCarriedItemPacket(crystal_slot));
260
                }
261
            }
262
263
            sendSequencedPacket(id -> new ServerboundUseItemOnPacket(offHand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND, result, id));
264
            sendPacket(new ServerboundSwingPacket(offHand ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND));
265
266
            if (!offHand) {
267
                mc.player.getInventory().setSelectedSlot(prev_slot);
268
                sendPacket(new ServerboundSetCarriedItemPacket(prev_slot));
269
            }
270
271
            stage = Stage.RedStone;
272
        };
273
    }
274
275
    private void placeFire(boolean extra) {
276
        if (firePos == null) {
277
            stage = Stage.Searching;
278
            return;
279
        }
280
281
        if (mc.level.getBlockState(firePos).getBlock() instanceof FireBlock) stage = Stage.Crystal;
282
283
        if (mc.level.getBlockState(firePos.below()).canBeReplaced() && supportPlace.getValue()) {
284
            InteractionUtility.placeBlock(firePos.below(), rotate.getValue(), interact.getValue(), placeMode.getValue(), InventoryUtility.findBlockInHotBar(Blocks.OBSIDIAN), false, false);
285
            return;
286
        }
287
288
        float[] angle = InteractionUtility.getPlaceAngle(firePos, interact.getValue(), false);
289
        if (angle == null) return;
290
        if (extra) {
291
            sendPacket(new ServerboundMovePlayerPacket.Rot(angle[0], angle[1], mc.player.onGround(), mc.player.horizontalCollision));
292
        } else {
293
            mc.player.setYRot(angle[0]);
294
            mc.player.setXRot(angle[1]);
295
        }
296
        postAction = () -> {
297
            InteractionUtility.placeBlock(firePos, InteractionUtility.Rotate.None, interact.getValue(), placeMode.getValue(), InventoryUtility.findItemInHotBar(Items.FLINT_AND_STEEL).slot(), false, false);
298
            stage = Stage.Crystal;
299
        };
300
    }
301
302
    public void buildTrap() {
303
        if (!trap.getValue()) {
304
            stage = Stage.Piston;
305
            return;
306
        }
307
        if (mc.level.getBlockState(targetPos.offset(0, 2, 0)).getBlock() == Blocks.OBSIDIAN || pistonPos.getY() >= targetPos.offset(0, 2, 0).getY()) {
308
            stage = Stage.Piston;
309
            return;
310
        }
311
312
        if (!builtTrap) {
313
            final BlockPos offset = new BlockPos(crystalPos.getX() - targetPos.getX(), 0, crystalPos.getZ() - targetPos.getZ());
314
            final BlockPos trapBase = targetPos.offset(offset.getX() * -1, 0, offset.getZ() * -1);
315
316
            List<BlockPos> trapPos = new ArrayList<>();
317
            trapPos.add(targetPos.offset(0, 2, 0));
318
            trapPos.add(trapBase.offset(0, 2, 0));
319
            trapPos.add(trapBase.offset(0, 1, 0));
320
321
            InventoryUtility.saveSlot();
322
            for (BlockPos bp : trapPos) {
323
                if (InteractionUtility.placeBlock(bp, rotate.getValue(), interact.getValue(), placeMode.getValue(), InventoryUtility.findBlockInHotBar(Blocks.OBSIDIAN), false, false)) {
324
                    if (bp == targetPos.offset(0, 2, 0)) {
325
                        builtTrap = true;
326
                        stage = Stage.Piston;
327
                    }
328
                    break;
329
                }
330
            }
331
            InventoryUtility.returnSlot();
332
        }
333
    }
334
335
    public void placePiston(boolean extra) {
336
        if (pistonPos == null) {
337
            stage = Stage.Searching;
338
            return;
339
        }
340
341
        if (pistonHeadPos == null) {
342
            stage = Stage.Searching;
343
            return;
344
        }
345
346
        if (mc.level.getBlockState(pistonPos).getBlock() instanceof PistonBaseBlock) {
347
            stage = isFire ? Stage.Fire : Stage.Crystal;
348
        }
349
350
        if (mc.level.getBlockState(pistonPos.below()).canBeReplaced() && supportPlace.getValue()) {
351
            InteractionUtility.placeBlock(pistonPos.below(), rotate.getValue(), interact.getValue(), placeMode.getValue(), InventoryUtility.findBlockInHotBar(Blocks.OBSIDIAN), false, false);
352
            return;
353
        }
354
355
        final float[] angle = InteractionUtility.getPlaceAngle(pistonPos, interact.getValue(), false);
356
        if (angle == null) return;
357
        if (extra) {
358
            sendPacket(new ServerboundMovePlayerPacket.Rot(angle[0], angle[1], mc.player.onGround(), mc.player.horizontalCollision));
359
        } else {
360
            mc.player.setYRot(angle[0]);
361
            mc.player.setXRot(angle[1]);
362
        }
363
364
365
        postAction = () -> {
366
            int piston_slot;
367
            if (!InventoryUtility.findBlockInHotBar(Blocks.PISTON).found()) {
368
                if (!InventoryUtility.findBlockInHotBar(Blocks.STICKY_PISTON).found()) {
369
                    disable(isRu() ? "Нет поршней!" : "No pistons!");
370
                    return;
371
                } else {
372
                    piston_slot = InventoryUtility.findBlockInHotBar(Blocks.STICKY_PISTON).slot();
373
                }
374
            } else {
375
                piston_slot = InventoryUtility.findBlockInHotBar(Blocks.PISTON).slot();
376
            }
377
378
379
            final float angle2 = InteractionUtility.calculateAngle(net.minecraft.world.phys.Vec3.atBottomCenterOf(pistonHeadPos), net.minecraft.world.phys.Vec3.atBottomCenterOf(pistonPos))[0];
380
381
            sendPacket(new ServerboundMovePlayerPacket.Rot(angle2, 0, mc.player.onGround(), mc.player.horizontalCollision));
382
            float prevYaw = mc.player.getYRot();
383
            mc.player.setYRot(angle2);
384
            ((thunder.hack.injection.accesors.IEntity) mc.player).setLastYaw(angle2);
385
            ((IEntity) mc.player).setLastYaw(angle2);
386
            int prevSlot = mc.player.getInventory().getSelectedSlot();
387
            InteractionUtility.placeBlock(pistonPos, InteractionUtility.Rotate.None, interact.getValue(), placeMode.getValue(), piston_slot, false, false);
388
            sendPacket(new ServerboundSetCarriedItemPacket(prevSlot));
389
            mc.player.getInventory().setSelectedSlot(prevSlot);
390
            mc.player.setYRot(prevYaw);
391
392
            stage = isFire ? Stage.Fire : Stage.Crystal;
393
        };
394
    }
395
396
    public @Nullable BlockHitResult getPlaceData(BlockPos bp) {
397
        Block base = mc.level.getBlockState(bp).getBlock();
398
        Block freeSpace = mc.level.getBlockState(bp.above()).getBlock();
399
        Block legacyFreeSpace = mc.level.getBlockState(bp.above().above()).getBlock();
400
401
        if (base != Blocks.OBSIDIAN && base != Blocks.BEDROCK)
402
            return null;
403
404
        if (!(freeSpace == Blocks.AIR && (!oldVersion.getValue() || legacyFreeSpace == Blocks.AIR)))
405
            return null;
406
407
        if (checkEntities(bp)) return null;
408
409
        Vec3 crystalVec = new Vec3(0.5f + bp.getX(), 1f + bp.getY(), 0.5f + bp.getZ());
410
411
        BlockHitResult interactResult = null;
412
413
        switch (interact.getValue()) {
414
            case Vanilla -> interactResult = getDefaultInteract(crystalVec, bp);
415
            case Strict -> interactResult = getStrictInteract(bp);
416
            case Legit -> interactResult = getLegitInteract(bp);
417
        }
418
419
        return interactResult;
420
    }
421
422
    private boolean checkEntities(@NotNull BlockPos base) {
423
        AABB posBoundingBox = new AABB(base.above());
424
425
        posBoundingBox = posBoundingBox.inflate(0, 1f, 0);
426
427
        for (Entity ent : mc.level.entitiesForRendering()) {
428
            if (ent == null) continue;
429
            if (ent.getBoundingBox().intersects(posBoundingBox)) {
430
                if (ent instanceof ExperienceOrb)
431
                    continue;
432
                if (ent instanceof EndCrystal) {
433
                    continue;
434
                }
435
                return true;
436
            }
437
        }
438
        return false;
439
    }
440
441
    private @Nullable BlockHitResult getDefaultInteract(Vec3 crystalVector, BlockPos bp) {
442
        if (PlayerUtility.squaredDistanceFromEyes(crystalVector) > placeRange.getPow2Value())
443
            return null;
444
445
        BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), crystalVector, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
446
447
        if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != bp)
448
            if (PlayerUtility.squaredDistanceFromEyes(crystalVector) > wallRange.getPow2Value())
449
                return null;
450
451
        return new BlockHitResult(crystalVector, Direction.DOWN, bp, false);
452
    }
453
454
    public @Nullable BlockHitResult getStrictInteract(@NotNull BlockPos bp) {
455
        float bestDistance = 999f;
456
        Direction bestDirection = null;
457
        Vec3 bestVector = null;
458
459
        if (mc.player.getEyePosition().y() > bp.above().getY()) {
460
            bestDirection = Direction.UP;
461
            bestVector = new Vec3(bp.getX() + 0.5, bp.getY() + 1, bp.getZ() + 0.5);
462
        } else if (mc.player.getEyePosition().y() < bp.getY()) {
463
            bestDirection = Direction.DOWN;
464
            bestVector = new Vec3(bp.getX() + 0.5, bp.getY(), bp.getZ() + 0.5);
465
        } else {
466
            for (Direction dir : Direction.values()) {
467
                Vec3 directionVec = new Vec3(bp.getX() + 0.5 + dir.getUnitVec3i().getX() * 0.5, bp.getY() + 0.5 + dir.getUnitVec3i().getY() * 0.5, bp.getZ() + 0.5 + dir.getUnitVec3i().getZ() * 0.5);
468
                float distance = PlayerUtility.squaredDistanceFromEyes(directionVec);
469
                if (bestDistance > distance) {
470
                    bestDirection = dir;
471
                    bestVector = directionVec;
472
                    bestDistance = distance;
473
                }
474
            }
475
        }
476
477
        if (bestVector == null)
478
            return null;
479
480
        if (PlayerUtility.squaredDistanceFromEyes(bestVector) > placeRange.getPow2Value())
481
            return null;
482
483
        BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), bestVector, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
484
485
        if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != bp)
486
            if (PlayerUtility.squaredDistanceFromEyes(bestVector) > wallRange.getPow2Value())
487
                return null;
488
489
        return new BlockHitResult(bestVector, bestDirection, bp, false);
490
    }
491
492
    public BlockHitResult getLegitInteract(BlockPos bp) {
493
        float bestDistance = 999f;
494
        BlockHitResult bestResult = null;
495
        for (float x = 0f; x <= 1f; x += 0.2f) {
496
            for (float y = 0f; y <= 1f; y += 0.2f) {
497
                for (float z = 0f; z <= 1f; z += 0.2f) {
498
                    Vec3 point = new Vec3(bp.getX() + x, bp.getY() + y, bp.getZ() + z);
499
                    float distance = PlayerUtility.squaredDistanceFromEyes(point);
500
501
                    BlockHitResult wallCheck = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), point, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player));
502
                    if (wallCheck != null && wallCheck.getType() == HitResult.Type.BLOCK && wallCheck.getBlockPos() != bp)
503
                        if (distance > wallRange.getPow2Value())
504
                            continue;
505
506
                    BlockHitResult result = ExplosionUtility.rayCastBlock(new ClipContext(InteractionUtility.getEyesPos(mc.player), point, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player), bp);
507
                    if (distance > placeRange.getPow2Value())
508
                        continue;
509
510
                    if (distance < bestDistance) {
511
                        if (result != null && result.getType() == HitResult.Type.BLOCK) {
512
                            bestResult = result;
513
                            bestDistance = distance;
514
                        }
515
                    }
516
                }
517
            }
518
        }
519
        return bestResult;
520
    }
521
522
    public void breakCrystal() {
523
        for (Entity ent : mc.level.entitiesForRendering()) {
524
            if (!(ent instanceof EndCrystal) || target.distanceToSqr(ent.position()) > 16 || ent.tickCount < 2)
525
                continue;
526
            float[] angle = InteractionUtility.calculateAngle(ent.position());
527
            mc.player.setYRot(angle[0] + MathUtility.random(-3f, 3f));
528
            mc.player.setXRot(angle[1]);
529
            if (attackTimer.passedMs(200)) {
530
                mc.gameMode.attack(mc.player, ent);
531
                mc.player.swing(InteractionHand.MAIN_HAND);
532
                attackTimer.reset();
533
            }
534
            lastCrystal = (EndCrystal) ent;
535
        }
536
    }
537
538
    @EventHandler
539
    @SuppressWarnings("unused")
540
    private void onPacketReceive(PacketEvent.@NotNull Receive event) {
541
        if (event.getPacket() instanceof ClientboundSoundPacket && ((ClientboundSoundPacket) event.getPacket()).getSource().equals(SoundSource.BLOCKS) && ((ClientboundSoundPacket) event.getPacket()).getSound().value().equals(SoundEvents.GENERIC_EXPLODE)) {
542
            if (lastCrystal == null || !lastCrystal.isAlive())
543
                return;
544
            double soundRange = lastCrystal.distanceToSqr(((ClientboundSoundPacket) event.getPacket()).getX() + 0.5, ((ClientboundSoundPacket) event.getPacket()).getY() + 0.5, ((ClientboundSoundPacket) event.getPacket()).getZ() + 0.5);
545
            if (soundRange > 121)
546
                return;
547
            reset();
548
        }
549
550
        if (event.getPacket() instanceof ClientboundSoundEntityPacket && ((ClientboundSoundEntityPacket) event.getPacket()).getSource().equals(SoundSource.BLOCKS) && ((ClientboundSoundEntityPacket) event.getPacket()).getSound().value().equals(SoundEvents.GENERIC_EXPLODE)) {
551
            if (lastCrystal == null || !lastCrystal.isAlive())
552
                return;
553
            if (((ClientboundSoundEntityPacket) event.getPacket()).getId() != lastCrystal.getId())
554
                return;
555
            reset();
556
        }
557
    }
558
559
560
    @EventHandler
561
    @SuppressWarnings("unused")
562
    public void onEntityRemove(EventEntityRemoved e) {
563
        if (lastCrystal != null && lastCrystal == e.entity)
564
            reset();
565
    }
566
567
568
    @Override
569
    public @NotNull String getDisplayInfo() {
570
        return stage.toString() + (target != null ? " | " + target.getName().getString() : "");
571
    }
572
573
    @Override
574
    public void onRender3D(PoseStack stack) {
575
        if (pistonPos == null || crystalPos == null || redStonePos == null) {
576
            return;
577
        }
578
        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(new AABB(pistonHeadPos.below()), Render2DEngine.injectAlpha(Color.CYAN, 100)));
579
        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(new AABB(crystalPos), Render2DEngine.injectAlpha(Color.PINK, 100)));
580
        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(new AABB(pistonPos.below()), Render2DEngine.injectAlpha(Color.GREEN, 100)));
581
        Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(new AABB(redStonePos.below()), Render2DEngine.injectAlpha(Color.RED, 100)));
582
583
        if (firePos != null)
584
            Render3DEngine.FILLED_QUEUE.add(new Render3DEngine.FillAction(new AABB(firePos.below()), Render2DEngine.injectAlpha(Color.yellow, 100)));
585
    }
586
587
588
    private void findPos() {
589
        ArrayList<Structure> list = new ArrayList<>();
590
        for (Player target : Objects.requireNonNull(getPlayersSorted(targetRange.getValue()))) {
591
            for (int i = 0; i <= 2; i++) {
592
                if (patternsSetting.getValue() == Pattern.Small || patternsSetting.getValue() == Pattern.All) {
593
                    list.add(new Structure(
594
                            target,
595
                            new BlockPos(1, i, 0),//crystal
596
                            new BlockPos(1, i, -1),//piston
597
                            new BlockPos(0, i, -1),//pistonHead
598
                            new BlockPos[]{new BlockPos(1, 0, -2)},//redstone
599
                            new BlockPos[]{new BlockPos(0, 0, 1), new BlockPos(1, i, 1), new BlockPos(0, 1 + i, 1)})//fire
600
                    );
601
                    list.add(new Structure(
602
                            target,
603
                            new BlockPos(1, i, 0),//crystal
604
                            new BlockPos(1, i, 1),//piston
605
                            new BlockPos(0, i, 1),//pistonHead
606
                            new BlockPos[]{new BlockPos(1, i, 2)},//redstone
607
                            new BlockPos[]{new BlockPos(0, i, -1), new BlockPos(1, i, -1), new BlockPos(0, 1 + i, -1)})//fire
608
                    );
609
                    list.add(new Structure(
610
                            target,
611
                            new BlockPos(0, i, 1),//crystal
612
                            new BlockPos(1, i, 1),//piston
613
                            new BlockPos(1, i, 0),//pistonHead
614
                            new BlockPos[]{new BlockPos(2, i, 1)},//redstone
615
                            new BlockPos[]{new BlockPos(-1, i, 1), new BlockPos(-1, i, 0), new BlockPos(-1, 1 + i, 0)})//fire
616
                    );
617
                    list.add(new Structure(
618
                            target,
619
                            new BlockPos(0, i, 1),//crystal
620
                            new BlockPos(-1, i, 1),//piston
621
                            new BlockPos(-1, i, 0),//pistonHead
622
                            new BlockPos[]{new BlockPos(-2, i, 1)},//redstone
623
                            new BlockPos[]{new BlockPos(1, i, 1), new BlockPos(1, i, 0), new BlockPos(1, 1 + i, 0)})//fire
624
                    );
625
                    list.add(new Structure(
626
                            target,
627
                            new BlockPos(-1, i, 0),//crystal
628
                            new BlockPos(-1, i, 1),//piston
629
                            new BlockPos(0, i, 1),//pistonHead
630
                            new BlockPos[]{new BlockPos(-1, i, 2)},//redstone
631
                            new BlockPos[]{new BlockPos(-1, i, -1), new BlockPos(0, i, -1), new BlockPos(0, 1 + i, -1)})//fire
632
                    );
633
                    list.add(new Structure(
634
                            target,
635
                            new BlockPos(-1, i, 0),//crystal
636
                            new BlockPos(-1, i, -1),//piston
637
                            new BlockPos(0, i, -1),//pistonHead
638
                            new BlockPos[]{new BlockPos(-1, i, -2)},//redstone
639
                            new BlockPos[]{new BlockPos(-1, i, 1), new BlockPos(0, i, 1), new BlockPos(0, 1 + i, 1)})//fire
640
                    );
641
                    list.add(new Structure(
642
                            target,
643
                            new BlockPos(0, i, -1),//crystal
644
                            new BlockPos(-1, i, -1),//piston
645
                            new BlockPos(-1, i, 0),//pistonHead
646
                            new BlockPos[]{new BlockPos(-2, i, -1)},//redstone
647
                            new BlockPos[]{new BlockPos(1, i, 0), new BlockPos(1, i, -1), new BlockPos(1, i + 1, 0)})//fire
648
                    );
649
                    list.add(new Structure(
650
                            target,
651
                            new BlockPos(0, i, -1),//crystal
652
                            new BlockPos(1, i, -1),//piston
653
                            new BlockPos(1, i, 0),//pistonHead
654
                            new BlockPos[]{new BlockPos(2, i, -1)},//redstone
655
                            new BlockPos[]{new BlockPos(-1, i, 0), new BlockPos(-1, i, -1), new BlockPos(-1, 1 + i, 0)})//fire
656
                    );
657
                }
658
                if (patternsSetting.getValue() == Pattern.Cross || patternsSetting.getValue() == Pattern.All) {
659
                    list.add(new Structure(
660
                            target,
661
                            new BlockPos(1, i, 0),//crystal
662
                            new BlockPos(2, i, -1),//piston
663
                            new BlockPos(1, i, -1),//pistonHead
664
                            new BlockPos[]{new BlockPos(3, i, -1), new BlockPos(2, i, -2)},//redstone
665
                            new BlockPos[]{new BlockPos(0, i, -1), new BlockPos(1, i, 1), new BlockPos(0, i, 1), new BlockPos(0, 1 + i, 1), new BlockPos(0, 1 + i, -1)})//fire
666
                    );
667
                    list.add(new Structure(
668
                            target,
669
                            new BlockPos(1, i, 0),//crystal
670
                            new BlockPos(2, i, 1),//piston
671
                            new BlockPos(1, i, 1),//pistonHead
672
                            new BlockPos[]{new BlockPos(3, i, 1), new BlockPos(2, i, 2)},//redstone
673
                            new BlockPos[]{new BlockPos(0, i, 1), new BlockPos(1, i, -1), new BlockPos(0, i, -1), new BlockPos(0, 1 + i, -1), new BlockPos(0, 1 + i, 1)})//fire
674
                    );
675
                    list.add(new Structure(
676
                            target,
677
                            new BlockPos(0, i, 1),//crystal
678
                            new BlockPos(1, i, 2),//piston
679
                            new BlockPos(1, i, 1),//pistonHead
680
                            new BlockPos[]{new BlockPos(1, i, 3), new BlockPos(2, i, 2)},//redstone
681
                            new BlockPos[]{new BlockPos(1, i, 0), new BlockPos(-1, i, 0), new BlockPos(-1, i, 1), new BlockPos(-1, 1 + i, 0), new BlockPos(1, 1 + i, 0)})//fire
682
                    );
683
                    list.add(new Structure(
684
                            target,
685
                            new BlockPos(0, i, 1),//crystal
686
                            new BlockPos(-1, i, 2),//piston
687
                            new BlockPos(-1, i, 1),//pistonHead
688
                            new BlockPos[]{new BlockPos(-1, i, 3), new BlockPos(-2, i, 2)},//redstone
689
                            new BlockPos[]{new BlockPos(-1, i, 0), new BlockPos(1, i, 1), new BlockPos(1, i, 0), new BlockPos(-1, 1 + i, 0), new BlockPos(1, 1 + i, 0)})//fire
690
                    );
691
                    list.add(new Structure(
692
                            target,
693
                            new BlockPos(-1, i, 0),//crystal
694
                            new BlockPos(-2, i, 1),//piston
695
                            new BlockPos(-1, i, 1),//pistonHead
696
                            new BlockPos[]{new BlockPos(-3, i, 1), new BlockPos(-2, i, 2)},//redstone
697
                            new BlockPos[]{new BlockPos(0, i, 1), new BlockPos(-1, i, -1), new BlockPos(0, i, -1), new BlockPos(0, 1 + i, 1), new BlockPos(0, 1 + i, -1)})//fire
698
                    );
699
                    list.add(new Structure(
700
                            target,
701
                            new BlockPos(-1, i, 0),//crystal
702
                            new BlockPos(-2, i, -1),//piston
703
                            new BlockPos(-1, i, -1),//pistonHead
704
                            new BlockPos[]{new BlockPos(-3, i, -1), new BlockPos(-2, i, -2)},//redstone
705
                            new BlockPos[]{new BlockPos(0, i, -1), new BlockPos(0, i, -1), new BlockPos(-1, i, 1), new BlockPos(0, 1 + i, 1), new BlockPos(0, 1 + i, -1)})//fire
706
                    );
707
                    list.add(new Structure(
708
                            target,
709
                            new BlockPos(0, i, -1),//crystal
710
                            new BlockPos(-1, i, -2),//piston
711
                            new BlockPos(-1, i, -1),//pistonHead
712
                            new BlockPos[]{new BlockPos(-1, i, -3), new BlockPos(-2, i, -2)},//redstone
713
                            new BlockPos[]{new BlockPos(-1, i, 0), new BlockPos(1, i, 0), new BlockPos(1, i, -1), new BlockPos(-1, 1 + i, 0), new BlockPos(1, 1 + i, 0)})//fire
714
                    );
715
                }
716
                if (patternsSetting.getValue() == Pattern.Liner || patternsSetting.getValue() == Pattern.All) {
717
                    list.add(new Structure(
718
                            target,
719
                            new BlockPos(1, i, 0),//crystal
720
                            new BlockPos(2, i, 0),//piston
721
                            new BlockPos(1, i, 0),//pistonHead
722
                            new BlockPos[]{new BlockPos(3, i, 0)},//redstone
723
                            new BlockPos[]{new BlockPos(1, i, 1), new BlockPos(1, i, -1), new BlockPos(0, i, 1),
724
                                    new BlockPos(0, i, -1), new BlockPos(0, 1 + i, 1), new BlockPos(0, 1 + i, -1)})//fire
725
                    );
726
                    list.add(new Structure(
727
                            target,
728
                            new BlockPos(-1, i, 0),//crystal
729
                            new BlockPos(-2, i, 0),//piston
730
                            new BlockPos(-1, i, 0),//pistonHead
731
                            new BlockPos[]{new BlockPos(-3, i, 0)},//redstone
732
                            new BlockPos[]{new BlockPos(-1, i, -1), new BlockPos(-1, i, 1), new BlockPos(0, i, 1),
733
                                    new BlockPos(0, i, -1), new BlockPos(0, 1 + i, 1), new BlockPos(0, 1 + i, -1)})//fire
734
                    );
735
                    list.add(new Structure(
736
                            target,
737
                            new BlockPos(0, i, 1),//crystal
738
                            new BlockPos(0, i, 2),//piston
739
                            new BlockPos(0, i, 1),//pistonHead
740
                            new BlockPos[]{new BlockPos(0, i, 3)},//redstone
741
                            new BlockPos[]{new BlockPos(-1, i, 1), new BlockPos(1, i, 1), new BlockPos(-1, i, 0),
742
                                    new BlockPos(1, i, 0), new BlockPos(1, 1 + i, 0), new BlockPos(-1, 1 + i, 0)})//fire
743
                    );
744
                    list.add(new Structure(
745
                            target,
746
                            new BlockPos(0, i, -1),//crystal
747
                            new BlockPos(0, i, -2),//piston
748
                            new BlockPos(0, i, -1),//pistonHead
749
                            new BlockPos[]{new BlockPos(0, i, -3)},//redstone
750
                            new BlockPos[]{new BlockPos(-1, i, -1), new BlockPos(1, i, -1), new BlockPos(-1, i, 0),
751
                                    new BlockPos(1, i, 0), new BlockPos(1, 1 + i, 0), new BlockPos(-1, 1 + i, 0)})//fire
752
                    );
753
                }
754
            }
755
            this.target = target;
756
        }
757
758
759
        if (bypass.getValue() && InventoryUtility.findItemInHotBar(Items.FLINT_AND_STEEL).found()) {
760
            List<Structure> bestStructure = list.stream()
761
                    .filter(Structure::isFirePa)
762
                    .sorted(Comparator.comparingDouble(Structure::getMaxRange))
763
                    .toList();
764
            if (bestStructure.isEmpty()) {
765
                isFire = false;
766
                bestStructure = list.stream()
767
                        .filter(Structure::isNormalPa)
768
                        .sorted(Comparator.comparingDouble(Structure::getMaxRange))
769
                        .toList();
770
                if (!bestStructure.isEmpty()) {
771
                    Structure structure = bestStructure.get(0);
772
                    pistonPos = structure.getPistonPos();
773
                    crystalPos = structure.getCrystalPos();
774
                    redStonePos = structure.getRedStonePos();
775
                    pistonHeadPos = structure.getPistonHeadPos();
776
                    targetPos = structure.targetPos;
777
                    target = structure.getTarget();
778
                } else {
779
                    disable(isRu() ? "Нет цели или места!" : "No target or free space!");
780
                }
781
            } else {
782
                isFire = true;
783
                Structure structure = bestStructure.get(0);
784
                pistonPos = structure.getPistonPos();
785
                crystalPos = structure.getCrystalPos();
786
                redStonePos = structure.getRedStonePos();
787
                firePos = structure.getFirePos();
788
                pistonHeadPos = structure.getPistonHeadPos();
789
                targetPos = structure.targetPos;
790
                target = structure.getTarget();
791
            }
792
        } else {
793
            isFire = false;
794
            List<Structure> bestStructure = list.stream()
795
                    .filter(Structure::isNormalPa)
796
                    .sorted(Comparator.comparingDouble(Structure::getMaxRange))
797
                    .toList();
798
            if (!bestStructure.isEmpty()) {
799
                Structure structure = bestStructure.getFirst();
800
                pistonPos = structure.getPistonPos();
801
                crystalPos = structure.getCrystalPos();
802
                redStonePos = structure.getRedStonePos();
803
                pistonHeadPos = structure.getPistonHeadPos();
804
                targetPos = structure.targetPos;
805
                target = structure.getTarget();
806
            } else {
807
                disable(isRu() ? "Нет цели или места!" : "No target or free space!");
808
            }
809
        }
810
    }
811
812
813
    public static @NotNull List<Player> getPlayersSorted(float range) {
814
        synchronized (mc.level.players()) {
815
            List<Player> playerList = new ArrayList<>();
816
            for (Player player : mc.level.players()) {
817
                if (mc.player != player && !Managers.FRIEND.isFriend(player) && mc.player.distanceToSqr(player) <= range * range) {
818
                    playerList.add(player);
819
                }
820
            }
821
            playerList.sort(Comparator.comparing(player -> mc.player.distanceToSqr(player)));
822
            return playerList;
823
        }
824
    }
825
826
827
    public class Structure {
828
        private final BlockPos pistonPos;
829
        private BlockPos crystalPos;
830
        private final BlockPos targetPos;
831
        private BlockPos redStonePos;
832
        private BlockPos firePos;
833
        private final Player target;
834
835
        private BlockPos pistonHeadPos;
836
837
        public BlockPos getPistonHeadPos() {
838
            return pistonHeadPos;
839
        }
840
841
        public BlockPos getPistonPos() {
842
            return pistonPos;
843
        }
844
845
        public BlockPos getCrystalPos() {
846
            return crystalPos;
847
        }
848
849
        public BlockPos getRedStonePos() {
850
            return redStonePos;
851
        }
852
853
        public BlockPos getFirePos() {
854
            return firePos;
855
        }
856
857
        public Player getTarget() {
858
            return target;
859
        }
860
861
        public Structure(@NotNull Player target, @NotNull BlockPos crystalPos, @NotNull BlockPos pistonPos, @NotNull BlockPos pistonHeadPos, BlockPos[] redStonePos, BlockPos[] firePos) {
862
            this.target = target;
863
            this.targetPos = BlockPos.containing(target.position());
864
            this.pistonPos = canPlace(targetPos.offset(pistonPos.getX(), pistonPos.getY() + 1, pistonPos.getZ())) ? targetPos.offset(pistonPos.getX(), pistonPos.getY() + 1, pistonPos.getZ()) : null;
865
            this.crystalPos = getPlaceData(targetPos.offset(crystalPos.getX(), crystalPos.getY(), crystalPos.getZ())) != null ? targetPos.offset(crystalPos.getX(), crystalPos.getY(), crystalPos.getZ()) : null;
866
            this.pistonHeadPos = mc.level.isEmptyBlock(targetPos.offset(pistonHeadPos.getX(), pistonHeadPos.getY() + 1, pistonHeadPos.getZ())) ? targetPos.offset(pistonHeadPos.getX(), pistonHeadPos.getY() + 1, pistonHeadPos.getZ()) : null;
867
868
            if (this.pistonHeadPos != null && !mc.level.getEntitiesOfClass(Player.class, new AABB(this.pistonHeadPos)).isEmpty()) {
869
                this.pistonHeadPos = null;
870
            }
871
872
            if (this.crystalPos != null && !mc.level.getEntitiesOfClass(Entity.class, new AABB(this.crystalPos)).isEmpty()) {
873
                this.crystalPos = null;
874
            }
875
876
            this.redStonePos = null;
877
            List<BlockPos> tempRed = Arrays.stream(redStonePos)
878
                    .map(blockPos -> targetPos.offset(blockPos.getX(), blockPos.getY() + 1, blockPos.getZ()))
879
                    .toList();
880
            BlockState preState = mc.level.getBlockState(pistonPos);
881
            mc.level.setBlockAndUpdate(pistonPos, Blocks.PISTON.defaultBlockState());
882
            for (BlockPos pos : tempRed) {
883
                if (canPlace(pos)) {
884
                    this.redStonePos = pos;
885
                    break;
886
                }
887
            }
888
            mc.level.setBlockAndUpdate(pistonPos, preState);
889
890
            this.firePos = null;
891
            List<BlockPos> tempFire = Arrays.stream(firePos)
892
                    .map(blockPos -> targetPos.offset(blockPos.getX(), blockPos.getY() + 1, blockPos.getZ()))
893
                    .toList();
894
            for (BlockPos pos : tempFire) {
895
                if (canPlace(pos)) {
896
                    this.firePos = pos;
897
                    break;
898
                }
899
            }
900
        }
901
902
        public boolean isNormalPa() {
903
            return pistonPos != null && crystalPos != null && targetPos != null && redStonePos != null && pistonHeadPos != null;
904
        }
905
906
        public boolean isFirePa() {
907
            return pistonPos != null && crystalPos != null && targetPos != null && redStonePos != null && pistonHeadPos != null && firePos != null;
908
        }
909
910
        private boolean canPlace(BlockPos pos) {
911
            if (pos == null) return false;
912
913
            BlockState prevBlockState = null;
914
            if (supportPlace.getValue()) {
915
                prevBlockState = mc.level.getBlockState(pos.below());
916
                if (prevBlockState.canBeReplaced()) {
917
                    mc.level.setBlockAndUpdate(pos.below(), Blocks.OBSIDIAN.defaultBlockState());
918
                } else prevBlockState = null;
919
            }
920
921
            boolean canPlace =  InteractionUtility.canPlaceBlock(pos, interact.getValue(), false);
922
923
            if (prevBlockState != null) {
924
                mc.level.setBlockAndUpdate(pos.below(), prevBlockState);
925
            }
926
927
            return canPlace;
928
        }
929
930
        public double getMaxRange() {
931
            if (this.pistonPos == null || this.crystalPos == null || this.redStonePos == null) return 999;
932
            final double piston = InteractionUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(this.pistonPos));
933
            final double crystal = InteractionUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(this.crystalPos));
934
            final double redStone = InteractionUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(this.redStonePos));
935
936
            BlockPos firePos = this.firePos != null ? this.firePos : this.pistonPos;
937
            final double fire = InteractionUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(firePos));
938
            return Math.max(Math.max(fire, crystal), Math.max(redStone, piston));
939
        }
940
    }
941
942
    public enum Stage {
943
        Searching,
944
        Trap,
945
        Piston,
946
        Fire,
947
        Crystal,
948
        RedStone,
949
        Break
950
    }
951
952
    public enum Pattern {
953
        Small,
954
        Cross,
955
        Liner,
956
        All
957
    }
958
}
959