package net.minecraft.world.level.storage.loot.entries;

import net.minecraft.util.GsonHelper;
import com.google.gson.JsonDeserializationContext;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonObject;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.item.ItemStack;
import java.util.function.Consumer;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.item.Item;

public class LootItem extends LootPoolSingletonContainer {
    private final Item item;
    
    private LootItem(final Item bke, final int integer2, final int integer3, final LootItemCondition[] arr, final LootItemFunction[] arr) {
        super(integer2, integer3, arr, arr);
        this.item = bke;
    }
    
    @Override
    public LootPoolEntryType getType() {
        return LootPoolEntries.ITEM;
    }
    
    public void createItemStack(final Consumer<ItemStack> consumer, final LootContext dat) {
        consumer.accept(new ItemStack(this.item));
    }
    
    public static Builder<?> lootTableItem(final ItemLike bqa) {
        return LootPoolSingletonContainer.simpleBuilder((integer2, integer3, arr, arr) -> new LootItem(bqa.asItem(), integer2, integer3, arr, arr));
    }
    
    public static class Serializer extends LootPoolSingletonContainer.Serializer<LootItem> {
        @Override
        public void serialize(final JsonObject jsonObject, final LootItem dbl, final JsonSerializationContext jsonSerializationContext) {
            super.serialize(jsonObject, dbl, jsonSerializationContext);
            final ResourceLocation uh5 = Registry.ITEM.getKey(dbl.item);
            if (uh5 == null) {
                throw new IllegalArgumentException("Can't serialize unknown item " + dbl.item);
            }
            jsonObject.addProperty("name", uh5.toString());
        }
        
        @Override
        protected LootItem deserialize(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext, final int integer3, final int integer4, final LootItemCondition[] arr, final LootItemFunction[] arr) {
            final Item bke8 = GsonHelper.getAsItem(jsonObject, "name");
            return new LootItem(bke8, integer3, integer4, arr, arr, null);
        }
    }
}
