Search in sources :

Example 1 with AntEntity

use of io.github.chaosawakens.common.entity.AntEntity 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);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockPos(net.minecraft.util.math.BlockPos) CreatureEntity(net.minecraft.entity.CreatureEntity) AggressiveAntEntity(io.github.chaosawakens.common.entity.AggressiveAntEntity) AntEntity(io.github.chaosawakens.common.entity.AntEntity) AggressiveAntEntity(io.github.chaosawakens.common.entity.AggressiveAntEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

AggressiveAntEntity (io.github.chaosawakens.common.entity.AggressiveAntEntity)1 AntEntity (io.github.chaosawakens.common.entity.AntEntity)1 CreatureEntity (net.minecraft.entity.CreatureEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1