Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private CraftingBookCategory category;
private final 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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;
}
Expand All @@ -49,6 +52,10 @@ public int getHeight() {
return this.group;
}

public @Nullable CraftingBookCategory getCategory() {
return this.category;
}

public @NotNull Ingredient[] getIngredients() {
return this.ingredients;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private CraftingBookCategory category;
private final 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;
}
Expand All @@ -44,4 +46,8 @@ public ShapelessRecipeData(@NotNull String group, @NotNull Ingredient[] ingredie
public @NotNull ItemStack getResult() {
return result;
}

public CraftingBookCategory getCategory() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the @Nullable annotation not needed?

return category;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +37,10 @@ public WrapperPlayServerDeclareRecipes(PacketSendEvent event) {
super(event);
}

public WrapperPlayServerDeclareRecipes(PacketTypeCommon packetType) {
super(packetType);
}

public Recipe[] getRecipes() {
return this.recipes;
}
Expand All @@ -54,28 +59,30 @@ 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();
}

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();
}

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:
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
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> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add private final everywhere

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(action == RecipeBookAction.INIT) {
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(action == RecipeBookAction.INIT) {
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;
}
}