Search in sources :

Example 6 with IGrowable

use of net.minecraft.block.IGrowable in project NetherEx by LogicTechCorp.

the class ItemWitherDust method applyBoneMeal.

private static boolean applyBoneMeal(ItemStack stack, World world, BlockPos pos, EntityPlayer player) {
    IBlockState state = world.getBlockState(pos);
    int hook = ForgeEventFactory.onApplyBonemeal(player, world, pos, state, stack);
    if (hook != 0) {
        return hook > 0;
    }
    if (state.getBlock() instanceof IGrowable) {
        IGrowable growable = (IGrowable) state.getBlock();
        if (growable.canGrow(world, pos, state, world.isRemote)) {
            if (!world.isRemote) {
                if (growable.canUseBonemeal(world, world.rand, pos, state)) {
                    growable.grow(world, world.rand, pos, state);
                }
                stack.shrink(1);
            }
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IGrowable(net.minecraft.block.IGrowable)

Example 7 with IGrowable

use of net.minecraft.block.IGrowable in project ArsMagica2 by Mithion.

the class HarvestPlants method applyEffectBlock.

@Override
public boolean applyEffectBlock(ItemStack stack, World world, int blockx, int blocky, int blockz, int blockFace, double impactX, double impactY, double impactZ, EntityLivingBase caster) {
    Block block = world.getBlock(blockx, blocky, blockz);
    if (!(block instanceof IGrowable))
        return false;
    if (!world.isRemote) {
        block.breakBlock(world, blockx, blocky, blockz, block, 0);
        block.dropBlockAsItem(world, blockx, blocky, blockz, world.getBlockMetadata(blockx, blocky, blockz), Block.getIdFromBlock(block));
        world.setBlock(blockx, blocky, blockz, Blocks.air);
    }
    return true;
}
Also used : IGrowable(net.minecraft.block.IGrowable) Block(net.minecraft.block.Block)

Example 8 with IGrowable

use of net.minecraft.block.IGrowable in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method initialize.

/**
     * This (re)initializes a field.
     * Checks the block above to see if it is a plant, if so, breaks it. Then tills.
     */
private AIState initialize() {
    @Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
    if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
        return AIState.PREPARING;
    }
    @Nullable final Field field = buildingFarmer.getCurrentField();
    if (workingOffset != null) {
        final BlockPos position = field.getLocation().down().south(workingOffset.getZ()).east(workingOffset.getX());
        // Still moving to the block
        if (walkToBlock(position.up())) {
            return AIState.FARMER_INITIALIZE;
        }
        // Check to see if the block is a plant, and if it is, break it.
        final IBlockState blockState = world.getBlockState(position.up());
        if (blockState.getBlock() instanceof IGrowable && (!(blockState.getBlock() instanceof BlockCrops) || ((BlockCrops) blockState.getBlock()).getItem(world, position.up(), blockState) != field.getSeed())) {
            mineBlock(position.up());
            setDelay(getLevelDelay());
            return AIState.FARMER_INITIALIZE;
        }
        // hoe the block if able to.
        if (hoeIfAble(position, field)) {
            setDelay(getLevelDelay());
            return AIState.FARMER_INITIALIZE;
        }
        if (shouldPlant(position, field) && !plantCrop(field.getSeed(), position)) {
            resetVariables();
            return AIState.PREPARING;
        }
    }
    if (!handleOffset(field)) {
        resetVariables();
        shouldDumpInventory = true;
        field.setInitialized(true);
        field.setNeedsWork(false);
        return AIState.IDLE;
    }
    setDelay(getLevelDelay());
    return AIState.FARMER_INITIALIZE;
}
Also used : BlockHutField(com.minecolonies.coremod.blocks.BlockHutField) IBlockState(net.minecraft.block.state.IBlockState) BlockCrops(net.minecraft.block.BlockCrops) IGrowable(net.minecraft.block.IGrowable) BlockPos(net.minecraft.util.math.BlockPos) BuildingFarmer(com.minecolonies.coremod.colony.buildings.BuildingFarmer) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with IGrowable

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

the class TileEntitySprinkler method irrigateColumn.

/**
 * This method will search through a vertical column of positions, starting from the top. It
 * will stop searching any lower once it hits anything other than air or plants. Any plant found
 * has an independant chance for a growth tick. That percentage is controlled by
 * AgriCraftConfig. Farmland also ends the search, but it first has its moisture set to max (7)
 * if it isn't already. The lowest position is special: a plant this far away is not helped.
 * Only farmland is currently.
 */
private void irrigateColumn(final int targetX, final int targetZ, final int highestY, final int lowestY) {
    for (int targetY = highestY; targetY >= lowestY; targetY -= 1) {
        BlockPos target = new BlockPos(targetX, targetY, targetZ);
        IBlockState state = this.getWorld().getBlockState(target);
        Block block = state.getBlock();
        // TODO: Is there a way to use isSideSolid to ignore minor obstructions? (Farmland isn't solid.)
        if (block.isAir(state, this.getWorld(), target)) {
            continue;
        }
        // Option B: Give plants a chance to grow, and then continue onward to irrigate the farmland too.
        if ((block instanceof IPlantable || block instanceof IGrowable) && targetY != lowestY) {
            if (this.getRandom().nextInt(100) < AgriCraftConfig.sprinklerGrowthChance) {
                block.updateTick(this.getWorld(), target, state, this.getRandom());
            }
            continue;
        }
        // Option C: Dry farmland gets set as moist.
        if (block instanceof BlockFarmland) {
            if (state.getValue(BlockFarmland.MOISTURE) < 7) {
                this.getWorld().setBlockState(target, state.withProperty(BlockFarmland.MOISTURE, 7), 2);
            }
            // Explicitly expresses the intent to stop.
            break;
        }
        // Option D: If it's none of the above, it blocks the sprinkler's irrigation. Stop.
        break;
    }
}
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) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IGrowable (net.minecraft.block.IGrowable)9 IBlockState (net.minecraft.block.state.IBlockState)7 Block (net.minecraft.block.Block)5 BlockPos (net.minecraft.util.math.BlockPos)4 IPlantable (net.minecraftforge.common.IPlantable)4 BlockFarmland (net.minecraft.block.BlockFarmland)2 Affinity (am2.api.spell.enums.Affinity)1 AMParticle (am2.particles.AMParticle)1 ParticleFloatUpward (am2.particles.ParticleFloatUpward)1 BlockHutField (com.minecolonies.coremod.blocks.BlockHutField)1 BuildingFarmer (com.minecolonies.coremod.colony.buildings.BuildingFarmer)1 CABlock (convenientadditions.base.block.CABlock)1 BlockCrops (net.minecraft.block.BlockCrops)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemBlock (net.minecraft.item.ItemBlock)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 HoverEvent (net.minecraft.util.text.event.HoverEvent)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1