diff --git a/src/main/java/net/minestom/server/network/packet/client/handler/ClientPlayPacketsHandler.java b/src/main/java/net/minestom/server/network/packet/client/handler/ClientPlayPacketsHandler.java index 31cb179a8..f044e5a0a 100644 --- a/src/main/java/net/minestom/server/network/packet/client/handler/ClientPlayPacketsHandler.java +++ b/src/main/java/net/minestom/server/network/packet/client/handler/ClientPlayPacketsHandler.java @@ -35,8 +35,8 @@ public class ClientPlayPacketsHandler extends ClientPacketsHandler { register(0x1B, ClientPlayerDiggingPacket::new); register(0x1C, ClientEntityActionPacket::new); register(0x1D, ClientSteerVehiclePacket::new); - register(0x1E, ClientRecipeBookData::new); - register(0x1F, ClientRecipeBookData::new); + register(0x1E, ClientSetRecipeBookStatePacket::new); + register(0x1F, ClientSetDisplayedRecipePacket::new); register(0x20, ClientNameItemPacket::new); diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientRecipeBookData.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientRecipeBookData.java deleted file mode 100644 index cc9698595..000000000 --- a/src/main/java/net/minestom/server/network/packet/client/play/ClientRecipeBookData.java +++ /dev/null @@ -1,67 +0,0 @@ -package net.minestom.server.network.packet.client.play; - -import net.minestom.server.network.packet.client.ClientPlayPacket; -import net.minestom.server.utils.binary.BinaryReader; -import net.minestom.server.utils.binary.BinaryWriter; -import org.jetbrains.annotations.NotNull; - -public class ClientRecipeBookData extends ClientPlayPacket { - - public int type; - - public String recipeId = ""; - - public boolean craftingRecipeBookOpen; - public boolean craftingRecipeFilterActive; - public boolean smeltingRecipeBookOpen; - public boolean smeltingRecipeFilterActive; - public boolean blastingRecipeBookOpen; - public boolean blastingRecipeFilterActive; - public boolean smokingRecipeBookOpen; - public boolean smokingRecipeFilterActive; - - @Override - public void read(@NotNull BinaryReader reader) { - this.type = reader.readVarInt(); - - switch (type) { - case 0: - this.recipeId = reader.readSizedString(256); - break; - case 1: - this.craftingRecipeBookOpen = reader.readBoolean(); - this.craftingRecipeFilterActive = reader.readBoolean(); - this.smeltingRecipeBookOpen = reader.readBoolean(); - this.smeltingRecipeFilterActive = reader.readBoolean(); - this.blastingRecipeBookOpen = reader.readBoolean(); - this.blastingRecipeFilterActive = reader.readBoolean(); - this.smokingRecipeBookOpen = reader.readBoolean(); - this.smokingRecipeFilterActive = reader.readBoolean(); - break; - } - } - - @Override - public void write(@NotNull BinaryWriter writer) { - writer.writeVarInt(type); - - switch (type) { - case 0: - if(recipeId.length() > 256) - throw new IllegalArgumentException("recipeId must be less than 256 bytes"); - writer.writeSizedString(recipeId); - break; - - case 1: - writer.writeBoolean(this.craftingRecipeBookOpen); - writer.writeBoolean(this.craftingRecipeFilterActive); - writer.writeBoolean(this.smeltingRecipeBookOpen); - writer.writeBoolean(this.smeltingRecipeFilterActive); - writer.writeBoolean(this.blastingRecipeBookOpen); - writer.writeBoolean(this.blastingRecipeFilterActive); - writer.writeBoolean(this.smokingRecipeBookOpen); - writer.writeBoolean(this.smokingRecipeFilterActive); - break; - } - } -} diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientSetDisplayedRecipePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientSetDisplayedRecipePacket.java new file mode 100644 index 000000000..aeeba34f0 --- /dev/null +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientSetDisplayedRecipePacket.java @@ -0,0 +1,21 @@ +package net.minestom.server.network.packet.client.play; + +import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; + +public class ClientSetDisplayedRecipePacket extends ClientPlayPacket { + + public String recipeId; + + @Override + public void read(@NotNull BinaryReader reader) { + this.recipeId = reader.readSizedString(256); + } + + @Override + public void write(@NotNull BinaryWriter writer) { + writer.writeSizedString(recipeId); + } +} \ No newline at end of file diff --git a/src/main/java/net/minestom/server/network/packet/client/play/ClientSetRecipeBookStatePacket.java b/src/main/java/net/minestom/server/network/packet/client/play/ClientSetRecipeBookStatePacket.java new file mode 100644 index 000000000..a4acef7f7 --- /dev/null +++ b/src/main/java/net/minestom/server/network/packet/client/play/ClientSetRecipeBookStatePacket.java @@ -0,0 +1,31 @@ +package net.minestom.server.network.packet.client.play; + +import net.minestom.server.network.packet.client.ClientPlayPacket; +import net.minestom.server.utils.binary.BinaryReader; +import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; + +public class ClientSetRecipeBookStatePacket extends ClientPlayPacket { + + public BookType type; + public boolean bookOpen; + public boolean filterActive; + + @Override + public void read(@NotNull BinaryReader reader) { + this.type = BookType.values()[reader.readVarInt()]; + this.bookOpen = reader.readBoolean(); + this.filterActive = reader.readBoolean(); + } + + @Override + public void write(@NotNull BinaryWriter writer) { + writer.writeVarInt(type.ordinal()); + writer.writeBoolean(bookOpen); + writer.writeBoolean(filterActive); + } + + public enum BookType { + CRAFTING, FURNACE, BLAST_FURNACE, SMOKER + } +}