package net.silentchaos512.gems.crafting.ingredient;

import com.google.gson.JsonObject;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.IIngredientSerializer;
import net.silentchaos512.gems.SilentGems;
import net.silentchaos512.gems.lib.soul.Soul;

import java.util.stream.Stream;

public class SoulGemIngredient extends Ingredient {
    private final ResourceLocation soulId;

    public SoulGemIngredient(ResourceLocation soulId) {
        super(getStream(soulId));
        this.soulId = soulId;
    }

    private static Stream<? extends IItemList> getStream(ResourceLocation soulId) {
        Soul soul = Soul.from(soulId);
        return soul != null ? Stream.of(new SingleItemList(soul.getSoulGem())) : Stream.of();
    }

    @Override
    public IIngredientSerializer<? extends Ingredient> getSerializer() {
        return Serializer.INSTANCE;
    }

    public static final class Serializer implements IIngredientSerializer<SoulGemIngredient> {
        public static final Serializer INSTANCE = new Serializer();
        public static final ResourceLocation NAME = SilentGems.getId("soul_gem");

        @Override
        public SoulGemIngredient parse(PacketBuffer buffer) {
            ResourceLocation soulId = buffer.readResourceLocation();
            return new SoulGemIngredient(soulId);
        }

        @Override
        public SoulGemIngredient parse(JsonObject json) {
            String soulIdStr = JSONUtils.getString(json, "soul");
            ResourceLocation soulId = new ResourceLocation(soulIdStr);
            return new SoulGemIngredient(soulId);
        }

        @Override
        public void write(PacketBuffer buffer, SoulGemIngredient ingredient) {
            buffer.writeResourceLocation(NAME);
            buffer.writeResourceLocation(ingredient.soulId);
        }

        public static void register() {
            CraftingHelper.register(NAME, INSTANCE);
        }
    }
}

@@ -82,16 +82,53 @@
 Object;%0A
+import net.minecraft.item.ItemStack;%0A
 import n
@@ -456,16 +456,65 @@
 ntGems;%0A
+import net.silentchaos512.gems.item.SoulGemItem;%0A
 import n
@@ -552,16 +552,50 @@
 .Soul;%0A%0A
+import javax.annotation.Nullable;%0A
 import j
@@ -785,25 +785,65 @@
   super(
-get
 Stream
+.of(new SingleItemList(SoulGemItem.getStack
 (soulId)
@@ -843,16 +843,18 @@
 soulId))
+))
 ;%0A      
@@ -892,218 +892,276 @@
     
-private static Stream%3C? extends I
+@Override%0A    public boolean test(@Nullable 
 Item
-List%3E getStream(ResourceLocation soulId) %7B%0A        Soul soul = Soul.from(soulId);%0A        return soul != null ? Stream.of(new SingleItemList(soul.getSoulGem())) : Stream.of(
+Stack stack) %7B%0A        if (stack == null %7C%7C stack.isEmpty()) return false;%0A        Soul soul = Soul.from(soulId);%0A        return soul != null && stack.getItem() instanceof SoulGemItem && soul == SoulGemItem.getSoul(stack
 );%0A 
@@ -2127,56 +2127,8 @@
 ) %7B%0A
-            buffer.writeResourceLocation(NAME);%0A
     

Fix soul gem ingredient