-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathPacketPlayerPositionAndLook.java
More file actions
93 lines (76 loc) · 2.58 KB
/
Copy pathPacketPlayerPositionAndLook.java
File metadata and controls
93 lines (76 loc) · 2.58 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
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
/*
* Copyright (C) 2020 Nan1t
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ua.nanit.limbo.protocol.packets.play;
import ua.nanit.limbo.protocol.ByteMessage;
import ua.nanit.limbo.protocol.PacketOut;
import ua.nanit.limbo.protocol.registry.Version;
public class PacketPlayerPositionAndLook implements PacketOut {
private double x;
private double y;
private double z;
private float yaw;
private float pitch;
private int teleportId;
public PacketPlayerPositionAndLook() {
}
public PacketPlayerPositionAndLook(double x, double y, double z, float yaw, float pitch, int teleportId) {
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
this.teleportId = teleportId;
}
@Override
public void encode(ByteMessage msg, Version version) {
if (version.moreOrEqual(Version.V1_21_2)) {
encodeModern(msg, version);
return;
}
encodeLegacy(msg, version);
}
private void encodeLegacy(ByteMessage msg, Version version) {
msg.writeDouble(x);
msg.writeDouble(y + (version.less(Version.V1_8) ? 1.62F : 0));
msg.writeDouble(z);
msg.writeFloat(yaw);
msg.writeFloat(pitch);
if (version.moreOrEqual(Version.V1_8)) {
msg.writeByte(0x08);
} else {
msg.writeBoolean(true);
}
if (version.moreOrEqual(Version.V1_9)) {
msg.writeVarInt(teleportId);
}
if (version.fromTo(Version.V1_17, Version.V1_19_3)) {
msg.writeBoolean(false); // Dismount vehicle
}
}
private void encodeModern(ByteMessage msg, Version version) {
msg.writeVarInt(teleportId);
msg.writeDouble(x);
msg.writeDouble(y);
msg.writeDouble(z);
msg.writeDouble(0);
msg.writeDouble(0);
msg.writeDouble(0);
msg.writeFloat(yaw);
msg.writeFloat(pitch);
msg.writeInt(0x08);
}
}