BodyMotionMoveAway class
Пакет: com.hypixel.hytale.server.npc.corecomponents.movement
Файл: com/hypixel/hytale/server/npc/corecomponents/movement/BodyMotionMoveAway.java
extends: BodyMotionFindWithTarget
Поля (16)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
double |
stopDistance |
|
MotionController |
var10 |
|
boolean |
var11 |
|
float |
var12 |
|
double |
var13 |
|
double |
var15 |
|
double |
var17 |
|
double |
var19 |
|
double |
var3 |
|
float |
var5 |
|
TransformComponent |
var6 |
|
Vector3d |
var7 |
|
NPCEntity |
var8 |
|
Rotation3f |
var8 |
|
float |
var9 |
|
Vector3d |
var9 |
Методы (6)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
|
if if(var9 == 0.0F) |
|
|
if if(this.holdDirectionTimeRemaining <= 0.0 || this.fleeDirectionBlocked) |
|
|
if if(var11) |
|
|
if if(!this.fleeDirectionBlocked && this.probeMoveData.edgeBlocked) |
|
|
if if(this.fleeDirectionBlocked) |
abstract |
|
super super(var1, var2) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.npc.corecomponents.movement;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.math.random.RandomExtra;
class="kw">import com.hypixel.hytale.math.util.MathUtil;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.modules.physics.util.PhysicsMath;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
class="kw">import com.hypixel.hytale.server.npc.corecomponents.movement.builders.BuilderBodyMotionMoveAway;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import com.hypixel.hytale.server.npc.movement.Steering;
class="kw">import com.hypixel.hytale.server.npc.movement.controllers.MotionController;
class="kw">import com.hypixel.hytale.server.npc.movement.steeringforces.SteeringForceEvade;
class="kw">import com.hypixel.hytale.server.npc.navigation.AStarBase;
class="kw">import com.hypixel.hytale.server.npc.navigation.AStarNode;
class="kw">import com.hypixel.hytale.server.npc.navigation.AStarWithTarget;
class="kw">import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
class="kw">import com.hypixel.hytale.server.npc.util.NPCPhysicsMath;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">public class BodyMotionMoveAway class="kw">extends BodyMotionFindWithTarget {
class="kw">protected class="kw">final double stopDistance;
class="kw">protected class="kw">final double stopDistanceSquared;
class="kw">protected class="kw">final double[] holdDirectionDurationRange;
class="kw">protected class="kw">final float changeDirectionViewSector;
class="kw">protected class="kw">final float jitterAngle;
class="kw">protected class="kw">final double erraticDistanceSquared;
class="kw">protected class="kw">final float erraticJitter;
class="kw">protected class="kw">final double erraticChangeDurationMultiplier;
class="kw">protected class="kw">final SteeringForceEvade evade = new SteeringForceEvade();
class="kw">private class="kw">final Vector3d tmpProbeDirection = new Vector3d();
class="kw">protected float fleeDirection;
class="kw">protected double holdDirectionTimeRemaining;
class="kw">protected boolean fleeDirectionBlocked;
class="kw">public BodyMotionMoveAway(@Nonnull BuilderBodyMotionMoveAway var1, @Nonnull BuilderSupport var2) {
super(var1, var2);
this.stopDistance = var1.getStopDistance(var2);
this.stopDistanceSquared = this.stopDistance * this.stopDistance;
this.holdDirectionDurationRange = var1.getHoldDirectionDurationRange(var2);
this.changeDirectionViewSector = var1.getChangeDirectionViewSectorRadians(var2);
this.jitterAngle = var1.getDirectionJitterRadians(var2);
double var3 = var1.getErraticDistance(var2);
this.erraticDistanceSquared = var3 * var3;
float var5 = var1.getErraticExtraJitterRadians(var2);
this.erraticJitter = MathUtil.clamp(this.jitterAngle + var5, 0.0F, (float) Math.PI);
this.erraticChangeDurationMultiplier = var1.getErraticChangeDurationMultiplier(var2);
this.evade.setDistances(var1.getSlowdownDistance(var2), this.stopDistance);
this.evade.setFalloff(var1.getFalloff(var2));
this.evade.setAdhereToDirectionHint(true);
}
@Override
class="kw">public void activate(@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, @Nonnull ComponentAccessor<EntityStore> var3) {
super.activate(var1, var2, var3);
this.holdDirectionTimeRemaining = 0.0;
this.fleeDirectionBlocked = false;
}
@Override
class="kw">public boolean computeSteering(
@Nonnull Ref<EntityStore> var1,
@Nonnull ExecutionSupport var2,
@Nullable InfoProvider var3,
double var4,
@Nonnull Steering var6,
@Nonnull ComponentAccessor<EntityStore> var7
) {
NPCEntity var8 = var7.getComponent(var1, NPCEntity.getComponentType());
assert var8 != null;
float var9 = var8.getCurrentHorizontalSpeedMultiplier(var1, var7);
if (var9 == 0.0F) {
var6.clear();
class="kw">return true;
} else {
this.holdDirectionTimeRemaining -= var4 * var9;
class="kw">return super.computeSteering(var1, var2, var3, var4, var6, var7);
}
}
@Override
class="kw">protected boolean computeSteering(
@Nonnull Ref<EntityStore> var1, @Nonnull ExecutionSupport var2, Vector3d var3, @Nonnull Steering var4, @Nonnull ComponentAccessor<EntityStore> var5
) {
TransformComponent var6 = var5.getComponent(var1, TransformComponent.getComponentType());
assert var6 != null;
Vector3d var7 = var6.getPosition();
Rotation3f var8 = var6.getRotation();
Vector3d var9 = this.getLastTargetPosition();
if (NPCPhysicsMath.inViewSector(var7.x, var7.z, var8.yaw(), this.changeDirectionViewSector, var9.x, var9.z)) {
this.holdDirectionTimeRemaining = 0.0;
}
MotionController var10 = var2.getMotionContextSupport().getActiveMotionController();
if (this.holdDirectionTimeRemaining <= 0.0 || this.fleeDirectionBlocked) {
boolean var11 = var7.distanceSquared(var9) < this.erraticDistanceSquared;
float var12 = var11 ? this.erraticJitter : this.jitterAngle;
this.fleeDirection = PhysicsMath.headingFromDirection(var7.x - var9.x, var7.z - var9.z) + RandomExtra.randomRange(-var12, var12);
this.holdDirectionTimeRemaining = RandomExtra.randomRange(this.holdDirectionDurationRange);
if (var11) {
this.holdDirectionTimeRemaining = this.holdDirectionTimeRemaining * this.erraticChangeDurationMultiplier;
}
double var13 = PhysicsMath.headingX(this.fleeDirection) * this.stopDistance;
double var15 = PhysicsMath.headingZ(this.fleeDirection) * this.stopDistance;
this.tmpProbeDirection.set(var13, 0.0, var15);
double var17 = var10.probeMove(var1, var7, this.tmpProbeDirection, this.probeMoveData, var5);
this.fleeDirectionBlocked = var17 < 1.0E-5;
if (!this.fleeDirectionBlocked && this.probeMoveData.edgeBlocked) {
this.holdDirectionTimeRemaining = 0.0;
}
}
if (this.fleeDirectionBlocked) {
class="kw">return false;
}
this.evade.setPositions(var7, var9);
this.evade.setDirectionHint(this.fleeDirection);
double var19 = this.desiredAltitudeWeight >= 0.0 ? this.desiredAltitudeWeight : var10.getDesiredAltitudeWeight();
class="kw">return this.scaleSteering(var1, var2, this.evade, var4, var19, var5);
}
@Override
class="kw">public boolean isGoalReached(Ref<EntityStore> var1, AStarBase var2, @Nonnull AStarNode var3, MotionController var4, ComponentAccessor<EntityStore> var5) {
class="kw">return var3.getEstimateToGoal() <= 0.0F;
}
@Override
class="kw">protected boolean isGoalReached(Ref<EntityStore> var1, @Nonnull MotionController var2, Vector3d var3, Vector3d var4, ComponentAccessor<EntityStore> var5) {
class="kw">return var2.waypointDistanceSquared(var3, var4) >= this.stopDistanceSquared;
}
@Override
class="kw">public float estimateToGoal(@Nonnull AStarBase var1, Vector3d var2, @Nonnull MotionController var3) {
class="kw">return Math.max(0.0F, (float)(this.stopDistance - var3.waypointDistance(var2, ((AStarWithTarget)var1).getTargetPosition())));
}
@Override
class="kw">public void findBestPath(@Nonnull AStarBase var1, MotionController var2) {
var1.buildBestPath(AStarNode::getEstimateToGoal, (var0, var1x) -> var1x < var0, Float.MAX_VALUE);
}
}