-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMoveToLocation.java
More file actions
65 lines (57 loc) · 2.79 KB
/
Copy pathMoveToLocation.java
File metadata and controls
65 lines (57 loc) · 2.79 KB
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
package dev.dfonline.codeclient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.Vec3d;
/**
* Utility for moving the player.
*/
public class MoveToLocation {
private final ClientPlayerEntity player;
public MoveToLocation(ClientPlayerEntity player) {
this.player = player;
}
/**
* Shifts a location, not a player.
* Will not shift more than 9.9 blocks, since the player cannot teleport further than that.
*/
public static Vec3d shiftTowards(Vec3d origin, Vec3d location) {
Vec3d pos = origin.relativize(location);
double maxLength = 9.9;
if (pos.length() > maxLength) {
return origin.add(pos.normalize().multiply(maxLength));
} else {
return location;
}
}
public static void shove(ClientPlayerEntity player, Vec3d location) {
new MoveToLocation(player).teleportTowards(player.getPos(), location);
}
public void setPos(Vec3d pos) {
setPos(pos.x, pos.y, pos.z);
}
public void setPos(double x, double y, double z) {
if (CodeClient.MC.getNetworkHandler() == null) return;
if (new Vec3d(x, y, x).distanceTo(player.getPos()) > 10) {
// I've always done it like this, problems?
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(false, true));
}
this.player.setPos(x, y, z);
this.player.teleport(x, y, z, false);
CodeClient.MC.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(x, y, z, false, true));
}
/**
* Moves the player up to 10 blocks towards `to` from `from`
*/
public void teleportTowards(Vec3d from, Vec3d to) {
setPos(shiftTowards(from, to));
}
}