In the time honoured tradition of trying to fix vanilla, we today attempt to patch the pathfinding AI so that it doesn't lag when

there's a lot of entities. Basically, if the zombie can't reach the villager, backoff subsequent pathfinding attempts. Hopefully
should really help with lag caused by zombie swarms.
This commit is contained in:
Christian 2013-08-20 11:55:57 -04:00
parent b2d309b17e
commit 8fed427251
1 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,64 @@
--- ../src_base/minecraft/net/minecraft/entity/ai/EntityAIAttackOnCollide.java
+++ ../src_work/minecraft/net/minecraft/entity/ai/EntityAIAttackOnCollide.java
@@ -3,6 +3,7 @@
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.pathfinding.PathEntity;
+import net.minecraft.pathfinding.PathPoint;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
@@ -22,6 +23,8 @@
PathEntity entityPathEntity;
Class classTarget;
private int field_75445_i;
+
+ private int failedPathFindingPenalty;
public EntityAIAttackOnCollide(EntityCreature par1EntityCreature, Class par2Class, double par3, boolean par5)
{
@@ -59,8 +62,16 @@
}
else
{
- this.entityPathEntity = this.attacker.getNavigator().getPathToEntityLiving(entitylivingbase);
- return this.entityPathEntity != null;
+ if (-- this.field_75445_i <= 0)
+ {
+ this.entityPathEntity = this.attacker.getNavigator().getPathToEntityLiving(entitylivingbase);
+ this.field_75445_i = 4 + this.attacker.getRNG().nextInt(7);
+ return this.entityPathEntity != null;
+ }
+ else
+ {
+ return true;
+ }
}
}
@@ -100,8 +111,24 @@
if ((this.field_75437_f || this.attacker.getEntitySenses().canSee(entitylivingbase)) && --this.field_75445_i <= 0)
{
- this.field_75445_i = 4 + this.attacker.getRNG().nextInt(7);
+ this.field_75445_i = failedPathFindingPenalty + 4 + this.attacker.getRNG().nextInt(7);
this.attacker.getNavigator().tryMoveToEntityLiving(entitylivingbase, this.field_75440_e);
+ if (this.attacker.getNavigator().getPath() != null)
+ {
+ PathPoint finalPathPoint = this.attacker.getNavigator().getPath().getFinalPathPoint();
+ if (entitylivingbase.getDistanceSq(finalPathPoint.xCoord, finalPathPoint.yCoord, finalPathPoint.zCoord) < 1)
+ {
+ failedPathFindingPenalty = 0;
+ }
+ else
+ {
+ failedPathFindingPenalty += 10;
+ }
+ }
+ else
+ {
+ failedPathFindingPenalty += 10;
+ }
}
this.attackTick = Math.max(this.attackTick - 1, 0);