mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 11:59:26 +00:00
NPCs no longer constantly pathfind when set to return to their home, and already there.
Flying NPCs: -Pathfinding has a cooldown to decrease the amount of times they create a new path. -Fly height limit implemented using getTopSolidOrLiquidBlock instead of iterating through blocks below the NPC.
This commit is contained in:
1 parent
7dc0c25330
commit
4bad48352c
3 files changed
+23
-12
No files matched your search
@@ -145,8 +145,11 @@ public class EntityAIReturn extends EntityAIBase
|
||||
}
|
||||
}
|
||||
}
|
||||
npc.getNavigator().clearPathEntity();
|
||||
npc.getNavigator().tryMoveToXYZ(posX, posY, posZ, 1);
|
||||
|
||||
if (range > 1f) {
|
||||
npc.getNavigator().clearPathEntity();
|
||||
npc.getNavigator().tryMoveToXYZ(posX, posY, posZ, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void resetTask(){
|
||||
|
||||
@@ -46,6 +46,9 @@ public class PathNavigateFlying extends PathNavigate {
|
||||
private boolean canSwim;
|
||||
private static final String __OBFID = "CL_00001627";
|
||||
|
||||
private int pathCooldown = 0;
|
||||
private int maxCooldown = 2;
|
||||
|
||||
public PathNavigateFlying(EntityLiving p_i45873_1_, World worldIn) {
|
||||
super(p_i45873_1_, worldIn);
|
||||
this.theEntity = (EntityNPCInterface)p_i45873_1_;
|
||||
@@ -129,6 +132,13 @@ public class PathNavigateFlying extends PathNavigate {
|
||||
*/
|
||||
public boolean tryMoveToXYZ(double p_75492_1_, double p_75492_3_, double p_75492_5_, double p_75492_7_)
|
||||
{
|
||||
if (this.pathCooldown == 0) {
|
||||
this.pathCooldown = this.maxCooldown;
|
||||
} else {
|
||||
this.pathCooldown--;
|
||||
return false;
|
||||
}
|
||||
|
||||
FlyPathEntity pathentity = this.getPathToXYZ((double)MathHelper.floor_double(p_75492_1_), (double)((int)p_75492_3_), (double)MathHelper.floor_double(p_75492_5_));
|
||||
return this.setPath(pathentity, p_75492_7_);
|
||||
}
|
||||
@@ -146,6 +156,13 @@ public class PathNavigateFlying extends PathNavigate {
|
||||
*/
|
||||
public boolean tryMoveToEntityLiving(Entity p_75497_1_, double p_75497_2_)
|
||||
{
|
||||
if (this.pathCooldown == 0) {
|
||||
this.pathCooldown = this.maxCooldown;
|
||||
} else {
|
||||
this.pathCooldown--;
|
||||
return false;
|
||||
}
|
||||
|
||||
FlyPathEntity pathentity = this.getPathToEntityLiving(p_75497_1_);
|
||||
return pathentity != null && this.setPath(pathentity, p_75497_2_);
|
||||
}
|
||||
|
||||
@@ -38,16 +38,7 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
|
||||
return;
|
||||
}
|
||||
|
||||
double heightOffGround = 0;
|
||||
if(this.ai.hasFlyLimit) {
|
||||
for (int blockY = (int) this.posY; blockY > 0; blockY--) {
|
||||
heightOffGround = this.posY - blockY;
|
||||
if (this.worldObj.getBlock((int) this.posX, blockY, (int) this.posZ) != Blocks.air || heightOffGround > this.ai.flyHeightLimit){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double heightOffGround = this.posY - this.worldObj.getTopSolidOrLiquidBlock((int) this.posX, (int) this.posZ);
|
||||
if (heightOffGround > this.ai.flyHeightLimit && this.ai.hasFlyLimit) {
|
||||
super.moveEntityWithHeading(p_70612_1_,p_70612_2_);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user