mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-12-17 23:48:00 +01:00
Add a recipe for cloning a spell
This commit is contained in:
parent
3166fb3919
commit
53775ce34b
4 changed files with 105 additions and 1 deletions
|
@ -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<SpellDuplicatingRecipe> {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ public class SpellEnhancingRecipe implements SpellbookRecipe {
|
|||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ public interface URecipes {
|
|||
RecipeSerializer<JarInsertRecipe> JAR_INSERT_SERIALIZER = RecipeSerializer.register("unicopia:jar_insert", new SpecialRecipeSerializer<>(JarInsertRecipe::new));
|
||||
RecipeSerializer<SpellCraftingRecipe> TRAIT_REQUIREMENT = RecipeSerializer.register("unicopia:spellbook/crafting", new SpellCraftingRecipe.Serializer());
|
||||
RecipeSerializer<SpellEnhancingRecipe> TRAIT_COMBINING = RecipeSerializer.register("unicopia:spellbook/combining", new SpellEnhancingRecipe.Serializer());
|
||||
RecipeSerializer<SpellDuplicatingRecipe> SPELL_DUPLICATING = RecipeSerializer.register("unicopia:spellbook/duplicating", new SpellDuplicatingRecipe.Serializer());
|
||||
|
||||
static DefaultedList<Ingredient> getIngredients(JsonArray json) {
|
||||
DefaultedList<Ingredient> defaultedList = DefaultedList.of();
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"type": "unicopia:spellbook/duplicating",
|
||||
"material": { "item": "unicopia:botched_gem" }
|
||||
}
|
Loading…
Reference in a new issue