package net.minecraft.advancements.critereon;

import net.minecraft.advancements.CriterionTriggerInstance;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class UsedEnderEyeTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return UsedEnderEyeTrigger.ID;
    }
    
    @Override
    public TriggerInstance createInstance(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
        final MinMaxBounds.Floats c4 = MinMaxBounds.Floats.fromJson(jsonObject.get("distance"));
        return new TriggerInstance(c4);
    }
    
    public void trigger(final ServerPlayer xe, final BlockPos fk) {
        final double double4 = xe.getX() - fk.getX();
        final double double5 = xe.getZ() - fk.getZ();
        final double double6 = double4 * double4 + double5 * double5;
        this.trigger(xe.getAdvancements(), a -> a.matches(double6));
    }
    
    static {
        ID = new ResourceLocation("used_ender_eye");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final MinMaxBounds.Floats level;
        
        public TriggerInstance(final MinMaxBounds.Floats c) {
            super(UsedEnderEyeTrigger.ID);
            this.level = c;
        }
        
        public boolean matches(final double double1) {
            return this.level.matchesSqr(double1);
        }
    }
}
