diff --git a/src/main/java/com/minelittlepony/unicopia/item/JarExtractRecipe.java b/src/main/java/com/minelittlepony/unicopia/item/JarExtractRecipe.java new file mode 100644 index 00000000..b480d05e --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/JarExtractRecipe.java @@ -0,0 +1,60 @@ +package com.minelittlepony.unicopia.item; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.inventory.RecipeInputInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.SpecialCraftingRecipe; +import net.minecraft.recipe.book.CraftingRecipeCategory; +import net.minecraft.registry.DynamicRegistryManager; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; + +public class JarExtractRecipe extends SpecialCraftingRecipe { + public JarExtractRecipe(Identifier id, CraftingRecipeCategory category) { + super(id, category); + } + + @Override + public final boolean fits(int i, int j) { + return i * j >= 1; + } + + @Override + public final boolean matches(RecipeInputInventory inventory, World world) { + return !craft(inventory, null).isEmpty(); + } + + @Override + public ItemStack craft(RecipeInputInventory inventory, @Nullable DynamicRegistryManager manager) { + ItemStack jar = ItemStack.EMPTY; + for (int i = 0; i < inventory.size(); i++) { + ItemStack stack = inventory.getStack(i); + if (stack.isEmpty()) { + continue; + } + + if (!stack.isOf(UItems.FILLED_JAR)) { + return ItemStack.EMPTY; + } + + if (!jar.isEmpty()) { + return ItemStack.EMPTY; + } + + if (!UItems.FILLED_JAR.hasAppearance(stack)) { + return ItemStack.EMPTY; + } + + jar = stack; + } + + return UItems.FILLED_JAR.getAppearanceStack(jar); + } + + @Override + public RecipeSerializer getSerializer() { + return URecipes.JAR_INSERT_SERIALIZER; + } +} \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/item/URecipes.java b/src/main/java/com/minelittlepony/unicopia/item/URecipes.java index 363d3855..d04d170d 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/URecipes.java +++ b/src/main/java/com/minelittlepony/unicopia/item/URecipes.java @@ -23,6 +23,7 @@ public interface URecipes { RecipeSerializer ZAP_APPLE_SERIALIZER = RecipeSerializer.register("unicopia:crafting_zap_apple", new ZapAppleRecipe.Serializer()); RecipeSerializer GLOWING_SERIALIZER = RecipeSerializer.register("unicopia:crafting_glowing", new SpecialRecipeSerializer<>(GlowingRecipe::new)); RecipeSerializer JAR_INSERT_SERIALIZER = RecipeSerializer.register("unicopia:jar_insert", new SpecialRecipeSerializer<>(JarInsertRecipe::new)); + RecipeSerializer JAR_EXTRACT_SERIALIZER = RecipeSerializer.register("unicopia:jar_extract", new SpecialRecipeSerializer<>(JarExtractRecipe::new)); RecipeSerializer CRAFTING_MAGICAL_SERIALIZER = RecipeSerializer.register("unicopia:crafting_magical", new SpellShapedCraftingRecipe.Serializer()); RecipeSerializer TRAIT_REQUIREMENT = RecipeSerializer.register("unicopia:spellbook/crafting", new SpellCraftingRecipe.Serializer()); RecipeSerializer TRAIT_COMBINING = RecipeSerializer.register("unicopia:spellbook/combining", new SpellEnhancingRecipe.Serializer()); diff --git a/src/main/resources/data/unicopia/recipes/filled_jar_emptied.json b/src/main/resources/data/unicopia/recipes/filled_jar_emptied.json new file mode 100644 index 00000000..7c78b525 --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/filled_jar_emptied.json @@ -0,0 +1,3 @@ +{ + "type": "unicopia:jar_extract" +} \ No newline at end of file