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

import net.minecraft.util.GsonHelper;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonObject;
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.resources.ResourceLocation;

public class DynamicLoot extends LootPoolSingletonContainer {
    private final ResourceLocation name;
    
    private DynamicLoot(final ResourceLocation uh, final int integer2, final int integer3, final LootItemCondition[] arr, final LootItemFunction[] arr) {
        super(integer2, integer3, arr, arr);
        this.name = uh;
    }
    
    @Override
    public LootPoolEntryType getType() {
        return LootPoolEntries.DYNAMIC;
    }
    
    public void createItemStack(final Consumer<ItemStack> consumer, final LootContext dat) {
        dat.addDynamicDrops(this.name, consumer);
    }
    
    public static Builder<?> dynamicEntry(final ResourceLocation uh) {
        return LootPoolSingletonContainer.simpleBuilder((integer2, integer3, arr, arr) -> new DynamicLoot(uh, integer2, integer3, arr, arr));
    }
    
    public static class Serializer extends LootPoolSingletonContainer.Serializer<DynamicLoot> {
        @Override
        public void serialize(final JsonObject jsonObject, final DynamicLoot dbi, final JsonSerializationContext jsonSerializationContext) {
            super.serialize(jsonObject, dbi, jsonSerializationContext);
            jsonObject.addProperty("name", dbi.name.toString());
        }
        
        @Override
        protected DynamicLoot deserialize(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext, final int integer3, final int integer4, final LootItemCondition[] arr, final LootItemFunction[] arr) {
            final ResourceLocation uh8 = new ResourceLocation(GsonHelper.getAsString(jsonObject, "name"));
            return new DynamicLoot(uh8, integer3, integer4, arr, arr, null);
        }
    }
}
