Search in sources :

Example 1 with IGrowable

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

the class EventHandler method onBoneMealUse.

@SubscribeEvent
public static void onBoneMealUse(BonemealEvent event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = event.getBlock();
    EntityPlayer player = event.getEntityPlayer();
    if (player.getHeldItem(EnumHand.MAIN_HAND).getItem() == NetherExItems.ITEM_DUST_WITHER) {
        if (state.getBlock() == Blocks.NETHER_WART) {
            int age = state.getValue(BlockNetherWart.AGE);
            if (age < 3) {
                state = state.withProperty(BlockNetherWart.AGE, age + 1);
                world.setBlockState(pos, state);
                event.setResult(Event.Result.ALLOW);
            }
        } else if (state.getBlock() instanceof IGrowable) {
            IGrowable growable = (IGrowable) state.getBlock();
            if (growable.canGrow(world, pos, state, world.isRemote)) {
                growable.grow(world, world.rand, pos, state);
            }
        } else {
            event.setCanceled(true);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IGrowable(net.minecraft.block.IGrowable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IGrowable

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

the class FlickerOperatorNaturesBounty method DoOperation.

@Override
public boolean DoOperation(World worldObj, IFlickerController habitat, boolean powered, Affinity[] flickers) {
    int radius = 6;
    int diameter = radius * 2 + 1;
    boolean updatedOnce = false;
    if (!worldObj.isRemote) {
        for (int i = 0; i < (powered ? 5 : 1); ++i) {
            int effectX = ((TileEntity) habitat).xCoord - radius + (worldObj.rand.nextInt(diameter));
            int effectZ = ((TileEntity) habitat).zCoord - radius + (worldObj.rand.nextInt(diameter));
            int effectY = ((TileEntity) habitat).yCoord;
            while (worldObj.isAirBlock(effectX, effectY, effectZ) && effectY > 0) {
                effectY--;
            }
            while (!worldObj.isAirBlock(effectX, effectY, effectZ) && effectY > 0) {
                effectY++;
            }
            effectY--;
            Block block = worldObj.getBlock(effectX, effectY, effectZ);
            if (block instanceof IPlantable || block instanceof IGrowable) {
                block.updateTick(worldObj, effectX, effectY, effectZ, worldObj.rand);
                updatedOnce = true;
            }
        }
    } else {
        int posY = ((TileEntity) habitat).yCoord;
        while (!worldObj.isAirBlock(((TileEntity) habitat).xCoord, posY, ((TileEntity) habitat).zCoord)) {
            posY++;
        }
        posY--;
        for (int i = 0; i < AMCore.config.getGFXLevel() * 2; ++i) {
            AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "plant", ((TileEntity) habitat).xCoord + 0.5, posY + 0.5f, ((TileEntity) habitat).zCoord + 0.5);
            if (particle != null) {
                particle.addRandomOffset(diameter, 0, diameter);
                particle.AddParticleController(new ParticleFloatUpward(particle, 0.01f, 0.04f, 1, false));
                particle.setMaxAge(16);
                particle.setParticleScale(0.08f);
            }
        }
    }
    if (powered) {
        for (Affinity aff : flickers) {
            if (aff == Affinity.WATER)
                FlickerOperatorRegistry.instance.getOperatorForMask(Affinity.WATER.getAffinityMask()).DoOperation(worldObj, habitat, powered);
        }
    }
    return updatedOnce;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMParticle(am2.particles.AMParticle) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) Affinity(am2.api.spell.enums.Affinity) ParticleFloatUpward(am2.particles.ParticleFloatUpward)

Example 3 with IGrowable

use of net.minecraft.block.IGrowable in project ConvenientAdditions by Necr0.

the class BlockCompostSoilTilled method updateTick.

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random r) {
    if (!world.isRemote) {
        BlockPos posU = new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ());
        IBlockState s = world.getBlockState(posU);
        Block b = s.getBlock();
        int deg = state.getValue(BlockCompostSoil.DEGRADATION);
        boolean flag = false;
        if (b != null && (b instanceof IPlantable || b instanceof IGrowable)) {
            if (b instanceof IGrowable)
                flag = ((IGrowable) b).canGrow(world, posU, s, false);
            //trigger growth tick
            b.updateTick(world, posU, world.getBlockState(posU), r);
            //degradation: 0-10
            int i = deg;
            if (//if random number(0-23) is bigger than degradation
            r.nextInt(24) > i)
                b.updateTick(world, posU, world.getBlockState(posU), r);
            i++;
            if (r.nextInt(24) > i)
                b.updateTick(world, posU, world.getBlockState(posU), r);
            i++;
            if (r.nextInt(24) > i)
                b.updateTick(world, posU, world.getBlockState(posU), r);
            i++;
            if (r.nextInt(24) > i)
                b.updateTick(world, posU, world.getBlockState(posU), r);
        }
        if (r.nextInt(5 + (flag ? 3 : 0)) == 0) {
            if (deg < 10)
                world.setBlockState(pos, state.withProperty(BlockCompostSoil.DEGRADATION, deg + 1));
            else
                world.setBlockState(pos, Blocks.FARMLAND.getDefaultState().withProperty(BlockFarmland.MOISTURE, 7));
        }
        if (s.getMaterial().isSolid())
            world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState().withProperty(BlockCompostSoil.DEGRADATION, deg), 2);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) CABlock(convenientadditions.base.block.CABlock) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with IGrowable

use of net.minecraft.block.IGrowable 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)

Example 5 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)

Aggregations

IGrowable (net.minecraft.block.IGrowable)7 IBlockState (net.minecraft.block.state.IBlockState)5 Block (net.minecraft.block.Block)4 BlockPos (net.minecraft.util.math.BlockPos)3 IPlantable (net.minecraftforge.common.IPlantable)3 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 BlockFarmland (net.minecraft.block.BlockFarmland)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemBlock (net.minecraft.item.ItemBlock)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 Nullable (org.jetbrains.annotations.Nullable)1