BodyMotionWanderInRect class
Пакет: com.hypixel.hytale.server.npc.corecomponents.movement
Файл: com/hypixel/hytale/server/npc/corecomponents/movement/BodyMotionWanderInRect.java
extends: BodyMotionWanderBase
Поля (23)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
int |
LEFT |
|
double |
var10 |
|
double |
var12 |
|
double |
var14 |
|
double |
var16 |
|
int |
var18 |
|
double |
var19 |
|
double |
var21 |
|
int |
var23 |
|
double |
var24 |
|
double |
var26 |
|
double |
var28 |
|
|
var28 |
|
|
var28 |
|
|
var28 |
|
double |
var30 |
|
|
var30 |
|
|
var30 |
|
|
var30 |
|
int |
var32 |
|
int |
var5 |
|
NPCEntity |
var8 |
|
Vector3d |
var9 |
Методы (11)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("WanderInRect: Constrained X outside of allowed range!") |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("WanderInRect: Constrained Z outside of allowed range!") |
protected |
double |
distanceSquareddouble distanceSquared(double var1, double var3, int var5) |
|
|
if if(var18 == 0) |
|
|
if if(var23 != 0) |
|
|
if if(var28 < 0.0 || var28 > 1.0) |
|
|
if if(var1 < -this.halfWidth) |
|
|
if if(var3 < -this.halfDepth) |
protected |
int |
sectorCodeint sectorCode(double var1, double var3) |
abstract |
|
super super(var1, var2) |
|
return |
switchreturn switch(var5) |
Исходный код
Показать/скрыть
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.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.BuilderBodyMotionWanderInRect;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import com.hypixel.hytale.server.npc.instructions.ExecutionSupport;
class="kw">import javax.annotation.Nonnull;
class="kw">import org.joml.Vector3d;
class="kw">public class BodyMotionWanderInRect class="kw">extends BodyMotionWanderBase {
class="kw">public class="kw">static class="kw">final int LEFT = 1;
class="kw">public class="kw">static class="kw">final int RIGHT = 2;
class="kw">public class="kw">static class="kw">final int BOTTOM = 4;
class="kw">public class="kw">static class="kw">final int TOP = 8;
class="kw">public class="kw">static class="kw">final int VERTICAL_MASK = 12;
class="kw">public class="kw">static class="kw">final int HORIZONTAL_MASK = 3;
class="kw">protected class="kw">final double width;
class="kw">protected class="kw">final double depth;
class="kw">protected class="kw">final double halfWidth;
class="kw">protected class="kw">final double halfDepth;
class="kw">public BodyMotionWanderInRect(@Nonnull BuilderBodyMotionWanderInRect var1, @Nonnull BuilderSupport var2) {
super(var1, var2);
this.width = var1.getWidth();
this.halfWidth = this.width / 2.0;
this.depth = var1.getDepth();
this.halfDepth = this.depth / 2.0;
}
@Override
class="kw">protected double constrainMove(
@Nonnull Ref<EntityStore> var1,
@Nonnull ExecutionSupport var2,
@Nonnull Vector3d var3,
@Nonnull Vector3d var4,
double var5,
@Nonnull ComponentAccessor<EntityStore> var7
) {
NPCEntity var8 = var7.getComponent(var1, NPCEntity.getComponentType());
assert var8 != null;
Vector3d var9 = var8.getLeashPoint();
double var10 = var9.x();
double var12 = var9.z();
double var14 = var4.x - var10;
double var16 = var4.z - var12;
int var18 = this.sectorCode(var14, var16);
if (var18 == 0) {
class="kw">return var5;
}
double var19 = var3.x - var10;
double var21 = var3.z - var12;
int var23 = this.sectorCode(var19, var21);
if (var23 != 0) {
if ((var23 & var18) != 0) {
class="kw">return this.distanceSquared(var14, var16, var18) < this.distanceSquared(var19, var21, var23) ? var5 : 0.0;
} else {
int var32 = var23 | var18;
if ((var32 & 12) == 12 || (var32 & 3) == 3) {
class="kw">return 0.0;
} else {
class="kw">return this.distanceSquared(var14, var16, var18) < this.distanceSquared(var19, var21, var23) ? var5 : 0.0;
}
}
} else {
double var24 = var14 - var19;
double var26 = var16 - var21;
double var28;
if ((var18 & 1) == 1) {
var28 = (-this.halfWidth - var19) / var24;
} else if ((var18 & 2) == 2) {
var28 = (this.halfWidth - var19) / var24;
} else {
var28 = 1.0;
}
double var30;
if ((var18 & 4) == 4) {
var30 = (-this.halfDepth - var21) / var26;
} else if ((var18 & 8) == 8) {
var30 = (this.halfDepth - var21) / var26;
} else {
var30 = 1.0;
}
if (var28 < 0.0 || var28 > 1.0) {
throw new IllegalArgumentException("WanderInRect: Constrained X outside of allowed range!");
} else if (!(var30 < 0.0) && !(var30 > 1.0)) {
class="kw">return var5 * Math.min(var28, var30);
} else {
throw new IllegalArgumentException("WanderInRect: Constrained Z outside of allowed range!");
}
}
}
class="kw">protected int sectorCode(double var1, double var3) {
int var5 = 0;
if (var1 < -this.halfWidth) {
var5 |= 1;
} else if (var1 > this.halfWidth) {
var5 |= 2;
}
if (var3 < -this.halfDepth) {
var5 |= 4;
} else if (var3 > this.halfDepth) {
var5 |= 8;
}
class="kw">return var5;
}
class="kw">protected double distanceSquared(double var1, double var3, int var5) {
class="kw">return class="kw">switch (var5) {
case 1 -> (var1 + this.halfWidth) * (var1 + this.halfWidth);
case 2 -> (var1 - this.halfWidth) * (var1 - this.halfWidth);
class="kw">default -> 0.0;
case 4 -> (var3 + this.halfDepth) * (var3 + this.halfDepth);
case 5 -> (var1 + this.halfWidth) * (var1 + this.halfWidth) + (var3 + this.halfDepth) * (var3 + this.halfDepth);
case 6 -> (var1 - this.halfWidth) * (var1 - this.halfWidth) + (var3 + this.halfDepth) * (var3 + this.halfDepth);
case 8 -> (var3 - this.halfDepth) * (var3 - this.halfDepth);
case 9 -> (var1 + this.halfWidth) * (var1 + this.halfWidth) + (var3 - this.halfDepth) * (var3 - this.halfDepth);
case 10 -> (var1 - this.halfWidth) * (var1 - this.halfWidth) + (var3 - this.halfDepth) * (var3 - this.halfDepth);
};
}
}