@Override public boolean continueExecuting() { return !thePathfinder.noPath() && theRobit.getDistanceSqToEntity(theOwner) > (maxDist * maxDist) && theRobit.getFollowing() && theRobit.getEnergy() > 0 && theOwner.worldObj.provider.dimensionId == theRobit.worldObj.provider.dimensionId; }
public RobitAIFollow(EntityRobit entityRobit, float speed, float min, float max) { theRobit = entityRobit; theWorld = entityRobit.worldObj; moveSpeed = speed; thePathfinder = entityRobit.getNavigator(); minDist = min; maxDist = max; setMutexBits(3); }
@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(theWorld, x + l, z - 1, y + i1) && !theWorld.getBlock(x + l, z, y + i1).isNormalCube() && !theWorld.getBlock(x + l, z + 1, y + i1).isNormalCube()) { theRobit.setLocationAndAngles( (x + l) + 0.5F, z, (y + i1) + 0.5F, theRobit.rotationYaw, theRobit.rotationPitch); thePathfinder.clearPathEntity(); return; } } } } } } } }
@Override public EnumActionResult onItemUse( ItemStack itemstack, EntityPlayer entityplayer, World world, BlockPos pos, EnumHand hand, EnumFacing side, float posX, float posY, float posZ) { TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity instanceof TileEntityChargepad) { TileEntityChargepad chargepad = (TileEntityChargepad) tileEntity; if (!chargepad.isActive) { if (!world.isRemote) { EntityRobit robit = new EntityRobit(world, pos.getX() + 0.5, pos.getY() + 0.1, pos.getZ() + 0.5); robit.setHome(Coord4D.get(chargepad)); robit.setEnergy(getEnergy(itemstack)); robit.setOwner(entityplayer.getName()); robit.setInventory(getInventory(itemstack)); robit.setCustomNameTag(getName(itemstack)); world.spawnEntityInWorld(robit); } entityplayer.setHeldItem(hand, null); return EnumActionResult.SUCCESS; } } return EnumActionResult.PASS; }
@Override public boolean shouldExecute() { EntityPlayer player = theRobit.getOwner(); if (player == null) { return false; } else if (theRobit.worldObj.provider.dimensionId != player.worldObj.provider.dimensionId) { 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 void resetTask() { theOwner = null; thePathfinder.clearPathEntity(); theRobit.getNavigator().setAvoidsWater(avoidWater); }
@Override public void startExecuting() { ticker = 0; avoidWater = theRobit.getNavigator().getAvoidsWater(); theRobit.getNavigator().setAvoidsWater(false); }