Skip to content

Commit 76335f2

Browse files
committed
1.21.6-pre1
1 parent b958c38 commit 76335f2

6 files changed

Lines changed: 129 additions & 48 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundTransferPacket;
1515
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundUpdateTagsPacket;
1616
import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundClientInformationPacket;
17+
import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundCustomClickActionPacket;
1718
import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket;
1819
import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundKeepAlivePacket;
1920
import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundPongPacket;
@@ -62,6 +63,7 @@
6263
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTickingStepPacket;
6364
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundUpdateAdvancementsPacket;
6465
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundUpdateRecipesPacket;
66+
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket;
6567
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAnimatePacket;
6668
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundDamageEventPacket;
6769
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket;
@@ -96,7 +98,6 @@
9698
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundSetExperiencePacket;
9799
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundSetHealthPacket;
98100
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundSetHeldSlotPacket;
99-
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket;
100101
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerClosePacket;
101102
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetContentPacket;
102103
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetDataPacket;
@@ -159,7 +160,6 @@
159160
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundClientTickEndPacket;
160161
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundCommandSuggestionPacket;
161162
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundConfigurationAcknowledgedPacket;
162-
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundCustomClickActionPacket;
163163
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundDebugSampleSubscriptionPacket;
164164
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundLockDifficultyPacket;
165165
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
@@ -224,8 +224,8 @@
224224

225225
public class MinecraftCodec {
226226
public static final PacketCodec CODEC = PacketCodec.builder()
227-
.protocolVersion((1 << 30) | 250)
228-
.minecraftVersion("25w20a")
227+
.protocolVersion((1 << 30) | 252)
228+
.minecraftVersion("1.21.6-pre1")
229229
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
230230
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
231231
)
@@ -274,6 +274,7 @@ public class MinecraftCodec {
274274
.registerServerboundPacket(ServerboundPongPacket.class, ServerboundPongPacket::new)
275275
.registerServerboundPacket(ServerboundResourcePackPacket.class, ServerboundResourcePackPacket::new)
276276
.registerServerboundPacket(ServerboundSelectKnownPacks.class, ServerboundSelectKnownPacks::new)
277+
.registerServerboundPacket(ServerboundCustomClickActionPacket.class, ServerboundCustomClickActionPacket::new)
277278
).state(ProtocolState.GAME, MinecraftPacketRegistry.builder()
278279
.registerClientboundPacket(ClientboundDelimiterPacket.class, ClientboundDelimiterPacket::new)
279280
.registerClientboundPacket(ClientboundAddEntityPacket.class, ClientboundAddEntityPacket::new)

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,32 @@ public static <T> void writeList(ByteBuf buf, List<T> value, BiConsumer<ByteBuf,
244244
}
245245
}
246246

247+
public static <T> T readLengthPrefixed(ByteBuf buf, int maxLength, Function<ByteBuf, T> reader) {
248+
int length = MinecraftTypes.readVarInt(buf);
249+
if (length > maxLength) {
250+
throw new IllegalArgumentException("Buffer is longer than maximum allowed length");
251+
} else {
252+
return reader.apply(buf);
253+
}
254+
}
255+
256+
public static <T> void writeLengthPrefixed(ByteBuf buf, int maxLength, T value, BiConsumer<ByteBuf, T> writer) {
257+
ByteBuf buf2 = Unpooled.buffer();
258+
259+
try {
260+
writer.accept(buf2, value);
261+
int length = buf2.readableBytes();
262+
if (length > maxLength) {
263+
throw new IllegalArgumentException("Buffer is longer than maximum allowed length");
264+
}
265+
266+
MinecraftTypes.writeVarInt(buf, length);
267+
buf.writeBytes(buf2);
268+
} finally {
269+
buf2.release();
270+
}
271+
}
272+
247273
public static <T> Holder<T> readHolder(ByteBuf buf, Function<ByteBuf, T> readCustom) {
248274
int registryId = MinecraftTypes.readVarInt(buf);
249275
return registryId == 0 ? Holder.ofCustom(readCustom.apply(buf)) : Holder.ofId(registryId - 1);
@@ -482,8 +508,7 @@ public static DataComponents readDataComponentPatch(ByteBuf buf, boolean untrust
482508
if (untrusted) {
483509
for (int k = 0; k < nonNullComponents; k++) {
484510
DataComponentType<?> dataComponentType = DataComponentTypes.read(buf);
485-
MinecraftTypes.readVarInt(buf);
486-
DataComponent<?, ?> dataComponent = dataComponentType.readDataComponent(buf);
511+
DataComponent<?, ?> dataComponent = MinecraftTypes.readLengthPrefixed(buf, Integer.MAX_VALUE, dataComponentType::readDataComponent);
487512
dataComponents.put(dataComponentType, dataComponent);
488513
}
489514
} else {
@@ -525,11 +550,7 @@ public static void writeDataComponentPatch(ByteBuf buf, DataComponents dataCompo
525550
for (DataComponent<?, ?> component : dataComponents.getDataComponents().values()) {
526551
if (component.getValue() != null) {
527552
MinecraftTypes.writeVarInt(buf, component.getType().getId());
528-
529-
ByteBuf buf2 = Unpooled.buffer();
530-
component.write(buf2);
531-
MinecraftTypes.writeVarInt(buf, buf2.readableBytes());
532-
buf.writeBytes(buf2);
553+
MinecraftTypes.writeLengthPrefixed(buf, Integer.MAX_VALUE, component, (buf2, component2) -> component2.write(buf2));
533554
}
534555
}
535556
} else {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ public enum BuiltinSound implements Sound {
773773
ENTITY_HORSE_AMBIENT("entity.horse.ambient"),
774774
ENTITY_HORSE_ANGRY("entity.horse.angry"),
775775
ENTITY_HORSE_ARMOR("entity.horse.armor"),
776+
ITEM_HORSE_ARMOR_UNEQUIP("item.horse_armor.unequip"),
776777
ENTITY_HORSE_BREATHE("entity.horse.breathe"),
777778
ENTITY_HORSE_DEATH("entity.horse.death"),
778779
ENTITY_HORSE_EAT("entity.horse.eat"),
@@ -844,8 +845,9 @@ public enum BuiltinSound implements Sound {
844845
BLOCK_LEAF_LITTER_PLACE("block.leaf_litter.place"),
845846
BLOCK_LEAF_LITTER_HIT("block.leaf_litter.hit"),
846847
BLOCK_LEAF_LITTER_FALL("block.leaf_litter.fall"),
847-
ENTITY_LEASH_KNOT_BREAK("entity.leash_knot.break"),
848-
ENTITY_LEASH_KNOT_PLACE("entity.leash_knot.place"),
848+
ITEM_LEAD_UNTIED("item.lead.untied"),
849+
ITEM_LEAD_TIED("item.lead.tied"),
850+
ITEM_LEAD_BREAK("item.lead.break"),
849851
BLOCK_LEVER_CLICK("block.lever.click"),
850852
ENTITY_LIGHTNING_BOLT_IMPACT("entity.lightning_bolt.impact"),
851853
ENTITY_LIGHTNING_BOLT_THUNDER("entity.lightning_bolt.thunder"),
@@ -859,6 +861,7 @@ public enum BuiltinSound implements Sound {
859861
ENTITY_LLAMA_SPIT("entity.llama.spit"),
860862
ENTITY_LLAMA_STEP("entity.llama.step"),
861863
ENTITY_LLAMA_SWAG("entity.llama.swag"),
864+
ITEM_LLAMA_CARPET_UNEQUIP("item.llama_carpet.unequip"),
862865
ENTITY_MAGMA_CUBE_DEATH_SMALL("entity.magma_cube.death_small"),
863866
BLOCK_LODESTONE_BREAK("block.lodestone.break"),
864867
BLOCK_LODESTONE_STEP("block.lodestone.step"),
@@ -1729,7 +1732,8 @@ public enum BuiltinSound implements Sound {
17291732
ENTITY_ZOMBIE_VILLAGER_STEP("entity.zombie_villager.step"),
17301733
EVENT_MOB_EFFECT_BAD_OMEN("event.mob_effect.bad_omen"),
17311734
EVENT_MOB_EFFECT_TRIAL_OMEN("event.mob_effect.trial_omen"),
1732-
EVENT_MOB_EFFECT_RAID_OMEN("event.mob_effect.raid_omen");
1735+
EVENT_MOB_EFFECT_RAID_OMEN("event.mob_effect.raid_omen"),
1736+
ITEM_SADDLE_UNEQUIP("item.saddle.unequip");
17331737

17341738
private final @NonNull String name;
17351739

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package org.geysermc.mcprotocollib.protocol.packet.common.serverbound;
2+
3+
import io.netty.buffer.ByteBuf;
4+
import io.netty.buffer.ByteBufInputStream;
5+
import io.netty.buffer.ByteBufOutputStream;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Data;
8+
import lombok.With;
9+
import net.kyori.adventure.key.Key;
10+
import org.cloudburstmc.nbt.NBTInputStream;
11+
import org.cloudburstmc.nbt.NBTOutputStream;
12+
import org.cloudburstmc.nbt.NbtMap;
13+
import org.cloudburstmc.nbt.NbtType;
14+
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
15+
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
16+
import org.jetbrains.annotations.Nullable;
17+
18+
import java.io.IOException;
19+
20+
@Data
21+
@With
22+
@AllArgsConstructor
23+
public class ServerboundCustomClickActionPacket implements MinecraftPacket {
24+
private final Key id;
25+
private final @Nullable NbtMap payload;
26+
27+
public ServerboundCustomClickActionPacket(ByteBuf in) {
28+
this.id = MinecraftTypes.readResourceLocation(in);
29+
30+
this.payload = MinecraftTypes.readLengthPrefixed(in, 65536, buf -> {
31+
if (!buf.readBoolean()) return null;
32+
33+
Object tag;
34+
try {
35+
ByteBufInputStream input = new ByteBufInputStream(buf);
36+
37+
int typeId = input.readUnsignedByte();
38+
if (typeId == 0) {
39+
tag = null;
40+
} else {
41+
NbtType<?> type = NbtType.byId(typeId);
42+
43+
tag = new NBTInputStream(input).readValue(type, 16);
44+
}
45+
} catch (IOException e) {
46+
throw new IllegalArgumentException(e);
47+
}
48+
49+
if (tag == null) {
50+
return null;
51+
}
52+
53+
Class<NbtMap> tagClass = NbtType.COMPOUND.getTagClass();
54+
if (!tagClass.isInstance(tag)) {
55+
throw new IllegalArgumentException("Expected tag of type " + tagClass.getName() + " but got " + tag.getClass().getName());
56+
}
57+
58+
return tagClass.cast(tag);
59+
});
60+
}
61+
62+
@Override
63+
public void serialize(ByteBuf out) {
64+
MinecraftTypes.writeResourceLocation(out, this.id);
65+
66+
MinecraftTypes.writeLengthPrefixed(out, 65536, this.payload, (buf, data) -> {
67+
try {
68+
ByteBufOutputStream output = new ByteBufOutputStream(buf);
69+
70+
if (data == null) {
71+
output.writeByte(0);
72+
return;
73+
}
74+
75+
NbtType<?> type = NbtType.byClass(data.getClass());
76+
output.writeByte(type.getId());
77+
78+
new NBTOutputStream(output).writeValue(data, 16);
79+
} catch (IOException e) {
80+
throw new IllegalArgumentException(e);
81+
}
82+
});
83+
}
84+
85+
@Override
86+
public boolean shouldRunOnGameThread() {
87+
return true;
88+
}
89+
}

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

Lines changed: 0 additions & 34 deletions
This file was deleted.
66 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)