2025-03-11 00:23:54 +01:00
|
|
|
package game.ai;
|
|
|
|
|
|
|
|
import game.entity.types.EntityLiving;
|
|
|
|
import game.entity.types.EntityTameable;
|
|
|
|
import game.pathfinding.PathNavigate;
|
|
|
|
import game.pathfinding.PathNavigateGround;
|
|
|
|
import game.world.World;
|
|
|
|
|
|
|
|
public class EntityAIFollowOwner extends EntityAIBase
|
|
|
|
{
|
|
|
|
private EntityTameable thePet;
|
|
|
|
private EntityLiving theOwner;
|
|
|
|
World theWorld;
|
|
|
|
private double followSpeed;
|
|
|
|
private PathNavigate petPathfinder;
|
|
|
|
private int field_75343_h;
|
|
|
|
float maxDist;
|
|
|
|
float minDist;
|
|
|
|
private boolean field_75344_i;
|
|
|
|
|
|
|
|
public EntityAIFollowOwner(EntityTameable thePetIn, double followSpeedIn, float minDistIn, float maxDistIn)
|
|
|
|
{
|
|
|
|
this.thePet = thePetIn;
|
|
|
|
this.theWorld = thePetIn.worldObj;
|
|
|
|
this.followSpeed = followSpeedIn;
|
|
|
|
this.petPathfinder = thePetIn.getNavigator();
|
|
|
|
this.minDist = minDistIn;
|
|
|
|
this.maxDist = maxDistIn;
|
|
|
|
this.setMutexBits(3);
|
|
|
|
|
|
|
|
if (!(thePetIn.getNavigator() instanceof PathNavigateGround))
|
|
|
|
{
|
|
|
|
throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the EntityAIBase should begin execution.
|
|
|
|
*/
|
|
|
|
public boolean shouldExecute()
|
|
|
|
{
|
|
|
|
EntityLiving entitylivingbase = this.thePet.getOwner();
|
|
|
|
|
|
|
|
if (entitylivingbase == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// else if (entitylivingbase.isPlayer() && ((EntityNPC)entitylivingbase).isSpectator())
|
|
|
|
// {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
else if (this.thePet.isSitting())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (this.thePet.getDistanceSqToEntity(entitylivingbase) < (double)(this.minDist * this.minDist))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.theOwner = entitylivingbase;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether an in-progress EntityAIBase should continue executing
|
|
|
|
*/
|
|
|
|
public boolean continueExecuting()
|
|
|
|
{
|
|
|
|
return !this.petPathfinder.noPath() && this.thePet.getDistanceSqToEntity(this.theOwner) > (double)(this.maxDist * this.maxDist) && !this.thePet.isSitting();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute a one shot task or start executing a continuous task
|
|
|
|
*/
|
|
|
|
public void startExecuting()
|
|
|
|
{
|
|
|
|
this.field_75343_h = 0;
|
|
|
|
this.field_75344_i = ((PathNavigateGround)this.thePet.getNavigator()).getAvoidsWater();
|
|
|
|
((PathNavigateGround)this.thePet.getNavigator()).setAvoidsWater(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the task
|
|
|
|
*/
|
|
|
|
public void resetTask()
|
|
|
|
{
|
|
|
|
this.theOwner = null;
|
|
|
|
this.petPathfinder.clearPathEntity();
|
|
|
|
((PathNavigateGround)this.thePet.getNavigator()).setAvoidsWater(true);
|
|
|
|
}
|
2025-03-20 00:29:25 +01:00
|
|
|
|
2025-03-11 00:23:54 +01:00
|
|
|
/**
|
|
|
|
* Updates the task
|
|
|
|
*/
|
|
|
|
public void updateTask()
|
|
|
|
{
|
|
|
|
this.thePet.getLookHelper().setLookPositionWithEntity(this.theOwner, 10.0F, (float)this.thePet.getVerticalFaceSpeed());
|
|
|
|
|
|
|
|
if (!this.thePet.isSitting())
|
|
|
|
{
|
|
|
|
if (--this.field_75343_h <= 0)
|
|
|
|
{
|
|
|
|
this.field_75343_h = 10;
|
|
|
|
|
|
|
|
if (!this.petPathfinder.tryMoveToEntityLiving(this.theOwner, this.followSpeed))
|
|
|
|
{
|
|
|
|
this.petPathfinder.clearPathEntity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|