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

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.Serializer;
import net.minecraft.world.level.storage.loot.ValidationContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParam;
import java.util.Set;
import net.minecraft.world.level.storage.loot.LootContext;

public class InvertedLootItemCondition implements LootItemCondition {
    private final LootItemCondition term;
    
    private InvertedLootItemCondition(final LootItemCondition ddm) {
        this.term = ddm;
    }
    
    @Override
    public LootItemConditionType getType() {
        return LootItemConditions.INVERTED;
    }
    
    @Override
    public final boolean test(final LootContext dat) {
        return !this.term.test(dat);
    }
    
    @Override
    public Set<LootContextParam<?>> getReferencedContextParams() {
        return this.term.getReferencedContextParams();
    }
    
    @Override
    public void validate(final ValidationContext dbe) {
        super.validate(dbe);
        this.term.validate(dbe);
    }
    
    public static Builder invert(final Builder a) {
        final InvertedLootItemCondition ddj2 = new InvertedLootItemCondition(a.build());
        return () -> ddj2;
    }
    
    public static class Serializer implements net.minecraft.world.level.storage.loot.Serializer<InvertedLootItemCondition> {
        @Override
        public void serialize(final JsonObject jsonObject, final InvertedLootItemCondition ddj, final JsonSerializationContext jsonSerializationContext) {
            jsonObject.add("term", jsonSerializationContext.serialize(ddj.term));
        }
        
        @Override
        public InvertedLootItemCondition deserialize(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
            final LootItemCondition ddm4 = GsonHelper.<LootItemCondition>getAsObject(jsonObject, "term", jsonDeserializationContext, LootItemCondition.class);
            return new InvertedLootItemCondition(ddm4, null);
        }
    }
}
