-
-
Notifications
You must be signed in to change notification settings - Fork 250
Update Declare Recipes packet and add packet for unlock recipes #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the CraftingBookCategory version-specific? If yes, please make a second constructor |
||
| 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; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| 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() { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the |
||||||
| return category; | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -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<WrapperPlayServerUnlockRecipes> { | ||||||||
|
|
||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| public WrapperPlayServerUnlockRecipes(PacketSendEvent event) { | ||||||||
| super(event); | ||||||||
| } | ||||||||
|
|
||||||||
| public WrapperPlayServerUnlockRecipes(PacketTypeCommon packetType) { | ||||||||
| super(packetType); | ||||||||
| } | ||||||||
|
|
||||||||
| RecipeBookAction action; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||||||||
| 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) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| 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) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| 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; | ||||||||
| } | ||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.