Skip to content

Commit fdc4bdb

Browse files
authored
Merge pull request #924 from GeyserMC/feature/26.1
Feature/26.1
2 parents 5863712 + d655e01 commit fdc4bdb

37 files changed

Lines changed: 475 additions & 293 deletions

protocol/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
jacoco
66
}
77

8-
version = "1.21.11-1"
8+
version = "26.1-SNAPSHOT"
99
description = "MCProtocolLib is a simple library for communicating with Minecraft clients and servers."
1010

1111
dependencies {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundCommandsPacket;
4040
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundCooldownPacket;
4141
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundCustomChatCompletionsPacket;
42+
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundGameRuleValuesPacket;
43+
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLowDiskSpaceWarningPacket;
4244
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.debug.ClientboundDebugSamplePacket;
4345
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundDeleteChatPacket;
4446
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundDelimiterPacket;
@@ -170,6 +172,7 @@
170172
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundDebugSubscriptionRequestPacket;
171173
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundLockDifficultyPacket;
172174
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
175+
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundSetGameRulePacket;
173176
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket;
174177
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClickPacket;
175178
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
@@ -202,6 +205,7 @@
202205
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundSignUpdatePacket;
203206
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundTeleportToEntityPacket;
204207
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundTestInstanceBlockActionPacket;
208+
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundAttackPacket;
205209
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundChangeGameModePacket;
206210
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
207211
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
@@ -212,6 +216,7 @@
212216
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
213217
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket;
214218
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSetCarriedItemPacket;
219+
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSpectateEntityPacket;
215220
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSwingPacket;
216221
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
217222
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemPacket;
@@ -231,8 +236,8 @@
231236

232237
public class MinecraftCodec {
233238
public static final PacketCodec CODEC = PacketCodec.builder()
234-
.protocolVersion(774)
235-
.minecraftVersion("1.21.11")
239+
.protocolVersion(775)
240+
.minecraftVersion("26.1")
236241
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
237242
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
238243
)
@@ -324,6 +329,7 @@ public class MinecraftCodec {
324329
.registerClientboundPacket(ClientboundExplodePacket.class, ClientboundExplodePacket::new)
325330
.registerClientboundPacket(ClientboundForgetLevelChunkPacket.class, ClientboundForgetLevelChunkPacket::new)
326331
.registerClientboundPacket(ClientboundGameEventPacket.class, ClientboundGameEventPacket::new)
332+
.registerClientboundPacket(ClientboundGameRuleValuesPacket.class, ClientboundGameRuleValuesPacket::new)
327333
.registerClientboundPacket(ClientboundGameTestHighlightPosPacket.class, ClientboundGameTestHighlightPosPacket::new)
328334
.registerClientboundPacket(ClientboundMountScreenOpenPacket.class, ClientboundMountScreenOpenPacket::new)
329335
.registerClientboundPacket(ClientboundHurtAnimationPacket.class, ClientboundHurtAnimationPacket::new)
@@ -334,6 +340,7 @@ public class MinecraftCodec {
334340
.registerClientboundPacket(ClientboundLevelParticlesPacket.class, ClientboundLevelParticlesPacket::new)
335341
.registerClientboundPacket(ClientboundLightUpdatePacket.class, ClientboundLightUpdatePacket::new)
336342
.registerClientboundPacket(ClientboundLoginPacket.class, ClientboundLoginPacket::new)
343+
.registerClientboundPacket(ClientboundLowDiskSpaceWarningPacket.class, ClientboundLowDiskSpaceWarningPacket::new)
337344
.registerClientboundPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataPacket::new)
338345
.registerClientboundPacket(ClientboundMerchantOffersPacket.class, ClientboundMerchantOffersPacket::new)
339346
.registerClientboundPacket(ClientboundMoveEntityPosPacket.class, ClientboundMoveEntityPosPacket::new)
@@ -425,6 +432,7 @@ public class MinecraftCodec {
425432
.registerClientboundPacket(ClientboundClearDialogPacket.class, ClientboundClearDialogPacket::new)
426433
.registerClientboundPacket(ClientboundShowDialogGamePacket.class, ClientboundShowDialogGamePacket::new)
427434
.registerServerboundPacket(ServerboundAcceptTeleportationPacket.class, ServerboundAcceptTeleportationPacket::new)
435+
.registerServerboundPacket(ServerboundAttackPacket.class, ServerboundAttackPacket::new)
428436
.registerServerboundPacket(ServerboundBlockEntityTagQueryPacket.class, ServerboundBlockEntityTagQueryPacket::new)
429437
.registerServerboundPacket(ServerboundSelectBundleItemPacket.class, ServerboundSelectBundleItemPacket::new)
430438
.registerServerboundPacket(ServerboundChangeDifficultyPacket.class, ServerboundChangeDifficultyPacket::new)
@@ -480,10 +488,12 @@ public class MinecraftCodec {
480488
.registerServerboundPacket(ServerboundSetCommandBlockPacket.class, ServerboundSetCommandBlockPacket::new)
481489
.registerServerboundPacket(ServerboundSetCommandMinecartPacket.class, ServerboundSetCommandMinecartPacket::new)
482490
.registerServerboundPacket(ServerboundSetCreativeModeSlotPacket.class, ServerboundSetCreativeModeSlotPacket::new)
491+
.registerServerboundPacket(ServerboundSetGameRulePacket.class, ServerboundSetGameRulePacket::new)
483492
.registerServerboundPacket(ServerboundSetJigsawBlockPacket.class, ServerboundSetJigsawBlockPacket::new)
484493
.registerServerboundPacket(ServerboundSetStructureBlockPacket.class, ServerboundSetStructureBlockPacket::new)
485494
.registerServerboundPacket(ServerboundSetTestBlockPacket.class, ServerboundSetTestBlockPacket::new)
486495
.registerServerboundPacket(ServerboundSignUpdatePacket.class, ServerboundSignUpdatePacket::new)
496+
.registerServerboundPacket(ServerboundSpectateEntityPacket.class, ServerboundSpectateEntityPacket::new)
487497
.registerServerboundPacket(ServerboundSwingPacket.class, ServerboundSwingPacket::new)
488498
.registerServerboundPacket(ServerboundTeleportToEntityPacket.class, ServerboundTeleportToEntityPacket::new)
489499
.registerServerboundPacket(ServerboundTestInstanceBlockActionPacket.class, ServerboundTestInstanceBlockActionPacket::new)

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

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,16 @@
105105
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.StonecutterRecipeDisplay;
106106
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.AnyFuelSlotDisplay;
107107
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.CompositeSlotDisplay;
108+
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.DyedSlotDisplay;
108109
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.EmptySlotDisplay;
109110
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.ItemSlotDisplay;
110111
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.ItemStackSlotDisplay;
112+
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.OnlyWithComponentSlotDisplay;
111113
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.RecipeSlotType;
112114
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay;
113115
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SmithingTrimDemoSlotDisplay;
114116
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.TagSlotDisplay;
117+
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.WithAnyPotionSlotDisplay;
115118
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.WithRemainderSlotDisplay;
116119
import org.geysermc.mcprotocollib.protocol.data.game.statistic.StatisticCategory;
117120
import org.geysermc.mcprotocollib.protocol.data.game.debug.DebugBeeInfo;
@@ -522,6 +525,19 @@ public static void writeItemStack(ByteBuf buf, @NotNull ItemStack item) {
522525
MinecraftTypes.writeOptionalItemStack(buf, item);
523526
}
524527

528+
public static ItemStack readItemStackTemplate(ByteBuf buf) {
529+
int id = MinecraftTypes.readVarInt(buf);
530+
int count = MinecraftTypes.readVarInt(buf);
531+
DataComponents components = MinecraftTypes.readDataComponentPatch(buf, false);
532+
return new ItemStack(id, count, components);
533+
}
534+
535+
public static void writeItemStackTemplate(ByteBuf buf, ItemStack template) {
536+
MinecraftTypes.writeVarInt(buf, template.getId());
537+
MinecraftTypes.writeVarInt(buf, template.getAmount());
538+
MinecraftTypes.writeDataComponentPatch(buf, template.getDataComponentsPatch(), false);
539+
}
540+
525541
@Nullable
526542
public static DataComponents readDataComponentPatch(ByteBuf buf, boolean untrusted) {
527543
int nonNullComponents = MinecraftTypes.readVarInt(buf);
@@ -821,42 +837,6 @@ public static void writePose(ByteBuf buf, Pose pose) {
821837
MinecraftTypes.writeEnum(buf, pose);
822838
}
823839

824-
public static Holder<Key> readChickenVariant(ByteBuf buf) {
825-
if (buf.readBoolean()) {
826-
return Holder.ofId(MinecraftTypes.readVarInt(buf));
827-
} else {
828-
return Holder.ofCustom(MinecraftTypes.readResourceLocation(buf));
829-
}
830-
}
831-
832-
public static void writeChickenVariant(ByteBuf buf, Holder<Key> variant) {
833-
if (variant.isId()) {
834-
buf.writeBoolean(true);
835-
MinecraftTypes.writeVarInt(buf, variant.id());
836-
} else {
837-
buf.writeBoolean(false);
838-
MinecraftTypes.writeResourceLocation(buf, variant.custom());
839-
}
840-
}
841-
842-
public static Holder<Key> readZombieNautilusVariant(ByteBuf buf) {
843-
if (buf.readBoolean()) {
844-
return Holder.ofId(MinecraftTypes.readVarInt(buf));
845-
} else {
846-
return Holder.ofCustom(MinecraftTypes.readResourceLocation(buf));
847-
}
848-
}
849-
850-
public static void writeZombieNautilusVariant(ByteBuf buf, Holder<Key> variant) {
851-
if (variant.isId()) {
852-
buf.writeBoolean(true);
853-
MinecraftTypes.writeVarInt(buf, variant.id());
854-
} else {
855-
buf.writeBoolean(false);
856-
MinecraftTypes.writeResourceLocation(buf, variant.custom());
857-
}
858-
}
859-
860840
public static Holder<PaintingVariant> readPaintingVariant(ByteBuf buf) {
861841
return MinecraftTypes.readHolder(buf, input -> {
862842
return new PaintingVariant(MinecraftTypes.readVarInt(input), MinecraftTypes.readVarInt(input), MinecraftTypes.readResourceLocation(input),
@@ -1053,7 +1033,7 @@ public static ParticleData readParticleData(ByteBuf buf, ParticleType type) {
10531033
yield new SpellParticleData(color, power);
10541034
}
10551035
case ENTITY_EFFECT, TINTED_LEAVES, FLASH -> new ColorParticleData(buf.readInt());
1056-
case ITEM -> new ItemParticleData(MinecraftTypes.readItemStack(buf));
1036+
case ITEM -> new ItemParticleData(MinecraftTypes.readItemStackTemplate(buf));
10571037
case SCULK_CHARGE -> new SculkChargeParticleData(buf.readFloat());
10581038
case SHRIEK -> new ShriekParticleData(MinecraftTypes.readVarInt(buf));
10591039
case TRAIL -> new TrailParticleData(Vector3d.from(buf.readDouble(), buf.readDouble(), buf.readDouble()), buf.readInt(), MinecraftTypes.readVarInt(buf));
@@ -1433,13 +1413,15 @@ public static SlotDisplay readSlotDisplay(ByteBuf buf) {
14331413
switch (type) {
14341414
case EMPTY -> display = EmptySlotDisplay.INSTANCE;
14351415
case ANY_FUEL -> display = new AnyFuelSlotDisplay();
1416+
case WITH_ANY_POTION -> display = new WithAnyPotionSlotDisplay(MinecraftTypes.readSlotDisplay(buf));
1417+
case ONLY_WITH_COMPONENT -> display = new OnlyWithComponentSlotDisplay(MinecraftTypes.readSlotDisplay(buf),
1418+
DataComponentTypes.from(MinecraftTypes.readVarInt(buf)));
14361419
case ITEM -> display = new ItemSlotDisplay(MinecraftTypes.readVarInt(buf));
1437-
case ITEM_STACK -> display = new ItemStackSlotDisplay(MinecraftTypes.readItemStack(buf));
1420+
case ITEM_STACK -> display = new ItemStackSlotDisplay(MinecraftTypes.readItemStackTemplate(buf));
14381421
case TAG -> display = new TagSlotDisplay(MinecraftTypes.readResourceLocation(buf));
1439-
case SMITHING_TRIM -> {
1440-
display = new SmithingTrimDemoSlotDisplay(MinecraftTypes.readSlotDisplay(buf), MinecraftTypes.readSlotDisplay(buf),
1441-
MinecraftTypes.readHolder(buf, ItemTypes::readTrimPattern));
1442-
}
1422+
case DYED -> display = new DyedSlotDisplay(MinecraftTypes.readSlotDisplay(buf), MinecraftTypes.readSlotDisplay(buf));
1423+
case SMITHING_TRIM -> display = new SmithingTrimDemoSlotDisplay(MinecraftTypes.readSlotDisplay(buf), MinecraftTypes.readSlotDisplay(buf),
1424+
MinecraftTypes.readHolder(buf, ItemTypes::readTrimPattern));
14431425
case WITH_REMAINDER -> display = new WithRemainderSlotDisplay(MinecraftTypes.readSlotDisplay(buf), MinecraftTypes.readSlotDisplay(buf));
14441426
case COMPOSITE -> display = new CompositeSlotDisplay(MinecraftTypes.readList(buf, MinecraftTypes::readSlotDisplay));
14451427
default -> throw new IllegalStateException("Unexpected value: " + type);
@@ -1450,9 +1432,22 @@ public static SlotDisplay readSlotDisplay(ByteBuf buf) {
14501432
public static void writeSlotDisplay(ByteBuf buf, SlotDisplay display) {
14511433
MinecraftTypes.writeVarInt(buf, display.getType().ordinal());
14521434
switch (display.getType()) {
1435+
case WITH_ANY_POTION -> MinecraftTypes.writeSlotDisplay(buf, ((WithAnyPotionSlotDisplay)display).display());
1436+
case ONLY_WITH_COMPONENT -> {
1437+
OnlyWithComponentSlotDisplay onlyWithComponentSlotDisplay = (OnlyWithComponentSlotDisplay) display;
1438+
1439+
MinecraftTypes.writeSlotDisplay(buf, onlyWithComponentSlotDisplay.source());
1440+
MinecraftTypes.writeVarInt(buf, onlyWithComponentSlotDisplay.component().getId());
1441+
}
14531442
case ITEM -> MinecraftTypes.writeVarInt(buf, ((ItemSlotDisplay)display).item());
1454-
case ITEM_STACK -> MinecraftTypes.writeItemStack(buf, ((ItemStackSlotDisplay)display).itemStack());
1443+
case ITEM_STACK -> MinecraftTypes.writeItemStackTemplate(buf, ((ItemStackSlotDisplay)display).itemStack());
14551444
case TAG -> MinecraftTypes.writeResourceLocation(buf, ((TagSlotDisplay)display).tag());
1445+
case DYED -> {
1446+
DyedSlotDisplay dyedSlotDisplay = (DyedSlotDisplay) display;
1447+
1448+
MinecraftTypes.writeSlotDisplay(buf, dyedSlotDisplay.dye());
1449+
MinecraftTypes.writeSlotDisplay(buf, dyedSlotDisplay.target());
1450+
}
14561451
case SMITHING_TRIM -> {
14571452
SmithingTrimDemoSlotDisplay smithingSlotDisplay = (SmithingTrimDemoSlotDisplay) display;
14581453

@@ -1783,14 +1778,16 @@ private static Palette readPalette(ByteBuf buf, PaletteType paletteType, int bit
17831778

17841779
public static ChunkSection readChunkSection(ByteBuf buf, int blockStateRegistrySize, int biomeRegistrySize) {
17851780
int blockCount = buf.readShort();
1781+
int fluidCount = buf.readShort();
17861782

17871783
DataPalette blockStatePalette = MinecraftTypes.readDataPalette(buf, PaletteType.BLOCK_STATE, blockStateRegistrySize);
17881784
DataPalette biomePalette = MinecraftTypes.readDataPalette(buf, PaletteType.BIOME, biomeRegistrySize);
1789-
return new ChunkSection(blockCount, blockStatePalette, biomePalette);
1785+
return new ChunkSection(blockCount, fluidCount, blockStatePalette, biomePalette);
17901786
}
17911787

17921788
public static void writeChunkSection(ByteBuf buf, ChunkSection section) {
17931789
buf.writeShort(section.getBlockCount());
1790+
buf.writeShort(section.getFluidCount());
17941791
MinecraftTypes.writeDataPalette(buf, section.getBlockData());
17951792
MinecraftTypes.writeDataPalette(buf, section.getBiomeData());
17961793
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ClientCommand.java

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

33
public enum ClientCommand {
4-
RESPAWN,
5-
STATS;
4+
PERFORM_RESPAWN,
5+
REQUEST_STATS,
6+
REQUEST_GAMERULE_VALUES;
67

78
private static final ClientCommand[] VALUES = values();
89

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/advancement/Advancement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public Advancement(@NonNull String id, @NonNull List<List<String>> requirements,
3535
public static class DisplayData {
3636
private final @NonNull Component title;
3737
private final @NonNull Component description;
38-
private final @Nullable ItemStack icon;
38+
private final @NonNull ItemStack icon;
3939
private final @NonNull AdvancementType advancementType;
4040
private final boolean showToast;
4141
private final boolean hidden;
4242
private final float posX;
4343
private final float posY;
4444
private final @Nullable String backgroundTexture;
4545

46-
public DisplayData(@NonNull Component title, @NonNull Component description, @Nullable ItemStack icon, @NonNull AdvancementType advancementType,
46+
public DisplayData(@NonNull Component title, @NonNull Component description, @NonNull ItemStack icon, @NonNull AdvancementType advancementType,
4747
boolean showToast, boolean hidden, float posX, float posY) {
4848
this(title, description, icon, advancementType, showToast, hidden, posX, posY, null);
4949
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chunk/ChunkSection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ public class ChunkSection {
1717
private static final int AIR = 0;
1818

1919
private int blockCount;
20+
private int fluidCount;
2021
private @NonNull DataPalette blockData;
2122
@Getter
2223
private @NonNull DataPalette biomeData;
2324

2425
public ChunkSection(int initialBlockState, int blockStateRegistrySize, int initialBiome, int biomeRegistrySize) {
25-
this(0, DataPalette.createForBlockState(initialBlockState, blockStateRegistrySize), DataPalette.createForBiome(initialBiome, biomeRegistrySize));
26+
this(0, 0, DataPalette.createForBlockState(initialBlockState, blockStateRegistrySize), DataPalette.createForBiome(initialBiome, biomeRegistrySize));
2627
}
2728

2829
public ChunkSection(ChunkSection original) {
29-
this(original.blockCount, new DataPalette(original.blockData), new DataPalette(original.biomeData));
30+
this(original.blockCount, original.fluidCount, new DataPalette(original.blockData), new DataPalette(original.biomeData));
3031
}
3132

3233
public int getBlock(int x, int y, int z) {

0 commit comments

Comments
 (0)