package net.minecraft.advancements.critereon;

import net.minecraft.world.entity.raid.Raid;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.Items;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import net.minecraft.util.GsonHelper;
import com.google.gson.JsonElement;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import javax.annotation.Nullable;
import net.minecraft.world.entity.Entity;

public class EntityEquipmentPredicate {
    public static final EntityEquipmentPredicate ANY;
    public static final EntityEquipmentPredicate CAPTAIN;
    private final ItemPredicate head;
    private final ItemPredicate chest;
    private final ItemPredicate legs;
    private final ItemPredicate feet;
    private final ItemPredicate mainhand;
    private final ItemPredicate offhand;
    
    public EntityEquipmentPredicate(final ItemPredicate bo1, final ItemPredicate bo2, final ItemPredicate bo3, final ItemPredicate bo4, final ItemPredicate bo5, final ItemPredicate bo6) {
        this.head = bo1;
        this.chest = bo2;
        this.legs = bo3;
        this.feet = bo4;
        this.mainhand = bo5;
        this.offhand = bo6;
    }
    
    public boolean matches(@Nullable final Entity aom) {
        if (this == EntityEquipmentPredicate.ANY) {
            return true;
        }
        if (!(aom instanceof LivingEntity)) {
            return false;
        }
        final LivingEntity aoy3 = (LivingEntity)aom;
        return this.head.matches(aoy3.getItemBySlot(EquipmentSlot.HEAD)) && this.chest.matches(aoy3.getItemBySlot(EquipmentSlot.CHEST)) && this.legs.matches(aoy3.getItemBySlot(EquipmentSlot.LEGS)) && this.feet.matches(aoy3.getItemBySlot(EquipmentSlot.FEET)) && this.mainhand.matches(aoy3.getItemBySlot(EquipmentSlot.MAINHAND)) && this.offhand.matches(aoy3.getItemBySlot(EquipmentSlot.OFFHAND));
    }
    
    public static EntityEquipmentPredicate fromJson(@Nullable final JsonElement jsonElement) {
        if (jsonElement == null || jsonElement.isJsonNull()) {
            return EntityEquipmentPredicate.ANY;
        }
        final JsonObject jsonObject2 = GsonHelper.convertToJsonObject(jsonElement, "equipment");
        final ItemPredicate bo3 = ItemPredicate.fromJson(jsonObject2.get("head"));
        final ItemPredicate bo4 = ItemPredicate.fromJson(jsonObject2.get("chest"));
        final ItemPredicate bo5 = ItemPredicate.fromJson(jsonObject2.get("legs"));
        final ItemPredicate bo6 = ItemPredicate.fromJson(jsonObject2.get("feet"));
        final ItemPredicate bo7 = ItemPredicate.fromJson(jsonObject2.get("mainhand"));
        final ItemPredicate bo8 = ItemPredicate.fromJson(jsonObject2.get("offhand"));
        return new EntityEquipmentPredicate(bo3, bo4, bo5, bo6, bo7, bo8);
    }
    
    public JsonElement serializeToJson() {
        if (this == EntityEquipmentPredicate.ANY) {
            return JsonNull.INSTANCE;
        }
        final JsonObject jsonObject2 = new JsonObject();
        jsonObject2.add("head", this.head.serializeToJson());
        jsonObject2.add("chest", this.chest.serializeToJson());
        jsonObject2.add("legs", this.legs.serializeToJson());
        jsonObject2.add("feet", this.feet.serializeToJson());
        jsonObject2.add("mainhand", this.mainhand.serializeToJson());
        jsonObject2.add("offhand", this.offhand.serializeToJson());
        return jsonObject2;
    }
    
    static {
        ANY = new EntityEquipmentPredicate(ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY);
        CAPTAIN = new EntityEquipmentPredicate(ItemPredicate.Builder.item().of(Items.WHITE_BANNER).hasNbt(Raid.getLeaderBannerInstance().getTag()).build(), ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY, ItemPredicate.ANY);
    }
    
    public static class Builder {
        private ItemPredicate head;
        private ItemPredicate chest;
        private ItemPredicate legs;
        private ItemPredicate feet;
        private ItemPredicate mainhand;
        private ItemPredicate offhand;
        
        public Builder() {
            this.head = ItemPredicate.ANY;
            this.chest = ItemPredicate.ANY;
            this.legs = ItemPredicate.ANY;
            this.feet = ItemPredicate.ANY;
            this.mainhand = ItemPredicate.ANY;
            this.offhand = ItemPredicate.ANY;
        }
        
        public static Builder equipment() {
            return new Builder();
        }
        
        public Builder head(final ItemPredicate bo) {
            this.head = bo;
            return this;
        }
        
        public Builder chest(final ItemPredicate bo) {
            this.chest = bo;
            return this;
        }
        
        public Builder legs(final ItemPredicate bo) {
            this.legs = bo;
            return this;
        }
        
        public Builder feet(final ItemPredicate bo) {
            this.feet = bo;
            return this;
        }
        
        public EntityEquipmentPredicate build() {
            return new EntityEquipmentPredicate(this.head, this.chest, this.legs, this.feet, this.mainhand, this.offhand);
        }
    }
}
