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 bj1, final ItemPredicate bj2, final ItemPredicate bj3, final ItemPredicate bj4, final ItemPredicate bj5, final ItemPredicate bj6) {
        this.head = bj1;
        this.chest = bj2;
        this.legs = bj3;
        this.feet = bj4;
        this.mainhand = bj5;
        this.offhand = bj6;
    }
    
    public boolean matches(@Nullable final Entity akq) {
        if (this == EntityEquipmentPredicate.ANY) {
            return true;
        }
        if (!(akq instanceof LivingEntity)) {
            return false;
        }
        final LivingEntity akz3 = (LivingEntity)akq;
        return this.head.matches(akz3.getItemBySlot(EquipmentSlot.HEAD)) && this.chest.matches(akz3.getItemBySlot(EquipmentSlot.CHEST)) && this.legs.matches(akz3.getItemBySlot(EquipmentSlot.LEGS)) && this.feet.matches(akz3.getItemBySlot(EquipmentSlot.FEET)) && this.mainhand.matches(akz3.getItemBySlot(EquipmentSlot.MAINHAND)) && this.offhand.matches(akz3.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 bj3 = ItemPredicate.fromJson(jsonObject2.get("head"));
        final ItemPredicate bj4 = ItemPredicate.fromJson(jsonObject2.get("chest"));
        final ItemPredicate bj5 = ItemPredicate.fromJson(jsonObject2.get("legs"));
        final ItemPredicate bj6 = ItemPredicate.fromJson(jsonObject2.get("feet"));
        final ItemPredicate bj7 = ItemPredicate.fromJson(jsonObject2.get("mainhand"));
        final ItemPredicate bj8 = ItemPredicate.fromJson(jsonObject2.get("offhand"));
        return new EntityEquipmentPredicate(bj3, bj4, bj5, bj6, bj7, bj8);
    }
    
    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);
    }
}
