9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 09:59:20 +00:00

修改配方结构

This commit is contained in:
XiaoMoMi
2025-08-05 20:07:14 +08:00
parent cceff15588
commit 9788052904
20 changed files with 201 additions and 183 deletions

View File

@@ -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<T> implements FixedResultRecipe<T> {
public abstract class AbstractGroupedRecipe<T> extends AbstractedFixedResultRecipe<T> {
protected final String group;
protected final Key id;
protected final CustomRecipeResult<T> result;
protected AbstractGroupedRecipe(Key id, String group, CustomRecipeResult<T> result) {
protected AbstractGroupedRecipe(Key id, boolean showNotification, CustomRecipeResult<T> 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<T> result() {
return this.result;
}
}

View File

@@ -0,0 +1,23 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.util.Key;
public abstract class AbstractRecipe<T> implements Recipe<T> {
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;
}
}

View File

@@ -103,7 +103,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
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<Key> usedKeys = new HashSet<>();

View File

@@ -26,6 +26,10 @@ public abstract class AbstractRecipeSerializer<T, R extends Recipe<T>> implement
new VanillaRecipeReader1_20_5() :
new VanillaRecipeReader1_20();
protected boolean showNotification(Map<String, Object> arguments) {
return ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("show-notification", true), "show-notification");
}
protected Ingredient<T> singleInputIngredient(Map<String, Object> arguments) {
List<String> ingredients = MiscUtils.getAsStringList(getIngredientOrThrow(arguments));
return toIngredient(ingredients);

View File

@@ -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<T> extends AbstractRecipe<T> {
protected CustomRecipeResult<T> result;
public AbstractedFixedResultRecipe(Key id, boolean showNotification, CustomRecipeResult<T> result) {
super(id, showNotification);
this.result = result;
}
public T result(ItemBuildContext context) {
return this.result.buildItemStack(context);
}
public CustomRecipeResult<T> result() {
return this.result;
}
@Override
public T assemble(RecipeInput input, ItemBuildContext context) {
return this.result(context);
}
}

View File

@@ -11,8 +11,15 @@ import java.util.Map;
public class CustomBlastingRecipe<T> extends CustomCookingRecipe<T> {
public static final Serializer<?> SERIALIZER = new Serializer<>();
public CustomBlastingRecipe(Key id, CookingRecipeCategory category, String group, Ingredient<T> ingredient, int cookingTime, float experience, CustomRecipeResult<T> result) {
super(id, category, group, ingredient, cookingTime, experience, result);
public CustomBlastingRecipe(Key id,
boolean showNotification,
CustomRecipeResult<T> result,
String group,
CookingRecipeCategory category,
Ingredient<T> ingredient,
int cookingTime,
float experience) {
super(id, showNotification, result, group, category, ingredient, cookingTime, experience);
}
@Override
@@ -31,24 +38,22 @@ public class CustomBlastingRecipe<T> extends CustomCookingRecipe<T> {
@Override
public CustomBlastingRecipe<A> readMap(Key id, Map<String, Object> 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<A> 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)
);
}
}

View File

@@ -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<T> implements FixedResultRecipe<T> {
public class CustomBrewingRecipe<T> extends AbstractedFixedResultRecipe<T> {
public static final Serializer<?> SERIALIZER = new Serializer<>();
private final Key id;
private final Ingredient<T> container;
private final Ingredient<T> ingredient;
private final CustomRecipeResult<T> result;
public CustomBrewingRecipe(@NotNull Key id,
@NotNull Ingredient<T> container,
@NotNull Ingredient<T> ingredient,
@NotNull CustomRecipeResult<T> result) {
this.id = id;
@NotNull CustomRecipeResult<T> result,
boolean showNotification) {
super(id, showNotification, result);
this.container = container;
this.ingredient = ingredient;
this.result = result;
}
@Override
public CustomRecipeResult<T> 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<T> implements FixedResultRecipe<T> {
return this.ingredient;
}
@Override
public Key id() {
return this.id;
}
@SuppressWarnings({"DuplicatedCode"})
public static class Serializer<A> extends AbstractRecipeSerializer<A, CustomBrewingRecipe<A>> {
@@ -98,7 +81,9 @@ public class CustomBrewingRecipe<T> implements FixedResultRecipe<T> {
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

View File

@@ -11,8 +11,15 @@ import java.util.Map;
public class CustomCampfireRecipe<T> extends CustomCookingRecipe<T> {
public static final Serializer<?> SERIALIZER = new Serializer<>();
public CustomCampfireRecipe(Key id, CookingRecipeCategory category, String group, Ingredient<T> ingredient, int cookingTime, float experience, CustomRecipeResult<T> result) {
super(id, category, group, ingredient, cookingTime, experience, result);
public CustomCampfireRecipe(Key id,
boolean showNotification,
CustomRecipeResult<T> result,
String group,
CookingRecipeCategory category,
Ingredient<T> ingredient,
int cookingTime,
float experience) {
super(id, showNotification, result, group, category, ingredient, cookingTime, experience);
}
@Override
@@ -31,24 +38,22 @@ public class CustomCampfireRecipe<T> extends CustomCookingRecipe<T> {
@Override
public CustomCampfireRecipe<A> readMap(Key id, Map<String, Object> 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<A> 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)
);
}
}

View File

@@ -14,13 +14,14 @@ public abstract class CustomCookingRecipe<T> extends AbstractGroupedRecipe<T> {
protected final int cookingTime;
protected CustomCookingRecipe(Key id,
CookingRecipeCategory category,
boolean showNotification,
CustomRecipeResult<T> result,
String group,
CookingRecipeCategory category,
Ingredient<T> ingredient,
int cookingTime,
float experience,
CustomRecipeResult<T> 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<T> extends AbstractGroupedRecipe<T> {
return ingredient;
}
public CustomRecipeResult<T> result() {
return result;
}
public float experience() {
return experience;
}

View File

@@ -6,8 +6,8 @@ import net.momirealms.craftengine.core.util.Key;
public abstract class CustomCraftingTableRecipe<T> extends AbstractGroupedRecipe<T> {
protected final CraftingRecipeCategory category;
protected CustomCraftingTableRecipe(Key id, CraftingRecipeCategory category, String group, CustomRecipeResult<T> result) {
super(id, group, result);
protected CustomCraftingTableRecipe(Key id, boolean showNotification, CustomRecipeResult<T> result, String group, CraftingRecipeCategory category) {
super(id, showNotification, result, group);
this.category = category == null ? CraftingRecipeCategory.MISC : category;
}

View File

@@ -18,8 +18,13 @@ public class CustomShapedRecipe<T> extends CustomCraftingTableRecipe<T> {
private final ParsedPattern<T> parsedPattern;
private final Pattern<T> pattern;
public CustomShapedRecipe(Key id, CraftingRecipeCategory category, String group, Pattern<T> pattern, CustomRecipeResult<T> result) {
super(id, category, group, result);
public CustomShapedRecipe(Key id,
boolean showNotification,
CustomRecipeResult<T> result,
String group,
CraftingRecipeCategory category,
Pattern<T> pattern) {
super(id, showNotification, result, group, category);
this.pattern = pattern;
this.parsedPattern = pattern.parse();
}
@@ -159,10 +164,9 @@ public class CustomShapedRecipe<T> extends CustomCraftingTableRecipe<T> {
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<T> extends CustomCraftingTableRecipe<T> {
public CustomShapedRecipe<A> readJson(Key id, JsonObject json) {
Map<Character, Ingredient<A>> 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)
);
}

View File

@@ -17,8 +17,13 @@ public class CustomShapelessRecipe<T> extends CustomCraftingTableRecipe<T> {
private final List<Ingredient<T>> ingredients;
private final PlacementInfo<T> placementInfo;
public CustomShapelessRecipe(Key id, CraftingRecipeCategory category, String group, List<Ingredient<T>> ingredients, CustomRecipeResult<T> result) {
super(id, category, group, result);
public CustomShapelessRecipe(Key id,
boolean showNotification,
CustomRecipeResult<T> result,
String group,
CraftingRecipeCategory category,
List<Ingredient<T>> ingredients) {
super(id, showNotification, result, group, category);
this.ingredients = ingredients;
this.placementInfo = PlacementInfo.create(ingredients);
}
@@ -43,7 +48,7 @@ public class CustomShapelessRecipe<T> extends CustomCraftingTableRecipe<T> {
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<T> extends CustomCraftingTableRecipe<T> {
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<A> 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()
);
}
}

View File

@@ -11,8 +11,15 @@ import java.util.Map;
public class CustomSmeltingRecipe<T> extends CustomCookingRecipe<T> {
public static final Serializer<?> SERIALIZER = new Serializer<>();
public CustomSmeltingRecipe(Key id, CookingRecipeCategory category, String group, Ingredient<T> ingredient, int cookingTime, float experience, CustomRecipeResult<T> result) {
super(id, category, group, ingredient, cookingTime, experience, result);
public CustomSmeltingRecipe(Key id,
boolean showNotification,
CustomRecipeResult<T> result,
String group,
CookingRecipeCategory category,
Ingredient<T> ingredient,
int cookingTime,
float experience) {
super(id, showNotification, result, group, category, ingredient, cookingTime, experience);
}
@Override
@@ -31,24 +38,22 @@ public class CustomSmeltingRecipe<T> extends CustomCookingRecipe<T> {
@Override
public CustomSmeltingRecipe<A> readMap(Key id, Map<String, Object> 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<A> 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)
);
}
}

View File

@@ -20,10 +20,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
public class CustomSmithingTransformRecipe<T> implements FixedResultRecipe<T> {
public class CustomSmithingTransformRecipe<T> extends AbstractedFixedResultRecipe<T> {
public static final Serializer<?> SERIALIZER = new Serializer<>();
private final Key id;
private final CustomRecipeResult<T> result;
private final Ingredient<T> base;
private final Ingredient<T> template;
private final Ingredient<T> addition;
@@ -31,15 +29,15 @@ public class CustomSmithingTransformRecipe<T> implements FixedResultRecipe<T> {
private final List<ItemDataProcessor> processors;
public CustomSmithingTransformRecipe(Key id,
@NotNull Ingredient<T> base,
boolean showNotification,
@Nullable Ingredient<T> template,
@NotNull Ingredient<T> base,
@Nullable Ingredient<T> addition,
CustomRecipeResult<T> result,
boolean mergeComponents,
List<ItemDataProcessor> processors
List<ItemDataProcessor> 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<T> implements FixedResultRecipe<T> {
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<T> implements FixedResultRecipe<T> {
return finalResult.getItem();
}
public CustomRecipeResult<T> result() {
return this.result;
}
@NotNull
public Ingredient<T> base() {
return this.base;
@@ -148,24 +132,20 @@ public class CustomSmithingTransformRecipe<T> implements FixedResultRecipe<T> {
@SuppressWarnings("unchecked")
List<Map<String, Object>> processors = (List<Map<String, Object>>) 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<A> 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<T> implements FixedResultRecipe<T> {
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()) {

View File

@@ -18,9 +18,8 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
public class CustomSmithingTrimRecipe<T> implements Recipe<T> {
public class CustomSmithingTrimRecipe<T> extends AbstractRecipe<T> {
public static final Serializer<?> SERIALIZER = new Serializer<>();
private final Key id;
private final Ingredient<T> base;
private final Ingredient<T> template;
private final Ingredient<T> addition;
@@ -28,12 +27,13 @@ public class CustomSmithingTrimRecipe<T> implements Recipe<T> {
private final Key pattern;
public CustomSmithingTrimRecipe(@NotNull Key id,
@NotNull Ingredient<T> base,
boolean showNotification,
@NotNull Ingredient<T> template,
@NotNull Ingredient<T> base,
@NotNull Ingredient<T> 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<T> implements Recipe<T> {
return RecipeType.SMITHING;
}
@Override
public Key id() {
return this.id;
}
@NotNull
public Ingredient<T> base() {
return this.base;
@@ -118,17 +113,20 @@ public class CustomSmithingTrimRecipe<T> implements Recipe<T> {
List<String> 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<A> 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
);

View File

@@ -11,8 +11,15 @@ import java.util.Map;
public class CustomSmokingRecipe<T> extends CustomCookingRecipe<T> {
public static final Serializer<?> SERIALIZER = new Serializer<>();
public CustomSmokingRecipe(Key id, CookingRecipeCategory category, String group, Ingredient<T> ingredient, int cookingTime, float experience, CustomRecipeResult<T> result) {
super(id, category, group, ingredient, cookingTime, experience, result);
public CustomSmokingRecipe(Key id,
boolean showNotification,
CustomRecipeResult<T> result,
String group,
CookingRecipeCategory category,
Ingredient<T> ingredient,
int cookingTime,
float experience) {
super(id, showNotification, result, group, category, ingredient, cookingTime, experience);
}
@Override
@@ -31,24 +38,22 @@ public class CustomSmokingRecipe<T> extends CustomCookingRecipe<T> {
@Override
public CustomSmokingRecipe<A> readMap(Key id, Map<String, Object> 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<A> 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)
);
}
}

View File

@@ -14,8 +14,8 @@ public class CustomStoneCuttingRecipe<T> extends AbstractGroupedRecipe<T> {
public static final Serializer<?> SERIALIZER = new Serializer<>();
protected final Ingredient<T> ingredient;
public CustomStoneCuttingRecipe(Key id, String group, Ingredient<T> ingredient, CustomRecipeResult<T> result) {
super(id, group, result);
public CustomStoneCuttingRecipe(Key id, boolean showNotification, CustomRecipeResult<T> result, String group, Ingredient<T> ingredient) {
super(id, showNotification, result, group);
this.ingredient = ingredient;
}
@@ -50,13 +50,21 @@ public class CustomStoneCuttingRecipe<T> extends AbstractGroupedRecipe<T> {
@Override
public CustomStoneCuttingRecipe<A> readMap(Key id, Map<String, Object> 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<A> 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")))
);
}
}
}

View File

@@ -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<T> extends Recipe<T> {
T result(ItemBuildContext context);
CustomRecipeResult<T> result();
@Override
default T assemble(RecipeInput input, ItemBuildContext context) {
return this.result(context);
}
}

View File

@@ -44,4 +44,6 @@ public interface VanillaRecipeReader {
@NotNull DatapackRecipeResult stoneCuttingResult(JsonObject json);
List<String> singleIngredient(JsonElement json);
boolean showNotification(JsonObject json);
}

View File

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