1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
package net.justlearning.arslaan3102.arslaansmagichax.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.LinkedList;
import java.util.Queue;
public class HackTP {
private static final Queue<double[]> stepQueue = new LinkedList<>();
public static BlockPos findClosestAirNearPosition(int x, int y, int z) {
World world = MinecraftClient.getInstance().world;
if (world == null) return null;
for (int blockY = y; blockY <= world.getHeight(); blockY++) {
BlockPos pos = new BlockPos(x, blockY, z);
if (world.getBlockState(pos).isAir() && world.getBlockState(pos.up()).isAir()) {
return pos;
}
}
for (int blockY = y; blockY >= 0; blockY--) {
BlockPos pos = new BlockPos(x, blockY, z);
if (world.getBlockState(pos).isAir() && world.getBlockState(pos.up()).isAir()) {
return pos;
}
}
return null;
}
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess access) {
dispatcher.register(ClientCommandManager.literal("hacktp")
.then(ClientCommandManager.argument("x", IntegerArgumentType.integer())
.then(ClientCommandManager.argument("y", IntegerArgumentType.integer())
.then(ClientCommandManager.argument("z", IntegerArgumentType.integer())
.executes(HackTP::run)
)
)
)
);
// ClientTickEvents.END_CLIENT_TICK.register(client -> {
// if (!stepQueue.isEmpty() && client.player != null) {
// double[] pos = stepQueue.poll();
//
// client.getNetworkHandler().sendPacket(
// new PlayerMoveC2SPacket.PositionAndOnGround(pos[0], pos[1], pos[2], true, client.player.horizontalCollision)
// );
//
// client.player.setPos(pos[0], pos[1], pos[2]);
//
// client.player.sendMessage(Text.literal("Teleported to " + pos[0] + " " + pos[1] + " " + pos[2]), false);
// }
// });
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (!stepQueue.isEmpty() && client.player != null) {
int packetsPerTick = 5; // how many packets you want per tick
for (int i = 0; i < packetsPerTick && !stepQueue.isEmpty(); i++) {
double[] pos = stepQueue.poll();
client.getNetworkHandler().sendPacket(
new PlayerMoveC2SPacket.PositionAndOnGround(
pos[0], pos[1], pos[2], true, client.player.horizontalCollision
)
);
client.player.setPos(pos[0], pos[1], pos[2]);
client.player.sendMessage(Text.literal("Teleported to " + pos[0] + " " + pos[1] + " " + pos[2]), false);
}
}
});
}
private static int run(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
int targetX = IntegerArgumentType.getInteger(context, "x");
int targetY = IntegerArgumentType.getInteger(context, "y");
int targetZ = IntegerArgumentType.getInteger(context, "z");
ClientPlayerEntity player = context.getSource().getPlayer();
if (player == null) {
context.getSource().sendFeedback(Text.literal("No player found."));
return -1;
}
double currentX = player.getX();
double currentY = player.getY();
double currentZ = player.getZ();
int stepX = (targetX > currentX) ? 5 : -5;
int stepY = (targetY > currentY) ? 2 : -2;
int stepZ = (targetZ > currentZ) ? 5 : -5;
while ((stepY > 0 && currentY < targetY) || (stepY < 0 && currentY > targetY)) {
currentY += stepY;
if ((stepY > 0 && currentY > targetY) || (stepY < 0 && currentY < targetY)) currentY = targetY;
stepQueue.add(new double[]{currentX, currentY, currentZ});
context.getSource().sendFeedback(Text.literal(
"Queued teleport to " + currentX + " " + currentY + " " + currentZ
));
}
while ((stepX > 0 && currentX < targetX) || (stepX < 0 && currentX > targetX)) {
currentX += stepX;
if ((stepX > 0 && currentX > targetX) || (stepX < 0 && currentX < targetX)) currentX = targetX;
BlockPos airPos = findClosestAirNearPosition((int) currentX, (int) currentY, (int) currentZ);
if (airPos != null) currentY = airPos.getY();
stepQueue.add(new double[]{currentX, currentY, currentZ});
context.getSource().sendFeedback(Text.literal(
"Queued teleport to " + currentX + " " + currentY + " " + currentZ
));
}
while ((stepZ > 0 && currentZ < targetZ) || (stepZ < 0 && currentZ > targetZ)) {
currentZ += stepZ;
if ((stepZ > 0 && currentZ > targetZ) || (stepZ < 0 && currentZ < targetZ)) currentZ = targetZ;
BlockPos airPos = findClosestAirNearPosition((int) currentX, (int) currentY, (int) currentZ);
if (airPos != null) currentY = airPos.getY();
stepQueue.add(new double[]{currentX, currentY, currentZ});
context.getSource().sendFeedback(Text.literal(
"Queued teleport to " + currentX + " " + currentY + " " + currentZ
));
}
context.getSource().sendFeedback(Text.literal(
"Queued teleport to " + targetX + " " + targetY + " " + targetZ
));
return 1;
}
}
|