package com.hypixel.hytale.server.npc.corecomponents.movement.builders;
import com.google.gson.JsonElement;
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.validators.DoubleRangeValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSequenceValidator;
import com.hypixel.hytale.server.npc.asset.builder.validators.DoubleSingleValidator;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderBodyMotionBase;
import com.hypixel.hytale.server.npc.corecomponents.movement.BodyMotionTeleport;
import com.hypixel.hytale.server.npc.instructions.BodyMotion;
import javax.annotation.Nonnull;
publicclassBuilderBodyMotionTeleportextendsBuilderBodyMotionBase {
publicstaticfinaldouble[] DEFAULT_OFFSET_RADIUS = newdouble[]{0.0, 0.0};
protecteddouble[] offsetRadius;
protecteddouble maxYOffset;
protectedfloat sector;
protected BodyMotionTeleport.Orientation orientation;
publicBuilderBodyMotionTeleport() {
}
@Nonnullpublic String getShortDescription() {
return"Teleport NPC to a position given by a sensor";
}
@Nonnullpublic String getLongDescription() {
return"Teleport NPC to a position given by a sensor or to a random position nearby with an optional minimum offset up to a maximum offset";
}
@Nonnullpublic BodyMotion build(BuilderSupport builderSupport) {
returnnewBodyMotionTeleport(this);
}
@Nonnullpublic BuilderDescriptorState getBuilderDescriptorState() {
return BuilderDescriptorState.Experimental;
}
@Nonnullpublic BuilderBodyMotionTeleport readConfig(@Nonnull JsonElement data) {
this.getDoubleRange(data, "OffsetRange", (v) -> this.offsetRadius = v, DEFAULT_OFFSET_RADIUS, DoubleSequenceValidator.betweenWeaklyMonotonic(0.0, 1.7976931348623157E308), BuilderDescriptorState.Experimental, "The minimum and maximum offset the NPC can be spawned from the target position", (String)null);
this.getDouble(data, "MaxYOffset", (v) -> this.maxYOffset = v, 5.0, DoubleSingleValidator.greater0(), BuilderDescriptorState.Experimental, "Maximum vertical offset from the target position in case of terrain obstacles", (String)null);
this.getFloat(data, "OffsetSector", (v) -> this.sector = v, 0.0F, DoubleRangeValidator.between(0.0, 360.0), BuilderDescriptorState.Experimental, "The sector around the target in which to teleport to", "The sector around the target in which to teleport to. The origin point is directly between the target and the NPC teleporting");
this.getEnum(data, "Orientation", (v) -> this.orientation = v, BodyMotionTeleport.Orientation.class, BodyMotionTeleport.Orientation.Unchanged, BuilderDescriptorState.Experimental, "The direction to face after teleporting", (String)null);
this.requireFeature(Feature.AnyPosition);
this.requireFeatureIf("Orientation", BodyMotionTeleport.Orientation.UseTarget, this.orientation, Feature.AnyEntity);
returnthis;
}
publicdouble[] getOffsetRadius() {
returnthis.offsetRadius;
}
publicdoublegetMaxYOffset() {
returnthis.maxYOffset;
}
publicfloatgetSectorRadians() {
return0.017453292F * this.sector;
}
public BodyMotionTeleport.Orientation getOrientation() {
returnthis.orientation;
}
}