Search in sources :

Example 1 with Spread

use of com.almuradev.content.type.block.type.leaf.processor.spread.Spread in project Almura by AlmuraDev.

the class LeafBlockImpl method updateSpreadTick.

private void updateSpreadTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    if (worldIn.isRemote) {
        return;
    }
    final IBlockState actualBlock = worldIn.getBlockState(pos);
    final Spread spread = this.definition.spread;
    if (spread == null) {
        return;
    }
    if (actualBlock.getBlock() != this) {
        return;
    }
    final Biome biome = worldIn.getBiome(pos);
    final DoubleRange chanceRoll = spread.getOrLoadChanceRangeForBiome(biome);
    if (chanceRoll == null) {
        return;
    }
    if (!(rand.nextDouble() <= (chanceRoll.random(rand) / 100))) {
        return;
    }
    for (final EnumFacing facing : EnumFacing.values()) {
        final BlockPos offset = pos.offset(facing);
        final IBlockState offsetBlock = worldIn.getBlockState(offset);
        if (offsetBlock.getBlock() == Blocks.AIR) {
            worldIn.setBlockState(offset, spread.getBlock().get());
            worldIn.playEvent(2005, pos, 0);
            break;
        }
    }
}
Also used : DoubleRange(com.almuradev.toolbox.util.math.DoubleRange) Spread(com.almuradev.content.type.block.type.leaf.processor.spread.Spread) IBlockState(net.minecraft.block.state.IBlockState) Biome(net.minecraft.world.biome.Biome) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Spread (com.almuradev.content.type.block.type.leaf.processor.spread.Spread)1 DoubleRange (com.almuradev.toolbox.util.math.DoubleRange)1 IBlockState (net.minecraft.block.state.IBlockState)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 Biome (net.minecraft.world.biome.Biome)1