Skip to content

Commit 8b70285

Browse files
committed
25w32a
1 parent a409aa6 commit 8b70285

6 files changed

Lines changed: 66 additions & 27 deletions

File tree

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@
224224

225225
public class MinecraftCodec {
226226
public static final PacketCodec CODEC = PacketCodec.builder()
227-
.protocolVersion((1 << 30) | 259)
228-
.minecraftVersion("25w31a")
227+
.protocolVersion((1 << 30) | 260)
228+
.minecraftVersion("25w32a")
229229
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
230230
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
231231
)

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftTypes.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,50 @@ public static void writeVec3i(ByteBuf buf, Vector3i vec) {
669669
MinecraftTypes.writeVarInt(buf, vec.getZ());
670670
}
671671

672+
public static Vector3d readLpVec3(ByteBuf buf) {
673+
int first = buf.readUnsignedByte();
674+
if (first == 0) {
675+
return Vector3d.ZERO;
676+
}
677+
678+
int second = buf.readUnsignedByte();
679+
long third = buf.readUnsignedInt();
680+
long packed = third << 16 | second << 8 | first;
681+
double encodedX = packed >> 3 & Short.MAX_VALUE;
682+
double encodedY = packed >> 18 & Short.MAX_VALUE;
683+
double encodedZ = packed >> 33 & Short.MAX_VALUE;
684+
int k = first & 3;
685+
if ((first & 4) == 4) {
686+
k |= MinecraftTypes.readVarInt(buf) << 2;
687+
}
688+
689+
return Vector3d.from((encodedX / 16383.0 - 1.0) * k, (encodedY / 16383.0 - 1.0) * k, (encodedZ / 16383.0 - 1.0) * k);
690+
}
691+
692+
public static void writeLpVec3(ByteBuf buf, Vector3d vec) {
693+
double maxVal = Math.max(Math.abs(vec.getX()), Math.max(Math.abs(vec.getY()), Math.abs(vec.getZ())));
694+
if (maxVal < 1.0E-5F) {
695+
buf.writeByte(0);
696+
return;
697+
}
698+
699+
int scale = (int) Math.ceil(maxVal);
700+
double quantizationFactor = 0.5 / scale;
701+
long encodedX = (long)((vec.getX() * quantizationFactor + 0.5) * 32767.0);
702+
long encodedY = (long)((vec.getY() * quantizationFactor + 0.5) * 32767.0);
703+
long encodedZ = (long)((vec.getZ() * quantizationFactor + 0.5) * 32767.0);
704+
705+
boolean scaleTooLargeForBits = (scale & 3) != scale;
706+
int scaleBits = scaleTooLargeForBits ? scale & 3 | 4 : scale;
707+
long packed = scaleBits | encodedX << 3 | encodedY << 18 | encodedZ << 33;
708+
buf.writeByte((byte)packed);
709+
buf.writeByte((byte)(packed >> 8));
710+
buf.writeInt((int)(packed >> 16));
711+
if (scaleTooLargeForBits) {
712+
MinecraftTypes.writeVarInt(buf, scale >> 2);
713+
}
714+
}
715+
672716
public static Vector3i readPosition(ByteBuf buf) {
673717
long val = buf.readLong();
674718

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/level/particle/ParticleType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public enum ParticleType {
66
BLOCK_MARKER,
77
BUBBLE,
88
CLOUD,
9+
COPPER_FIRE_FLAME,
910
CRIT,
1011
DAMAGE_INDICATOR,
1112
DRAGON_BREATH,

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/entity/ClientboundAddEntityPacket.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.Data;
66
import lombok.NonNull;
77
import lombok.With;
8+
import org.cloudburstmc.math.vector.Vector3d;
89
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
910
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
1011
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;
@@ -31,27 +32,25 @@ public class ClientboundAddEntityPacket implements MinecraftPacket {
3132
private final double x;
3233
private final double y;
3334
private final double z;
35+
private final Vector3d movement;
3436
private final float yaw;
3537
private final float headYaw;
3638
private final float pitch;
37-
private final double motionX;
38-
private final double motionY;
39-
private final double motionZ;
4039

4140
public ClientboundAddEntityPacket(int entityId, @NonNull UUID uuid, @NonNull EntityType type,
4241
double x, double y, double z, float yaw, float pitch, float headYaw) {
43-
this(entityId, uuid, type, EMPTY_DATA, x, y, z, yaw, headYaw, pitch, 0, 0, 0);
42+
this(entityId, uuid, type, EMPTY_DATA, x, y, z, Vector3d.ZERO, yaw, headYaw, pitch);
4443
}
4544

4645
public ClientboundAddEntityPacket(int entityId, @NonNull UUID uuid, @NonNull EntityType type, @NonNull ObjectData data,
4746
double x, double y, double z, float yaw, float pitch, float headYaw) {
48-
this(entityId, uuid, type, data, x, y, z, yaw, headYaw, pitch, 0, 0, 0);
47+
this(entityId, uuid, type, data, x, y, z, Vector3d.ZERO, yaw, headYaw, pitch);
4948
}
5049

5150
public ClientboundAddEntityPacket(int entityId, @NonNull UUID uuid, @NonNull EntityType type,
52-
double x, double y, double z, float yaw, float pitch,
53-
float headYaw, double motionX, double motionY, double motionZ) {
54-
this(entityId, uuid, type, EMPTY_DATA, x, y, z, yaw, headYaw, pitch, motionX, motionY, motionZ);
51+
double x, double y, double z, Vector3d movement, float yaw,
52+
float pitch, float headYaw) {
53+
this(entityId, uuid, type, EMPTY_DATA, x, y, z, movement, yaw, headYaw, pitch);
5554
}
5655

5756
public ClientboundAddEntityPacket(ByteBuf in) {
@@ -61,6 +60,7 @@ public ClientboundAddEntityPacket(ByteBuf in) {
6160
this.x = in.readDouble();
6261
this.y = in.readDouble();
6362
this.z = in.readDouble();
63+
this.movement = MinecraftTypes.readLpVec3(in);
6464
this.pitch = in.readByte() * 360 / 256f;
6565
this.yaw = in.readByte() * 360 / 256f;
6666
this.headYaw = in.readByte() * 360 / 256f;
@@ -83,10 +83,6 @@ public ClientboundAddEntityPacket(ByteBuf in) {
8383
this.data = new GenericObjectData(data);
8484
}
8585
}
86-
87-
this.motionX = in.readShort() / 8000D;
88-
this.motionY = in.readShort() / 8000D;
89-
this.motionZ = in.readShort() / 8000D;
9086
}
9187

9288
@Override
@@ -97,6 +93,7 @@ public void serialize(ByteBuf out) {
9793
out.writeDouble(this.x);
9894
out.writeDouble(this.y);
9995
out.writeDouble(this.z);
96+
MinecraftTypes.writeLpVec3(out, this.movement);
10097
out.writeByte((byte) (this.pitch * 256 / 360));
10198
out.writeByte((byte) (this.yaw * 256 / 360));
10299
out.writeByte((byte) (this.headYaw * 256 / 360));
@@ -115,10 +112,6 @@ public void serialize(ByteBuf out) {
115112
}
116113

117114
MinecraftTypes.writeVarInt(out, data);
118-
119-
out.writeShort((int) (this.motionX * 8000));
120-
out.writeShort((int) (this.motionY * 8000));
121-
out.writeShort((int) (this.motionZ * 8000));
122115
}
123116

124117
@Override

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/entity/ClientboundSetEntityMotionPacket.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import lombok.AllArgsConstructor;
55
import lombok.Data;
66
import lombok.With;
7+
import org.cloudburstmc.math.vector.Vector3d;
78
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
89
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
910

@@ -12,23 +13,17 @@
1213
@AllArgsConstructor
1314
public class ClientboundSetEntityMotionPacket implements MinecraftPacket {
1415
private final int entityId;
15-
private final double motionX;
16-
private final double motionY;
17-
private final double motionZ;
16+
private final Vector3d movement;
1817

1918
public ClientboundSetEntityMotionPacket(ByteBuf in) {
2019
this.entityId = MinecraftTypes.readVarInt(in);
21-
this.motionX = in.readShort() / 8000D;
22-
this.motionY = in.readShort() / 8000D;
23-
this.motionZ = in.readShort() / 8000D;
20+
this.movement = MinecraftTypes.readLpVec3(in);
2421
}
2522

2623
@Override
2724
public void serialize(ByteBuf out) {
2825
MinecraftTypes.writeVarInt(out, this.entityId);
29-
out.writeShort((int) (this.motionX * 8000));
30-
out.writeShort((int) (this.motionY * 8000));
31-
out.writeShort((int) (this.motionZ * 8000));
26+
MinecraftTypes.writeLpVec3(out, this.movement);
3227
}
3328

3429
@Override

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/entity/player/ClientboundPlayerRotationPacket.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@
1111
@AllArgsConstructor
1212
public class ClientboundPlayerRotationPacket implements MinecraftPacket {
1313
private final float yRot;
14+
private final boolean relativeY;
1415
private final float xRot;
16+
private final boolean relativeX;
1517

1618
public ClientboundPlayerRotationPacket(ByteBuf in) {
1719
this.yRot = in.readFloat();
20+
this.relativeY = in.readBoolean();
1821
this.xRot = in.readFloat();
22+
this.relativeX = in.readBoolean();
1923
}
2024

2125
@Override
2226
public void serialize(ByteBuf out) {
2327
out.writeFloat(this.yRot);
28+
out.writeBoolean(this.relativeY);
2429
out.writeFloat(this.xRot);
30+
out.writeBoolean(this.relativeX);
2531
}
2632

2733
@Override

0 commit comments

Comments
 (0)