Skip to content

Commit 7f7445f

Browse files
committed
24w36a
1 parent 2f2a2e2 commit 7f7445f

File tree

10 files changed

+127
-56
lines changed

10 files changed

+127
-56
lines changed

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
@@ -210,9 +210,9 @@
210210

211211
public class MinecraftCodec {
212212
public static final PacketCodec CODEC = PacketCodec.builder()
213-
.protocolVersion((1 << 30) | 207)
213+
.protocolVersion((1 << 30) | 208)
214214
.helper(MinecraftCodecHelper::new)
215-
.minecraftVersion("24w35a")
215+
.minecraftVersion("24w36a")
216216
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
217217
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
218218
)

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/player/PositionElement.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ public enum PositionElement {
44
X,
55
Y,
66
Z,
7-
PITCH,
8-
YAW;
7+
Y_ROT,
8+
X_ROT,
9+
DELTA_X,
10+
DELTA_Y,
11+
DELTA_Z,
12+
ROTATE_DELTA;
913

1014
private static final PositionElement[] VALUES = values();
1115

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
22

3-
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
43
import net.kyori.adventure.key.Key;
54
import net.kyori.adventure.text.Component;
65
import org.geysermc.mcprotocollib.protocol.data.game.Holder;
76

7+
import java.util.Map;
8+
89
public record ArmorTrim(Holder<TrimMaterial> material, Holder<TrimPattern> pattern, boolean showInTooltip) {
910
public record TrimMaterial(String assetName, int ingredientId, float itemModelIndex,
10-
Int2ObjectMap<String> overrideArmorMaterials, Component description) {
11+
Map<Key, String> overrideArmorMaterials, Component description) {
1112
}
1213

1314
public record TrimPattern(Key assetId, int templateItemId, Component description, boolean decal) {

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class DataComponentType<T> {
2828
public static final BooleanComponentType UNBREAKABLE = new BooleanComponentType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanDataComponent::new);
2929
public static final DataComponentType<Component> CUSTOM_NAME = new DataComponentType<>(ItemCodecHelper::readComponent, ItemCodecHelper::writeComponent, ObjectDataComponent::new);
3030
public static final DataComponentType<Component> ITEM_NAME = new DataComponentType<>(ItemCodecHelper::readComponent, ItemCodecHelper::writeComponent, ObjectDataComponent::new);
31+
public static final DataComponentType<Key> ITEM_MODEL = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new);
3132
public static final DataComponentType<List<Component>> LORE = new DataComponentType<>(listReader(ItemCodecHelper::readComponent), listWriter(ItemCodecHelper::writeComponent), ObjectDataComponent::new);
3233
public static final IntComponentType RARITY = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
3334
public static final DataComponentType<ItemEnchantments> ENCHANTMENTS = new DataComponentType<>(ItemCodecHelper::readItemEnchantments, ItemCodecHelper::writeItemEnchantments, ObjectDataComponent::new);
@@ -48,7 +49,10 @@ public class DataComponentType<T> {
4849
public static final DataComponentType<Unit> FIRE_RESISTANT = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
4950
public static final DataComponentType<ToolData> TOOL = new DataComponentType<>(ItemCodecHelper::readToolData, ItemCodecHelper::writeToolData, ObjectDataComponent::new);
5051
public static final IntComponentType ENCHANTABLE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
52+
public static final DataComponentType<Equippable> EQUIPPABLE = new DataComponentType<>(ItemCodecHelper::readEquippable, ItemCodecHelper::writeEquippable, ObjectDataComponent::new);
5153
public static final DataComponentType<HolderSet> REPAIRABLE = new DataComponentType<>(ItemCodecHelper::readHolderSet, ItemCodecHelper::writeHolderSet, ObjectDataComponent::new);
54+
public static final DataComponentType<Unit> GLIDER = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
55+
public static final DataComponentType<Key> TOOLTIP_STYLE = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new);
5256
public static final DataComponentType<ItemEnchantments> STORED_ENCHANTMENTS = new DataComponentType<>(ItemCodecHelper::readItemEnchantments, ItemCodecHelper::writeItemEnchantments, ObjectDataComponent::new);
5357
public static final DataComponentType<DyedItemColor> DYED_COLOR = new DataComponentType<>(ItemCodecHelper::readDyedItemColor, ItemCodecHelper::writeDyedItemColor, ObjectDataComponent::new);
5458
public static final IntComponentType MAP_COLOR = new IntComponentType((helper, input) -> input.readInt(), (helper, output, value) -> output.writeInt(value), IntDataComponent::new);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
2+
3+
import net.kyori.adventure.key.Key;
4+
import org.checkerframework.checker.nullness.qual.Nullable;
5+
import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot;
6+
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
7+
8+
public record Equippable(EquipmentSlot slot, Sound equipSound, @Nullable Key model, @Nullable HolderSet allowedEntities, boolean dispensable) {
9+
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
1212
import org.geysermc.mcprotocollib.protocol.data.game.Holder;
1313
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
14+
import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot;
1415
import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation;
1516
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
1617
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound;
@@ -165,6 +166,29 @@ public void writeToolData(ByteBuf buf, ToolData data) {
165166
this.writeVarInt(buf, data.getDamagePerBlock());
166167
}
167168

169+
public Equippable readEquippable(ByteBuf buf) {
170+
EquipmentSlot slot = EquipmentSlot.from(this.readVarInt(buf));
171+
Sound equipSound = this.readById(buf, BuiltinSound::from, this::readSoundEvent);
172+
Key model = this.readNullable(buf, this::readResourceLocation);
173+
HolderSet allowedEntities = this.readNullable(buf, this::readHolderSet);
174+
boolean dispensable = buf.readBoolean();
175+
return new Equippable(slot, equipSound, model, allowedEntities, dispensable);
176+
}
177+
178+
public void writeEquippable(ByteBuf buf, Equippable equippable) {
179+
this.writeVarInt(buf, equippable.slot().ordinal());
180+
if (equippable.equipSound() instanceof CustomSound) {
181+
this.writeVarInt(buf, 0);
182+
this.writeSoundEvent(buf, equippable.equipSound());
183+
} else {
184+
this.writeVarInt(buf, ((BuiltinSound) equippable.equipSound()).ordinal() + 1);
185+
}
186+
187+
this.writeNullable(buf, equippable.model(), this::writeResourceLocation);
188+
this.writeNullable(buf, equippable.allowedEntities(), this::writeHolderSet);
189+
buf.writeBoolean(equippable.dispensable());
190+
}
191+
168192
public ItemAttributeModifiers readItemAttributeModifiers(ByteBuf buf) {
169193
List<ItemAttributeModifiers.Entry> modifiers = this.readList(buf, (input) -> {
170194
int attribute = this.readVarInt(input);
@@ -409,10 +433,10 @@ public ArmorTrim.TrimMaterial readTrimMaterial(ByteBuf buf) {
409433
int ingredientId = this.readVarInt(buf);
410434
float itemModelIndex = buf.readFloat();
411435

412-
Int2ObjectMap<String> overrideArmorMaterials = new Int2ObjectOpenHashMap<>();
436+
Map<Key, String> overrideArmorMaterials = new HashMap<>();
413437
int overrideCount = this.readVarInt(buf);
414438
for (int i = 0; i < overrideCount; i++) {
415-
overrideArmorMaterials.put(this.readVarInt(buf), this.readString(buf));
439+
overrideArmorMaterials.put(this.readResourceLocation(buf), this.readString(buf));
416440
}
417441

418442
Component description = this.readComponent(buf);
@@ -425,8 +449,8 @@ public void writeTrimMaterial(ByteBuf buf, ArmorTrim.TrimMaterial material) {
425449
buf.writeFloat(material.itemModelIndex());
426450

427451
this.writeVarInt(buf, material.overrideArmorMaterials().size());
428-
for (Int2ObjectMap.Entry<String> entry : material.overrideArmorMaterials().int2ObjectEntrySet()) {
429-
this.writeVarInt(buf, entry.getIntKey());
452+
for (Map.Entry<Key, String> entry : material.overrideArmorMaterials().entrySet()) {
453+
this.writeResourceLocation(buf, entry.getKey());
430454
this.writeString(buf, entry.getValue());
431455
}
432456

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/level/sound/BuiltinSound.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ public enum BuiltinSound implements Sound {
625625
ENTITY_GOAT_PREPARE_RAM("entity.goat.prepare_ram"),
626626
ENTITY_GOAT_RAM_IMPACT("entity.goat.ram_impact"),
627627
ENTITY_GOAT_HORN_BREAK("entity.goat.horn_break"),
628-
ITEM_GOAT_HORN_PLAY("item.goat_horn.play"),
629628
ENTITY_GOAT_SCREAMING_AMBIENT("entity.goat.screaming.ambient"),
630629
ENTITY_GOAT_SCREAMING_DEATH("entity.goat.screaming.death"),
631630
ENTITY_GOAT_SCREAMING_EAT("entity.goat.screaming.eat"),
@@ -634,7 +633,6 @@ public enum BuiltinSound implements Sound {
634633
ENTITY_GOAT_SCREAMING_MILK("entity.goat.screaming.milk"),
635634
ENTITY_GOAT_SCREAMING_PREPARE_RAM("entity.goat.screaming.prepare_ram"),
636635
ENTITY_GOAT_SCREAMING_RAM_IMPACT("entity.goat.screaming.ram_impact"),
637-
ENTITY_GOAT_SCREAMING_HORN_BREAK("entity.goat.screaming.horn_break"),
638636
ENTITY_GOAT_STEP("entity.goat.step"),
639637
BLOCK_GRASS_BREAK("block.grass.break"),
640638
BLOCK_GRASS_FALL("block.grass.fall"),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public ClientboundSetEquipmentPacket(ByteBuf in, MinecraftCodecHelper helper) {
2626
boolean hasNextEntry = true;
2727
List<Equipment> list = new ArrayList<>();
2828
while (hasNextEntry) {
29-
int rawSlot = in.readByte();
30-
EquipmentSlot slot = EquipmentSlot.from(((byte) rawSlot) & 127);
29+
byte rawSlot = in.readByte();
30+
EquipmentSlot slot = EquipmentSlot.from(rawSlot & 127);
3131
ItemStack item = helper.readOptionalItemStack(in);
3232
list.add(new Equipment(slot, item));
3333
hasNextEntry = (rawSlot & 128) == 128;

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

Lines changed: 31 additions & 27 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.MinecraftCodecHelper;
910
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
1011
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PositionElement;
@@ -17,52 +18,55 @@
1718
@With
1819
@AllArgsConstructor
1920
public class ClientboundPlayerPositionPacket implements MinecraftPacket {
20-
private final double x;
21-
private final double y;
22-
private final double z;
23-
private final float yaw;
24-
private final float pitch;
25-
private final int teleportId;
26-
private final @NonNull List<PositionElement> relative;
21+
private final int id;
22+
private final Vector3d position;
23+
private final Vector3d deltaMovement;
24+
private final float yRot;
25+
private final float xRot;
26+
private final @NonNull List<PositionElement> relativeArguments;
2727

28-
public ClientboundPlayerPositionPacket(double x, double y, double z, float yaw, float pitch, int teleportId, PositionElement... relative) {
29-
this(x, y, z, yaw, pitch, teleportId, Arrays.asList(relative != null ? relative : new PositionElement[0]));
28+
public ClientboundPlayerPositionPacket(int id, double x, double y, double z, double dX, double dY, double dZ, float yRot, float xRot, PositionElement... relative) {
29+
this(id, Vector3d.from(x, y, z), Vector3d.from(dX, dY, dZ), yRot, xRot, Arrays.asList(relative != null ? relative : new PositionElement[0]));
3030
}
3131

3232
public ClientboundPlayerPositionPacket(ByteBuf in, MinecraftCodecHelper helper) {
33-
this.x = in.readDouble();
34-
this.y = in.readDouble();
35-
this.z = in.readDouble();
36-
this.yaw = in.readFloat();
37-
this.pitch = in.readFloat();
33+
this.id = helper.readVarInt(in);
34+
this.position = Vector3d.from(in.readDouble(), in.readDouble(), in.readDouble());
35+
this.deltaMovement = Vector3d.from(in.readDouble(), in.readDouble(), in.readDouble());
36+
this.yRot = in.readByte() * 360 / 256F;
37+
this.xRot = in.readByte() * 360 / 256F;
3838

39-
this.relative = new ArrayList<>();
40-
int flags = in.readUnsignedByte();
39+
this.relativeArguments = new ArrayList<>();
40+
int flags = in.readInt();
4141
for (PositionElement element : PositionElement.values()) {
4242
int bit = 1 << element.ordinal();
4343
if ((flags & bit) == bit) {
44-
this.relative.add(element);
44+
this.relativeArguments.add(element);
4545
}
4646
}
4747

48-
this.teleportId = helper.readVarInt(in);
4948
}
5049

5150
@Override
5251
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
53-
out.writeDouble(this.x);
54-
out.writeDouble(this.y);
55-
out.writeDouble(this.z);
56-
out.writeFloat(this.yaw);
57-
out.writeFloat(this.pitch);
52+
helper.writeVarInt(out, this.id);
53+
out.writeDouble(this.position.getX());
54+
out.writeDouble(this.position.getY());
55+
out.writeDouble(this.position.getZ());
56+
out.writeDouble(this.deltaMovement.getX());
57+
out.writeDouble(this.deltaMovement.getY());
58+
out.writeDouble(this.deltaMovement.getZ());
59+
60+
float yRot = this.yRot * 256F / 360F;
61+
out.writeByte(yRot < (int)yRot ? (int)yRot - 1 : (int)yRot);
62+
float xRot = this.xRot * 256F / 360F;
63+
out.writeByte(xRot < (int)xRot ? (int)xRot - 1 : (int)xRot);
5864

5965
int flags = 0;
60-
for (PositionElement element : this.relative) {
66+
for (PositionElement element : this.relativeArguments) {
6167
flags |= 1 << element.ordinal();
6268
}
6369

64-
out.writeByte(flags);
65-
66-
helper.writeVarInt(out, this.teleportId);
70+
out.writeInt(flags);
6771
}
6872
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/serverbound/level/ServerboundPlayerInputPacket.java

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,62 @@
1111
@With
1212
@AllArgsConstructor
1313
public class ServerboundPlayerInputPacket implements MinecraftPacket {
14-
private static final int FLAG_JUMP = 0x01;
15-
private static final int FLAG_DISMOUNT = 0x02;
14+
private static final byte FLAG_FORWARD = 0x01;
15+
private static final byte FLAG_BACKWARD = 0x02;
16+
private static final byte FLAG_LEFT = 0x04;
17+
private static final byte FLAG_RIGHT = 0x08;
18+
private static final byte FLAG_JUMP = 0x10;
19+
private static final byte FLAG_SHIFT = 0x20;
20+
private static final byte FLAG_SPRINT = 0x40;
1621

17-
private final float sideways;
18-
private final float forward;
22+
private final boolean forward;
23+
private final boolean backward;
24+
private final boolean left;
25+
private final boolean right;
1926
private final boolean jump;
20-
private final boolean dismount;
27+
private final boolean shift;
28+
private final boolean sprint;
2129

2230
public ServerboundPlayerInputPacket(ByteBuf in, MinecraftCodecHelper helper) {
23-
this.sideways = in.readFloat();
24-
this.forward = in.readFloat();
25-
26-
int flags = in.readUnsignedByte();
31+
byte flags = in.readByte();
32+
this.forward = (flags & FLAG_FORWARD) != 0;
33+
this.backward = (flags & FLAG_BACKWARD) != 0;
34+
this.left = (flags & FLAG_LEFT) != 0;
35+
this.right = (flags & FLAG_RIGHT) != 0;
2736
this.jump = (flags & FLAG_JUMP) != 0;
28-
this.dismount = (flags & FLAG_DISMOUNT) != 0;
37+
this.shift = (flags & FLAG_SHIFT) != 0;
38+
this.sprint = (flags & FLAG_SPRINT) != 0;
2939
}
3040

3141
@Override
3242
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
33-
out.writeFloat(this.sideways);
34-
out.writeFloat(this.forward);
43+
byte flags = 0;
44+
if (this.forward) {
45+
flags |= FLAG_FORWARD;
46+
}
47+
48+
if (this.backward) {
49+
flags |= FLAG_BACKWARD;
50+
}
51+
52+
if (this.left) {
53+
flags |= FLAG_LEFT;
54+
}
55+
56+
if (this.right) {
57+
flags |= FLAG_RIGHT;
58+
}
3559

36-
int flags = 0;
3760
if (this.jump) {
3861
flags |= FLAG_JUMP;
3962
}
4063

41-
if (this.dismount) {
42-
flags |= FLAG_DISMOUNT;
64+
if (this.shift) {
65+
flags |= FLAG_SHIFT;
66+
}
67+
68+
if (this.sprint) {
69+
flags |= FLAG_SPRINT;
4370
}
4471

4572
out.writeByte(flags);

0 commit comments

Comments
 (0)