diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeBookAction.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeBookAction.java new file mode 100644 index 0000000000..e4cd878e2c --- /dev/null +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeBookAction.java @@ -0,0 +1,27 @@ +package com.github.retrooper.packetevents.protocol.recipe; + +public enum RecipeBookAction { + + INIT(0), + ADD(1), + REMOVE(2); + + private final int id; + + RecipeBookAction(int id) { + this.id = id; + } + + public static RecipeBookAction getById(int readVarInt) { + for (RecipeBookAction recipeBookAction : values()) { + if (recipeBookAction.id == readVarInt) { + return recipeBookAction; + } + } + return null; + } + + public int getId() { + return id; + } +} diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/CraftingBookCategory.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/CraftingBookCategory.java new file mode 100644 index 0000000000..5643efcf22 --- /dev/null +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/CraftingBookCategory.java @@ -0,0 +1,27 @@ +package com.github.retrooper.packetevents.protocol.recipe.data; + +public enum CraftingBookCategory { + BUILDING(0), + REDSTONE(1), + EQUIPMENT(2), + MISC(3); + + private final int id; + + public static CraftingBookCategory byId(int category) { + for (CraftingBookCategory value : values()) { + if (value.getId() == category) { + return value; + } + } + return null; + } + + CraftingBookCategory(int id) { + this.id = id; + } + + public int getId() { + return id; + } +} diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/ShapedRecipeData.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/ShapedRecipeData.java index ce27d32e2d..fd59d4b957 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/ShapedRecipeData.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/ShapedRecipeData.java @@ -21,18 +21,21 @@ import com.github.retrooper.packetevents.protocol.item.ItemStack; import com.github.retrooper.packetevents.protocol.recipe.Ingredient; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ShapedRecipeData implements RecipeData { private final int width; private final int height; private final @NotNull String group; + private CraftingBookCategory category; private final @NotNull Ingredient[] ingredients; private final ItemStack result; - public ShapedRecipeData(final int width, final int height, final @NotNull String group, final @NotNull Ingredient[] ingredients, final ItemStack result) { + public ShapedRecipeData(final int width, final int height, final @NotNull String group, final @NotNull CraftingBookCategory category, final @NotNull Ingredient[] ingredients, final ItemStack result) { this.width = width; this.height = height; this.group = group; + this.category = category; this.ingredients = ingredients; this.result = result; } @@ -49,6 +52,10 @@ public int getHeight() { return this.group; } + public @Nullable CraftingBookCategory getCategory() { + return this.category; + } + public @NotNull Ingredient[] getIngredients() { return this.ingredients; } diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/ShapelessRecipeData.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/ShapelessRecipeData.java index a37a7a3270..d408d24329 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/ShapelessRecipeData.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/data/ShapelessRecipeData.java @@ -26,9 +26,11 @@ public class ShapelessRecipeData implements RecipeData { private final @NotNull String group; private final @NotNull Ingredient[] ingredients; private final ItemStack result; + private CraftingBookCategory category; - public ShapelessRecipeData(@NotNull String group, @NotNull Ingredient[] ingredients, @NotNull ItemStack result) { + public ShapelessRecipeData(@NotNull String group, @NotNull CraftingBookCategory category, @NotNull Ingredient[] ingredients, @NotNull ItemStack result) { this.group = group; + this.category = category; this.ingredients = ingredients; this.result = result; } @@ -44,4 +46,8 @@ public ShapelessRecipeData(@NotNull String group, @NotNull Ingredient[] ingredie public @NotNull ItemStack getResult() { return result; } + + public CraftingBookCategory getCategory() { + return category; + } } \ No newline at end of file diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerDeclareRecipes.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerDeclareRecipes.java index 67bd3ce327..818ee087b4 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerDeclareRecipes.java +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerDeclareRecipes.java @@ -20,6 +20,7 @@ import com.github.retrooper.packetevents.event.PacketSendEvent; import com.github.retrooper.packetevents.protocol.item.ItemStack; +import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; import com.github.retrooper.packetevents.protocol.recipe.Ingredient; import com.github.retrooper.packetevents.protocol.recipe.Recipe; import com.github.retrooper.packetevents.protocol.recipe.RecipeType; @@ -36,6 +37,10 @@ public WrapperPlayServerDeclareRecipes(PacketSendEvent event) { super(event); } + public WrapperPlayServerDeclareRecipes(PacketTypeCommon packetType) { + super(packetType); + } + public Recipe[] getRecipes() { return this.recipes; } @@ -54,6 +59,7 @@ public void read() { switch (type) { case CRAFTING_SHAPELESS: { String group = readString(); + int category = readVarInt(); Ingredient[] ingredients = new Ingredient[readVarInt()]; for (int j = 0; j < ingredients.length; j++) { ingredients[j] = this.readIngredient(); @@ -61,13 +67,14 @@ public void read() { ItemStack result = readItemStack(); - data = new ShapelessRecipeData(group, ingredients, result); + data = new ShapelessRecipeData(group, CraftingBookCategory.byId(category), ingredients, result); break; } case CRAFTING_SHAPED: { int width = readVarInt(); int height = readVarInt(); String group = readString(); + int category = readVarInt(); Ingredient[] ingredients = new Ingredient[width * height]; for (int j = 0; j < ingredients.length; j++) { ingredients[j] = this.readIngredient(); @@ -75,7 +82,7 @@ public void read() { ItemStack result = readItemStack(); - data = new ShapedRecipeData(width, height, group, ingredients, result); + data = new ShapedRecipeData(width, height, group, CraftingBookCategory.byId(category), ingredients, result); break; } case SMELTING: @@ -146,6 +153,7 @@ public void write() { ShapelessRecipeData data = (ShapelessRecipeData) recipe.getData(); writeString(data.getGroup()); + writeVarInt(data.getCategory().getId()); writeVarInt(data.getIngredients().length); for (Ingredient ingredient : data.getIngredients()) { this.writeIngredient(ingredient); @@ -163,6 +171,7 @@ public void write() { writeVarInt(data.getWidth()); writeVarInt(data.getHeight()); writeString(data.getGroup()); + writeVarInt(data.getCategory().getId()); for (Ingredient ingredient : data.getIngredients()) { this.writeIngredient(ingredient); } diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerUnlockRecipes.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerUnlockRecipes.java new file mode 100644 index 0000000000..af55725aec --- /dev/null +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerUnlockRecipes.java @@ -0,0 +1,170 @@ +package com.github.retrooper.packetevents.wrapper.play.server; + +import com.github.retrooper.packetevents.event.PacketSendEvent; +import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon; +import com.github.retrooper.packetevents.protocol.recipe.RecipeBookAction; +import com.github.retrooper.packetevents.wrapper.PacketWrapper; + +public class WrapperPlayServerUnlockRecipes extends PacketWrapper { + + + public WrapperPlayServerUnlockRecipes(PacketSendEvent event) { + super(event); + } + + public WrapperPlayServerUnlockRecipes(PacketTypeCommon packetType) { + super(packetType); + } + + RecipeBookAction action; + boolean craftingRecipeBookOpen; + boolean craftingRecipeBookFilterActive; + boolean smeltingRecipeBookOpen; + boolean smeltingRecipeBookFilterActive; + boolean blastFurnaceRecipeBookOpen; + boolean blastFurnaceRecipeBookFilterActive; + boolean smokerRecipeBookOpen; + boolean smokerRecipeBookFilterActive; + String[] recipeIds; + String[] hightlightRecipes; + + @Override + public void read() { + action = RecipeBookAction.getById(readVarInt()); + + craftingRecipeBookOpen = readBoolean(); + craftingRecipeBookFilterActive = readBoolean(); + smeltingRecipeBookOpen = readBoolean(); + smeltingRecipeBookFilterActive = readBoolean(); + blastFurnaceRecipeBookOpen = readBoolean(); + blastFurnaceRecipeBookFilterActive = readBoolean(); + smokerRecipeBookOpen = readBoolean(); + smokerRecipeBookFilterActive = readBoolean(); + + recipeIds = new String[readVarInt()]; + for (int i = 0; i < recipeIds.length; i++) { + recipeIds[i] = readString(); + } + + if(action == RecipeBookAction.INIT) { + hightlightRecipes = new String[readVarInt()]; + for (int i = 0; i < hightlightRecipes.length; i++) { + hightlightRecipes[i] = readString(); + } + } + } + + @Override + public void write() { + writeVarInt(action.getId()); + + writeBoolean(craftingRecipeBookOpen); + writeBoolean(craftingRecipeBookFilterActive); + writeBoolean(smeltingRecipeBookOpen); + writeBoolean(smeltingRecipeBookFilterActive); + writeBoolean(blastFurnaceRecipeBookOpen); + writeBoolean(blastFurnaceRecipeBookFilterActive); + writeBoolean(smokerRecipeBookOpen); + writeBoolean(smokerRecipeBookFilterActive); + + writeVarInt(recipeIds.length); + for (String recipeId : recipeIds) { + writeString(recipeId); + } + + if(action == RecipeBookAction.INIT) { + writeVarInt(hightlightRecipes.length); + for (String hightlightRecipe : hightlightRecipes) { + writeString(hightlightRecipe); + } + } + } + + public RecipeBookAction getAction() { + return action; + } + + public void setAction(RecipeBookAction action) { + this.action = action; + } + + public boolean isCraftingRecipeBookOpen() { + return craftingRecipeBookOpen; + } + + public void setCraftingRecipeBookOpen(boolean craftingRecipeBookOpen) { + this.craftingRecipeBookOpen = craftingRecipeBookOpen; + } + + public boolean isCraftingRecipeBookFilterActive() { + return craftingRecipeBookFilterActive; + } + + public void setCraftingRecipeBookFilterActive(boolean craftingRecipeBookFilterActive) { + this.craftingRecipeBookFilterActive = craftingRecipeBookFilterActive; + } + + public boolean isSmeltingRecipeBookOpen() { + return smeltingRecipeBookOpen; + } + + public void setSmeltingRecipeBookOpen(boolean smeltingRecipeBookOpen) { + this.smeltingRecipeBookOpen = smeltingRecipeBookOpen; + } + + public boolean isSmeltingRecipeBookFilterActive() { + return smeltingRecipeBookFilterActive; + } + + public void setSmeltingRecipeBookFilterActive(boolean smeltingRecipeBookFilterActive) { + this.smeltingRecipeBookFilterActive = smeltingRecipeBookFilterActive; + } + + public boolean isBlastFurnaceRecipeBookOpen() { + return blastFurnaceRecipeBookOpen; + } + + public void setBlastFurnaceRecipeBookOpen(boolean blastFurnaceRecipeBookOpen) { + this.blastFurnaceRecipeBookOpen = blastFurnaceRecipeBookOpen; + } + + public boolean isBlastFurnaceRecipeBookFilterActive() { + return blastFurnaceRecipeBookFilterActive; + } + + public void setBlastFurnaceRecipeBookFilterActive(boolean blastFurnaceRecipeBookFilterActive) { + this.blastFurnaceRecipeBookFilterActive = blastFurnaceRecipeBookFilterActive; + } + + public boolean isSmokerRecipeBookOpen() { + return smokerRecipeBookOpen; + } + + public void setSmokerRecipeBookOpen(boolean smokerRecipeBookOpen) { + this.smokerRecipeBookOpen = smokerRecipeBookOpen; + } + + public boolean isSmokerRecipeBookFilterActive() { + return smokerRecipeBookFilterActive; + } + + public void setSmokerRecipeBookFilterActive(boolean smokerRecipeBookFilterActive) { + this.smokerRecipeBookFilterActive = smokerRecipeBookFilterActive; + } + + public String[] getRecipeIds() { + return recipeIds; + } + + public void setRecipeIds(String[] recipeIds) { + this.recipeIds = recipeIds; + } + + public String[] getHightlightRecipes() { + return hightlightRecipes; + } + + public void setHightlightRecipes(String[] hightlightRecipes) { + this.hightlightRecipes = hightlightRecipes; + } +}