package net.darkhax.bookshelf.api.serialization;

import com.google.gson.JsonElement;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.item.crafting.Ingredient;

public class SerializerIngredient implements ISerializer<Ingredient> {

    public static final ISerializer<Ingredient> SERIALIZER = new SerializerIngredient();

    private SerializerIngredient() {

    }

    @Override
    public Ingredient fromJSON(JsonElement json) {

        return Ingredient.fromJson(json);
    }

    @Override
    public JsonElement toJSON(Ingredient toWrite) {

        return toWrite.toJson();
    }

    @Override
    public Ingredient fromByteBuf(FriendlyByteBuf buffer) {

        return Ingredient.fromNetwork(buffer);
    }

    @Override
    public void toByteBuf(FriendlyByteBuf buffer, Ingredient toWrite) {

        toWrite.toNetwork(buffer);
    }

    @Override
    public Tag toNBT(Ingredient toWrite) {

        return Serializers.STRING.toNBT(this.toJSONString(toWrite));
    }

    @Override
    public Ingredient fromNBT(Tag nbt) {

        return this.fromJSONString(Serializers.STRING.fromNBT(nbt));
    }
}
@@ -43,16 +43,50 @@
 ation;%0A%0A
+import com.google.gson.JsonArray;%0A
 import c
@@ -512,24 +512,175 @@
 nt json) %7B%0A%0A
+        // Support Empty Ingredient%0A        if (json instanceof JsonArray array && array.isEmpty()) %7B%0A%0A            return Ingredient.EMPTY;%0A        %7D%0A%0A
         retu

Fix crash when serializing empty JSON ingredients.