From ea231bf52e7982a2ffc9733aaa5a3953deccb9b8 Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 14 Jul 2021 16:26:32 +0200 Subject: [PATCH] Add 1.17.1 support --- .../net/minestom/server/MinecraftServer.java | 4 ++-- .../net/minestom/server/entity/Entity.java | 2 +- .../net/minestom/server/entity/Player.java | 6 ++--- .../server/listener/WindowListener.java | 2 +- .../client/play/ClientClickWindowPacket.java | 3 +++ .../packet/server/ServerPacketIdentifier.java | 2 +- ...Packet.java => DestroyEntitiesPacket.java} | 19 +++++++-------- .../packet/server/play/SetSlotPacket.java | 3 +++ .../packet/server/play/WindowItemsPacket.java | 24 ++++++++++++------- 9 files changed, 38 insertions(+), 27 deletions(-) rename src/main/java/net/minestom/server/network/packet/server/play/{DestroyEntityPacket.java => DestroyEntitiesPacket.java} (56%) diff --git a/src/main/java/net/minestom/server/MinecraftServer.java b/src/main/java/net/minestom/server/MinecraftServer.java index ea9344106..a90a08b8f 100644 --- a/src/main/java/net/minestom/server/MinecraftServer.java +++ b/src/main/java/net/minestom/server/MinecraftServer.java @@ -66,8 +66,8 @@ public final class MinecraftServer { public final static Logger LOGGER = LoggerFactory.getLogger(MinecraftServer.class); - public static final String VERSION_NAME = "1.17"; - public static final int PROTOCOL_VERSION = 755; + public static final String VERSION_NAME = "1.17.1"; + public static final int PROTOCOL_VERSION = 756; // Threads public static final String THREAD_NAME_BENCHMARK = "Ms-Benchmark"; diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 006dd207b..04029d7ad 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -371,7 +371,7 @@ public class Entity implements Viewable, Tickable, EventHandler, Da if (!viewers.remove(player)) { return false; } - player.getPlayerConnection().sendPacket(DestroyEntityPacket.of(getEntityId())); + player.getPlayerConnection().sendPacket(new DestroyEntitiesPacket(getEntityId())); player.viewableEntities.remove(this); return true; } diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index c58e8f685..9422e34eb 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -1140,7 +1140,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, if (instance == null) return; - DestroyEntityPacket destroyEntityPacket = DestroyEntityPacket.of(getEntityId()); + DestroyEntitiesPacket destroyEntitiesPacket = new DestroyEntitiesPacket(getEntityId()); final PlayerInfoPacket removePlayerPacket = getRemovePlayerToList(); final PlayerInfoPacket addPlayerPacket = getAddPlayerToList(); @@ -1151,14 +1151,14 @@ public class Player extends LivingEntity implements CommandSender, Localizable, respawnPacket.isFlat = levelFlat; playerConnection.sendPacket(removePlayerPacket); - playerConnection.sendPacket(destroyEntityPacket); + playerConnection.sendPacket(destroyEntitiesPacket); playerConnection.sendPacket(respawnPacket); playerConnection.sendPacket(addPlayerPacket); { // Remove player sendPacketToViewers(removePlayerPacket); - sendPacketToViewers(destroyEntityPacket); + sendPacketToViewers(destroyEntitiesPacket); // Show player again getViewers().forEach(player -> showPlayer(player.getPlayerConnection())); diff --git a/src/main/java/net/minestom/server/listener/WindowListener.java b/src/main/java/net/minestom/server/listener/WindowListener.java index 142dfebaa..41f99f464 100644 --- a/src/main/java/net/minestom/server/listener/WindowListener.java +++ b/src/main/java/net/minestom/server/listener/WindowListener.java @@ -18,7 +18,7 @@ import java.util.Objects; public class WindowListener { public static void clickWindowListener(ClientClickWindowPacket packet, Player player) { - final byte windowId = packet.windowId; + final int windowId = packet.windowId; final AbstractInventory inventory = windowId == 0 ? player.getInventory() : player.getOpenInventory(); if (inventory == null) { // Invalid packet diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowPacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowPacket.java index 45f981e71..fe762a408 100644 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientClickWindowPacket.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.NotNull; public class ClientClickWindowPacket extends ClientPlayPacket { public byte windowId; + public int stateId; public short slot; public byte button; public ClickType clickType = ClickType.PICKUP; @@ -20,6 +21,7 @@ public class ClientClickWindowPacket extends ClientPlayPacket { @Override public void read(@NotNull BinaryReader reader) { this.windowId = reader.readByte(); + this.stateId = reader.readVarInt(); this.slot = reader.readShort(); this.button = reader.readByte(); this.clickType = ClickType.values()[reader.readVarInt()]; @@ -37,6 +39,7 @@ public class ClientClickWindowPacket extends ClientPlayPacket { @Override public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); + writer.writeVarInt(stateId); writer.writeShort(slot); writer.writeByte(button); writer.writeVarInt(clickType.ordinal()); diff --git a/src/main/java/net/minestom/server/network/packet/server/ServerPacketIdentifier.java b/src/main/java/net/minestom/server/network/packet/server/ServerPacketIdentifier.java index 5bc03c9e7..41ef029a4 100644 --- a/src/main/java/net/minestom/server/network/packet/server/ServerPacketIdentifier.java +++ b/src/main/java/net/minestom/server/network/packet/server/ServerPacketIdentifier.java @@ -66,7 +66,7 @@ public class ServerPacketIdentifier { public static final int FACE_PLAYER = 0x37; public static final int PLAYER_POSITION_AND_LOOK = 0x38; public static final int UNLOCK_RECIPES = 0x39; - public static final int DESTROY_ENTITY = 0x3A; + public static final int DESTROY_ENTITIES = 0x3A; public static final int REMOVE_ENTITY_EFFECT = 0x3B; public static final int RESOURCE_PACK_SEND = 0x3C; public static final int RESPAWN = 0x3D; diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DestroyEntityPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DestroyEntitiesPacket.java similarity index 56% rename from src/main/java/net/minestom/server/network/packet/server/play/DestroyEntityPacket.java rename to src/main/java/net/minestom/server/network/packet/server/play/DestroyEntitiesPacket.java index d13fbc468..06efdc9d7 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DestroyEntityPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DestroyEntitiesPacket.java @@ -6,31 +6,30 @@ import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; import org.jetbrains.annotations.NotNull; -public class DestroyEntityPacket implements ServerPacket { +public class DestroyEntitiesPacket implements ServerPacket { - public int entityId; + public int[] entityIds; - public DestroyEntityPacket() { + public DestroyEntitiesPacket(int[] entityIds) { + this.entityIds = entityIds; } - public static DestroyEntityPacket of(int entityId) { - DestroyEntityPacket packet = new DestroyEntityPacket(); - packet.entityId = entityId; - return packet; + public DestroyEntitiesPacket(int entityId) { + this(new int[]{entityId}); } @Override public void write(@NotNull BinaryWriter writer) { - writer.writeVarInt(entityId); + writer.writeVarIntArray(entityIds); } @Override public void read(@NotNull BinaryReader reader) { - this.entityId = reader.readVarInt(); + this.entityIds = reader.readVarIntArray(); } @Override public int getId() { - return ServerPacketIdentifier.DESTROY_ENTITY; + return ServerPacketIdentifier.DESTROY_ENTITIES; } } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/SetSlotPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/SetSlotPacket.java index d4d6676fe..e446afb73 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/SetSlotPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/SetSlotPacket.java @@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull; public class SetSlotPacket implements ServerPacket { public byte windowId; + public int stateId; public short slot; public ItemStack itemStack; @@ -20,6 +21,7 @@ public class SetSlotPacket implements ServerPacket { @Override public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); + writer.writeVarInt(stateId); writer.writeShort(slot); writer.writeItemStack(itemStack); } @@ -27,6 +29,7 @@ public class SetSlotPacket implements ServerPacket { @Override public void read(@NotNull BinaryReader reader) { windowId = reader.readByte(); + stateId = reader.readVarInt(); slot = reader.readShort(); itemStack = reader.readItemStack(); } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java index eff759117..67f450018 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/WindowItemsPacket.java @@ -10,37 +10,43 @@ import org.jetbrains.annotations.NotNull; public class WindowItemsPacket implements ServerPacket { public byte windowId; + public int stateId; public ItemStack[] items; + public ItemStack carriedItem = ItemStack.AIR; /** * Default constructor, required for reflection operations. */ - public WindowItemsPacket() {} + public WindowItemsPacket() { + } @Override public void write(@NotNull BinaryWriter writer) { writer.writeByte(windowId); + writer.writeVarInt(stateId); if (items == null) { - writer.writeShort((short) 0); - return; - } - - writer.writeShort((short) items.length); - for (ItemStack item : items) { - writer.writeItemStack(item); + writer.writeVarInt(0); + } else { + writer.writeVarInt(items.length); + for (ItemStack item : items) { + writer.writeItemStack(item); + } } + writer.writeItemStack(carriedItem); } @Override public void read(@NotNull BinaryReader reader) { windowId = reader.readByte(); + stateId = reader.readVarInt(); - short length = reader.readShort(); + final int length = reader.readVarInt(); items = new ItemStack[length]; for (int i = 0; i < length; i++) { items[i] = reader.readItemStack(); } + carriedItem = reader.readItemStack(); } @Override