// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.npc.corecomponents.world.builders;

import com.hypixel.hytale.server.npc.asset.builder.Builder;
import java.util.EnumSet;
import com.hypixel.hytale.server.npc.asset.builder.Feature;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSingleValidator;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.corecomponents.world.ActionPlaceBlock;
import com.hypixel.hytale.server.npc.instructions.Action;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.asset.builder.holder.BooleanHolder;
import com.hypixel.hytale.server.npc.asset.builder.holder.DoubleHolder;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderActionBase;

public class BuilderActionPlaceBlock extends BuilderActionBase
{
    protected final DoubleHolder range;
    protected final BooleanHolder allowEmptyMaterials;
    
    public BuilderActionPlaceBlock() {
        this.range = new DoubleHolder();
        this.allowEmptyMaterials = new BooleanHolder();
    }
    
    @Nonnull
    @Override
    public String getShortDescription() {
        return "Place a block (chosen by another action) at a position returned by a Sensor if close enough";
    }
    
    @Nonnull
    @Override
    public String getLongDescription() {
        return this.getShortDescription();
    }
    
    @Nonnull
    @Override
    public Action build(@Nonnull final BuilderSupport builderSupport) {
        return new ActionPlaceBlock(this, builderSupport);
    }
    
    @Nonnull
    @Override
    public BuilderDescriptorState getBuilderDescriptorState() {
        return BuilderDescriptorState.Stable;
    }
    
    @Nonnull
    @Override
    public BuilderActionPlaceBlock readConfig(@Nonnull final JsonElement data) {
        this.getDouble(data, "Range", this.range, 3.0, DoubleSingleValidator.greater0(), BuilderDescriptorState.Stable, "The range to target position before block will be placed", null);
        this.getBoolean(data, "AllowEmptyMaterials", this.allowEmptyMaterials, false, BuilderDescriptorState.Stable, "Whether it should be possible to replace blocks that have empty material", null);
        this.requireFeature(EnumSet.of(Feature.Position));
        return this;
    }
    
    public double getRange(@Nonnull final BuilderSupport support) {
        return this.range.get(support.getExecutionContext());
    }
    
    public boolean isAllowEmptyMaterials(@Nonnull final BuilderSupport support) {
        return this.allowEmptyMaterials.get(support.getExecutionContext());
    }
}
