package net.minecraft.advancements.critereon;

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

public class NetherTravelTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return NetherTravelTrigger.ID;
    }
    
    public TriggerInstance createInstance(final JsonObject jsonObject, final EntityPredicate.Composite b, final DeserializationContext av) {
        final LocationPredicate bu5 = LocationPredicate.fromJson(jsonObject.get("entered"));
        final LocationPredicate bu6 = LocationPredicate.fromJson(jsonObject.get("exited"));
        final DistancePredicate aw7 = DistancePredicate.fromJson(jsonObject.get("distance"));
        return new TriggerInstance(b, bu5, bu6, aw7);
    }
    
    public void trigger(final ServerPlayer ze, final Vec3 dem) {
        this.trigger(ze, a -> a.matches(ze.getLevel(), dem, ze.getX(), ze.getY(), ze.getZ()));
    }
    
    static {
        ID = new ResourceLocation("nether_travel");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final LocationPredicate entered;
        private final LocationPredicate exited;
        private final DistancePredicate distance;
        
        public TriggerInstance(final EntityPredicate.Composite b, final LocationPredicate bu2, final LocationPredicate bu3, final DistancePredicate aw) {
            super(NetherTravelTrigger.ID, b);
            this.entered = bu2;
            this.exited = bu3;
            this.distance = aw;
        }
        
        public static TriggerInstance travelledThroughNether(final DistancePredicate aw) {
            return new TriggerInstance(EntityPredicate.Composite.ANY, LocationPredicate.ANY, LocationPredicate.ANY, aw);
        }
        
        public boolean matches(final ServerLevel zd, final Vec3 dem, final double double3, final double double4, final double double5) {
            return this.entered.matches(zd, dem.x, dem.y, dem.z) && this.exited.matches(zd, double3, double4, double5) && this.distance.matches(dem.x, dem.y, dem.z, double3, double4, double5);
        }
        
        @Override
        public JsonObject serializeToJson(final SerializationContext cg) {
            final JsonObject jsonObject3 = super.serializeToJson(cg);
            jsonObject3.add("entered", this.entered.serializeToJson());
            jsonObject3.add("exited", this.exited.serializeToJson());
            jsonObject3.add("distance", this.distance.serializeToJson());
            return jsonObject3;
        }
    }
}
