mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
使用更高效的合成配方判定
This commit is contained in:
@@ -174,7 +174,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
}
|
||||
|
||||
static {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.SMITHING_TRANSFORM, (BukkitRecipeConvertor<CustomSmithingTransformRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.SMITHING_TRANSFORM, (BukkitRecipeConvertor<CustomSmithingTransformRecipe<ItemStack>>) (id, recipe) -> {
|
||||
try {
|
||||
Object nmsRecipe = createMinecraftSmithingTransformRecipe(recipe);
|
||||
return () -> MINECRAFT_RECIPE_ADDER.accept(id, nmsRecipe);
|
||||
@@ -185,7 +185,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.SMITHING_TRIM, (BukkitRecipeConvertor<CustomSmithingTrimRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.SMITHING_TRIM, (BukkitRecipeConvertor<CustomSmithingTrimRecipe<ItemStack>>) (id, recipe) -> {
|
||||
try {
|
||||
Object nmsRecipe = createMinecraftSmithingTrimRecipe(recipe);
|
||||
return () -> MINECRAFT_RECIPE_ADDER.accept(id, nmsRecipe);
|
||||
@@ -197,7 +197,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
}
|
||||
});
|
||||
// TODO DO NOT USE BUKKIT RECIPE AS BRIDGE IN FUTURE VERSIONS, WE SHOULD DIRECTLY CONSTRUCT THOSE NMS RECIPES
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.SHAPED, (BukkitRecipeConvertor<CustomShapedRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.SHAPED, (BukkitRecipeConvertor<CustomShapedRecipe<ItemStack>>) (id, recipe) -> {
|
||||
ShapedRecipe shapedRecipe = new ShapedRecipe(new NamespacedKey(id.namespace(), id.value()), recipe.result(ItemBuildContext.EMPTY));
|
||||
if (recipe.group() != null) shapedRecipe.setGroup(Objects.requireNonNull(recipe.group()));
|
||||
if (recipe.category() != null) shapedRecipe.setCategory(CraftingBookCategory.valueOf(Objects.requireNonNull(recipe.category()).name()));
|
||||
@@ -210,7 +210,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
injectShapedRecipe(id, recipe);
|
||||
};
|
||||
});
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.SHAPELESS, (BukkitRecipeConvertor<CustomShapelessRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.SHAPELESS, (BukkitRecipeConvertor<CustomShapelessRecipe<ItemStack>>) (id, recipe) -> {
|
||||
ShapelessRecipe shapelessRecipe = new ShapelessRecipe(new NamespacedKey(id.namespace(), id.value()), recipe.result(ItemBuildContext.EMPTY));
|
||||
if (recipe.group() != null) shapelessRecipe.setGroup(Objects.requireNonNull(recipe.group()));
|
||||
if (recipe.category() != null) shapelessRecipe.setCategory(CraftingBookCategory.valueOf(Objects.requireNonNull(recipe.category()).name()));
|
||||
@@ -222,7 +222,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
injectShapelessRecipe(id, recipe);
|
||||
};
|
||||
});
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.SMELTING, (BukkitRecipeConvertor<CustomSmeltingRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.SMELTING, (BukkitRecipeConvertor<CustomSmeltingRecipe<ItemStack>>) (id, recipe) -> {
|
||||
FurnaceRecipe furnaceRecipe = new FurnaceRecipe(
|
||||
new NamespacedKey(id.namespace(), id.value()), recipe.result(ItemBuildContext.EMPTY),
|
||||
ingredientToBukkitRecipeChoice(recipe.ingredient()),
|
||||
@@ -235,7 +235,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
injectCookingRecipe(id, recipe);
|
||||
};
|
||||
});
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.SMOKING, (BukkitRecipeConvertor<CustomSmokingRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.SMOKING, (BukkitRecipeConvertor<CustomSmokingRecipe<ItemStack>>) (id, recipe) -> {
|
||||
SmokingRecipe smokingRecipe = new SmokingRecipe(
|
||||
new NamespacedKey(id.namespace(), id.value()), recipe.result(ItemBuildContext.EMPTY),
|
||||
ingredientToBukkitRecipeChoice(recipe.ingredient()),
|
||||
@@ -248,7 +248,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
injectCookingRecipe(id, recipe);
|
||||
};
|
||||
});
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.BLASTING, (BukkitRecipeConvertor<CustomBlastingRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.BLASTING, (BukkitRecipeConvertor<CustomBlastingRecipe<ItemStack>>) (id, recipe) -> {
|
||||
BlastingRecipe blastingRecipe = new BlastingRecipe(
|
||||
new NamespacedKey(id.namespace(), id.value()), recipe.result(ItemBuildContext.EMPTY),
|
||||
ingredientToBukkitRecipeChoice(recipe.ingredient()),
|
||||
@@ -261,7 +261,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
injectCookingRecipe(id, recipe);
|
||||
};
|
||||
});
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.CAMPFIRE_COOKING, (BukkitRecipeConvertor<CustomCampfireRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.CAMPFIRE_COOKING, (BukkitRecipeConvertor<CustomCampfireRecipe<ItemStack>>) (id, recipe) -> {
|
||||
CampfireRecipe campfireRecipe = new CampfireRecipe(
|
||||
new NamespacedKey(id.namespace(), id.value()), recipe.result(ItemBuildContext.EMPTY),
|
||||
ingredientToBukkitRecipeChoice(recipe.ingredient()),
|
||||
@@ -274,7 +274,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
injectCookingRecipe(id, recipe);
|
||||
};
|
||||
});
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeTypes.STONECUTTING, (BukkitRecipeConvertor<CustomStoneCuttingRecipe<ItemStack>>) (id, recipe) -> {
|
||||
MIXED_RECIPE_CONVERTORS.put(RecipeSerializers.STONECUTTING, (BukkitRecipeConvertor<CustomStoneCuttingRecipe<ItemStack>>) (id, recipe) -> {
|
||||
List<ItemStack> itemStacks = new ArrayList<>();
|
||||
for (UniqueKey item : recipe.ingredient().items()) {
|
||||
itemStacks.add(BukkitItemManager.instance().buildItemStack(item.key(), null));
|
||||
@@ -304,10 +304,10 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
private final BukkitCraftEngine plugin;
|
||||
private final RecipeEventListener recipeEventListener;
|
||||
private final CrafterEventListener crafterEventListener;
|
||||
// To optimize recipes loading, will return the flag later
|
||||
private Object stolenFeatureFlagSet;
|
||||
// Some delayed tasks on main thread
|
||||
private final List<Runnable> delayedTasksOnMainThread = new ArrayList<>();
|
||||
// To optimize recipes loading, will return the flag later
|
||||
private Object stolenFeatureFlagSet;
|
||||
|
||||
public BukkitRecipeManager(BukkitCraftEngine plugin) {
|
||||
instance = this;
|
||||
@@ -431,7 +431,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager<ItemStack> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends Recipe<ItemStack>> BukkitRecipeConvertor<T> findNMSRecipeConvertor(T recipe) {
|
||||
return (BukkitRecipeConvertor<T>) MIXED_RECIPE_CONVERTORS.get(recipe.type());
|
||||
return (BukkitRecipeConvertor<T>) MIXED_RECIPE_CONVERTORS.get(recipe.serializerType());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemManager;
|
||||
import net.momirealms.craftengine.core.item.recipe.Recipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeType;
|
||||
import net.momirealms.craftengine.core.item.recipe.UniqueIdItem;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.CraftingInput;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
@@ -71,12 +71,7 @@ public class CrafterEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(RecipeTypes.SHAPELESS, input);
|
||||
if (ceRecipe != null) {
|
||||
event.setResult(ceRecipe.assemble(input, ItemBuildContext.EMPTY));
|
||||
return;
|
||||
}
|
||||
ceRecipe = this.recipeManager.recipeByInput(RecipeTypes.SHAPED, input);
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(RecipeType.CRAFTING, input);
|
||||
if (ceRecipe != null) {
|
||||
event.setResult(ceRecipe.assemble(input, ItemBuildContext.EMPTY));
|
||||
return;
|
||||
|
||||
@@ -75,13 +75,13 @@ public class RecipeEventListener implements Listener {
|
||||
if (ItemStackUtils.isEmpty(item)) return;
|
||||
if (ItemStackUtils.isEmpty(fuelStack)) {
|
||||
SingleItemInput<ItemStack> input = new SingleItemInput<>(getUniqueIdItem(item));
|
||||
Key recipeType;
|
||||
RecipeType recipeType;
|
||||
if (furnaceInventory.getType() == InventoryType.FURNACE) {
|
||||
recipeType = RecipeTypes.SMELTING;
|
||||
recipeType = RecipeType.SMELTING;
|
||||
} else if (furnaceInventory.getType() == InventoryType.BLAST_FURNACE) {
|
||||
recipeType = RecipeTypes.BLASTING;
|
||||
recipeType = RecipeType.BLASTING;
|
||||
} else {
|
||||
recipeType = RecipeTypes.SMOKING;
|
||||
recipeType = RecipeType.SMOKING;
|
||||
}
|
||||
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(recipeType, input);
|
||||
@@ -352,7 +352,7 @@ public class RecipeEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
SingleItemInput<ItemStack> input = new SingleItemInput<>(getUniqueIdItem(itemStack));
|
||||
CustomCampfireRecipe<ItemStack> ceRecipe = (CustomCampfireRecipe<ItemStack>) this.recipeManager.recipeByInput(RecipeTypes.CAMPFIRE_COOKING, input);
|
||||
CustomCampfireRecipe<ItemStack> ceRecipe = (CustomCampfireRecipe<ItemStack>) this.recipeManager.recipeByInput(RecipeType.CAMPFIRE_COOKING, input);
|
||||
if (ceRecipe == null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -377,7 +377,7 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
ItemStack itemStack = event.getSource();
|
||||
SingleItemInput<ItemStack> input = new SingleItemInput<>(getUniqueIdItem(itemStack));
|
||||
CustomCampfireRecipe<ItemStack> ceRecipe = (CustomCampfireRecipe<ItemStack>) this.recipeManager.recipeByInput(RecipeTypes.CAMPFIRE_COOKING, input);
|
||||
CustomCampfireRecipe<ItemStack> ceRecipe = (CustomCampfireRecipe<ItemStack>) this.recipeManager.recipeByInput(RecipeType.CAMPFIRE_COOKING, input);
|
||||
if (ceRecipe == null) {
|
||||
event.setTotalCookTime(Integer.MAX_VALUE);
|
||||
return;
|
||||
@@ -405,7 +405,7 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
ItemStack itemStack = event.getSource();
|
||||
SingleItemInput<ItemStack> input = new SingleItemInput<>(getUniqueIdItem(itemStack));
|
||||
CustomCampfireRecipe<ItemStack> ceRecipe = (CustomCampfireRecipe<ItemStack>) this.recipeManager.recipeByInput(RecipeTypes.CAMPFIRE_COOKING, input);
|
||||
CustomCampfireRecipe<ItemStack> ceRecipe = (CustomCampfireRecipe<ItemStack>) this.recipeManager.recipeByInput(RecipeType.CAMPFIRE_COOKING, input);
|
||||
if (ceRecipe == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@@ -815,18 +815,8 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
Player player = InventoryUtils.getPlayerFromInventoryEvent(event);
|
||||
BukkitServerPlayer serverPlayer = this.plugin.adapt(player);
|
||||
Key lastRecipe = serverPlayer.lastUsedRecipe();
|
||||
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(RecipeTypes.SHAPELESS, input, lastRecipe);
|
||||
if (ceRecipe != null) {
|
||||
inventory.setResult(ceRecipe.assemble(input, new ItemBuildContext(serverPlayer, ContextHolder.EMPTY)));
|
||||
serverPlayer.setLastUsedRecipe(ceRecipe.id());
|
||||
if (!ceRecipe.id().equals(recipeId)) {
|
||||
correctCraftingRecipeUsed(inventory, ceRecipe);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ceRecipe = this.recipeManager.recipeByInput(RecipeTypes.SHAPED, input, lastRecipe);
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(RecipeType.CRAFTING, input, recipeId);
|
||||
if (ceRecipe != null) {
|
||||
inventory.setResult(ceRecipe.assemble(input, new ItemBuildContext(serverPlayer, ContextHolder.EMPTY)));
|
||||
serverPlayer.setLastUsedRecipe(ceRecipe.id());
|
||||
@@ -902,7 +892,7 @@ public class RecipeEventListener implements Listener {
|
||||
getUniqueIdItem(inventory.getInputMineral())
|
||||
);
|
||||
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(RecipeTypes.SMITHING_TRIM, input);
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(RecipeType.SMITHING, input, recipeId);
|
||||
if (ceRecipe == null) {
|
||||
event.setResult(null);
|
||||
return;
|
||||
@@ -940,7 +930,7 @@ public class RecipeEventListener implements Listener {
|
||||
getUniqueIdItem(addition)
|
||||
);
|
||||
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(RecipeTypes.SMITHING_TRANSFORM, input);
|
||||
Recipe<ItemStack> ceRecipe = this.recipeManager.recipeByInput(RecipeType.SMITHING, input, recipeId);
|
||||
if (ceRecipe == null) {
|
||||
event.setResult(null);
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.injector;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeType;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public interface InjectedCacheCheck {
|
||||
@@ -8,9 +9,9 @@ public interface InjectedCacheCheck {
|
||||
|
||||
void recipeType(Object recipeType);
|
||||
|
||||
Key customRecipeType();
|
||||
RecipeType customRecipeType();
|
||||
|
||||
void customRecipeType(Key customRecipeType);
|
||||
void customRecipeType(RecipeType customRecipeType);
|
||||
|
||||
Object lastRecipe();
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemKeys;
|
||||
import net.momirealms.craftengine.core.item.data.FireworkExplosion;
|
||||
import net.momirealms.craftengine.core.item.recipe.CustomCookingRecipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeType;
|
||||
import net.momirealms.craftengine.core.item.recipe.UniqueIdItem;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.SingleItemInput;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
@@ -61,7 +61,7 @@ public class RecipeInjector {
|
||||
.defineField("recipeType", Object.class, Visibility.PUBLIC)
|
||||
.method(ElementMatchers.named("recipeType"))
|
||||
.intercept(FieldAccessor.ofField("recipeType"))
|
||||
.defineField("customRecipeType", Key.class, Visibility.PUBLIC)
|
||||
.defineField("customRecipeType", RecipeType.class, Visibility.PUBLIC)
|
||||
.method(ElementMatchers.named("customRecipeType"))
|
||||
.intercept(FieldAccessor.ofField("customRecipeType"))
|
||||
.defineField("lastRecipe", Object.class, Visibility.PUBLIC)
|
||||
@@ -158,13 +158,13 @@ public class RecipeInjector {
|
||||
Object recipeType = FastNMS.INSTANCE.field$AbstractFurnaceBlockEntity$recipeType(entity);
|
||||
InjectedCacheCheck injectedChecker = (InjectedCacheCheck) ReflectionUtils.UNSAFE.allocateInstance(clazz$InjectedCacheChecker);
|
||||
if (recipeType == MRecipeTypes.SMELTING) {
|
||||
injectedChecker.customRecipeType(RecipeTypes.SMELTING);
|
||||
injectedChecker.customRecipeType(RecipeType.SMELTING);
|
||||
injectedChecker.recipeType(MRecipeTypes.SMELTING);
|
||||
} else if (recipeType == MRecipeTypes.BLASTING) {
|
||||
injectedChecker.customRecipeType(RecipeTypes.BLASTING);
|
||||
injectedChecker.customRecipeType(RecipeType.BLASTING);
|
||||
injectedChecker.recipeType(MRecipeTypes.BLASTING);
|
||||
} else if (recipeType == MRecipeTypes.SMOKING) {
|
||||
injectedChecker.customRecipeType(RecipeTypes.SMOKING);
|
||||
injectedChecker.customRecipeType(RecipeType.SMOKING);
|
||||
injectedChecker.recipeType(MRecipeTypes.SMOKING);
|
||||
} else {
|
||||
throw new IllegalStateException("RecipeType " + recipeType + " not supported");
|
||||
@@ -174,7 +174,7 @@ public class RecipeInjector {
|
||||
Object quickCheck = CoreReflections.field$CampfireBlockEntity$quickCheck.get(entity);
|
||||
if (clazz$InjectedCacheChecker.isInstance(quickCheck)) return; // already injected
|
||||
InjectedCacheCheck injectedChecker = (InjectedCacheCheck) ReflectionUtils.UNSAFE.allocateInstance(clazz$InjectedCacheChecker);
|
||||
injectedChecker.customRecipeType(RecipeTypes.CAMPFIRE_COOKING);
|
||||
injectedChecker.customRecipeType(RecipeType.CAMPFIRE_COOKING);
|
||||
injectedChecker.recipeType(MRecipeTypes.CAMPFIRE_COOKING);
|
||||
CoreReflections.field$CampfireBlockEntity$quickCheck.set(entity, injectedChecker);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.momirealms.craftengine.core.entity.EntityTypeKeys;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemKeys;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeTypes;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeType;
|
||||
import net.momirealms.craftengine.core.item.recipe.UniqueIdItem;
|
||||
import net.momirealms.craftengine.core.item.recipe.input.SingleItemInput;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
@@ -129,13 +129,13 @@ public class InteractUtils {
|
||||
});
|
||||
registerInteraction(BlockKeys.SOUL_CAMPFIRE, (player, item, blockState, result) -> {
|
||||
if (!Config.enableRecipeSystem()) return false;
|
||||
return BukkitRecipeManager.instance().recipeByInput(RecipeTypes.CAMPFIRE_COOKING, new SingleItemInput<>(new UniqueIdItem<>(
|
||||
return BukkitRecipeManager.instance().recipeByInput(RecipeType.CAMPFIRE_COOKING, new SingleItemInput<>(new UniqueIdItem<>(
|
||||
item.recipeIngredientId(), item
|
||||
))) != null;
|
||||
});
|
||||
registerInteraction(BlockKeys.CAMPFIRE, (player, item, blockState, result) -> {
|
||||
if (!Config.enableRecipeSystem()) return false;
|
||||
return BukkitRecipeManager.instance().recipeByInput(RecipeTypes.CAMPFIRE_COOKING, new SingleItemInput<>(new UniqueIdItem<>(
|
||||
return BukkitRecipeManager.instance().recipeByInput(RecipeType.CAMPFIRE_COOKING, new SingleItemInput<>(new UniqueIdItem<>(
|
||||
item.recipeIngredientId(), item
|
||||
))) != null;
|
||||
});
|
||||
|
||||
@@ -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