Search in sources :

Example 6 with BlockBush

use of net.minecraft.block.BlockBush in project Almura by AlmuraDev.

the class GrassFeature method canPlace.

private boolean canPlace(final IBlockAccess access, final BlockPos pos, final IBlockState toPlaceState, final List<LazyBlockState> requires) {
    World world;
    if (access instanceof ChunkCache) {
        world = ((ChunkCacheAccessor) access).accessor$getWorld();
    } else {
        world = (World) access;
    }
    final Block toPlaceBlock = toPlaceState.getBlock();
    boolean canPlace = true;
    if (!requires.isEmpty()) {
        final IBlockState underState = access.getBlockState(pos.down());
        boolean found = false;
        for (final LazyBlockState lbs : requires) {
            if (lbs.partialTest(underState)) {
                found = true;
                break;
            }
        }
        canPlace = found;
    }
    if (canPlace) {
        if (toPlaceBlock instanceof BlockBush) {
            canPlace = ((BlockBush) toPlaceBlock).canBlockStay(world, pos, toPlaceState);
        }
    }
    return canPlace;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) Block(net.minecraft.block.Block) World(net.minecraft.world.World) WeightedLazyBlockState(com.almuradev.content.util.WeightedLazyBlockState) LazyBlockState(com.almuradev.content.type.block.state.LazyBlockState) BlockBush(net.minecraft.block.BlockBush)

Example 7 with BlockBush

use of net.minecraft.block.BlockBush in project Almura by AlmuraDev.

the class CactusFeature method canPlace.

private boolean canPlace(final IBlockAccess access, final BlockPos pos, final IBlockState toPlaceState, final List<LazyBlockState> requires) {
    World world;
    if (access instanceof ChunkCache) {
        world = ((ChunkCacheAccessor) access).accessor$getWorld();
    } else {
        world = (World) access;
    }
    final Block toPlaceBlock = toPlaceState.getBlock();
    boolean canPlace = true;
    if (!requires.isEmpty()) {
        final IBlockState underState = access.getBlockState(pos.down());
        boolean found = false;
        for (final LazyBlockState lbs : requires) {
            if (lbs.partialTest(underState)) {
                found = true;
                break;
            }
        }
        canPlace = found;
    }
    if (canPlace) {
        // Why Vanilla lol
        if (toPlaceBlock instanceof BlockCactus) {
            canPlace = ((BlockCactus) toPlaceBlock).canBlockStay(world, pos);
        } else if (toPlaceBlock instanceof BlockBush) {
            canPlace = ((BlockBush) toPlaceBlock).canBlockStay(world, pos, toPlaceState);
        }
    }
    return canPlace;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) Block(net.minecraft.block.Block) World(net.minecraft.world.World) BlockCactus(net.minecraft.block.BlockCactus) WeightedLazyBlockState(com.almuradev.content.util.WeightedLazyBlockState) LazyBlockState(com.almuradev.content.type.block.state.LazyBlockState) BlockBush(net.minecraft.block.BlockBush)

Example 8 with BlockBush

use of net.minecraft.block.BlockBush in project Gaia-Dimension by Andromander.

the class GDGlitterGrass method grow.

@Override
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) {
    BlockPos blockpos = pos.up();
    for (int i = 0; i < 128; ++i) {
        BlockPos blockpos1 = blockpos;
        int j = 0;
        while (true) {
            if (j >= i / 16) {
                if (worldIn.isAirBlock(blockpos1)) {
                    if (rand.nextInt(8) == 0) {
                        worldIn.getBiome(blockpos1).plantFlower(worldIn, rand, blockpos1);
                    } else {
                        IBlockState normalGrowth = GDBlocks.crystal_growth.getDefaultState();
                        IBlockState mutantGrowth = GDBlocks.crystal_growth_mutant.getDefaultState();
                        if (((BlockBush) GDBlocks.crystal_growth).canBlockStay(worldIn, blockpos1, normalGrowth)) {
                            if (worldIn.getBiome(pos) instanceof GDMutantAgateWildwood) {
                                worldIn.setBlockState(blockpos1, mutantGrowth, 3);
                            } else {
                                worldIn.setBlockState(blockpos1, normalGrowth, 3);
                            }
                        }
                    }
                }
                break;
            }
            blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
            if (worldIn.getBlockState(blockpos1.down()).getBlock() != GDBlocks.glitter_grass || worldIn.getBlockState(blockpos1).isNormalCube()) {
                break;
            }
            ++j;
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) BlockBush(net.minecraft.block.BlockBush)

Example 9 with BlockBush

use of net.minecraft.block.BlockBush in project BluePower by Qmunity.

the class ItemSickle method onBlockDestroyed.

@Override
public boolean onBlockDestroyed(ItemStack itemStack, World world, Block block, int x, int y, int z, EntityLivingBase entityLiving) {
    boolean used = false;
    if (!(entityLiving instanceof EntityPlayer))
        return false;
    EntityPlayer player = (EntityPlayer) entityLiving;
    if ((block != null) && (block.isLeaves(world, x, y, z))) {
        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                for (int k = -1; k <= 1; k++) {
                    Block blockToCheck = world.getBlock(x + i, y + j, z + k);
                    int meta = world.getBlockMetadata(x + i, y + j, z + k);
                    if ((blockToCheck != null) && (blockToCheck.isLeaves(world, x + i, y + j, z + k))) {
                        if (blockToCheck.canHarvestBlock(player, meta)) {
                            blockToCheck.harvestBlock(world, player, x + i, y + j, z + k, meta);
                        }
                        world.setBlock(x + i, y + j, z + k, Blocks.air);
                        used = true;
                    }
                }
            }
        }
        if (used) {
            itemStack.damageItem(1, entityLiving);
        }
        return used;
    }
    if ((block != null) && (block instanceof BlockLilyPad)) {
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                Block blockToCheck = world.getBlock(x + i, y, z + j);
                int meta = world.getBlockMetadata(x + i, y, z + j);
                if (blockToCheck != null && blockToCheck instanceof BlockLilyPad) {
                    if (blockToCheck.canHarvestBlock(player, meta)) {
                        blockToCheck.harvestBlock(world, player, x + i, y, z + j, meta);
                    }
                    world.setBlock(x + i, y, z + j, Blocks.air);
                    used = true;
                }
            }
        }
    }
    if ((block != null) && !(block instanceof BlockLilyPad)) {
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                Block blockToCheck = world.getBlock(x + i, y, z + j);
                int meta = world.getBlockMetadata(x + i, y, z + j);
                if (blockToCheck != null) {
                    if (blockToCheck instanceof BlockBush && !(blockToCheck instanceof BlockLilyPad)) {
                        if (blockToCheck.canHarvestBlock(player, meta)) {
                            blockToCheck.harvestBlock(world, player, x + i, y, z + j, meta);
                        }
                        world.setBlock(x + i, y, z + j, Blocks.air);
                        used = true;
                    }
                }
            }
        }
    }
    if (used) {
        itemStack.damageItem(1, entityLiving);
    }
    return used;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) BlockLilyPad(net.minecraft.block.BlockLilyPad) BlockBush(net.minecraft.block.BlockBush)

Example 10 with BlockBush

use of net.minecraft.block.BlockBush in project Gaia-Dimension by Andromander.

the class GDCorruptGrass method grow.

@Override
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) {
    BlockPos blockpos = pos.up();
    for (int i = 0; i < 128; ++i) {
        BlockPos blockpos1 = blockpos;
        int j = 0;
        while (true) {
            if (j >= i / 16) {
                if (worldIn.isAirBlock(blockpos1)) {
                    if (rand.nextInt(8) == 0) {
                        worldIn.getBiome(blockpos1).plantFlower(worldIn, rand, blockpos1);
                    } else {
                        IBlockState blackGrowth = GDBlocks.crystal_growth_black.getDefaultState();
                        IBlockState redGrowth = GDBlocks.crystal_growth_red.getDefaultState();
                        if (((BlockBush) GDBlocks.crystal_growth_black).canBlockStay(worldIn, blockpos1, blackGrowth)) {
                            if (rand.nextInt(2) == 0) {
                                worldIn.setBlockState(blockpos1, blackGrowth, 3);
                            } else {
                                worldIn.setBlockState(blockpos1, redGrowth, 3);
                            }
                        }
                    }
                }
                break;
            }
            blockpos1 = blockpos1.add(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
            if (worldIn.getBlockState(blockpos1.down()).getBlock() != GDBlocks.corrupt_grass || worldIn.getBlockState(blockpos1).isNormalCube()) {
                break;
            }
            ++j;
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) BlockBush(net.minecraft.block.BlockBush)

Aggregations

BlockBush (net.minecraft.block.BlockBush)15 Block (net.minecraft.block.Block)9 IBlockState (net.minecraft.block.state.IBlockState)8 BlockPos (net.minecraft.util.math.BlockPos)7 LazyBlockState (com.almuradev.content.type.block.state.LazyBlockState)4 WeightedLazyBlockState (com.almuradev.content.util.WeightedLazyBlockState)4 ChunkCache (net.minecraft.world.ChunkCache)4 World (net.minecraft.world.World)4 BlockCactus (net.minecraft.block.BlockCactus)3 ItemStack (net.minecraft.item.ItemStack)2 BlockBOPDecoration (biomesoplenty.common.block.BlockBOPDecoration)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 ITerraformableBlock (micdoodle8.mods.galacticraft.api.block.ITerraformableBlock)1 BlockLilyPad (net.minecraft.block.BlockLilyPad)1 BlockSapling (net.minecraft.block.BlockSapling)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 Item (net.minecraft.item.Item)1 BlockPos (net.minecraft.util.BlockPos)1 WorldGenBush (net.minecraft.world.gen.feature.WorldGenBush)1