mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 18:57:32 +00:00
Revert "Better Diagonal Flight Pathing"
This reverts commit 960b223155.
This commit is contained in:
1 parent
6dce4e5cdc
commit
455d303971
2 files changed
+14
-47
No files matched your search
@@ -25,9 +25,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FlyPathFinder extends PathFinder {
|
||||
private static final float STRAIGHT_COST = 1.0F;
|
||||
private static final float DIAGONAL_2D_COST = 1.4142135F;
|
||||
private static final float DIAGONAL_3D_COST = 1.7320508F;
|
||||
/**
|
||||
* Used to find obstacles
|
||||
*/
|
||||
@@ -144,7 +141,7 @@ public class FlyPathFinder extends PathFinder {
|
||||
|
||||
private NPCPath addToPath(Entity p_75861_1_, NPCPathPoint p_75861_2_, NPCPathPoint p_75861_3_, NPCPathPoint p_75861_4_, float p_75861_5_) {
|
||||
p_75861_2_.totalPathDistance = 0.0F;
|
||||
p_75861_2_.distanceToNext = this.estimateCostToTarget(p_75861_2_, p_75861_3_);
|
||||
p_75861_2_.distanceToNext = p_75861_2_.distanceToSquared(p_75861_3_);
|
||||
p_75861_2_.distanceToTarget = p_75861_2_.distanceToNext;
|
||||
this.path.clearPath();
|
||||
this.path.addPoint(p_75861_2_);
|
||||
@@ -164,7 +161,7 @@ public class FlyPathFinder extends PathFinder {
|
||||
return this.createEntityPath(p_75861_2_, p_75861_3_);
|
||||
}
|
||||
|
||||
if (this.estimateCostToTarget(pathpoint4, p_75861_3_) < this.estimateCostToTarget(pathpoint3, p_75861_3_)) {
|
||||
if (pathpoint4.distanceToSquared(p_75861_3_) < pathpoint3.distanceToSquared(p_75861_3_)) {
|
||||
pathpoint3 = pathpoint4;
|
||||
}
|
||||
|
||||
@@ -173,12 +170,12 @@ public class FlyPathFinder extends PathFinder {
|
||||
|
||||
for (int j = 0; j < i; ++j) {
|
||||
NPCPathPoint pathpoint5 = this.pathOptions[j];
|
||||
float f1 = pathpoint4.totalPathDistance + this.getTraversalCost(pathpoint4, pathpoint5);
|
||||
float f1 = pathpoint4.totalPathDistance + pathpoint4.distanceToSquared(pathpoint5);
|
||||
|
||||
if (!pathpoint5.isAssigned() || f1 < pathpoint5.totalPathDistance) {
|
||||
pathpoint5.previous = pathpoint4;
|
||||
pathpoint5.totalPathDistance = f1;
|
||||
pathpoint5.distanceToNext = this.estimateCostToTarget(pathpoint5, p_75861_3_);
|
||||
pathpoint5.distanceToNext = pathpoint5.distanceToSquared(p_75861_3_);
|
||||
|
||||
if (pathpoint5.isAssigned()) {
|
||||
this.path.changeDistance(pathpoint5, pathpoint5.totalPathDistance + pathpoint5.distanceToNext);
|
||||
@@ -197,32 +194,6 @@ public class FlyPathFinder extends PathFinder {
|
||||
}
|
||||
}
|
||||
|
||||
private float getTraversalCost(NPCPathPoint from, NPCPathPoint to) {
|
||||
int dx = Math.abs(to.xCoord - from.xCoord);
|
||||
int dy = Math.abs(to.yCoord - from.yCoord);
|
||||
int dz = Math.abs(to.zCoord - from.zCoord);
|
||||
int changedAxes = dx + dy + dz;
|
||||
if (changedAxes <= 1) {
|
||||
return STRAIGHT_COST;
|
||||
}
|
||||
if (changedAxes == 2) {
|
||||
return DIAGONAL_2D_COST;
|
||||
}
|
||||
return DIAGONAL_3D_COST;
|
||||
}
|
||||
|
||||
private float estimateCostToTarget(NPCPathPoint from, NPCPathPoint to) {
|
||||
float dx = Math.abs(to.xCoord - from.xCoord);
|
||||
float dy = Math.abs(to.yCoord - from.yCoord);
|
||||
float dz = Math.abs(to.zCoord - from.zCoord);
|
||||
|
||||
float max = Math.max(dx, Math.max(dy, dz));
|
||||
float min = Math.min(dx, Math.min(dy, dz));
|
||||
float mid = dx + dy + dz - max - min;
|
||||
|
||||
return DIAGONAL_3D_COST * min + DIAGONAL_2D_COST * (mid - min) + STRAIGHT_COST * (max - mid);
|
||||
}
|
||||
|
||||
/**
|
||||
* populates pathOptions with available points and returns the number of options found (args: unused1, currentPoint,
|
||||
* unused2, targetPoint, maxDistance)
|
||||
|
||||
@@ -7,8 +7,6 @@ import noppes.npcs.entity.EntityNPCFlying;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
public class FlyingMoveHelper extends EntityMoveHelper {
|
||||
private static final double CLOSE_ENOUGH_SQ = 0.01D;
|
||||
private static final float MAX_TURN_PER_TICK = 35.0F;
|
||||
private final EntityNPCInterface entity;
|
||||
|
||||
private double posX;
|
||||
@@ -40,24 +38,22 @@ public class FlyingMoveHelper extends EntityMoveHelper {
|
||||
double d5 = MathHelper.sqrt_double(d4);
|
||||
speed = Math.min(d5 / 5.0D, speed);
|
||||
|
||||
if (d4 > CLOSE_ENOUGH_SQ && d5 > 1.0E-4D) {
|
||||
double targetMotionX = speed * (d0 / d5);
|
||||
double targetMotionZ = speed * (d2 / d5);
|
||||
double horizontalLerp = Math.min(1.0D, Math.max(0.12D, speed * 0.6D));
|
||||
this.entity.motionX += (targetMotionX - this.entity.motionX) * horizontalLerp;
|
||||
this.entity.motionZ += (targetMotionZ - this.entity.motionZ) * horizontalLerp;
|
||||
// its here louis!
|
||||
// This is the hurt time that stuns the NPC!!!!!!
|
||||
// if (this.entity.hurtTime == 0 && d4 > 0.5D) {
|
||||
if (d4 >= 0.5D) {
|
||||
this.entity.motionX += (speed * (d0 / d5) - this.entity.motionX) * speed;
|
||||
this.entity.motionZ += (speed * (d2 / d5) - this.entity.motionZ) * speed;
|
||||
|
||||
if (((EntityNPCFlying) this.entity).flyLimitAllow || !this.entity.ais.hasFlyLimit) {
|
||||
double targetMotionY = verticalSpeed * (d1 / d5);
|
||||
if (targetMotionY > 0.0D) {
|
||||
targetMotionY += 0.05D;
|
||||
this.entity.motionY = verticalSpeed * (d1 / d5);
|
||||
if (this.entity.motionY > 0) {
|
||||
this.entity.motionY += 0.1D;
|
||||
}
|
||||
double verticalLerp = Math.min(1.0D, Math.max(0.15D, verticalSpeed * 0.85D));
|
||||
this.entity.motionY += (targetMotionY - this.entity.motionY) * verticalLerp;
|
||||
}
|
||||
|
||||
this.entity.velocityChanged = true;
|
||||
this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, (float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI)), MAX_TURN_PER_TICK);
|
||||
this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw, (float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI)), 20.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user