package net.minecraft.advancements.critereon;

import com.google.gson.JsonElement;
import net.minecraft.advancements.CriterionTriggerInstance;
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class ConstructBeaconTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return ConstructBeaconTrigger.ID;
    }
    
    @Override
    public TriggerInstance createInstance(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
        final MinMaxBounds.Ints d4 = MinMaxBounds.Ints.fromJson(jsonObject.get("level"));
        return new TriggerInstance(d4);
    }
    
    public void trigger(final ServerPlayer xe, final BeaconBlockEntity bwg) {
        this.trigger(xe.getAdvancements(), a -> a.matches(bwg));
    }
    
    static {
        ID = new ResourceLocation("construct_beacon");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final MinMaxBounds.Ints level;
        
        public TriggerInstance(final MinMaxBounds.Ints d) {
            super(ConstructBeaconTrigger.ID);
            this.level = d;
        }
        
        public static TriggerInstance constructedBeacon(final MinMaxBounds.Ints d) {
            return new TriggerInstance(d);
        }
        
        public boolean matches(final BeaconBlockEntity bwg) {
            return this.level.matches(bwg.getLevels());
        }
        
        @Override
        public JsonElement serializeToJson() {
            final JsonObject jsonObject2 = new JsonObject();
            jsonObject2.add("level", this.level.serializeToJson());
            return jsonObject2;
        }
    }
}
