package com.hypixel.hytale.server.npc.corecomponents.world.builders;
import com.google.gson.JsonElement;
import com.hypixel.hytale.server.core.asset.type.blockset.config.BlockSet;
import com.hypixel.hytale.server.npc.asset.builder.Builder;
import com.hypixel.hytale.server.npc.asset.builder.BuilderDescriptorState;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import com.hypixel.hytale.server.npc.asset.builder.Feature;
import com.hypixel.hytale.server.npc.asset.builder.holder.AssetHolder;
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.asset.builder.validators.DoubleRangeValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.asset.BlockSetExistsValidator;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderSensorBase;
import com.hypixel.hytale.server.npc.corecomponents.world.SensorBlock;
import com.hypixel.hytale.server.npc.instructions.Sensor;
import javax.annotation.Nonnull;
publicclassBuilderSensorBlockextendsBuilderSensorBase {
protectedfinalDoubleHolderrange=newDoubleHolder();
protectedfinalDoubleHolderyRange=newDoubleHolder();
protectedfinalAssetHolderblockSet=newAssetHolder();
protectedfinalBooleanHolderpickRandom=newBooleanHolder();
protectedfinalBooleanHolderreserveBlock=newBooleanHolder();
publicBuilderSensorBlock() {
}
@Nonnullpublic String getShortDescription() {
return"Checks for one of a set of blocks in the nearby area";
}
@Nonnullpublic String getLongDescription() {
return"Checks for one of a set of blocks in the nearby area and caches the result until explicitly reset or the targeted block changes/is removed. All block sensors with the same sought blockset share the same targeted block once found";
}
@Nonnullpublic Sensor build(@Nonnull BuilderSupport builderSupport) {
returnnewSensorBlock(this, builderSupport);
}
@Nonnullpublic BuilderDescriptorState getBuilderDescriptorState() {
return BuilderDescriptorState.Experimental;
}
@Nonnullpublic Builder<Sensor> readConfig(@Nonnull JsonElement data) {
this.requireDouble(data, "Range", this.range, DoubleRangeValidator.fromExclToIncl(0.0, 1.7976931348623157E308), BuilderDescriptorState.Stable, "The range to search for the blocks in", (String)null);
this.getDouble(data, "MaxHeight", this.yRange, 4.0, DoubleRangeValidator.fromExclToIncl(0.0, 1.7976931348623157E308), BuilderDescriptorState.Stable, "The vertical range to search for the blocks in", (String)null);
this.requireAsset(data, "Blocks", this.blockSet, BlockSetExistsValidator.required(), BuilderDescriptorState.Stable, "The set of blocks to search for", (String)null);
this.getBoolean(data, "Random", this.pickRandom, false, BuilderDescriptorState.Stable, "Whether to pick at random from within the matched blocks or pick the closest", (String)null);
this.getBoolean(data, "Reserve", this.reserveBlock, false, BuilderDescriptorState.Stable, "Whether to reserve the found block to prevent other NPCs selecting it", (String)null);
this.provideFeature(Feature.Position);
returnthis;
}
publicdoublegetRange(@Nonnull BuilderSupport support) {
returnthis.range.get(support.getExecutionContext());
}
publicdoublegetYRange(@Nonnull BuilderSupport support) {
returnthis.yRange.get(support.getExecutionContext());
}
publicintgetBlockSet(@Nonnull BuilderSupport support) {
Stringkey=this.blockSet.get(support.getExecutionContext());
intindex= BlockSet.getAssetMap().getIndex(key);
if (index == -2147483648) {
thrownewIllegalArgumentException("Unknown key! " + key);
} else {
return index;
}
}
publicbooleanisPickRandom(@Nonnull BuilderSupport support) {
returnthis.pickRandom.get(support.getExecutionContext());
}
publicbooleanisReserveBlock(@Nonnull BuilderSupport support) {
returnthis.reserveBlock.get(support.getExecutionContext());
}
}