|
6 | 6 | package meteordevelopment.meteorclient.systems.modules.movement;
|
7 | 7 |
|
8 | 8 | import meteordevelopment.meteorclient.events.world.TickEvent;
|
9 |
| -import meteordevelopment.meteorclient.settings.DoubleSetting; |
10 |
| -import meteordevelopment.meteorclient.settings.Setting; |
11 |
| -import meteordevelopment.meteorclient.settings.SettingGroup; |
12 | 9 | import meteordevelopment.meteorclient.systems.modules.Categories;
|
13 | 10 | import meteordevelopment.meteorclient.systems.modules.Module;
|
14 | 11 | import meteordevelopment.orbit.EventHandler;
|
15 | 12 | import net.minecraft.block.BlockState;
|
| 13 | +import net.minecraft.client.render.Camera; |
| 14 | +import net.minecraft.item.BlockItem; |
| 15 | +import net.minecraft.item.consume.UseAction; |
| 16 | +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; |
16 | 17 | import net.minecraft.util.ActionResult;
|
17 | 18 | import net.minecraft.util.Hand;
|
18 | 19 | import net.minecraft.util.hit.BlockHitResult;
|
19 | 20 | import net.minecraft.util.hit.EntityHitResult;
|
20 | 21 | import net.minecraft.util.hit.HitResult;
|
21 | 22 | import net.minecraft.util.math.BlockPos;
|
22 | 23 | import net.minecraft.util.math.Direction;
|
| 24 | +import net.minecraft.util.math.Vec3d; |
23 | 25 | import net.minecraft.util.shape.VoxelShape;
|
| 26 | +import net.minecraft.world.RaycastContext; |
24 | 27 |
|
25 | 28 | public class ClickTP extends Module {
|
26 |
| - private final SettingGroup sgGeneral = settings.getDefaultGroup(); |
27 |
| - |
28 |
| - private final Setting<Double> maxDistance = sgGeneral.add(new DoubleSetting.Builder() |
29 |
| - .name("max-distance") |
30 |
| - .description("The maximum distance you can teleport.") |
31 |
| - .defaultValue(5) |
32 |
| - .build() |
33 |
| - ); |
34 | 29 |
|
35 | 30 | public ClickTP() {
|
36 | 31 | super(Categories.Movement, "click-tp", "Teleports you to the block you click on.");
|
37 | 32 | }
|
38 | 33 |
|
39 | 34 | @EventHandler
|
40 | 35 | private void onTick(TickEvent.Post event) {
|
41 |
| - if (mc.player.isUsingItem()) return; |
| 36 | + if (mc.player.getInventory().getSelectedStack().getUseAction() != UseAction.NONE) return; |
| 37 | + if (!mc.options.useKey.isPressed()) return; |
| 38 | + |
| 39 | + if (mc.crosshairTarget != null) { |
| 40 | + if (mc.crosshairTarget.getType() == HitResult.Type.ENTITY && mc.player.interact(((EntityHitResult) mc.crosshairTarget).getEntity(), Hand.MAIN_HAND) != ActionResult.PASS) return; |
| 41 | + if (mc.crosshairTarget.getType() == HitResult.Type.BLOCK && mc.player.getMainHandStack().getItem() instanceof BlockItem) return; |
| 42 | + } |
| 43 | + |
| 44 | + Camera camera = mc.gameRenderer.getCamera(); |
| 45 | + Vec3d cameraPos = camera.getPos(); |
42 | 46 |
|
43 |
| - if (mc.options.useKey.isPressed()) { |
44 |
| - HitResult hitResult = mc.player.raycast(maxDistance.get(), 1f / 20f, false); |
| 47 | + // Calculate the direction the camera is looking based on its pitch and yaw, and extend this direction 210 units away from the camera position |
| 48 | + // 210 is used here as the maximum distance for this exploit is 200 blocks |
| 49 | + // This is done to be able to click tp while in freecam |
| 50 | + Vec3d direction = Vec3d.fromPolar(camera.getPitch(), camera.getYaw()).multiply(210); |
| 51 | + Vec3d targetPos = cameraPos.add(direction); |
45 | 52 |
|
46 |
| - if (hitResult.getType() == HitResult.Type.ENTITY && mc.player.interact(((EntityHitResult) hitResult).getEntity(), Hand.MAIN_HAND) != ActionResult.PASS) return; |
| 53 | + RaycastContext context = new RaycastContext( |
| 54 | + cameraPos, // start position of the ray |
| 55 | + targetPos, // end position of the ray |
| 56 | + RaycastContext.ShapeType.OUTLINE, |
| 57 | + RaycastContext.FluidHandling.NONE, |
| 58 | + mc.player |
| 59 | + ); |
47 | 60 |
|
48 |
| - if (hitResult.getType() == HitResult.Type.BLOCK) { |
49 |
| - BlockPos pos = ((BlockHitResult) hitResult).getBlockPos(); |
50 |
| - Direction side = ((BlockHitResult) hitResult).getSide(); |
| 61 | + BlockHitResult hitResult = mc.world.raycast(context); |
51 | 62 |
|
52 |
| - if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, (BlockHitResult) hitResult) != ActionResult.PASS) return; |
| 63 | + if (hitResult.getType() == HitResult.Type.BLOCK) { |
| 64 | + BlockPos pos = hitResult.getBlockPos(); |
| 65 | + Direction side = hitResult.getSide(); |
53 | 66 |
|
54 |
| - BlockState state = mc.world.getBlockState(pos); |
| 67 | + if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, hitResult) != ActionResult.PASS) return; |
55 | 68 |
|
56 |
| - VoxelShape shape = state.getCollisionShape(mc.world, pos); |
57 |
| - if (shape.isEmpty()) shape = state.getOutlineShape(mc.world, pos); |
| 69 | + BlockState state = mc.world.getBlockState(pos); |
58 | 70 |
|
59 |
| - double height = shape.isEmpty() ? 1 : shape.getMax(Direction.Axis.Y); |
| 71 | + VoxelShape shape = state.getCollisionShape(mc.world, pos); |
| 72 | + if (shape.isEmpty()) shape = state.getOutlineShape(mc.world, pos); |
60 | 73 |
|
61 |
| - mc.player.setPosition(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + height, pos.getZ() + 0.5 + side.getOffsetZ()); |
| 74 | + double height = shape.isEmpty() ? 1 : shape.getMax(Direction.Axis.Y); |
| 75 | + |
| 76 | + Vec3d newPos = new Vec3d(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + height, pos.getZ() + 0.5 + side.getOffsetZ()); |
| 77 | + int packetsRequired = (int) Math.ceil(mc.player.getPos().distanceTo(newPos) / 10) - 1; // subtract 1 to account for the final packet with movement |
| 78 | + if (packetsRequired > 19) packetsRequired = 0; |
| 79 | + |
| 80 | + for (int packetNumber = 0; packetNumber < (packetsRequired); packetNumber++) { |
| 81 | + mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true, true)); |
62 | 82 | }
|
| 83 | + |
| 84 | + mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(newPos.x, newPos.y, newPos.z, true, true)); |
| 85 | + mc.player.setPosition(newPos); |
63 | 86 | }
|
64 | 87 | }
|
65 | 88 | }
|
0 commit comments