mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 03:19:14 +00:00
使用更高效的合成配方判定
This commit is contained in:
@@ -22,7 +22,7 @@ import java.util.*;
|
||||
|
||||
public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
|
||||
protected final VanillaRecipeReader recipeReader;
|
||||
protected final Map<Key, List<Recipe<T>>> byType = new HashMap<>();
|
||||
protected final Map<RecipeType, List<Recipe<T>>> byType = new HashMap<>();
|
||||
protected final Map<Key, Recipe<T>> byId = new HashMap<>();
|
||||
protected final Map<Key, List<Recipe<T>>> byResult = new HashMap<>();
|
||||
protected final Map<Key, List<Recipe<T>>> byIngredient = new HashMap<>();
|
||||
@@ -84,7 +84,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Recipe<T>> recipesByType(Key type) {
|
||||
public List<Recipe<T>> recipesByType(RecipeType type) {
|
||||
if (this.isReloading) return List.of();
|
||||
return this.byType.getOrDefault(type, List.of());
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Recipe<T> recipeByInput(Key type, RecipeInput input) {
|
||||
public Recipe<T> recipeByInput(RecipeType type, RecipeInput input) {
|
||||
if (this.isReloading) return null;
|
||||
List<Recipe<T>> recipes = this.byType.get(type);
|
||||
if (recipes == null) return null;
|
||||
@@ -117,7 +117,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Recipe<T> recipeByInput(Key type, RecipeInput input, Key lastRecipe) {
|
||||
public Recipe<T> recipeByInput(RecipeType type, RecipeInput input, Key lastRecipe) {
|
||||
if (this.isReloading) return null;
|
||||
if (lastRecipe != null) {
|
||||
Recipe<T> last = this.byId.get(lastRecipe);
|
||||
@@ -164,7 +164,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
|
||||
if (AbstractRecipeManager.this.byId.containsKey(id)) {
|
||||
throw new LocalizedResourceConfigException("warning.config.recipe.duplicate", path, id);
|
||||
}
|
||||
Recipe<T> recipe = RecipeTypes.fromMap(id, section);
|
||||
Recipe<T> recipe = RecipeSerializers.fromMap(id, section);
|
||||
try {
|
||||
registerInternalRecipe(id, recipe);
|
||||
registerPlatformRecipe(id, recipe);
|
||||
|
||||
@@ -16,8 +16,13 @@ public class CustomBlastingRecipe<T> extends CustomCookingRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.BLASTING;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.BLASTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.BLASTING;
|
||||
}
|
||||
|
||||
public static class Factory<A> extends AbstractRecipeFactory<A> {
|
||||
|
||||
@@ -56,8 +56,13 @@ public class CustomBrewingRecipe<T> implements FixedResultRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.BREWING;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.BREWING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.BREWING;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,8 +16,13 @@ public class CustomCampfireRecipe<T> extends CustomCookingRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.CAMPFIRE_COOKING;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.CAMPFIRE_COOKING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.CAMPFIRE_COOKING;
|
||||
}
|
||||
|
||||
public static class Factory<A> extends AbstractRecipeFactory<A> {
|
||||
|
||||
@@ -13,4 +13,9 @@ public abstract class CustomCraftingTableRecipe<T> extends AbstractGroupedRecipe
|
||||
public CraftingRecipeCategory category() {
|
||||
return category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.CRAFTING;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ public class CustomShapedRecipe<T> extends CustomCraftingTableRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.SHAPED;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.SHAPED;
|
||||
}
|
||||
|
||||
public Pattern<T> pattern() {
|
||||
|
||||
@@ -47,8 +47,8 @@ public class CustomShapelessRecipe<T> extends CustomCraftingTableRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.SHAPELESS;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.SHAPELESS;
|
||||
}
|
||||
|
||||
public static class Factory<A> extends AbstractRecipeFactory<A> {
|
||||
|
||||
@@ -16,8 +16,13 @@ public class CustomSmeltingRecipe<T> extends CustomCookingRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.SMELTING;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.SMELTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.SMELTING;
|
||||
}
|
||||
|
||||
public static class Factory<A> extends AbstractRecipeFactory<A> {
|
||||
|
||||
@@ -78,8 +78,13 @@ public class CustomSmithingTransformRecipe<T> implements FixedResultRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.SMITHING_TRANSFORM;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.SMITHING_TRANSFORM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.SMITHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,8 +80,13 @@ public class CustomSmithingTrimRecipe<T> implements Recipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.SMITHING_TRIM;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.SMITHING_TRIM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.SMITHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,8 +16,13 @@ public class CustomSmokingRecipe<T> extends CustomCookingRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.SMOKING;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.SMOKING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.SMOKING;
|
||||
}
|
||||
|
||||
public static class Factory<A> extends AbstractRecipeFactory<A> {
|
||||
|
||||
@@ -31,8 +31,13 @@ public class CustomStoneCuttingRecipe<T> extends AbstractGroupedRecipe<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Key type() {
|
||||
return RecipeTypes.STONECUTTING;
|
||||
public @NotNull Key serializerType() {
|
||||
return RecipeSerializers.STONECUTTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType type() {
|
||||
return RecipeType.STONECUTTING;
|
||||
}
|
||||
|
||||
public Ingredient<T> ingredient() {
|
||||
|
||||
@@ -16,7 +16,9 @@ public interface Recipe<T> {
|
||||
List<Ingredient<T>> ingredientsInUse();
|
||||
|
||||
@NotNull
|
||||
Key type();
|
||||
Key serializerType();
|
||||
|
||||
RecipeType type();
|
||||
|
||||
Key id();
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ public interface RecipeManager<T> extends Manageable {
|
||||
|
||||
Optional<Recipe<T>> recipeById(Key id);
|
||||
|
||||
List<Recipe<T>> recipesByType(Key type);
|
||||
List<Recipe<T>> recipesByType(RecipeType type);
|
||||
|
||||
List<Recipe<T>> recipeByResult(Key result);
|
||||
|
||||
List<Recipe<T>> recipeByIngredient(Key ingredient);
|
||||
|
||||
@Nullable
|
||||
Recipe<T> recipeByInput(Key type, RecipeInput input);
|
||||
Recipe<T> recipeByInput(RecipeType type, RecipeInput input);
|
||||
|
||||
@Nullable
|
||||
Recipe<T> recipeByInput(Key type, RecipeInput input, @Nullable Key lastRecipe);
|
||||
Recipe<T> recipeByInput(RecipeType type, RecipeInput input, @Nullable Key lastRecipe);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class RecipeTypes {
|
||||
public final class RecipeSerializers {
|
||||
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");
|
||||
@@ -21,7 +21,6 @@ public class RecipeTypes {
|
||||
public static final Key SMITHING_TRANSFORM = Key.of("minecraft:smithing_transform");
|
||||
public static final Key SMITHING_TRIM = Key.of("minecraft:smithing_trim");
|
||||
public static final Key BREWING = Key.of("minecraft:brewing");
|
||||
public static final Key SPECIAL = Key.of("minecraft:special");
|
||||
|
||||
static {
|
||||
register(SHAPED, CustomShapedRecipe.FACTORY);
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.momirealms.craftengine.core.item.recipe;
|
||||
|
||||
public enum RecipeType {
|
||||
CRAFTING("crafting"),
|
||||
SMELTING("smelting"),
|
||||
BLASTING("blasting"),
|
||||
SMOKING("smoking"),
|
||||
CAMPFIRE_COOKING("campfire_cooking"),
|
||||
STONECUTTING("stonecutting"),
|
||||
BREWING("brewing"),
|
||||
SMITHING("smithing");
|
||||
|
||||
private final String id;
|
||||
|
||||
RecipeType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,6 +14,6 @@ public class VanillaBlastingRecipe extends VanillaCookingRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.BLASTING;
|
||||
return RecipeSerializers.BLASTING;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,6 +14,6 @@ public class VanillaCampfireRecipe extends VanillaCookingRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.CAMPFIRE_COOKING;
|
||||
return RecipeSerializers.CAMPFIRE_COOKING;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
@@ -31,6 +31,6 @@ public class VanillaShapedRecipe extends VanillaCraftingRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.SHAPED;
|
||||
return RecipeSerializers.SHAPED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.CraftingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
@@ -20,6 +20,6 @@ public class VanillaShapelessRecipe extends VanillaCraftingRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.SHAPELESS;
|
||||
return RecipeSerializers.SHAPELESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,6 +14,6 @@ public class VanillaSmeltingRecipe extends VanillaCookingRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.SMELTING;
|
||||
return RecipeSerializers.SMELTING;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
@@ -20,7 +20,7 @@ public class VanillaSmithingTransformRecipe implements VanillaRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.SMITHING_TRANSFORM;
|
||||
return RecipeSerializers.SMITHING_TRANSFORM;
|
||||
}
|
||||
|
||||
public RecipeResult result() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class VanillaSmithingTrimRecipe implements VanillaRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.SMITHING_TRIM;
|
||||
return RecipeSerializers.SMITHING_TRIM;
|
||||
}
|
||||
|
||||
public List<String> base() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.CookingRecipeCategory;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,6 +14,6 @@ public class VanillaSmokingRecipe extends VanillaCookingRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.SMOKING;
|
||||
return RecipeSerializers.SMOKING;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.item.recipe.vanilla;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeSerializers;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
@@ -19,6 +19,6 @@ public class VanillaStoneCuttingRecipe extends VanillaGroupedRecipe {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return RecipeTypes.STONECUTTING;
|
||||
return RecipeSerializers.STONECUTTING;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,24 +392,24 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
if (index >= recipes.size()) return;
|
||||
if (depth > MAX_RECIPE_DEPTH) return;
|
||||
Recipe<Object> recipe = recipes.get(index);
|
||||
Key recipeType = recipe.type();
|
||||
if (recipeType == RecipeTypes.SHAPELESS || recipeType == RecipeTypes.SHAPED) {
|
||||
Key recipeType = recipe.serializerType();
|
||||
if (recipeType == RecipeSerializers.SHAPELESS || recipeType == RecipeSerializers.SHAPED) {
|
||||
openCraftingRecipePage(player, (CustomCraftingTableRecipe<Object>) recipe, parentGui, recipes, index, depth, canOpenNoRecipePage);
|
||||
return;
|
||||
}
|
||||
if (recipeType == RecipeTypes.BLASTING || recipeType == RecipeTypes.CAMPFIRE_COOKING || recipeType == RecipeTypes.SMOKING || recipeType == RecipeTypes.SMELTING) {
|
||||
if (recipeType == RecipeSerializers.BLASTING || recipeType == RecipeSerializers.CAMPFIRE_COOKING || recipeType == RecipeSerializers.SMOKING || recipeType == RecipeSerializers.SMELTING) {
|
||||
openCookingRecipePage(player, (CustomCookingRecipe<Object>) recipe, parentGui, recipes, index, depth, canOpenNoRecipePage);
|
||||
return;
|
||||
}
|
||||
if (recipeType == RecipeTypes.STONECUTTING) {
|
||||
if (recipeType == RecipeSerializers.STONECUTTING) {
|
||||
openStoneCuttingRecipePage(player, (CustomStoneCuttingRecipe<Object>) recipe, parentGui, recipes, index, depth, canOpenNoRecipePage);
|
||||
return;
|
||||
}
|
||||
if (recipeType == RecipeTypes.SMITHING_TRANSFORM) {
|
||||
if (recipeType == RecipeSerializers.SMITHING_TRANSFORM) {
|
||||
openSmithingTransformRecipePage(player, (CustomSmithingTransformRecipe<Object>) recipe, parentGui, recipes, index, depth, canOpenNoRecipePage);
|
||||
return;
|
||||
}
|
||||
if (recipeType == RecipeTypes.BREWING) {
|
||||
if (recipeType == RecipeSerializers.BREWING) {
|
||||
openBrewingRecipePage(player, (CustomBrewingRecipe<Object>) recipe, parentGui, recipes, index, depth, canOpenNoRecipePage);
|
||||
return;
|
||||
}
|
||||
@@ -1041,11 +1041,11 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}));
|
||||
|
||||
String title;
|
||||
if (recipe.type() == RecipeTypes.SMELTING) {
|
||||
if (recipe.serializerType() == RecipeSerializers.SMELTING) {
|
||||
title = Constants.RECIPE_SMELTING_TITLE;
|
||||
} else if (recipe.type() == RecipeTypes.BLASTING) {
|
||||
} else if (recipe.serializerType() == RecipeSerializers.BLASTING) {
|
||||
title = Constants.RECIPE_BLASTING_TITLE;
|
||||
} else if (recipe.type() == RecipeTypes.CAMPFIRE_COOKING) {
|
||||
} else if (recipe.serializerType() == RecipeSerializers.CAMPFIRE_COOKING) {
|
||||
title = Constants.RECIPE_CAMPFIRE_TITLE;
|
||||
} else {
|
||||
title = Constants.RECIPE_SMOKING_TITLE;
|
||||
@@ -1154,7 +1154,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}));
|
||||
|
||||
char start = 'A';
|
||||
if (recipe.type() == RecipeTypes.SHAPED) {
|
||||
if (recipe.serializerType() == RecipeSerializers.SHAPED) {
|
||||
String[] pattern = ((CustomShapedRecipe<Object>) recipe).pattern().pattern();
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 3; y++) {
|
||||
|
||||
Reference in New Issue
Block a user