Changes to NPC flight:

-Improved flight pathing greatly, MUCH MUCH smoother now.
-The "flying speed" of an NPC now correctly speeds up how fast the NPC climbs vertically while flying
-NPCs now properly return to start while flying
This commit is contained in:
Luis C.M committed 2022-05-04 03:06:40 -05:00
1 parent bfd872a239
commit 85a1892c71
4 files changed
+20 -150

No files matched your search

@@ -29,8 +29,12 @@ public class EntityAIReturn extends EntityAIBase
/**
* Returns whether the EntityAIBase should begin execution.
*/
public boolean shouldExecute(){
if(npc.hasOwner() || !npc.ai.returnToStart || npc.isKilled() || !npc.getNavigator().noPath() || npc.isInteracting()){
public boolean shouldExecute() {
if (npc.getNavigator().noPath() || (!npc.isAttacking() && wasAttacked)){
return true;
}
if(npc.hasOwner() || !npc.ai.returnToStart || npc.isKilled() || npc.isInteracting()){
return false;
}
@@ -52,9 +56,6 @@ public class EntityAIReturn extends EntityAIBase
}
return false;
}
if(!npc.isAttacking() && wasAttacked){
return true;
}
if(npc.ai.movingType == EnumMovingType.MovingPath && npc.ai.getDistanceSqToPathPoint() < CustomNpcs.NpcNavRange * CustomNpcs.NpcNavRange)
return false;
@@ -29,10 +29,10 @@ public class FlyingMoveHelper extends EntityMoveHelper{
if (this.update) {
this.update = false;
double speed = this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue() * this.entity.ai.flySpeed;
double speed = this.speed * this.entity.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();
double d0 = this.posX - this.entity.posX;
double d1 = this.posY - MathHelper.floor_double(this.entity.boundingBox.minY + 0.05D);
double d1 = this.posY - this.entity.posY;//MathHelper.floor_double(this.entity.boundingBox.minY + 0.05D);
double d2 = this.posZ - this.entity.posZ;
double d4 = d0 * d0 + d1 * d1 + d2 * d2;
double d5 = MathHelper.sqrt_double(d4);
@@ -48,17 +48,17 @@ public class FlyingMoveHelper extends EntityMoveHelper{
}
if (this.entity.hurtTime == 0 && d4 > 0.5D) {
this.entity.motionX += (d0 / d5 * speed - this.entity.motionX) * speed;
this.entity.motionZ += (d2 / d5 * speed - this.entity.motionZ) * speed;
this.entity.motionX += (speed * (d0 / d5) - this.entity.motionX) * speed;
this.entity.motionZ += (speed * (d2 / d5) - this.entity.motionZ) * speed;
if (heightOffGround < this.entity.ai.flyHeightLimit || !this.entity.ai.hasFlyLimit) {
this.entity.motionY += (d1 / d5 * speed - this.entity.motionY) * speed;
this.entity.motionY += ((speed + this.entity.ai.flySpeed/10.0D + 0.05) * (d1 / d5) - this.entity.motionY) * (speed + this.entity.ai.flySpeed/10.0D + 0.05);
}
this.entity.velocityChanged = true;
}
this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw,(float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI)),18.0F);
this.entity.rotationYaw = this.limitAngle(this.entity.rotationYaw,(float) ((Math.atan2(-d0, -d2) + Math.PI) * -(180F / Math.PI)),15.0F);
}
}
@@ -118,7 +118,7 @@ public class PathNavigateFlying extends PathNavigate {
*/
public FlyPathEntity getPathToXYZ(double p_75488_1_, double p_75488_3_, double p_75488_5_)
{
return !this.canNavigate() ? null : this.getEntityPathToXYZ(this.theEntity, MathHelper.floor_double(p_75488_1_), (int)p_75488_3_, MathHelper.floor_double(p_75488_5_), this.getPathSearchRange(), this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim);
return this.getEntityPathToXYZ(this.theEntity, MathHelper.floor_double(p_75488_1_), (int)p_75488_3_, MathHelper.floor_double(p_75488_5_), this.getPathSearchRange(), this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim);
}
/**
@@ -135,7 +135,7 @@ public class PathNavigateFlying extends PathNavigate {
*/
public FlyPathEntity getPathToEntityLiving(Entity p_75494_1_)
{
return !this.canNavigate() ? null : this.getPathEntityToEntity(this.theEntity, p_75494_1_, this.getPathSearchRange(), this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim);
return this.getPathEntityToEntity(this.theEntity, p_75494_1_, this.getPathSearchRange(), this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim);
}
/**
@@ -202,10 +202,7 @@ public class PathNavigateFlying extends PathNavigate {
if (!this.noPath())
{
if (this.canNavigate())
{
this.pathFollow();
}
this.pathFollow();
if (!this.noPath())
{
@@ -224,15 +221,6 @@ public class PathNavigateFlying extends PathNavigate {
Vec3 vec3 = this.getEntityPosition();
int i = this.currentPath.getCurrentPathLength();
for (int j = this.currentPath.getCurrentPathIndex(); j < this.currentPath.getCurrentPathLength(); ++j)
{
if (this.currentPath.getPathPointFromIndex(j).yCoord != (int)vec3.yCoord)
{
i = j;
break;
}
}
float f = this.theEntity.width * this.theEntity.width;
int k;
@@ -300,23 +288,6 @@ public class PathNavigateFlying extends PathNavigate {
return this.theEntity.boundingBox.minY + 0.05D;
}
/**
* If on ground or swimming and can swim
*/
private boolean canNavigate()
{
return true;
}
/**
* Returns true when an entity could stand at a position, including solid blocks under the entire entity. Args:
* xOffset, yOffset, zOffset, entityXSize, entityYSize, entityZSize, originPosition, vecX, vecZ
*/
private boolean isSafeToStandAt(int p_75483_1_, int p_75483_2_, int p_75483_3_, int p_75483_4_, int p_75483_5_, int p_75483_6_, Vec3 p_75483_7_, double p_75483_8_, double p_75483_10_)
{
return true;
}
/**
* Trims path data from the end to the first sun covered block
*/
@@ -343,112 +314,11 @@ public class PathNavigateFlying extends PathNavigate {
*/
private boolean isDirectPathBetweenPoints(Vec3 p_75493_1_, Vec3 p_75493_2_, int p_75493_3_, int p_75493_4_, int p_75493_5_)
{
int l = MathHelper.floor_double(p_75493_1_.xCoord);
int i1 = MathHelper.floor_double(p_75493_1_.zCoord);
double d0 = p_75493_2_.xCoord - p_75493_1_.xCoord;
double d1 = p_75493_2_.zCoord - p_75493_1_.zCoord;
double d2 = d0 * d0 + d1 * d1;
if (d2 < 1.0E-8D)
{
return false;
}
else
{
double d3 = 1.0D / Math.sqrt(d2);
d0 *= d3;
d1 *= d3;
p_75493_3_ += 2;
p_75493_5_ += 2;
if (!this.isSafeToStandAt(l, (int)p_75493_1_.yCoord, i1, p_75493_3_, p_75493_4_, p_75493_5_, p_75493_1_, d0, d1))
{
return false;
}
else
{
p_75493_3_ -= 2;
p_75493_5_ -= 2;
double d4 = 1.0D / Math.abs(d0);
double d5 = 1.0D / Math.abs(d1);
double d6 = (double)(l * 1) - p_75493_1_.xCoord;
double d7 = (double)(i1 * 1) - p_75493_1_.zCoord;
if (d0 >= 0.0D)
{
++d6;
}
if (d1 >= 0.0D)
{
++d7;
}
d6 /= d0;
d7 /= d1;
int j1 = d0 < 0.0D ? -1 : 1;
int k1 = d1 < 0.0D ? -1 : 1;
int l1 = MathHelper.floor_double(p_75493_2_.xCoord);
int i2 = MathHelper.floor_double(p_75493_2_.zCoord);
int j2 = l1 - l;
int k2 = i2 - i1;
do
{
if (j2 * j1 <= 0 && k2 * k1 <= 0)
{
return true;
}
if (d6 < d7)
{
d6 += d4;
l += j1;
j2 = l1 - l;
}
else
{
d7 += d5;
i1 += k1;
k2 = i2 - i1;
}
}
while (this.isSafeToStandAt(l, (int)p_75493_1_.yCoord, i1, p_75493_3_, p_75493_4_, p_75493_5_, p_75493_1_, d0, d1));
return false;
}
}
}
/**
* Returns true if an entity does not collide with any solid blocks at the position. Args: xOffset, yOffset,
* zOffset, entityXSize, entityYSize, entityZSize, originPosition, vecX, vecZ
*/
private boolean isPositionClear(int p_75496_1_, int p_75496_2_, int p_75496_3_, int p_75496_4_, int p_75496_5_, int p_75496_6_, Vec3 p_75496_7_, double p_75496_8_, double p_75496_10_)
{
for (int k1 = p_75496_1_; k1 < p_75496_1_ + p_75496_4_; ++k1)
{
for (int l1 = p_75496_2_; l1 < p_75496_2_ + p_75496_5_; ++l1)
{
for (int i2 = p_75496_3_; i2 < p_75496_3_ + p_75496_6_; ++i2)
{
double d2 = (double)k1 + 0.5D - p_75496_7_.xCoord;
double d3 = (double)i2 + 0.5D - p_75496_7_.zCoord;
if (d2 * p_75496_8_ + d3 * p_75496_10_ >= 0.0D)
{
Block block = this.worldObj.getBlock(k1, l1, i2);
if (!block.getBlocksMovement(this.worldObj, k1, l1, i2))
{
return false;
}
}
}
}
}
return true;
return !(d2 < 1.0E-8D);
}
public FlyPathEntity getPathEntityToEntity(Entity p_72865_1_, Entity p_72865_2_, float p_72865_3_, boolean p_72865_4_, boolean p_72865_5_, boolean p_72865_6_, boolean p_72865_7_)
@@ -232,7 +232,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
public int getMaxSafePointTries()
{
return 5;
return 10;
}
@Override
@@ -426,13 +426,13 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
protected void updateAITasks()
{
this.getNavigator().onUpdateNavigation();
this.getMoveHelper().onUpdateMoveHelper();
try {
super.updateAITasks();
} catch (ConcurrentModificationException ignored){
}
this.getNavigator().onUpdateNavigation();
this.getMoveHelper().onUpdateMoveHelper();
}
public void addInteract(EntityLivingBase entity){
@@ -631,7 +631,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
if (canFly()) {
this.getNavigator().setCanSwim(true);
this.tasks.addTask(0, new EntityAISwimming(this));
} else {
this.tasks.addTask(0, new EntityAIWaterNav(this));
}