Search in sources :

Example 1 with BlockAlveary

use of forestry.apiculture.blocks.BlockAlveary in project ForestryMC by ForestryMC.

the class AlleleEffectRadioactive method destroyEnvironment.

private static IEffectData destroyEnvironment(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
    World world = housing.getWorldObj();
    Random rand = world.rand;
    Vec3i area = VectUtil.scale(genome.getTerritory(), 2);
    Vec3i offset = VectUtil.scale(area, -1 / 2.0f);
    BlockPos posHousing = housing.getCoordinates();
    for (int i = 0; i < 20; i++) {
        BlockPos randomPos = VectUtil.getRandomPositionInArea(rand, area);
        BlockPos posBlock = randomPos.add(posHousing);
        posBlock = posBlock.add(offset);
        if (posBlock.getY() <= 1 || posBlock.getY() >= world.getActualHeight()) {
            continue;
        }
        // Don't destroy ourselves or blocks below us.
        if (posBlock.getX() == posHousing.getX() && posBlock.getZ() == posHousing.getZ() && posBlock.getY() <= posHousing.getY()) {
            continue;
        }
        if (!world.isBlockLoaded(posBlock) || world.isAirBlock(posBlock)) {
            continue;
        }
        IBlockState blockState = world.getBlockState(posBlock);
        Block block = blockState.getBlock();
        if (block instanceof BlockAlveary) {
            continue;
        }
        TileEntity tile = TileUtil.getTile(world, posBlock);
        if (tile instanceof IBeeHousing) {
            continue;
        }
        if (blockState.getBlockHardness(world, posBlock) < 0) {
            continue;
        }
        BlockUtil.setBlockToAirWithSound(world, posBlock, blockState);
        break;
    }
    return storedData;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Vec3i(net.minecraft.util.math.Vec3i) BlockAlveary(forestry.apiculture.blocks.BlockAlveary) IBlockState(net.minecraft.block.state.IBlockState) Random(java.util.Random) Block(net.minecraft.block.Block) IBeeHousing(forestry.api.apiculture.IBeeHousing) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Aggregations

IBeeHousing (forestry.api.apiculture.IBeeHousing)1 BlockAlveary (forestry.apiculture.blocks.BlockAlveary)1 Random (java.util.Random)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3i (net.minecraft.util.math.Vec3i)1 World (net.minecraft.world.World)1