use of net.minecraft.entity.CreatureEntity in project ChaosAwakens by ChaosAwakens.
the class AntNestBlock method randomTick.
@Override
public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
if (worldIn.isClientSide || worldIn.isRainingAt(pos.above()))
return;
List<PlayerEntity> nearbyPlayerExists = worldIn.getEntitiesOfClass(PlayerEntity.class, (new AxisAlignedBB(pos)).inflate(8.0D, 8.0D, 8.0D));
List<AntEntity> nearbyAntEntityList = worldIn.getEntitiesOfClass(AntEntity.class, (new AxisAlignedBB(pos)).inflate(12.0D, 8.0D, 12.0D));
List<AggressiveAntEntity> nearbyAggressiveAntEntityList = worldIn.getEntitiesOfClass(AggressiveAntEntity.class, (new AxisAlignedBB(pos)).inflate(12.0D, 8.0D, 12.0D));
if (nearbyPlayerExists.isEmpty())
return;
if (nearbyAntEntityList.size() + nearbyAggressiveAntEntityList.size() > 10)
return;
final BlockPos abovePos = pos.above();
final int amountToSpawn = MathHelper.nextInt(random, 0, 3);
if (worldIn.getBlockState(abovePos).isAir(worldIn, abovePos)) {
for (int i = 0; i < amountToSpawn; ++i) {
CreatureEntity entity = ant.get().create(worldIn);
assert entity != null;
entity.setPos(pos.getX() + Math.random(), pos.getY() + 1, pos.getZ() + Math.random());
worldIn.addFreshEntity(entity);
}
}
}
Aggregations