Search in sources :

Example 1 with BlockFarmland

use of net.minecraft.block.BlockFarmland in project AgriCraft by AgriCraft.

the class TileEntitySprinkler method irrigate.

/**
     * Depending on the block type either irrigates farmland or forces plant
     * GROWTH (based on chance)
     */
private void irrigate(BlockPos pos, boolean farmlandOnly) {
    IBlockState state = this.getWorld().getBlockState(pos);
    Block block = state.getBlock();
    if (block instanceof BlockFarmland && block.getMetaFromState(state) < 7) {
        // irrigate farmland
        int flag = counter == 0 ? 2 : 6;
        worldObj.setBlockState(pos, block.getStateFromMeta(7), flag);
    } else if (!farmlandOnly && ((block instanceof IPlantable) || (block instanceof IGrowable))) {
        // X1 chance to force GROWTH tick on plant every Y1 ticks
        if (counter == 0 && worldObj.rand.nextDouble() <= AgriCraftConfig.sprinklerGrowthChancePercent) {
            block.updateTick(this.getWorld(), pos, state, worldObj.rand);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockFarmland(net.minecraft.block.BlockFarmland) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block)

Aggregations

Block (net.minecraft.block.Block)1 BlockFarmland (net.minecraft.block.BlockFarmland)1 IGrowable (net.minecraft.block.IGrowable)1 IBlockState (net.minecraft.block.state.IBlockState)1 IPlantable (net.minecraftforge.common.IPlantable)1