diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/SpellDuplicatingRecipe.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/SpellDuplicatingRecipe.java new file mode 100644 index 00000000..16104530 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/SpellDuplicatingRecipe.java @@ -0,0 +1,99 @@ +package com.minelittlepony.unicopia.ability.magic.spell.crafting; + +import com.google.gson.JsonObject; +import com.minelittlepony.unicopia.container.SpellbookScreenHandler.SpellbookInventory; +import com.minelittlepony.unicopia.item.*; +import com.minelittlepony.unicopia.util.InventoryUtil; + +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; + +/** + * A recipe for creating a new spell from input traits and items. + */ +public class SpellDuplicatingRecipe implements SpellbookRecipe { + private final Identifier id; + + private final IngredientWithSpell material; + + private SpellDuplicatingRecipe(Identifier id, IngredientWithSpell material) { + this.id = id; + this.material = material; + } + + @Override + public void buildCraftingTree(CraftingTreeBuilder builder) { + + } + + @Override + public int getPriority() { + return 1; + } + + @Override + public boolean matches(SpellbookInventory inventory, World world) { + ItemStack stack = inventory.getItemToModify(); + return InventoryUtil.stream(inventory) + .limit(inventory.size() - 1) + .filter(i -> !i.isEmpty()) + .noneMatch(i -> !i.isOf(UItems.GEMSTONE) || !GemstoneItem.isEnchanted(i)) + && material.test(stack) + && !GemstoneItem.isEnchanted(stack); + } + + @Override + public ItemStack craft(SpellbookInventory inventory) { + return InventoryUtil.stream(inventory) + .filter(i -> i.isOf(UItems.GEMSTONE)) + .filter(GemstoneItem::isEnchanted) + .map(stack -> stack.copy()) + .map(stack -> { + stack.setCount(2); + return stack; + }) + .findFirst().get(); + } + + @Override + public boolean fits(int width, int height) { + return (width * height) > 0; + } + + @Override + public ItemStack getOutput() { + ItemStack stack = UItems.GEMSTONE.getDefaultStack(); + stack.setCount(2); + return stack; + } + + @Override + public Identifier getId() { + return id; + } + + @Override + public RecipeSerializer getSerializer() { + return URecipes.SPELL_DUPLICATING; + } + + public static class Serializer implements RecipeSerializer { + @Override + public SpellDuplicatingRecipe read(Identifier id, JsonObject json) { + return new SpellDuplicatingRecipe(id, IngredientWithSpell.fromJson(json.get("material"))); + } + + @Override + public SpellDuplicatingRecipe read(Identifier id, PacketByteBuf buf) { + return new SpellDuplicatingRecipe(id, IngredientWithSpell.fromPacket(buf)); + } + + @Override + public void write(PacketByteBuf buf, SpellDuplicatingRecipe recipe) { + recipe.material.write(buf); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/SpellEnhancingRecipe.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/SpellEnhancingRecipe.java index 71a8629e..0683d827 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/SpellEnhancingRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/SpellEnhancingRecipe.java @@ -31,7 +31,7 @@ public class SpellEnhancingRecipe implements SpellbookRecipe { @Override public int getPriority() { - return 1; + return 2; } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/URecipes.java b/src/main/java/com/minelittlepony/unicopia/item/URecipes.java index e4e01c58..7c1a72c1 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 JAR_INSERT_SERIALIZER = RecipeSerializer.register("unicopia:jar_insert", new SpecialRecipeSerializer<>(JarInsertRecipe::new)); RecipeSerializer TRAIT_REQUIREMENT = RecipeSerializer.register("unicopia:spellbook/crafting", new SpellCraftingRecipe.Serializer()); RecipeSerializer TRAIT_COMBINING = RecipeSerializer.register("unicopia:spellbook/combining", new SpellEnhancingRecipe.Serializer()); + RecipeSerializer SPELL_DUPLICATING = RecipeSerializer.register("unicopia:spellbook/duplicating", new SpellDuplicatingRecipe.Serializer()); static DefaultedList getIngredients(JsonArray json) { DefaultedList defaultedList = DefaultedList.of(); diff --git a/src/main/resources/data/unicopia/recipes/spell_duplicating_botched_gemstone.json b/src/main/resources/data/unicopia/recipes/spell_duplicating_botched_gemstone.json new file mode 100644 index 00000000..7994e225 --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/spell_duplicating_botched_gemstone.json @@ -0,0 +1,4 @@ +{ + "type": "unicopia:spellbook/duplicating", + "material": { "item": "unicopia:botched_gem" } +} \ No newline at end of file