fixes recipes for 1.20.1 (and probably 1.20.4) (#95)

* fixes recipes for 1.20.1 (and probably 1.20.4)

* add support for smithing trims and transforms

(cherry picked from commit 78cb62fa72)
This commit is contained in:
Tyreece Rozycki 2023-12-27 11:24:48 +10:00 committed by Matt Worzala
parent ffb33526f1
commit 2b236b441c
14 changed files with 285 additions and 44 deletions

View File

@ -49,7 +49,7 @@ public final class NetworkBuffer {
public static final Type<Point> BLOCK_POSITION = NetworkBufferTypes.BLOCK_POSITION;
public static final Type<Component> COMPONENT = NetworkBufferTypes.COMPONENT;
public static final Type<UUID> UUID = NetworkBufferTypes.UUID;
public static final Type<ItemStack> ITEM = NetworkBufferTypes.ITEM;
public static final Type<@Nullable ItemStack> ITEM = NetworkBufferTypes.ITEM;
public static final Type<byte[]> BYTE_ARRAY = NetworkBufferTypes.BYTE_ARRAY;
public static final Type<long[]> LONG_ARRAY = NetworkBufferTypes.LONG_ARRAY;

View File

@ -4,7 +4,9 @@ import net.minestom.server.item.ItemStack;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.recipe.RecipeCategory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@ -27,7 +29,8 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
case "smoking" -> new DeclaredSmokingRecipe(reader);
case "campfire_cooking" -> new DeclaredCampfireCookingRecipe(reader);
case "stonecutting" -> new DeclaredStonecutterRecipe(reader);
case "smithing" -> new DeclaredSmithingRecipe(reader);
case "smithing_trim" -> new DeclaredSmithingTrimRecipe(reader);
case "smithing_transform" -> new DeclaredSmithingTransformRecipe(reader);
default -> throw new UnsupportedOperationException("Unrecognized type: " + type);
};
}));
@ -50,23 +53,27 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
public sealed interface DeclaredRecipe extends NetworkBuffer.Writer
permits DeclaredShapelessCraftingRecipe, DeclaredShapedCraftingRecipe,
DeclaredSmeltingRecipe, DeclaredBlastingRecipe, DeclaredSmokingRecipe,
DeclaredCampfireCookingRecipe, DeclaredStonecutterRecipe, DeclaredSmithingRecipe {
DeclaredCampfireCookingRecipe, DeclaredStonecutterRecipe,
DeclaredSmithingTrimRecipe, DeclaredSmithingTransformRecipe {
@NotNull String type();
@NotNull String recipeId();
}
public record DeclaredShapelessCraftingRecipe(String recipeId, String group,
List<Ingredient> ingredients,
ItemStack result) implements DeclaredRecipe {
public record DeclaredShapelessCraftingRecipe(@NotNull String recipeId, @NotNull String group,
@NotNull RecipeCategory.Crafting crafting,
@NotNull List<Ingredient> ingredients,
@NotNull ItemStack result) implements DeclaredRecipe {
private DeclaredShapelessCraftingRecipe(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), reader.read(STRING),
reader.readEnum(RecipeCategory.Crafting.class),
reader.readCollection(Ingredient::new), reader.read(ITEM));
}
@Override
public void write(@NotNull NetworkBuffer writer) {
writer.write(STRING, group);
writer.writeEnum(RecipeCategory.Crafting.class, crafting);
writer.writeCollection(ingredients);
writer.write(ITEM, result);
}
@ -78,14 +85,15 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
}
public record DeclaredShapedCraftingRecipe(@NotNull String recipeId, int width, int height,
@NotNull String group, @NotNull List<Ingredient> ingredients,
@NotNull ItemStack result) implements DeclaredRecipe {
@NotNull String group, @NotNull RecipeCategory.Crafting category,
@NotNull List<Ingredient> ingredients,
@NotNull ItemStack result, boolean showNotification) implements DeclaredRecipe {
public DeclaredShapedCraftingRecipe {
ingredients = List.copyOf(ingredients);
}
private DeclaredShapedCraftingRecipe(DeclaredShapedCraftingRecipe packet) {
this(packet.recipeId, packet.width, packet.height, packet.group, packet.ingredients, packet.result);
this(packet.recipeId, packet.width, packet.height, packet.group, packet.category, packet.ingredients, packet.result, packet.showNotification);
}
public DeclaredShapedCraftingRecipe(@NotNull NetworkBuffer reader) {
@ -98,12 +106,14 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
int width = reader.read(VAR_INT);
int height = reader.read(VAR_INT);
String group = reader.read(STRING);
RecipeCategory.Crafting category = reader.readEnum(RecipeCategory.Crafting.class);
List<Ingredient> ingredients = new ArrayList<>();
for (int slot = 0; slot < width * height; slot++) {
ingredients.add(new Ingredient(reader));
}
ItemStack result = reader.read(ITEM);
return new DeclaredShapedCraftingRecipe(recipeId, width, height, group, ingredients, result);
boolean showNotification = reader.read(BOOLEAN);
return new DeclaredShapedCraftingRecipe(recipeId, width, height, group, category, ingredients, result, showNotification);
}
@Override
@ -111,10 +121,12 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
writer.write(VAR_INT, width);
writer.write(VAR_INT, height);
writer.write(STRING, group);
writer.writeEnum(RecipeCategory.Crafting.class, category);
for (Ingredient ingredient : ingredients) {
ingredient.write(writer);
}
writer.write(ITEM, result);
writer.write(BOOLEAN, showNotification);
}
@Override
@ -124,10 +136,12 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
}
public record DeclaredSmeltingRecipe(@NotNull String recipeId, @NotNull String group,
@NotNull Ingredient ingredient, @NotNull ItemStack result,
float experience, int cookingTime) implements DeclaredRecipe {
@NotNull RecipeCategory.Cooking category, @NotNull Ingredient ingredient,
@NotNull ItemStack result, float experience,
int cookingTime) implements DeclaredRecipe {
public DeclaredSmeltingRecipe(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), reader.read(STRING),
reader.readEnum(RecipeCategory.Cooking.class),
new Ingredient(reader), reader.read(ITEM),
reader.read(FLOAT), reader.read(VAR_INT));
}
@ -135,6 +149,7 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
@Override
public void write(@NotNull NetworkBuffer writer) {
writer.write(STRING, group);
writer.writeEnum(RecipeCategory.Cooking.class, category);
writer.write(ingredient);
writer.write(ITEM, result);
writer.write(FLOAT, experience);
@ -148,10 +163,12 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
}
public record DeclaredBlastingRecipe(@NotNull String recipeId, @NotNull String group,
@NotNull Ingredient ingredient, @NotNull ItemStack result,
float experience, int cookingTime) implements DeclaredRecipe {
@NotNull RecipeCategory.Cooking category, @NotNull Ingredient ingredient,
@NotNull ItemStack result, float experience,
int cookingTime) implements DeclaredRecipe {
public DeclaredBlastingRecipe(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), reader.read(STRING),
reader.readEnum(RecipeCategory.Cooking.class),
new Ingredient(reader), reader.read(ITEM),
reader.read(FLOAT), reader.read(VAR_INT));
}
@ -159,6 +176,7 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
@Override
public void write(@NotNull NetworkBuffer writer) {
writer.write(STRING, group);
writer.writeEnum(RecipeCategory.Cooking.class, category);
writer.write(ingredient);
writer.write(ITEM, result);
writer.write(FLOAT, experience);
@ -172,10 +190,12 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
}
public record DeclaredSmokingRecipe(@NotNull String recipeId, @NotNull String group,
@NotNull Ingredient ingredient, @NotNull ItemStack result,
float experience, int cookingTime) implements DeclaredRecipe {
@NotNull RecipeCategory.Cooking category, @NotNull Ingredient ingredient,
@NotNull ItemStack result, float experience,
int cookingTime) implements DeclaredRecipe {
public DeclaredSmokingRecipe(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), reader.read(STRING),
reader.readEnum(RecipeCategory.Cooking.class),
new Ingredient(reader), reader.read(ITEM),
reader.read(FLOAT), reader.read(VAR_INT));
}
@ -183,6 +203,7 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
@Override
public void write(@NotNull NetworkBuffer writer) {
writer.write(STRING, group);
writer.writeEnum(RecipeCategory.Cooking.class, category);
writer.write(ingredient);
writer.write(ITEM, result);
writer.write(FLOAT, experience);
@ -196,10 +217,12 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
}
public record DeclaredCampfireCookingRecipe(@NotNull String recipeId, @NotNull String group,
@NotNull Ingredient ingredient, @NotNull ItemStack result,
float experience, int cookingTime) implements DeclaredRecipe {
@NotNull RecipeCategory.Cooking category, @NotNull Ingredient ingredient,
@NotNull ItemStack result, float experience,
int cookingTime) implements DeclaredRecipe {
public DeclaredCampfireCookingRecipe(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), reader.read(STRING),
reader.readEnum(RecipeCategory.Cooking.class),
new Ingredient(reader), reader.read(ITEM),
reader.read(FLOAT), reader.read(VAR_INT));
}
@ -207,6 +230,7 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
@Override
public void write(@NotNull NetworkBuffer writer) {
writer.write(STRING, group);
writer.writeEnum(RecipeCategory.Cooking.class, category);
writer.write(ingredient);
writer.write(ITEM, result);
writer.write(FLOAT, experience);
@ -239,14 +263,16 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
}
}
public record DeclaredSmithingRecipe(String recipeId, Ingredient base, Ingredient addition,
ItemStack result) implements DeclaredRecipe {
public DeclaredSmithingRecipe(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), new Ingredient(reader), new Ingredient(reader), reader.read(ITEM));
public record DeclaredSmithingTransformRecipe(String recipeId, Ingredient template,
Ingredient base, Ingredient addition,
ItemStack result) implements DeclaredRecipe {
public DeclaredSmithingTransformRecipe(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), new Ingredient(reader), new Ingredient(reader), new Ingredient(reader), reader.read(ITEM));
}
@Override
public void write(@NotNull NetworkBuffer writer) {
writer.write(template);
writer.write(base);
writer.write(addition);
writer.write(ITEM, result);
@ -254,13 +280,32 @@ public record DeclareRecipesPacket(@NotNull List<DeclaredRecipe> recipes) implem
@Override
public @NotNull String type() {
return "smithing";
return "smithing_transform";
}
}
public record Ingredient(@NotNull List<ItemStack> items) implements NetworkBuffer.Writer {
public record DeclaredSmithingTrimRecipe(String recipeId, Ingredient template,
Ingredient base, Ingredient addition) implements DeclaredRecipe {
public DeclaredSmithingTrimRecipe(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), new Ingredient(reader), new Ingredient(reader), new Ingredient(reader));
}
@Override
public void write(@NotNull NetworkBuffer writer) {
writer.write(template);
writer.write(base);
writer.write(addition);
}
@Override
public @NotNull String type() {
return "smithing_trim";
}
}
public record Ingredient(@Nullable List<ItemStack> items) implements NetworkBuffer.Writer {
public Ingredient {
items = List.copyOf(items);
items = items == null ? null : List.copyOf(items);
}
public Ingredient(@NotNull NetworkBuffer reader) {

View File

@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
public abstract class BlastingRecipe extends Recipe {
private String group;
private RecipeCategory.Cooking category;
private DeclareRecipesPacket.Ingredient ingredient;
private ItemStack result;
private float experience;
@ -14,12 +15,14 @@ public abstract class BlastingRecipe extends Recipe {
protected BlastingRecipe(
@NotNull String recipeId,
@NotNull String group,
@NotNull RecipeCategory.Cooking category,
@NotNull ItemStack result,
float experience,
int cookingTime
) {
super(Type.BLASTING, recipeId);
this.group = group;
this.category = category;
this.result = result;
this.experience = experience;
this.cookingTime = cookingTime;
@ -34,8 +37,15 @@ public abstract class BlastingRecipe extends Recipe {
this.group = group;
}
@NotNull
public DeclareRecipesPacket.Ingredient getIngredient() {
public @NotNull RecipeCategory.Cooking getCategory() {
return category;
}
public void setCategory(@NotNull RecipeCategory.Cooking category) {
this.category = category;
}
public @NotNull DeclareRecipesPacket.Ingredient getIngredient() {
return ingredient;
}

View File

@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
public abstract class CampfireCookingRecipe extends Recipe {
private String group;
private RecipeCategory.Cooking category;
private DeclareRecipesPacket.Ingredient ingredient;
private ItemStack result;
private float experience;
@ -14,12 +15,14 @@ public abstract class CampfireCookingRecipe extends Recipe {
protected CampfireCookingRecipe(
@NotNull String recipeId,
@NotNull String group,
@NotNull RecipeCategory.Cooking category,
@NotNull ItemStack result,
float experience,
int cookingTime
) {
super(Type.CAMPFIRE_COOKING, recipeId);
this.group = group;
this.category = category;
this.result = result;
this.experience = experience;
this.cookingTime = cookingTime;
@ -34,6 +37,15 @@ public abstract class CampfireCookingRecipe extends Recipe {
this.group = group;
}
@NotNull
public RecipeCategory.Cooking getCategory() {
return category;
}
public void setCategory(@NotNull RecipeCategory.Cooking category) {
this.category = category;
}
@NotNull
public DeclareRecipesPacket.Ingredient getIngredient() {
return ingredient;

View File

@ -32,7 +32,8 @@ public abstract class Recipe {
SMOKING,
CAMPFIRE_COOKING,
STONECUTTING,
SMITHING
SMITHING_TRANSFORM,
SMITHING_TRIM
}
}

View File

@ -0,0 +1,11 @@
package net.minestom.server.recipe;
public interface RecipeCategory {
enum Cooking {
FOOD, BLOCKS, MISC
}
enum Crafting {
BUILDING, REDSTONE, EQUIPMENT, MISC
}
}

View File

@ -50,6 +50,7 @@ public class RecipeManager {
new DeclareRecipesPacket.DeclaredShapelessCraftingRecipe(
shapelessRecipe.getRecipeId(),
shapelessRecipe.getGroup(),
shapelessRecipe.getCategory(),
shapelessRecipe.getIngredients(),
shapelessRecipe.getResult()));
}
@ -61,8 +62,10 @@ public class RecipeManager {
shapedRecipe.getWidth(),
shapedRecipe.getHeight(),
shapedRecipe.getGroup(),
shapedRecipe.getCategory(),
shapedRecipe.getIngredients(),
shapedRecipe.getResult()));
shapedRecipe.getResult(),
shapedRecipe.getShowNotification()));
}
case SMELTING -> {
SmeltingRecipe smeltingRecipe = (SmeltingRecipe) recipe;
@ -70,6 +73,7 @@ public class RecipeManager {
new DeclareRecipesPacket.DeclaredSmeltingRecipe(
smeltingRecipe.getRecipeId(),
smeltingRecipe.getGroup(),
smeltingRecipe.getCategory(),
smeltingRecipe.getIngredient(),
smeltingRecipe.getResult(),
smeltingRecipe.getExperience(),
@ -81,6 +85,7 @@ public class RecipeManager {
new DeclareRecipesPacket.DeclaredBlastingRecipe(
blastingRecipe.getRecipeId(),
blastingRecipe.getGroup(),
blastingRecipe.getCategory(),
blastingRecipe.getIngredient(),
blastingRecipe.getResult(),
blastingRecipe.getExperience(),
@ -92,6 +97,7 @@ public class RecipeManager {
new DeclareRecipesPacket.DeclaredSmokingRecipe(
smokingRecipe.getRecipeId(),
smokingRecipe.getGroup(),
smokingRecipe.getCategory(),
smokingRecipe.getIngredient(),
smokingRecipe.getResult(),
smokingRecipe.getExperience(),
@ -103,6 +109,7 @@ public class RecipeManager {
new DeclareRecipesPacket.DeclaredCampfireCookingRecipe(
campfireCookingRecipe.getRecipeId(),
campfireCookingRecipe.getGroup(),
campfireCookingRecipe.getCategory(),
campfireCookingRecipe.getIngredient(),
campfireCookingRecipe.getResult(),
campfireCookingRecipe.getExperience(),
@ -117,14 +124,24 @@ public class RecipeManager {
stonecuttingRecipe.getIngredient(),
stonecuttingRecipe.getResult()));
}
case SMITHING -> {
SmithingRecipe smithingRecipe = (SmithingRecipe) recipe;
case SMITHING_TRANSFORM -> {
SmithingTransformRecipe smithingTransformRecipe = (SmithingTransformRecipe) recipe;
recipesCache.add(
new DeclareRecipesPacket.DeclaredSmithingRecipe(
smithingRecipe.getRecipeId(),
smithingRecipe.getBaseIngredient(),
smithingRecipe.getAdditionIngredient(),
smithingRecipe.getResult()));
new DeclareRecipesPacket.DeclaredSmithingTransformRecipe(
smithingTransformRecipe.getRecipeId(),
smithingTransformRecipe.getTemplate(),
smithingTransformRecipe.getBaseIngredient(),
smithingTransformRecipe.getAdditionIngredient(),
smithingTransformRecipe.getResult()));
}
case SMITHING_TRIM -> {
SmithingTrimRecipe smithingTrimRecipe = (SmithingTrimRecipe) recipe;
recipesCache.add(
new DeclareRecipesPacket.DeclaredSmithingTrimRecipe(
smithingTrimRecipe.getRecipeId(),
smithingTrimRecipe.getTemplate(),
smithingTrimRecipe.getBaseIngredient(),
smithingTrimRecipe.getAdditionIngredient()));
}
}
}

View File

@ -13,21 +13,26 @@ public abstract class ShapedRecipe extends Recipe {
private final int width;
private final int height;
private String group;
private RecipeCategory.Crafting category;
private final List<DeclareRecipesPacket.Ingredient> ingredients;
private ItemStack result;
private boolean showNotification;
protected ShapedRecipe(@NotNull String recipeId,
int width,
int height,
@NotNull String group,
@NotNull RecipeCategory.Crafting category,
@Nullable List<DeclareRecipesPacket.Ingredient> ingredients,
@NotNull ItemStack result) {
@NotNull ItemStack result, boolean showNotification) {
super(Type.SHAPED, recipeId);
this.width = width;
this.height = height;
this.group = group;
this.category = category;
this.ingredients = Objects.requireNonNullElseGet(ingredients, LinkedList::new);
this.result = result;
this.showNotification = showNotification;
}
public int getWidth() {
@ -47,6 +52,15 @@ public abstract class ShapedRecipe extends Recipe {
this.group = group;
}
@NotNull
public RecipeCategory.Crafting getCategory() {
return category;
}
public void setCategory(@NotNull RecipeCategory.Crafting category) {
this.category = category;
}
public void addIngredient(DeclareRecipesPacket.Ingredient ingredient) {
if (ingredients.size() + 1 > width * height) {
throw new IndexOutOfBoundsException("You cannot add more ingredients than width*height");
@ -68,4 +82,12 @@ public abstract class ShapedRecipe extends Recipe {
public void setResult(@NotNull ItemStack result) {
this.result = result;
}
public boolean getShowNotification() {
return showNotification;
}
public void setShowNotification(boolean showNotification) {
this.showNotification = showNotification;
}
}

View File

@ -11,17 +11,20 @@ import java.util.Objects;
public abstract class ShapelessRecipe extends Recipe {
private String group;
private RecipeCategory.Crafting category;
private final List<DeclareRecipesPacket.Ingredient> ingredients;
private ItemStack result;
protected ShapelessRecipe(
@NotNull String recipeId,
@NotNull String group,
@NotNull RecipeCategory.Crafting category,
@Nullable List<DeclareRecipesPacket.Ingredient> ingredients,
@NotNull ItemStack result
) {
super(Type.SHAPELESS, recipeId);
this.group = group;
this.category = category;
this.ingredients = Objects.requireNonNullElseGet(ingredients, LinkedList::new);
this.result = result;
}
@ -35,6 +38,15 @@ public abstract class ShapelessRecipe extends Recipe {
this.group = group;
}
@NotNull
public RecipeCategory.Crafting getCategory() {
return category;
}
public void setCategory(@NotNull RecipeCategory.Crafting category) {
this.category = category;
}
public void addIngredient(DeclareRecipesPacket.Ingredient ingredient) {
ingredients.add(ingredient);
}

View File

@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
public abstract class SmeltingRecipe extends Recipe {
private String group;
private RecipeCategory.Cooking category;
private DeclareRecipesPacket.Ingredient ingredient;
private ItemStack result;
private float experience;
@ -14,12 +15,14 @@ public abstract class SmeltingRecipe extends Recipe {
protected SmeltingRecipe(
@NotNull String recipeId,
@NotNull String group,
@NotNull RecipeCategory.Cooking category,
@NotNull ItemStack result,
float experience,
int cookingTime
) {
super(Type.SMELTING, recipeId);
this.group = group;
this.category = category;
this.result = result;
this.experience = experience;
this.cookingTime = cookingTime;
@ -34,8 +37,15 @@ public abstract class SmeltingRecipe extends Recipe {
this.group = group;
}
@NotNull
public DeclareRecipesPacket.Ingredient getIngredient() {
public @NotNull RecipeCategory.Cooking getCategory() {
return category;
}
public void setCategory(@NotNull RecipeCategory.Cooking category) {
this.category = category;
}
public @NotNull DeclareRecipesPacket.Ingredient getIngredient() {
return ingredient;
}

View File

@ -4,23 +4,35 @@ import net.minestom.server.item.ItemStack;
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
import org.jetbrains.annotations.NotNull;
public abstract class SmithingRecipe extends Recipe {
public abstract class SmithingTransformRecipe extends Recipe {
private DeclareRecipesPacket.Ingredient template;
private DeclareRecipesPacket.Ingredient baseIngredient;
private DeclareRecipesPacket.Ingredient additionIngredient;
private ItemStack result;
protected SmithingRecipe(
protected SmithingTransformRecipe(
@NotNull String recipeId,
@NotNull DeclareRecipesPacket.Ingredient template,
@NotNull DeclareRecipesPacket.Ingredient baseIngredient,
@NotNull DeclareRecipesPacket.Ingredient additionIngredient,
@NotNull ItemStack result
) {
super(Type.SMITHING, recipeId);
super(Type.SMITHING_TRANSFORM, recipeId);
this.template = template;
this.baseIngredient = baseIngredient;
this.additionIngredient = additionIngredient;
this.result = result;
}
@NotNull
public DeclareRecipesPacket.Ingredient getTemplate() {
return template;
}
public void setTemplate(@NotNull DeclareRecipesPacket.Ingredient template) {
this.template = template;
}
@NotNull
public DeclareRecipesPacket.Ingredient getBaseIngredient() {
return baseIngredient;

View File

@ -0,0 +1,50 @@
package net.minestom.server.recipe;
import net.minestom.server.item.ItemStack;
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
import org.jetbrains.annotations.NotNull;
public abstract class SmithingTrimRecipe extends Recipe {
private DeclareRecipesPacket.Ingredient template;
private DeclareRecipesPacket.Ingredient baseIngredient;
private DeclareRecipesPacket.Ingredient additionIngredient;
protected SmithingTrimRecipe(
@NotNull String recipeId,
@NotNull DeclareRecipesPacket.Ingredient template,
@NotNull DeclareRecipesPacket.Ingredient baseIngredient,
@NotNull DeclareRecipesPacket.Ingredient additionIngredient
) {
super(Type.SMITHING_TRIM, recipeId);
this.template = template;
this.baseIngredient = baseIngredient;
this.additionIngredient = additionIngredient;
}
@NotNull
public DeclareRecipesPacket.Ingredient getTemplate() {
return template;
}
public void setTemplate(@NotNull DeclareRecipesPacket.Ingredient template) {
this.template = template;
}
@NotNull
public DeclareRecipesPacket.Ingredient getBaseIngredient() {
return baseIngredient;
}
public void setBaseIngredient(@NotNull DeclareRecipesPacket.Ingredient baseIngredient) {
this.baseIngredient = baseIngredient;
}
@NotNull
public DeclareRecipesPacket.Ingredient getAdditionIngredient() {
return additionIngredient;
}
public void setAdditionIngredient(@NotNull DeclareRecipesPacket.Ingredient additionIngredient) {
this.additionIngredient = additionIngredient;
}
}

View File

@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
public abstract class SmokingRecipe extends Recipe {
private String group;
private RecipeCategory.Cooking category;
private DeclareRecipesPacket.Ingredient ingredient;
private ItemStack result;
private float experience;
@ -14,12 +15,14 @@ public abstract class SmokingRecipe extends Recipe {
protected SmokingRecipe(
@NotNull String recipeId,
@NotNull String group,
@NotNull RecipeCategory.Cooking category,
@NotNull ItemStack result,
float experience,
int cookingTime
) {
super(Type.SMOKING, recipeId);
this.group = group;
this.category = category;
this.result = result;
this.experience = experience;
this.cookingTime = cookingTime;
@ -34,6 +37,15 @@ public abstract class SmokingRecipe extends Recipe {
this.group = group;
}
@NotNull
public RecipeCategory.Cooking getCategory() {
return category;
}
public void setCategory(@NotNull RecipeCategory.Cooking category) {
this.category = category;
}
@NotNull
public DeclareRecipesPacket.Ingredient getIngredient() {
return ingredient;

View File

@ -26,6 +26,7 @@ import net.minestom.server.network.packet.server.login.SetCompressionPacket;
import net.minestom.server.network.packet.server.play.*;
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket.Ingredient;
import net.minestom.server.network.packet.server.status.PongPacket;
import net.minestom.server.recipe.RecipeCategory;
import net.minestom.server.utils.crypto.KeyUtils;
import org.apache.commons.net.util.Base64;
import org.jglrxavpok.hephaistos.nbt.NBT;
@ -95,6 +96,7 @@ public class PacketWriteReadTest {
List.of(new DeclareRecipesPacket.DeclaredShapelessCraftingRecipe(
"minecraft:sticks",
"sticks",
RecipeCategory.Crafting.MISC,
List.of(new Ingredient(List.of(ItemStack.of(Material.OAK_PLANKS)))),
ItemStack.of(Material.STICK)
),
@ -103,10 +105,35 @@ public class PacketWriteReadTest {
1,
2,
"",
RecipeCategory.Crafting.MISC,
List.of(new Ingredient(List.of(ItemStack.of(Material.COAL))),
new Ingredient(List.of(ItemStack.of(Material.STICK)))),
ItemStack.of(Material.TORCH)
))));
ItemStack.of(Material.TORCH),
true
),
new DeclareRecipesPacket.DeclaredBlastingRecipe(
"minecraft:coal",
"forging",
RecipeCategory.Cooking.MISC,
new Ingredient(List.of(ItemStack.of(Material.COAL))),
ItemStack.of(Material.IRON_INGOT),
5,
5
),
new DeclareRecipesPacket.DeclaredSmithingTransformRecipe(
"minecraft:iron_to_diamond",
new Ingredient(List.of(ItemStack.of(Material.COAST_ARMOR_TRIM_SMITHING_TEMPLATE))),
new Ingredient(List.of(ItemStack.of(Material.DIAMOND))),
new Ingredient(List.of(ItemStack.of(Material.IRON_INGOT))),
ItemStack.of(Material.DIAMOND)
),
new DeclareRecipesPacket.DeclaredSmithingTrimRecipe(
"minecraft:iron_to_coast",
new Ingredient(List.of(ItemStack.of(Material.IRON_INGOT))),
new Ingredient(List.of(ItemStack.of(Material.COAST_ARMOR_TRIM_SMITHING_TEMPLATE))),
new Ingredient(List.of(ItemStack.of(Material.COAL)))
)
)));
SERVER_PACKETS.add(new DestroyEntitiesPacket(List.of(5, 5, 5)));
SERVER_PACKETS.add(new DisconnectPacket(COMPONENT));