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

import com.google.common.collect.HashBiMap;
import javax.annotation.Nullable;
import java.util.function.Consumer;
import net.minecraft.resources.ResourceLocation;
import com.google.common.collect.BiMap;

public class LootContextParamSets {
    private static final BiMap<ResourceLocation, LootContextParamSet> REGISTRY;
    public static final LootContextParamSet EMPTY;
    public static final LootContextParamSet CHEST;
    public static final LootContextParamSet COMMAND;
    public static final LootContextParamSet SELECTOR;
    public static final LootContextParamSet FISHING;
    public static final LootContextParamSet ENTITY;
    public static final LootContextParamSet GIFT;
    public static final LootContextParamSet ADVANCEMENT_REWARD;
    public static final LootContextParamSet ALL_PARAMS;
    public static final LootContextParamSet BLOCK;
    
    private static LootContextParamSet register(final String string, final Consumer<LootContextParamSet.Builder> consumer) {
        final LootContextParamSet.Builder a3 = new LootContextParamSet.Builder();
        consumer.accept(a3);
        final LootContextParamSet cty4 = a3.build();
        final ResourceLocation sm5 = new ResourceLocation(string);
        final LootContextParamSet cty5 = LootContextParamSets.REGISTRY.put(sm5, cty4);
        if (cty5 != null) {
            throw new IllegalStateException("Loot table parameter set " + sm5 + " is already registered");
        }
        return cty4;
    }
    
    @Nullable
    public static LootContextParamSet get(final ResourceLocation sm) {
        return LootContextParamSets.REGISTRY.get(sm);
    }
    
    @Nullable
    public static ResourceLocation getKey(final LootContextParamSet cty) {
        return LootContextParamSets.REGISTRY.inverse().get(cty);
    }
    
    static {
        REGISTRY = HashBiMap.create();
        EMPTY = register("empty", a -> {});
        CHEST = register("chest", a -> a.required(LootContextParams.BLOCK_POS).optional(LootContextParams.THIS_ENTITY));
        COMMAND = register("command", a -> a.required(LootContextParams.BLOCK_POS).optional(LootContextParams.THIS_ENTITY));
        SELECTOR = register("selector", a -> a.required(LootContextParams.BLOCK_POS).required(LootContextParams.THIS_ENTITY));
        FISHING = register("fishing", a -> a.required(LootContextParams.BLOCK_POS).required(LootContextParams.TOOL));
        ENTITY = register("entity", a -> a.required(LootContextParams.THIS_ENTITY).required(LootContextParams.BLOCK_POS).required(LootContextParams.DAMAGE_SOURCE).optional(LootContextParams.KILLER_ENTITY).optional(LootContextParams.DIRECT_KILLER_ENTITY).optional(LootContextParams.LAST_DAMAGE_PLAYER));
        GIFT = register("gift", a -> a.required(LootContextParams.BLOCK_POS).required(LootContextParams.THIS_ENTITY));
        ADVANCEMENT_REWARD = register("advancement_reward", a -> a.required(LootContextParams.THIS_ENTITY).required(LootContextParams.BLOCK_POS));
        ALL_PARAMS = register("generic", a -> a.required(LootContextParams.THIS_ENTITY).required(LootContextParams.LAST_DAMAGE_PLAYER).required(LootContextParams.DAMAGE_SOURCE).required(LootContextParams.KILLER_ENTITY).required(LootContextParams.DIRECT_KILLER_ENTITY).required(LootContextParams.BLOCK_POS).required(LootContextParams.BLOCK_STATE).required(LootContextParams.BLOCK_ENTITY).required(LootContextParams.TOOL).required(LootContextParams.EXPLOSION_RADIUS));
        BLOCK = register("block", a -> a.required(LootContextParams.BLOCK_STATE).required(LootContextParams.BLOCK_POS).required(LootContextParams.TOOL).optional(LootContextParams.THIS_ENTITY).optional(LootContextParams.BLOCK_ENTITY).optional(LootContextParams.EXPLOSION_RADIUS));
    }
}
