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.resources.ResourceLocation;
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 cum) {
        this.term = cum;
    }
    
    @Override
    public final boolean test(final LootContext crx) {
        return !this.term.test(crx);
    }
    
    @Override
    public Set<LootContextParam<?>> getReferencedContextParams() {
        return this.term.getReferencedContextParams();
    }
    
    @Override
    public void validate(final ValidationContext csg) {
        super.validate(csg);
        this.term.validate(csg);
    }
    
    public static Builder invert(final Builder a) {
        final InvertedLootItemCondition cuj2 = new InvertedLootItemCondition(a.build());
        return () -> cuj2;
    }
    
    public static class Serializer extends LootItemCondition.Serializer<InvertedLootItemCondition> {
        public Serializer() {
            super(new ResourceLocation("inverted"), InvertedLootItemCondition.class);
        }
        
        @Override
        public void serialize(final JsonObject jsonObject, final InvertedLootItemCondition cuj, final JsonSerializationContext jsonSerializationContext) {
            jsonObject.add("term", jsonSerializationContext.serialize(cuj.term));
        }
        
        @Override
        public InvertedLootItemCondition deserialize(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
            final LootItemCondition cum4 = GsonHelper.<LootItemCondition>getAsObject(jsonObject, "term", jsonDeserializationContext, LootItemCondition.class);
            return new InvertedLootItemCondition(cum4, null);
        }
    }
}
