package net.minecraft.advancements.critereon;

import net.minecraft.world.phys.Vec3;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class LevitationTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return LevitationTrigger.ID;
    }
    
    public TriggerInstance createInstance(final JsonObject jsonObject, final EntityPredicate.Composite b, final DeserializationContext av) {
        final DistancePredicate aw5 = DistancePredicate.fromJson(jsonObject.get("distance"));
        final MinMaxBounds.Ints d6 = MinMaxBounds.Ints.fromJson(jsonObject.get("duration"));
        return new TriggerInstance(b, aw5, d6);
    }
    
    public void trigger(final ServerPlayer ze, final Vec3 dem, final int integer) {
        this.trigger(ze, a -> a.matches(ze, dem, integer));
    }
    
    static {
        ID = new ResourceLocation("levitation");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final DistancePredicate distance;
        private final MinMaxBounds.Ints duration;
        
        public TriggerInstance(final EntityPredicate.Composite b, final DistancePredicate aw, final MinMaxBounds.Ints d) {
            super(LevitationTrigger.ID, b);
            this.distance = aw;
            this.duration = d;
        }
        
        public static TriggerInstance levitated(final DistancePredicate aw) {
            return new TriggerInstance(EntityPredicate.Composite.ANY, aw, MinMaxBounds.Ints.ANY);
        }
        
        public boolean matches(final ServerPlayer ze, final Vec3 dem, final int integer) {
            return this.distance.matches(dem.x, dem.y, dem.z, ze.getX(), ze.getY(), ze.getZ()) && this.duration.matches(integer);
        }
        
        @Override
        public JsonObject serializeToJson(final SerializationContext cg) {
            final JsonObject jsonObject3 = super.serializeToJson(cg);
            jsonObject3.add("distance", this.distance.serializeToJson());
            jsonObject3.add("duration", this.duration.serializeToJson());
            return jsonObject3;
        }
    }
}
