2013-05-20 00:43:01 +02:00
|
|
|
package mekanism.common;
|
|
|
|
|
2014-01-08 02:55:50 +01:00
|
|
|
import mekanism.common.entity.EntityRobit;
|
2013-05-20 00:43:01 +02:00
|
|
|
import net.minecraft.entity.ai.EntityAIBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.pathfinding.PathNavigate;
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class RobitAIFollow extends EntityAIBase
|
|
|
|
{
|
|
|
|
/** The robit entity. */
|
2014-03-08 02:00:25 +01:00
|
|
|
private EntityRobit theRobit;
|
|
|
|
|
|
|
|
/** The robit's owner. */
|
|
|
|
private EntityPlayer theOwner;
|
|
|
|
|
|
|
|
/** The world the robit is located in. */
|
|
|
|
private World theWorld;
|
|
|
|
|
|
|
|
/** How fast the robit can travel. */
|
|
|
|
private float moveSpeed;
|
|
|
|
|
|
|
|
/** The robit's pathfinder. */
|
|
|
|
private PathNavigate thePathfinder;
|
|
|
|
|
|
|
|
/** The ticker for updates. */
|
|
|
|
private int ticker;
|
|
|
|
|
|
|
|
/** The distance between the owner the robit must be at in order for the protocol to begin. */
|
|
|
|
private float maxDist;
|
|
|
|
|
|
|
|
/** The distance between the owner the robit must reach before it stops the protocol. */
|
|
|
|
private float minDist;
|
|
|
|
|
|
|
|
/** Whether or not this robit avoids water. */
|
|
|
|
private boolean avoidWater;
|
|
|
|
|
|
|
|
public RobitAIFollow(EntityRobit entityRobit, float speed, float min, float max)
|
|
|
|
{
|
|
|
|
theRobit = entityRobit;
|
2014-04-20 05:34:19 +02:00
|
|
|
theWorld = entityRobit.getWorldObj();
|
2014-03-08 02:00:25 +01:00
|
|
|
moveSpeed = speed;
|
|
|
|
thePathfinder = entityRobit.getNavigator();
|
|
|
|
minDist = min;
|
|
|
|
maxDist = max;
|
|
|
|
setMutexBits(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldExecute()
|
|
|
|
{
|
|
|
|
EntityPlayer player = theRobit.getOwner();
|
|
|
|
|
|
|
|
if(player == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-20 23:34:45 +02:00
|
|
|
else if(theRobit.getWorldObj().provider.dimensionId != player.worldObj.provider.dimensionId)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(!theRobit.getFollowing())
|
|
|
|
{
|
|
|
|
//Still looks up at the player if on chargepad or not following
|
|
|
|
|
|
|
|
theRobit.getLookHelper().setLookPositionWithEntity(player, 6.0F, theRobit.getVerticalFaceSpeed()/10);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(theRobit.getDistanceSqToEntity(player) < (minDist * minDist))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(theRobit.getEnergy() == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
theOwner = player;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean continueExecuting()
|
|
|
|
{
|
2014-04-20 05:34:19 +02:00
|
|
|
return !thePathfinder.noPath() && theRobit.getDistanceSqToEntity(theOwner) > (maxDist * maxDist) && theRobit.getFollowing() && theRobit.getEnergy() > 0 && theOwner.getWorldObj().provider.dimensionId == theRobit.getWorldObj().provider.dimensionId;
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startExecuting()
|
|
|
|
{
|
|
|
|
ticker = 0;
|
|
|
|
avoidWater = theRobit.getNavigator().getAvoidsWater();
|
|
|
|
theRobit.getNavigator().setAvoidsWater(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void resetTask()
|
|
|
|
{
|
|
|
|
theOwner = null;
|
|
|
|
thePathfinder.clearPathEntity();
|
|
|
|
theRobit.getNavigator().setAvoidsWater(avoidWater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateTask()
|
|
|
|
{
|
|
|
|
theRobit.getLookHelper().setLookPositionWithEntity(theOwner, 6.0F, theRobit.getVerticalFaceSpeed()/10);
|
|
|
|
|
|
|
|
if(theRobit.getFollowing())
|
|
|
|
{
|
|
|
|
if(--ticker <= 0)
|
|
|
|
{
|
|
|
|
ticker = 10;
|
|
|
|
|
|
|
|
if(!thePathfinder.tryMoveToEntityLiving(theOwner, moveSpeed))
|
|
|
|
{
|
|
|
|
if(theRobit.getDistanceSqToEntity(theOwner) >= 144.0D)
|
|
|
|
{
|
|
|
|
int x = MathHelper.floor_double(theOwner.posX) - 2;
|
|
|
|
int y = MathHelper.floor_double(theOwner.posZ) - 2;
|
|
|
|
int z = MathHelper.floor_double(theOwner.boundingBox.minY);
|
|
|
|
|
|
|
|
for(int l = 0; l <= 4; ++l)
|
|
|
|
{
|
|
|
|
for(int i1 = 0; i1 <= 4; ++i1)
|
|
|
|
{
|
|
|
|
if((l < 1 || i1 < 1 || l > 3 || i1 > 3) && theWorld.doesBlockHaveSolidTopSurface(x + l, z - 1, y + i1) && !theWorld.isBlockNormalCube(x + l, z, y + i1) && !theWorld.isBlockNormalCube(x + l, z + 1, y + i1))
|
|
|
|
{
|
|
|
|
theRobit.setLocationAndAngles((x + l) + 0.5F, z, (y + i1) + 0.5F, theRobit.rotationYaw, theRobit.rotationPitch);
|
|
|
|
thePathfinder.clearPathEntity();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-20 00:43:01 +02:00
|
|
|
}
|