9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-28 03:19:14 +00:00

Seeing Through the Trick

This commit is contained in:
XiaoMoMi
2025-02-15 01:44:26 +08:00
parent 6f850ff7b3
commit f832614755
65 changed files with 985 additions and 106 deletions

View File

@@ -6,8 +6,10 @@ import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.sparrow.nbt.StringTag;
import net.momirealms.sparrow.nbt.Tag;
import java.lang.reflect.Array;
import java.util.*;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
public class StringProperty extends Property<String> {
public static final Factory FACTORY = new Factory();

View File

@@ -2,9 +2,6 @@ package net.momirealms.craftengine.core.item.modifier;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.plugin.minimessage.ImageTag;
import net.momirealms.craftengine.core.plugin.minimessage.PlaceholderTag;
import net.momirealms.craftengine.core.util.AdventureHelper;
public class UnbreakableModifier<I> implements ItemModifier<I> {
private final boolean argument;

View File

@@ -3,20 +3,12 @@ package net.momirealms.craftengine.core.item.recipe;
import org.jetbrains.annotations.Nullable;
public abstract class AbstractRecipe<T> implements Recipe<T> {
protected RecipeCategory category;
protected String group;
protected AbstractRecipe(RecipeCategory category, String group) {
this.category = category;
protected AbstractRecipe(String group) {
this.group = group;
}
@Override
@Nullable
public RecipeCategory category() {
return category;
}
@Override
@Nullable
public String group() {

View File

@@ -0,0 +1,15 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.item.recipe.input.RecipeInput;
public class CookingInput<T> implements RecipeInput {
private final OptimizedIDItem<T> input;
public CookingInput(OptimizedIDItem<T> input) {
this.input = input;
}
public OptimizedIDItem<T> input() {
return input;
}
}

View File

@@ -0,0 +1,57 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.recipe.input.RecipeInput;
public abstract class CookingRecipe<T> extends AbstractRecipe<T> {
protected final CookingRecipeCategory category;
protected final Ingredient<T> ingredient;
protected final CustomRecipeResult<T> result;
protected final float experience;
protected final int cookingTime;
protected CookingRecipe(CookingRecipeCategory category,
String group,
Ingredient<T> ingredient,
int cookingTime,
float experience,
CustomRecipeResult<T> result) {
super(group);
this.category = category;
this.ingredient = ingredient;
this.result = result;
this.experience = experience;
this.cookingTime = cookingTime;
}
@SuppressWarnings("unchecked")
@Override
public boolean matches(RecipeInput input) {
return this.ingredient.test(((CookingInput<T>) input).input());
}
@Override
public T getResult(Player player) {
return this.result.buildItemStack(player);
}
public CookingRecipeCategory category() {
return category;
}
public Ingredient<T> ingredient() {
return ingredient;
}
public CustomRecipeResult<T> result() {
return result;
}
public float experience() {
return experience;
}
public int cookingTime() {
return cookingTime;
}
}

View File

@@ -0,0 +1,7 @@
package net.momirealms.craftengine.core.item.recipe;
public enum CookingRecipeCategory {
FOOD,
BLOCKS,
MISC
}

View File

@@ -1,6 +1,6 @@
package net.momirealms.craftengine.core.item.recipe;
public enum RecipeCategory {
public enum CraftingRecipeCategory {
BUILDING,
REDSTONE,
EQUIPMENT,

View File

@@ -1,8 +1,14 @@
package net.momirealms.craftengine.core.item.recipe;
public abstract class CraftingTableRecipe<T> extends AbstractRecipe<T> {
protected final CraftingRecipeCategory category;
protected CraftingTableRecipe(RecipeCategory category, String group) {
super(category, group);
protected CraftingTableRecipe(CraftingRecipeCategory category, String group) {
super(group);
this.category = category;
}
public CraftingRecipeCategory category() {
return category;
}
}

View File

@@ -0,0 +1,52 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class CustomBlastingRecipe<T> extends CookingRecipe<T> {
public static final Factory<?> FACTORY = new Factory<>();
public CustomBlastingRecipe(CookingRecipeCategory category, String group, Ingredient<T> ingredient, int cookingTime, float experience, CustomRecipeResult<T> result) {
super(category, group, ingredient, cookingTime, experience, result);
}
@Override
public @NotNull Key type() {
return RecipeTypes.BLASTING;
}
public static class Factory<A> implements RecipeFactory<CustomBlastingRecipe<A>> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<CustomBlastingRecipe<A>> create(Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80));
float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f));
List<String> items = MiscUtils.getAsStringList(arguments.get("ingredient"));
Set<Holder<Key>> holders = new HashSet<>();
for (String item : items) {
if (item.charAt(0) == '#') {
holders.addAll(CraftEngine.instance().itemManager().tagToItems(Key.of(item.substring(1))));
} else {
holders.add(BuiltInRegistries.OPTIMIZED_ITEM_ID.get(Key.of(item)).orElseThrow(() -> new IllegalArgumentException("Invalid vanilla/custom item: " + item)));
}
}
return new CustomBlastingRecipe(
recipeCategory,
group,
Ingredient.of(holders),
cookingTime,
experience,
parseResult(arguments)
);
}
}
}

View File

@@ -0,0 +1,52 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class CustomCampfireRecipe<T> extends CookingRecipe<T> {
public static final Factory<?> FACTORY = new Factory<>();
public CustomCampfireRecipe(CookingRecipeCategory category, String group, Ingredient<T> ingredient, int cookingTime, float experience, CustomRecipeResult<T> result) {
super(category, group, ingredient, cookingTime, experience, result);
}
@Override
public @NotNull Key type() {
return RecipeTypes.CAMPFIRE_COOKING;
}
public static class Factory<A> implements RecipeFactory<CustomCampfireRecipe<A>> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<CustomCampfireRecipe<A>> create(Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80));
float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f));
List<String> items = MiscUtils.getAsStringList(arguments.get("ingredient"));
Set<Holder<Key>> holders = new HashSet<>();
for (String item : items) {
if (item.charAt(0) == '#') {
holders.addAll(CraftEngine.instance().itemManager().tagToItems(Key.of(item.substring(1))));
} else {
holders.add(BuiltInRegistries.OPTIMIZED_ITEM_ID.get(Key.of(item)).orElseThrow(() -> new IllegalArgumentException("Invalid vanilla/custom item: " + item)));
}
}
return new CustomCampfireRecipe(
recipeCategory,
group,
Ingredient.of(holders),
cookingTime,
experience,
parseResult(arguments)
);
}
}
}

View File

@@ -18,7 +18,7 @@ public class CustomShapedRecipe<T> extends CraftingTableRecipe<T> {
private final Pattern<T> pattern;
private final CustomRecipeResult<T> result;
public CustomShapedRecipe(RecipeCategory category, String group, Pattern<T> pattern, CustomRecipeResult<T> result) {
public CustomShapedRecipe(CraftingRecipeCategory category, String group, Pattern<T> pattern, CustomRecipeResult<T> result) {
super(category, group);
this.pattern = pattern;
this.parsedPattern = pattern.parse();
@@ -152,7 +152,7 @@ public class CustomShapedRecipe<T> extends CraftingTableRecipe<T> {
if (ingredientMap == null) {
throw new IllegalArgumentException("ingredients cannot be empty");
}
RecipeCategory recipeCategory = arguments.containsKey("category") ? RecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
CraftingRecipeCategory recipeCategory = arguments.containsKey("category") ? CraftingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
Map<Character, Ingredient<A>> ingredients = new HashMap<>();
for (Map.Entry<String, Object> entry : ingredientMap.entrySet()) {

View File

@@ -18,7 +18,7 @@ public class CustomShapelessRecipe<T> extends CraftingTableRecipe<T> {
private final PlacementInfo<T> placementInfo;
private final CustomRecipeResult<T> result;
public CustomShapelessRecipe(RecipeCategory category, String group, List<Ingredient<T>> ingredients, CustomRecipeResult<T> result) {
public CustomShapelessRecipe(CraftingRecipeCategory category, String group, List<Ingredient<T>> ingredients, CustomRecipeResult<T> result) {
super(category, group);
this.ingredients = ingredients;
this.result = result;
@@ -68,7 +68,7 @@ public class CustomShapelessRecipe<T> extends CraftingTableRecipe<T> {
if (ingredientMap == null) {
throw new IllegalArgumentException("ingredients cannot be empty");
}
RecipeCategory recipeCategory = arguments.containsKey("category") ? RecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
CraftingRecipeCategory recipeCategory = arguments.containsKey("category") ? CraftingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
List<Ingredient<A>> ingredients = new ArrayList<>();
for (Map.Entry<String, Object> entry : ingredientMap.entrySet()) {

View File

@@ -0,0 +1,52 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class CustomSmeltingRecipe<T> extends CookingRecipe<T> {
public static final Factory<?> FACTORY = new Factory<>();
public CustomSmeltingRecipe(CookingRecipeCategory category, String group, Ingredient<T> ingredient, int cookingTime, float experience, CustomRecipeResult<T> result) {
super(category, group, ingredient, cookingTime, experience, result);
}
@Override
public @NotNull Key type() {
return RecipeTypes.SMELTING;
}
public static class Factory<A> implements RecipeFactory<CustomSmeltingRecipe<A>> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<CustomSmeltingRecipe<A>> create(Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80));
float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f));
List<String> items = MiscUtils.getAsStringList(arguments.get("ingredient"));
Set<Holder<Key>> holders = new HashSet<>();
for (String item : items) {
if (item.charAt(0) == '#') {
holders.addAll(CraftEngine.instance().itemManager().tagToItems(Key.of(item.substring(1))));
} else {
holders.add(BuiltInRegistries.OPTIMIZED_ITEM_ID.get(Key.of(item)).orElseThrow(() -> new IllegalArgumentException("Invalid vanilla/custom item: " + item)));
}
}
return new CustomSmeltingRecipe(
recipeCategory,
group,
Ingredient.of(holders),
cookingTime,
experience,
parseResult(arguments)
);
}
}
}

View File

@@ -0,0 +1,52 @@
package net.momirealms.craftengine.core.item.recipe;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class CustomSmokingRecipe<T> extends CookingRecipe<T> {
public static final Factory<?> FACTORY = new Factory<>();
public CustomSmokingRecipe(CookingRecipeCategory category, String group, Ingredient<T> ingredient, int cookingTime, float experience, CustomRecipeResult<T> result) {
super(category, group, ingredient, cookingTime, experience, result);
}
@Override
public @NotNull Key type() {
return RecipeTypes.SMOKING;
}
public static class Factory<A> implements RecipeFactory<CustomSmokingRecipe<A>> {
@SuppressWarnings({"unchecked", "rawtypes", "DuplicatedCode"})
@Override
public Recipe<CustomSmokingRecipe<A>> create(Map<String, Object> arguments) {
CookingRecipeCategory recipeCategory = arguments.containsKey("category") ? CookingRecipeCategory.valueOf(arguments.get("category").toString().toUpperCase(Locale.ENGLISH)) : null;
String group = arguments.containsKey("group") ? arguments.get("group").toString() : null;
int cookingTime = MiscUtils.getAsInt(arguments.getOrDefault("time", 80));
float experience = MiscUtils.getAsFloat(arguments.getOrDefault("experience", 0.0f));
List<String> items = MiscUtils.getAsStringList(arguments.get("ingredient"));
Set<Holder<Key>> holders = new HashSet<>();
for (String item : items) {
if (item.charAt(0) == '#') {
holders.addAll(CraftEngine.instance().itemManager().tagToItems(Key.of(item.substring(1))));
} else {
holders.add(BuiltInRegistries.OPTIMIZED_ITEM_ID.get(Key.of(item)).orElseThrow(() -> new IllegalArgumentException("Invalid vanilla/custom item: " + item)));
}
}
return new CustomSmokingRecipe(
recipeCategory,
group,
Ingredient.of(holders),
cookingTime,
experience,
parseResult(arguments)
);
}
}
}

View File

@@ -15,9 +15,6 @@ public interface Recipe<T> {
@NotNull
Key type();
@Nullable
RecipeCategory category();
@Nullable
String group();
}

View File

@@ -12,10 +12,18 @@ import java.util.Map;
public class RecipeTypes {
public static final Key SHAPED = Key.of("minecraft:shaped");
public static final Key SHAPELESS = Key.of("minecraft:shapeless");
public static final Key SMELTING = Key.of("minecraft:smelting");
public static final Key BLASTING = Key.of("minecraft:blasting");
public static final Key SMOKING = Key.of("minecraft:smoking");
public static final Key CAMPFIRE_COOKING = Key.of("minecraft:campfire_cooking");
static {
register(SHAPED, CustomShapedRecipe.FACTORY);
register(SHAPELESS, CustomShapelessRecipe.FACTORY);
register(SMELTING, CustomSmeltingRecipe.FACTORY);
register(SMOKING, CustomSmokingRecipe.FACTORY);
register(BLASTING, CustomBlastingRecipe.FACTORY);
register(CAMPFIRE_COOKING, CustomCampfireRecipe.FACTORY);
}
public static <T> void register(Key key, RecipeFactory<T> factory) {

View File

@@ -0,0 +1,12 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
import java.util.List;
public class VanillaBlastingRecipe extends VanillaCookingRecipe {
public VanillaBlastingRecipe(CookingRecipeCategory category, String group, RecipeResult result, List<String> ingredient, float experience, int cookingTime) {
super(category, group, result, ingredient, experience, cookingTime);
}
}

View File

@@ -0,0 +1,12 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
import java.util.List;
public class VanillaCampfireRecipe extends VanillaCookingRecipe {
public VanillaCampfireRecipe(CookingRecipeCategory category, String group, RecipeResult result, List<String> ingredient, float experience, int cookingTime) {
super(category, group, result, ingredient, experience, cookingTime);
}
}

View File

@@ -0,0 +1,36 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
import java.util.List;
public abstract class VanillaCookingRecipe extends VanillaRecipe {
protected final List<String> ingredient;
protected final CookingRecipeCategory category;
protected final float experience;
protected final int cookingTime;
protected VanillaCookingRecipe(CookingRecipeCategory category, String group, RecipeResult result, List<String> ingredient, float experience, int cookingTime) {
super(group, result);
this.ingredient = ingredient;
this.experience = experience;
this.cookingTime = cookingTime;
this.category = category;
}
public CookingRecipeCategory category() {
return category;
}
public List<String> ingredient() {
return ingredient;
}
public float experience() {
return experience;
}
public int cookingTime() {
return cookingTime;
}
}

View File

@@ -0,0 +1,16 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
public class VanillaCraftingRecipe extends VanillaRecipe {
protected final CraftingRecipeCategory category;
protected VanillaCraftingRecipe(CraftingRecipeCategory category, String group, RecipeResult result) {
super(group, result);
this.category = category;
}
public CraftingRecipeCategory category() {
return category;
}
}

View File

@@ -1,22 +1,14 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.RecipeCategory;
public abstract class VanillaRecipe {
protected final String group;
protected final RecipeCategory category;
protected final RecipeResult result;
protected VanillaRecipe(RecipeCategory category, String group, RecipeResult result) {
this.category = category;
protected VanillaRecipe(String group, RecipeResult result) {
this.group = group;
this.result = result;
}
public RecipeCategory category() {
return category;
}
public String group() {
return group;
}

View File

@@ -7,4 +7,12 @@ public interface VanillaRecipeReader {
VanillaShapedRecipe readShaped(JsonObject json);
VanillaShapelessRecipe readShapeless(JsonObject json);
VanillaBlastingRecipe readBlasting(JsonObject json);
VanillaSmeltingRecipe readSmelting(JsonObject json);
VanillaSmokingRecipe readSmoking(JsonObject json);
VanillaCampfireRecipe readCampfire(JsonObject json);
}

View File

@@ -1,15 +1,15 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.RecipeCategory;
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
import java.util.List;
import java.util.Map;
public class VanillaShapedRecipe extends VanillaRecipe {
public class VanillaShapedRecipe extends VanillaCraftingRecipe {
private final String[] pattern;
private final Map<Character, List<String>> key;
public VanillaShapedRecipe(RecipeCategory category,
public VanillaShapedRecipe(CraftingRecipeCategory category,
String group,
Map<Character, List<String>> key,
String[] pattern,

View File

@@ -1,13 +1,13 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.RecipeCategory;
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
import java.util.List;
public class VanillaShapelessRecipe extends VanillaRecipe {
public class VanillaShapelessRecipe extends VanillaCraftingRecipe {
private final List<List<String>> ingredients;
public VanillaShapelessRecipe(RecipeCategory category, String group, List<List<String>> ingredients, RecipeResult result) {
public VanillaShapelessRecipe(CraftingRecipeCategory category, String group, List<List<String>> ingredients, RecipeResult result) {
super(category, group, result);
this.ingredients = ingredients;
}

View File

@@ -0,0 +1,12 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
import java.util.List;
public class VanillaSmeltingRecipe extends VanillaCookingRecipe {
public VanillaSmeltingRecipe(CookingRecipeCategory category, String group, RecipeResult result, List<String> ingredient, float experience, int cookingTime) {
super(category, group, result, ingredient, experience, cookingTime);
}
}

View File

@@ -0,0 +1,12 @@
package net.momirealms.craftengine.core.item.recipe.vanilla;
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
import java.util.List;
public class VanillaSmokingRecipe extends VanillaCookingRecipe {
public VanillaSmokingRecipe(CookingRecipeCategory category, String group, RecipeResult result, List<String> ingredient, float experience, int cookingTime) {
super(category, group, result, ingredient, experience, cookingTime);
}
}

View File

@@ -3,7 +3,8 @@ package net.momirealms.craftengine.core.item.recipe.vanilla.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.item.recipe.RecipeCategory;
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
import net.momirealms.craftengine.core.item.recipe.vanilla.VanillaRecipeReader;
import org.jetbrains.annotations.Nullable;
@@ -28,7 +29,20 @@ public abstract class AbstractRecipeReader implements VanillaRecipeReader {
}
@Nullable
protected RecipeCategory readCategory(JsonObject object) {
return object.has("category") ? RecipeCategory.valueOf(object.get("category").getAsString().toUpperCase(Locale.ENGLISH)) : null;
protected CraftingRecipeCategory readCraftingCategory(JsonObject object) {
return object.has("category") ? CraftingRecipeCategory.valueOf(object.get("category").getAsString().toUpperCase(Locale.ENGLISH)) : null;
}
@Nullable
protected CookingRecipeCategory readCookingCategory(JsonObject object) {
return object.has("category") ? CookingRecipeCategory.valueOf(object.get("category").getAsString().toUpperCase(Locale.ENGLISH)) : null;
}
protected float readExperience(JsonObject object) {
return object.has("experience") ? object.get("experience").getAsFloat() : 0;
}
protected int readCookingTime(JsonObject object) {
return object.has("cookingtime") ? object.get("cookingtime").getAsInt() : 200;
}
}

View File

@@ -3,9 +3,7 @@ package net.momirealms.craftengine.core.item.recipe.vanilla.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.item.recipe.vanilla.RecipeResult;
import net.momirealms.craftengine.core.item.recipe.vanilla.VanillaShapedRecipe;
import net.momirealms.craftengine.core.item.recipe.vanilla.VanillaShapelessRecipe;
import net.momirealms.craftengine.core.item.recipe.vanilla.*;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -18,7 +16,7 @@ public class VanillaRecipeReader1_20 extends AbstractRecipeReader {
@Override
public VanillaShapedRecipe readShaped(JsonObject json) {
return new VanillaShapedRecipe(
readCategory(json),
readCraftingCategory(json),
readGroup(json),
readShapedIngredientMap(json.getAsJsonObject("key")),
readPattern(json),
@@ -29,13 +27,77 @@ public class VanillaRecipeReader1_20 extends AbstractRecipeReader {
@Override
public VanillaShapelessRecipe readShapeless(JsonObject json) {
return new VanillaShapelessRecipe(
readCategory(json),
readCraftingCategory(json),
readGroup(json),
readShapelessIngredients(json.getAsJsonArray("ingredients")),
readResult(json.getAsJsonObject("result"))
);
}
@Override
public VanillaBlastingRecipe readBlasting(JsonObject json) {
return new VanillaBlastingRecipe(
readCookingCategory(json),
readGroup(json),
readResult(json.getAsJsonObject("result")),
readCookingIngredients(json.get("ingredient")),
readExperience(json),
readCookingTime(json)
);
}
@Override
public VanillaSmeltingRecipe readSmelting(JsonObject json) {
return new VanillaSmeltingRecipe(
readCookingCategory(json),
readGroup(json),
readResult(json.getAsJsonObject("result")),
readCookingIngredients(json.get("ingredient")),
readExperience(json),
readCookingTime(json)
);
}
@Override
public VanillaSmokingRecipe readSmoking(JsonObject json) {
return new VanillaSmokingRecipe(
readCookingCategory(json),
readGroup(json),
readResult(json.getAsJsonObject("result")),
readCookingIngredients(json.get("ingredient")),
readExperience(json),
readCookingTime(json)
);
}
@Override
public VanillaCampfireRecipe readCampfire(JsonObject json) {
return new VanillaCampfireRecipe(
readCookingCategory(json),
readGroup(json),
readResult(json.getAsJsonObject("result")),
readCookingIngredients(json.get("ingredient")),
readExperience(json),
readCookingTime(json)
);
}
protected List<String> readCookingIngredients(JsonElement json) {
List<String> ingredients = new ArrayList<>();
if (json.isJsonObject()) {
JsonObject argument = json.getAsJsonObject();
if (argument.has("item")) {
ingredients.add(argument.get("item").getAsString());
} else if (argument.has("tag")) {
ingredients.add("#" + argument.get("tag").getAsString());
}
} else if (json.isJsonArray()) {
List<String> items = readIngredientList((JsonArray) json);
ingredients.addAll(items);
}
return ingredients;
}
@NotNull
protected RecipeResult readResult(JsonObject object) {
String item = object.get("item").getAsString();

View File

@@ -11,6 +11,20 @@ import java.util.Map;
public class VanillaRecipeReader1_21_2 extends VanillaRecipeReader1_20_5 {
@Override
protected List<String> readCookingIngredients(JsonElement json) {
if (json.isJsonPrimitive()) {
return List.of(json.getAsString());
} else {
JsonArray array = json.getAsJsonArray();
List<String> ingredients = new ArrayList<>();
for (JsonElement element : array) {
ingredients.add(element.getAsString());
}
return ingredients;
}
}
@Override
protected Map<Character, List<String>> readShapedIngredientMap(JsonObject json) {
Map<Character, List<String>> ingredients = new HashMap<>();

View File

@@ -7,7 +7,6 @@ import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.loot.provider.NumberProvider;
import net.momirealms.craftengine.core.loot.provider.NumberProviders;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.Collections;
import java.util.List;

View File

@@ -8,10 +8,11 @@ import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.loot.provider.NumberProvider;
import net.momirealms.craftengine.core.loot.provider.NumberProviders;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.world.Vec3d;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class DropExpFunction<T> extends AbstractLootConditionalFunction<T> {
public static final Factory<?> FACTORY = new Factory<>();

View File

@@ -7,7 +7,6 @@ import net.momirealms.craftengine.core.font.FontManagerImpl;
import net.momirealms.craftengine.core.item.ItemManager;
import net.momirealms.craftengine.core.item.recipe.RecipeManager;
import net.momirealms.craftengine.core.pack.PackManager;
import net.momirealms.craftengine.core.pack.PackManagerImpl;
import net.momirealms.craftengine.core.plugin.classpath.ClassPathAppender;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
import net.momirealms.craftengine.core.plugin.command.sender.SenderFactory;

View File

@@ -0,0 +1,6 @@
package net.momirealms.craftengine.core.util;
@FunctionalInterface
public interface HexaFunction<T, U, V, W, X, Y, R> {
R apply(T t, U u, V v, W w, X x, Y y);
}

View File

@@ -0,0 +1,6 @@
package net.momirealms.craftengine.core.util;
@FunctionalInterface
public interface PentaFunction<T, U, V, W, X, R> {
R apply(T t, U u, V v, W w, X x);
}