Java Code Examples for net.minecraft.entity.EntityCreature#getBlockPathWeight()

The following examples show how to use net.minecraft.entity.EntityCreature#getBlockPathWeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpawnUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
public static boolean isSpaceAvailableForSpawn(World worldObj, EntityLiving entity, EntityCreature asCreature, boolean checkEntityCollisions, boolean canSpawnInLiquid) {
  if(asCreature != null && asCreature.getBlockPathWeight(entity.getPosition()) < 0) {
    return false;
  }
  if(checkEntityCollisions && !worldObj.checkNoEntityCollision(entity.getEntityBoundingBox())) {
    return false;
  }
  if(!worldObj.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty()) {
    return false;
  }    
  if(!canSpawnInLiquid && worldObj.containsAnyLiquid(entity.getEntityBoundingBox())) {
    return false;
  }    
  return true;
}
 
Example 2
Source File: EntityAIHerdMove.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
public static Vec3d generateRandomPos(EntityCreature entity, int xz, int y, @Nullable Vec3d target, boolean p_191379_4_)
{
	PathNavigate pathnavigate = entity.getNavigator();
	Random random = entity.getRNG();
	boolean flag;

	if (entity.hasHome())
	{
		double d0 = entity.getHomePosition().distanceSq((double)MathHelper.floor(entity.posX), (double)MathHelper.floor(entity.posY), (double)MathHelper.floor(entity.posZ)) + 4.0D;
		double d1 = (double)(entity.getMaximumHomeDistance() + (float)xz);
		flag = d0 < d1 * d1;
	}
	else
	{
		flag = false;
	}

	boolean flag1 = false;
	float weight = -99999.0F;
	int outX = 0;
	int outY = 0;
	int outZ = 0;

	for (int k = 0; k < 10; ++k)
	{
		int _x = random.nextInt(2 * xz + 1) - xz;
		int _y = random.nextInt(2 * y + 1) - y;
		int _z = random.nextInt(2 * xz + 1) - xz;

		if (target == null || (double)_x * target.xCoord + (double)_z * target.zCoord >= 0.0D)
		{
			if (entity.hasHome() && xz > 1)
			{
				BlockPos blockpos = entity.getHomePosition();

				if (entity.posX > (double)blockpos.getX())
				{
					_x -= random.nextInt(xz / 2);
				}
				else
				{
					_x += random.nextInt(xz / 2);
				}

				if (entity.posZ > (double)blockpos.getZ())
				{
					_z -= random.nextInt(xz / 2);
				}
				else
				{
					_z += random.nextInt(xz / 2);
				}
			}

			BlockPos blockpos1 = new BlockPos((double)_x + entity.posX, (double)_y + entity.posY, (double)_z + entity.posZ);

			if ((!flag || entity.isWithinHomeDistanceFromPosition(blockpos1)) && pathnavigate.canEntityStandOnPos(blockpos1))
			{
				if (!p_191379_4_)
				{
					blockpos1 = moveAboveSolid(blockpos1, entity);

					if (isWaterDestination(blockpos1, entity))
					{
						continue;
					}
				}

				float _weight = entity.getBlockPathWeight(blockpos1);

				if (_weight > weight)
				{
					weight = _weight;
					outX = _x;
					outY = _y;
					outZ = _z;
					flag1 = true;
				}
			}
		}
	}

	if (flag1)
	{
		return new Vec3d((double)outX + entity.posX, (double)outY + entity.posY, (double)outZ + entity.posZ);
	}
	else
	{
		return null;
	}
}
 
Example 3
Source File: EntityAIWanderHex.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
public static Vec3d generateRandomPosInCenter(EntityCreature entity, int xz, int y,boolean pathThroughWater, IslandMap map, Center c)
{
	PathNavigate pathnavigate = entity.getNavigator();
	Random random = entity.getRNG();
	boolean flag;
	BlockPos centerPos = c.point.toBlockPos().add(map.getParams().getWorldX(), 0, map.getParams().getWorldZ());

	if (entity.hasHome())
	{
		double d0 = entity.getHomePosition().distanceSq((double)MathHelper.floor(entity.posX), (double)MathHelper.floor(entity.posY), (double)MathHelper.floor(entity.posZ)) + 4.0D;
		double d1 = (double)(entity.getMaximumHomeDistance() + (float)xz);
		flag = d0 < d1 * d1;
	}
	else
	{
		flag = false;
	}

	boolean flag1 = false;
	float weight = -99999.0F;
	int outX = 0;
	int outY = 0;
	int outZ = 0;

	for (int k = 0; k < 10; ++k)
	{
		int _x = random.nextInt(2 * xz + 1) - xz;
		int _y = random.nextInt(2 * y + 1) - y;
		int _z = random.nextInt(2 * xz + 1) - xz;


		if (entity.hasHome() && xz > 1)
		{
			BlockPos blockpos = entity.getHomePosition();

			if (entity.posX > (double)blockpos.getX())
			{
				_x -= random.nextInt(xz / 2);
			}
			else
			{
				_x += random.nextInt(xz / 2);
			}

			if (entity.posZ > (double)blockpos.getZ())
			{
				_z -= random.nextInt(xz / 2);
			}
			else
			{
				_z += random.nextInt(xz / 2);
			}
		}

		BlockPos blockpos1 = new BlockPos((double)_x + centerPos.getX(), (double)_y + centerPos.getY(), (double)_z + centerPos.getZ());

		if ((!flag || entity.isWithinHomeDistanceFromPosition(blockpos1)) && pathnavigate.canEntityStandOnPos(blockpos1))
		{
			if (!pathThroughWater)
			{
				blockpos1 = moveAboveSolid(blockpos1, entity);

				if (isWaterDestination(blockpos1, entity))
				{
					continue;
				}
			}

			float _weight = entity.getBlockPathWeight(blockpos1);

			if (_weight > weight)
			{
				weight = _weight;
				outX = _x;
				outY = _y;
				outZ = _z;
				flag1 = true;
			}
		}
	}

	if (flag1)
	{
		return new Vec3d((double)outX + centerPos.getX(), (double)outY + centerPos.getY(), (double)outZ + centerPos.getZ());
	}
	else
	{
		return null;
	}
}