diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractGroupedRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractGroupedRecipe.java index c0634f467..c19dfee24 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractGroupedRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractGroupedRecipe.java @@ -1,38 +1,19 @@ package net.momirealms.craftengine.core.item.recipe; -import net.momirealms.craftengine.core.item.ItemBuildContext; import net.momirealms.craftengine.core.item.recipe.result.CustomRecipeResult; import net.momirealms.craftengine.core.util.Key; import org.jetbrains.annotations.Nullable; -public abstract class AbstractGroupedRecipe implements FixedResultRecipe { +public abstract class AbstractGroupedRecipe extends AbstractedFixedResultRecipe { protected final String group; - protected final Key id; - protected final CustomRecipeResult result; - protected AbstractGroupedRecipe(Key id, String group, CustomRecipeResult result) { + protected AbstractGroupedRecipe(Key id, boolean showNotification, CustomRecipeResult result, String group) { + super(id, showNotification, result); this.group = group == null ? "" : group; - this.id = id; - this.result = result; } @Nullable public String group() { return group; } - - @Override - public Key id() { - return id; - } - - @Override - public T result(ItemBuildContext context) { - return result.buildItemStack(context); - } - - @Override - public CustomRecipeResult result() { - return this.result; - } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipe.java new file mode 100644 index 000000000..884d766bb --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipe.java @@ -0,0 +1,23 @@ +package net.momirealms.craftengine.core.item.recipe; + +import net.momirealms.craftengine.core.util.Key; + +public abstract class AbstractRecipe implements Recipe { + protected final Key id; + protected final boolean showNotification; + + public AbstractRecipe(Key id, boolean showNotification) { + this.id = id; + this.showNotification = showNotification; + } + + @Override + public boolean showNotification() { + return this.showNotification; + } + + @Override + public Key id() { + return this.id; + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeManager.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeManager.java index 796c79e9f..a8e27adfe 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeManager.java @@ -103,7 +103,7 @@ public abstract class AbstractRecipeManager implements RecipeManager { if (this.byId.containsKey(id)) return false; this.byType.computeIfAbsent(recipe.type(), k -> new ArrayList<>()).add(recipe); this.byId.put(id, recipe); - if (recipe instanceof FixedResultRecipe fixedResult) { + if (recipe instanceof AbstractedFixedResultRecipe fixedResult) { this.byResult.computeIfAbsent(fixedResult.result().item().id(), k -> new ArrayList<>()).add(recipe); } HashSet usedKeys = new HashSet<>(); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeSerializer.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeSerializer.java index ddb4b0e4c..7f02a3fff 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeSerializer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractRecipeSerializer.java @@ -26,6 +26,10 @@ public abstract class AbstractRecipeSerializer> implement new VanillaRecipeReader1_20_5() : new VanillaRecipeReader1_20(); + protected boolean showNotification(Map arguments) { + return ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("show-notification", true), "show-notification"); + } + protected Ingredient singleInputIngredient(Map arguments) { List ingredients = MiscUtils.getAsStringList(getIngredientOrThrow(arguments)); return toIngredient(ingredients); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractedFixedResultRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractedFixedResultRecipe.java new file mode 100644 index 000000000..fa9d8a674 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/AbstractedFixedResultRecipe.java @@ -0,0 +1,28 @@ +package net.momirealms.craftengine.core.item.recipe; + +import net.momirealms.craftengine.core.item.ItemBuildContext; +import net.momirealms.craftengine.core.item.recipe.input.RecipeInput; +import net.momirealms.craftengine.core.item.recipe.result.CustomRecipeResult; +import net.momirealms.craftengine.core.util.Key; + +public abstract class AbstractedFixedResultRecipe extends AbstractRecipe { + protected CustomRecipeResult result; + + public AbstractedFixedResultRecipe(Key id, boolean showNotification, CustomRecipeResult result) { + super(id, showNotification); + this.result = result; + } + + public T result(ItemBuildContext context) { + return this.result.buildItemStack(context); + } + + public CustomRecipeResult result() { + return this.result; + } + + @Override + public T assemble(RecipeInput input, ItemBuildContext context) { + return this.result(context); + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBlastingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBlastingRecipe.java index eaff6e37a..4cd515793 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBlastingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBlastingRecipe.java @@ -11,8 +11,15 @@ import java.util.Map; public class CustomBlastingRecipe extends CustomCookingRecipe { public static final Serializer SERIALIZER = new Serializer<>(); - public CustomBlastingRecipe(Key id, CookingRecipeCategory category, String group, Ingredient ingredient, int cookingTime, float experience, CustomRecipeResult result) { - super(id, category, group, ingredient, cookingTime, experience, result); + public CustomBlastingRecipe(Key id, + boolean showNotification, + CustomRecipeResult result, + String group, + CookingRecipeCategory category, + Ingredient ingredient, + int cookingTime, + float experience) { + super(id, showNotification, result, group, category, ingredient, cookingTime, experience); } @Override @@ -31,24 +38,22 @@ public class CustomBlastingRecipe extends CustomCookingRecipe { @Override public CustomBlastingRecipe readMap(Key id, Map arguments) { return new CustomBlastingRecipe(id, - cookingRecipeCategory(arguments), - arguments.containsKey("group") ? arguments.get("group").toString() : null, + showNotification(arguments), + parseResult(arguments), arguments.containsKey("group") ? arguments.get("group").toString() : null, cookingRecipeCategory(arguments), singleInputIngredient(arguments), ResourceConfigUtils.getAsInt(arguments.getOrDefault("time", 80), "time"), - ResourceConfigUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f), "experience"), - parseResult(arguments) + ResourceConfigUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f), "experience") ); } @Override public CustomBlastingRecipe readJson(Key id, JsonObject json) { return new CustomBlastingRecipe<>(id, - VANILLA_RECIPE_HELPER.cookingCategory(json), - VANILLA_RECIPE_HELPER.readGroup(json), + true, + parseResult(VANILLA_RECIPE_HELPER.cookingResult(json.get("result"))), VANILLA_RECIPE_HELPER.readGroup(json), VANILLA_RECIPE_HELPER.cookingCategory(json), toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("ingredient"))), VANILLA_RECIPE_HELPER.cookingTime(json), - VANILLA_RECIPE_HELPER.cookingExperience(json), - parseResult(VANILLA_RECIPE_HELPER.cookingResult(json.get("result"))) + VANILLA_RECIPE_HELPER.cookingExperience(json) ); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBrewingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBrewingRecipe.java index 38e349063..96078dc1c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBrewingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomBrewingRecipe.java @@ -1,7 +1,6 @@ package net.momirealms.craftengine.core.item.recipe; import com.google.gson.JsonObject; -import net.momirealms.craftengine.core.item.ItemBuildContext; import net.momirealms.craftengine.core.item.recipe.input.BrewingInput; import net.momirealms.craftengine.core.item.recipe.input.RecipeInput; import net.momirealms.craftengine.core.item.recipe.result.CustomRecipeResult; @@ -15,33 +14,22 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -public class CustomBrewingRecipe implements FixedResultRecipe { +public class CustomBrewingRecipe extends AbstractedFixedResultRecipe { public static final Serializer SERIALIZER = new Serializer<>(); - private final Key id; private final Ingredient container; private final Ingredient ingredient; - private final CustomRecipeResult result; public CustomBrewingRecipe(@NotNull Key id, @NotNull Ingredient container, @NotNull Ingredient ingredient, - @NotNull CustomRecipeResult result) { - this.id = id; + @NotNull CustomRecipeResult result, + boolean showNotification) { + super(id, showNotification, result); this.container = container; this.ingredient = ingredient; this.result = result; } - @Override - public CustomRecipeResult result() { - return this.result; - } - - @Override - public T result(ItemBuildContext context) { - return this.result.buildItemStack(context); - } - @SuppressWarnings("unchecked") @Override public boolean matches(RecipeInput input) { @@ -77,11 +65,6 @@ public class CustomBrewingRecipe implements FixedResultRecipe { return this.ingredient; } - @Override - public Key id() { - return this.id; - } - @SuppressWarnings({"DuplicatedCode"}) public static class Serializer extends AbstractRecipeSerializer> { @@ -98,7 +81,9 @@ public class CustomBrewingRecipe implements FixedResultRecipe { return new CustomBrewingRecipe<>(id, ResourceConfigUtils.requireNonNullOrThrow(toIngredient(container), "warning.config.recipe.brewing.missing_container"), ResourceConfigUtils.requireNonNullOrThrow(toIngredient(ingredient), "warning.config.recipe.brewing.missing_ingredient"), - parseResult(arguments)); + parseResult(arguments), + showNotification(arguments) + ); } @Override diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCampfireRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCampfireRecipe.java index 9522de1fa..16fa94a62 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCampfireRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCampfireRecipe.java @@ -11,8 +11,15 @@ import java.util.Map; public class CustomCampfireRecipe extends CustomCookingRecipe { public static final Serializer SERIALIZER = new Serializer<>(); - public CustomCampfireRecipe(Key id, CookingRecipeCategory category, String group, Ingredient ingredient, int cookingTime, float experience, CustomRecipeResult result) { - super(id, category, group, ingredient, cookingTime, experience, result); + public CustomCampfireRecipe(Key id, + boolean showNotification, + CustomRecipeResult result, + String group, + CookingRecipeCategory category, + Ingredient ingredient, + int cookingTime, + float experience) { + super(id, showNotification, result, group, category, ingredient, cookingTime, experience); } @Override @@ -31,24 +38,22 @@ public class CustomCampfireRecipe extends CustomCookingRecipe { @Override public CustomCampfireRecipe readMap(Key id, Map arguments) { return new CustomCampfireRecipe(id, - cookingRecipeCategory(arguments), - arguments.containsKey("group") ? arguments.get("group").toString() : null, + showNotification(arguments), + parseResult(arguments), arguments.containsKey("group") ? arguments.get("group").toString() : null, cookingRecipeCategory(arguments), singleInputIngredient(arguments), ResourceConfigUtils.getAsInt(arguments.getOrDefault("time", 80), "time"), - ResourceConfigUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f), "experience"), - parseResult(arguments) + ResourceConfigUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f), "experience") ); } @Override public CustomCampfireRecipe readJson(Key id, JsonObject json) { return new CustomCampfireRecipe<>(id, - VANILLA_RECIPE_HELPER.cookingCategory(json), - VANILLA_RECIPE_HELPER.readGroup(json), + true, + parseResult(VANILLA_RECIPE_HELPER.cookingResult(json.get("result"))), VANILLA_RECIPE_HELPER.readGroup(json), VANILLA_RECIPE_HELPER.cookingCategory(json), toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("ingredient"))), VANILLA_RECIPE_HELPER.cookingTime(json), - VANILLA_RECIPE_HELPER.cookingExperience(json), - parseResult(VANILLA_RECIPE_HELPER.cookingResult(json.get("result"))) + VANILLA_RECIPE_HELPER.cookingExperience(json) ); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCookingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCookingRecipe.java index 78009eab6..47eb23aa0 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCookingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCookingRecipe.java @@ -14,13 +14,14 @@ public abstract class CustomCookingRecipe extends AbstractGroupedRecipe { protected final int cookingTime; protected CustomCookingRecipe(Key id, - CookingRecipeCategory category, + boolean showNotification, + CustomRecipeResult result, String group, + CookingRecipeCategory category, Ingredient ingredient, int cookingTime, - float experience, - CustomRecipeResult result) { - super(id, group, result); + float experience) { + super(id, showNotification, result, group); this.category = category == null ? CookingRecipeCategory.MISC : category; this.ingredient = ingredient; this.experience = experience; @@ -41,10 +42,6 @@ public abstract class CustomCookingRecipe extends AbstractGroupedRecipe { return ingredient; } - public CustomRecipeResult result() { - return result; - } - public float experience() { return experience; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCraftingTableRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCraftingTableRecipe.java index be75eede6..2adf21dc3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCraftingTableRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomCraftingTableRecipe.java @@ -6,8 +6,8 @@ import net.momirealms.craftengine.core.util.Key; public abstract class CustomCraftingTableRecipe extends AbstractGroupedRecipe { protected final CraftingRecipeCategory category; - protected CustomCraftingTableRecipe(Key id, CraftingRecipeCategory category, String group, CustomRecipeResult result) { - super(id, group, result); + protected CustomCraftingTableRecipe(Key id, boolean showNotification, CustomRecipeResult result, String group, CraftingRecipeCategory category) { + super(id, showNotification, result, group); this.category = category == null ? CraftingRecipeCategory.MISC : category; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapedRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapedRecipe.java index 806beee76..70faa1450 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapedRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapedRecipe.java @@ -18,8 +18,13 @@ public class CustomShapedRecipe extends CustomCraftingTableRecipe { private final ParsedPattern parsedPattern; private final Pattern pattern; - public CustomShapedRecipe(Key id, CraftingRecipeCategory category, String group, Pattern pattern, CustomRecipeResult result) { - super(id, category, group, result); + public CustomShapedRecipe(Key id, + boolean showNotification, + CustomRecipeResult result, + String group, + CraftingRecipeCategory category, + Pattern pattern) { + super(id, showNotification, result, group, category); this.pattern = pattern; this.parsedPattern = pattern.parse(); } @@ -159,10 +164,9 @@ public class CustomShapedRecipe extends CustomCraftingTableRecipe { ingredients.put(ch, toIngredient(items)); } return new CustomShapedRecipe(id, - craftingRecipeCategory(arguments), - arguments.containsKey("group") ? arguments.get("group").toString() : null, - new Pattern<>(pattern.toArray(new String[0]), ingredients), - parseResult(arguments) + showNotification(arguments), + parseResult(arguments), arguments.containsKey("group") ? arguments.get("group").toString() : null, craftingRecipeCategory(arguments), + new Pattern<>(pattern.toArray(new String[0]), ingredients) ); } @@ -170,10 +174,9 @@ public class CustomShapedRecipe extends CustomCraftingTableRecipe { public CustomShapedRecipe readJson(Key id, JsonObject json) { Map> ingredients = Maps.transformValues(VANILLA_RECIPE_HELPER.shapedIngredientMap(json.getAsJsonObject("key")), this::toIngredient); return new CustomShapedRecipe<>(id, - VANILLA_RECIPE_HELPER.craftingCategory(json), - VANILLA_RECIPE_HELPER.readGroup(json), - new Pattern<>(VANILLA_RECIPE_HELPER.craftingShapedPattern(json), ingredients), - parseResult(VANILLA_RECIPE_HELPER.craftingResult(json.getAsJsonObject("result"))) + true, + parseResult(VANILLA_RECIPE_HELPER.craftingResult(json.getAsJsonObject("result"))), VANILLA_RECIPE_HELPER.readGroup(json), VANILLA_RECIPE_HELPER.craftingCategory(json), + new Pattern<>(VANILLA_RECIPE_HELPER.craftingShapedPattern(json), ingredients) ); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapelessRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapelessRecipe.java index 16637d5bd..d8ca669ef 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapelessRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomShapelessRecipe.java @@ -17,8 +17,13 @@ public class CustomShapelessRecipe extends CustomCraftingTableRecipe { private final List> ingredients; private final PlacementInfo placementInfo; - public CustomShapelessRecipe(Key id, CraftingRecipeCategory category, String group, List> ingredients, CustomRecipeResult result) { - super(id, category, group, result); + public CustomShapelessRecipe(Key id, + boolean showNotification, + CustomRecipeResult result, + String group, + CraftingRecipeCategory category, + List> ingredients) { + super(id, showNotification, result, group, category); this.ingredients = ingredients; this.placementInfo = PlacementInfo.create(ingredients); } @@ -43,7 +48,7 @@ public class CustomShapelessRecipe extends CustomCraftingTableRecipe { return false; } if (input.size() == 1 && this.ingredients.size() == 1) { - return this.ingredients.get(0).test(input.getItem(0)); + return this.ingredients.getFirst().test(input.getItem(0)); } return input.finder().canCraft(this); } @@ -78,19 +83,18 @@ public class CustomShapelessRecipe extends CustomCraftingTableRecipe { ingredients.add(toIngredient(ingredientsObject.toString())); } return new CustomShapelessRecipe(id, - craftingRecipeCategory(arguments), - arguments.containsKey("group") ? arguments.get("group").toString() : null, - ingredients, - parseResult(arguments)); + showNotification(arguments), + parseResult(arguments), arguments.containsKey("group") ? arguments.get("group").toString() : null, craftingRecipeCategory(arguments), + ingredients + ); } @Override public CustomShapelessRecipe readJson(Key id, JsonObject json) { return new CustomShapelessRecipe<>(id, - VANILLA_RECIPE_HELPER.craftingCategory(json), - VANILLA_RECIPE_HELPER.readGroup(json), - VANILLA_RECIPE_HELPER.shapelessIngredients(json.getAsJsonArray("ingredients")).stream().map(this::toIngredient).toList(), - parseResult(VANILLA_RECIPE_HELPER.craftingResult(json.getAsJsonObject("result"))) + true, + parseResult(VANILLA_RECIPE_HELPER.craftingResult(json.getAsJsonObject("result"))), VANILLA_RECIPE_HELPER.readGroup(json), VANILLA_RECIPE_HELPER.craftingCategory(json), + VANILLA_RECIPE_HELPER.shapelessIngredients(json.getAsJsonArray("ingredients")).stream().map(this::toIngredient).toList() ); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmeltingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmeltingRecipe.java index 7cadcc45c..9df7351f2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmeltingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmeltingRecipe.java @@ -11,8 +11,15 @@ import java.util.Map; public class CustomSmeltingRecipe extends CustomCookingRecipe { public static final Serializer SERIALIZER = new Serializer<>(); - public CustomSmeltingRecipe(Key id, CookingRecipeCategory category, String group, Ingredient ingredient, int cookingTime, float experience, CustomRecipeResult result) { - super(id, category, group, ingredient, cookingTime, experience, result); + public CustomSmeltingRecipe(Key id, + boolean showNotification, + CustomRecipeResult result, + String group, + CookingRecipeCategory category, + Ingredient ingredient, + int cookingTime, + float experience) { + super(id, showNotification, result, group, category, ingredient, cookingTime, experience); } @Override @@ -31,24 +38,22 @@ public class CustomSmeltingRecipe extends CustomCookingRecipe { @Override public CustomSmeltingRecipe readMap(Key id, Map arguments) { return new CustomSmeltingRecipe(id, - cookingRecipeCategory(arguments), - arguments.containsKey("group") ? arguments.get("group").toString() : null, + showNotification(arguments), + parseResult(arguments), arguments.containsKey("group") ? arguments.get("group").toString() : null, cookingRecipeCategory(arguments), singleInputIngredient(arguments), ResourceConfigUtils.getAsInt(arguments.getOrDefault("time", 80), "time"), - ResourceConfigUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f), "experience"), - parseResult(arguments) + ResourceConfigUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f), "experience") ); } @Override public CustomSmeltingRecipe readJson(Key id, JsonObject json) { return new CustomSmeltingRecipe<>(id, - VANILLA_RECIPE_HELPER.cookingCategory(json), - VANILLA_RECIPE_HELPER.readGroup(json), + true, + parseResult(VANILLA_RECIPE_HELPER.cookingResult(json.get("result"))), VANILLA_RECIPE_HELPER.readGroup(json), VANILLA_RECIPE_HELPER.cookingCategory(json), toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("ingredient"))), VANILLA_RECIPE_HELPER.cookingTime(json), - VANILLA_RECIPE_HELPER.cookingExperience(json), - parseResult(VANILLA_RECIPE_HELPER.cookingResult(json.get("result"))) + VANILLA_RECIPE_HELPER.cookingExperience(json) ); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTransformRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTransformRecipe.java index c73ac1b6e..dd3d7920d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTransformRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTransformRecipe.java @@ -20,10 +20,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; -public class CustomSmithingTransformRecipe implements FixedResultRecipe { +public class CustomSmithingTransformRecipe extends AbstractedFixedResultRecipe { public static final Serializer SERIALIZER = new Serializer<>(); - private final Key id; - private final CustomRecipeResult result; private final Ingredient base; private final Ingredient template; private final Ingredient addition; @@ -31,15 +29,15 @@ public class CustomSmithingTransformRecipe implements FixedResultRecipe { private final List processors; public CustomSmithingTransformRecipe(Key id, - @NotNull Ingredient base, + boolean showNotification, @Nullable Ingredient template, + @NotNull Ingredient base, @Nullable Ingredient addition, CustomRecipeResult result, - boolean mergeComponents, - List processors + List processors, + boolean mergeComponents ) { - this.id = id; - this.result = result; + super(id, showNotification, result); this.base = base; this.template = template; this.addition = addition; @@ -90,16 +88,6 @@ public class CustomSmithingTransformRecipe implements FixedResultRecipe { return RecipeType.SMITHING; } - @Override - public Key id() { - return this.id; - } - - @Nullable - public T result(ItemBuildContext context) { - return this.result.buildItemStack(context); - } - @SuppressWarnings("unchecked") @Override public T assemble(RecipeInput input, ItemBuildContext context) { @@ -117,10 +105,6 @@ public class CustomSmithingTransformRecipe implements FixedResultRecipe { return finalResult.getItem(); } - public CustomRecipeResult result() { - return this.result; - } - @NotNull public Ingredient base() { return this.base; @@ -148,24 +132,20 @@ public class CustomSmithingTransformRecipe implements FixedResultRecipe { @SuppressWarnings("unchecked") List> processors = (List>) arguments.getOrDefault("post-processors", List.of()); return new CustomSmithingTransformRecipe<>(id, - ResourceConfigUtils.requireNonNullOrThrow(toIngredient(base), "warning.config.recipe.smithing_transform.missing_base"), + showNotification(arguments), toIngredient(template), + ResourceConfigUtils.requireNonNullOrThrow(toIngredient(base), "warning.config.recipe.smithing_transform.missing_base"), toIngredient(addition), parseResult(arguments), - mergeComponents, - ItemDataProcessors.fromMapList(processors) + ItemDataProcessors.fromMapList(processors), + mergeComponents ); } @Override public CustomSmithingTransformRecipe readJson(Key id, JsonObject json) { return new CustomSmithingTransformRecipe<>(id, - Objects.requireNonNull(toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("base")))), - toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("template"))), - toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("addition"))), - parseResult(VANILLA_RECIPE_HELPER.smithingResult(json.getAsJsonObject("result"))), - true, - null + true, toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("template"))), Objects.requireNonNull(toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("base")))), toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("addition"))), parseResult(VANILLA_RECIPE_HELPER.smithingResult(json.getAsJsonObject("result"))), null, true ); } } @@ -173,7 +153,6 @@ public class CustomSmithingTransformRecipe implements FixedResultRecipe { public static class ItemDataProcessors { public static final Key KEEP_COMPONENTS = Key.of("craftengine:keep_components"); public static final Key KEEP_TAGS = Key.of("craftengine:keep_tags"); - public static final Key APPLY_DATA = Key.of("craftengine:apply_data"); static { if (VersionHelper.isOrAbove1_20_5()) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTrimRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTrimRecipe.java index 51c2a5491..a85d30573 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTrimRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTrimRecipe.java @@ -18,9 +18,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; -public class CustomSmithingTrimRecipe implements Recipe { +public class CustomSmithingTrimRecipe extends AbstractRecipe { public static final Serializer SERIALIZER = new Serializer<>(); - private final Key id; private final Ingredient base; private final Ingredient template; private final Ingredient addition; @@ -28,12 +27,13 @@ public class CustomSmithingTrimRecipe implements Recipe { private final Key pattern; public CustomSmithingTrimRecipe(@NotNull Key id, - @NotNull Ingredient base, + boolean showNotification, @NotNull Ingredient template, + @NotNull Ingredient base, @NotNull Ingredient addition, @Nullable Key pattern ) { - this.id = id; + super(id, showNotification); this.base = base; this.template = template; this.addition = addition; @@ -83,11 +83,6 @@ public class CustomSmithingTrimRecipe implements Recipe { return RecipeType.SMITHING; } - @Override - public Key id() { - return this.id; - } - @NotNull public Ingredient base() { return this.base; @@ -118,17 +113,20 @@ public class CustomSmithingTrimRecipe implements Recipe { List addition = MiscUtils.getAsStringList(arguments.get("addition")); Key pattern = VersionHelper.isOrAbove1_21_5() ? Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("pattern"), "warning.config.recipe.smithing_trim.missing_pattern")) : null; return new CustomSmithingTrimRecipe<>(id, - ResourceConfigUtils.requireNonNullOrThrow(toIngredient(base), "warning.config.recipe.smithing_trim.missing_base"), + showNotification(arguments), ResourceConfigUtils.requireNonNullOrThrow(toIngredient(template), "warning.config.recipe.smithing_trim.missing_template_type"), + ResourceConfigUtils.requireNonNullOrThrow(toIngredient(base), "warning.config.recipe.smithing_trim.missing_base"), ResourceConfigUtils.requireNonNullOrThrow(toIngredient(addition), "warning.config.recipe.smithing_trim.missing_addition"), - pattern); + pattern + ); } @Override public CustomSmithingTrimRecipe readJson(Key id, JsonObject json) { return new CustomSmithingTrimRecipe<>(id, - Objects.requireNonNull(toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("base")))), + VANILLA_RECIPE_HELPER.showNotification(json), Objects.requireNonNull(toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("template")))), + Objects.requireNonNull(toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("base")))), Objects.requireNonNull(toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("addition")))), VersionHelper.isOrAbove1_21_5() ? Key.of(json.get("pattern").getAsString()) : null ); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmokingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmokingRecipe.java index eb0bca8f5..357d047f4 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmokingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmokingRecipe.java @@ -11,8 +11,15 @@ import java.util.Map; public class CustomSmokingRecipe extends CustomCookingRecipe { public static final Serializer SERIALIZER = new Serializer<>(); - public CustomSmokingRecipe(Key id, CookingRecipeCategory category, String group, Ingredient ingredient, int cookingTime, float experience, CustomRecipeResult result) { - super(id, category, group, ingredient, cookingTime, experience, result); + public CustomSmokingRecipe(Key id, + boolean showNotification, + CustomRecipeResult result, + String group, + CookingRecipeCategory category, + Ingredient ingredient, + int cookingTime, + float experience) { + super(id, showNotification, result, group, category, ingredient, cookingTime, experience); } @Override @@ -31,24 +38,22 @@ public class CustomSmokingRecipe extends CustomCookingRecipe { @Override public CustomSmokingRecipe readMap(Key id, Map arguments) { return new CustomSmokingRecipe(id, - cookingRecipeCategory(arguments), - arguments.containsKey("group") ? arguments.get("group").toString() : null, + showNotification(arguments), + parseResult(arguments), arguments.containsKey("group") ? arguments.get("group").toString() : null, cookingRecipeCategory(arguments), singleInputIngredient(arguments), ResourceConfigUtils.getAsInt(arguments.getOrDefault("time", 80), "time"), - ResourceConfigUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f), "experience"), - parseResult(arguments) + ResourceConfigUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f), "experience") ); } @Override public CustomSmokingRecipe readJson(Key id, JsonObject json) { return new CustomSmokingRecipe<>(id, - VANILLA_RECIPE_HELPER.cookingCategory(json), - VANILLA_RECIPE_HELPER.readGroup(json), + true, + parseResult(VANILLA_RECIPE_HELPER.cookingResult(json.get("result"))), VANILLA_RECIPE_HELPER.readGroup(json), VANILLA_RECIPE_HELPER.cookingCategory(json), toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("ingredient"))), VANILLA_RECIPE_HELPER.cookingTime(json), - VANILLA_RECIPE_HELPER.cookingExperience(json), - parseResult(VANILLA_RECIPE_HELPER.cookingResult(json.get("result"))) + VANILLA_RECIPE_HELPER.cookingExperience(json) ); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomStoneCuttingRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomStoneCuttingRecipe.java index 0476b96d7..2277e5a7a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomStoneCuttingRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomStoneCuttingRecipe.java @@ -14,8 +14,8 @@ public class CustomStoneCuttingRecipe extends AbstractGroupedRecipe { public static final Serializer SERIALIZER = new Serializer<>(); protected final Ingredient ingredient; - public CustomStoneCuttingRecipe(Key id, String group, Ingredient ingredient, CustomRecipeResult result) { - super(id, group, result); + public CustomStoneCuttingRecipe(Key id, boolean showNotification, CustomRecipeResult result, String group, Ingredient ingredient) { + super(id, showNotification, result, group); this.ingredient = ingredient; } @@ -50,13 +50,21 @@ public class CustomStoneCuttingRecipe extends AbstractGroupedRecipe { @Override public CustomStoneCuttingRecipe readMap(Key id, Map arguments) { String group = arguments.containsKey("group") ? arguments.get("group").toString() : null; - return new CustomStoneCuttingRecipe<>(id, group, singleInputIngredient(arguments), parseResult(arguments)); + return new CustomStoneCuttingRecipe<>(id, + showNotification(arguments), + parseResult(arguments), group, + singleInputIngredient(arguments) + ); } @Override public CustomStoneCuttingRecipe readJson(Key id, JsonObject json) { String group = VANILLA_RECIPE_HELPER.readGroup(json); - return new CustomStoneCuttingRecipe<>(id, group, toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("ingredient"))), parseResult(VANILLA_RECIPE_HELPER.stoneCuttingResult(json))); + return new CustomStoneCuttingRecipe<>(id, + true, + parseResult(VANILLA_RECIPE_HELPER.stoneCuttingResult(json)), group, + toIngredient(VANILLA_RECIPE_HELPER.singleIngredient(json.get("ingredient"))) + ); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/FixedResultRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/FixedResultRecipe.java deleted file mode 100644 index 757d37533..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/FixedResultRecipe.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.momirealms.craftengine.core.item.recipe; - -import net.momirealms.craftengine.core.item.ItemBuildContext; -import net.momirealms.craftengine.core.item.recipe.input.RecipeInput; -import net.momirealms.craftengine.core.item.recipe.result.CustomRecipeResult; - -public interface FixedResultRecipe extends Recipe { - - T result(ItemBuildContext context); - - CustomRecipeResult result(); - - - - @Override - default T assemble(RecipeInput input, ItemBuildContext context) { - return this.result(context); - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/reader/VanillaRecipeReader.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/reader/VanillaRecipeReader.java index 3f5e432d9..a811f4c26 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/reader/VanillaRecipeReader.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/reader/VanillaRecipeReader.java @@ -44,4 +44,6 @@ public interface VanillaRecipeReader { @NotNull DatapackRecipeResult stoneCuttingResult(JsonObject json); List singleIngredient(JsonElement json); + + boolean showNotification(JsonObject json); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/reader/VanillaRecipeReader1_20.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/reader/VanillaRecipeReader1_20.java index 4a34fd17d..1d3fdfd98 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/reader/VanillaRecipeReader1_20.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/reader/VanillaRecipeReader1_20.java @@ -144,4 +144,9 @@ public class VanillaRecipeReader1_20 implements VanillaRecipeReader { } return ingredients; } + + @Override + public boolean showNotification(JsonObject json) { + return !json.has("show_notification") || json.get("show_notification").getAsBoolean(); + } }