Search in sources :

Example 1 with IPlantable

use of net.minecraftforge.common.IPlantable 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 2 with IPlantable

use of net.minecraftforge.common.IPlantable 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 3 with IPlantable

use of net.minecraftforge.common.IPlantable in project ConvenientAdditions by Necr0.

the class BlockCompostSoil 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(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(DEGRADATION, deg + 1));
            else
                world.setBlockState(pos, Blocks.DIRT.getDefaultState());
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IPlantable(net.minecraftforge.common.IPlantable) CABlock(convenientadditions.base.block.CABlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with IPlantable

use of net.minecraftforge.common.IPlantable in project ConvenientAdditions by Necr0.

the class ItemCompost method tryCompostApply.

public boolean tryCompostApply(ItemStack compost, World world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    Block b = state.getBlock();
    //change to support applying compost on the plant instead of the soil
    if (b != null && (b instanceof IPlantable)) {
        pos = pos.down();
        state = world.getBlockState(pos);
        b = state.getBlock();
    }
    if (!(b == Blocks.DIRT || b == Blocks.FARMLAND || b == Blocks.GRASS || ((b == ModBlocks.compostSoilBlock || b == ModBlocks.compostSoilTilledBlock) && b.getMetaFromState(state) != 0)))
        return false;
    if (!world.isRemote) {
        if (b == Blocks.DIRT)
            world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState());
        else if (b == Blocks.FARMLAND)
            world.setBlockState(pos, ModBlocks.compostSoilTilledBlock.getDefaultState());
        else if (b == Blocks.GRASS) {
            if (compost.getItemDamage() == 1 && world.rand.nextFloat() < ModConfigMisc.composter_sporesMyceliumChance)
                world.setBlockState(pos, Blocks.MYCELIUM.getDefaultState());
            else
                world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState(), 3);
        } else if (b == ModBlocks.compostSoilBlock || b == ModBlocks.compostSoilTilledBlock) {
            world.setBlockState(pos, b.getDefaultState(), 3 + 4);
        }
        compost.shrink(1);
    }
    world.playSound(null, pos, Blocks.GRASS.getSoundType().getHitSound(), SoundCategory.BLOCKS, Blocks.GRASS.getSoundType().getVolume(), Blocks.GRASS.getSoundType().getPitch());
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block)

Example 5 with IPlantable

use of net.minecraftforge.common.IPlantable in project Railcraft by Railcraft.

the class EntityCartTrackLayer method isValidReplacementBlock.

private boolean isValidReplacementBlock(BlockPos pos) {
    IBlockState state = WorldPlugin.getBlockState(worldObj, pos);
    Block block = state.getBlock();
    return (WorldPlugin.isBlockAir(worldObj, pos, state) || block instanceof IPlantable || block instanceof IShearable || EntityTunnelBore.replaceableBlocks.contains(block)) || block.isReplaceable(worldObj, pos);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IPlantable(net.minecraftforge.common.IPlantable) IShearable(net.minecraftforge.common.IShearable) Block(net.minecraft.block.Block)

Aggregations

IPlantable (net.minecraftforge.common.IPlantable)15 Block (net.minecraft.block.Block)11 IBlockState (net.minecraft.block.state.IBlockState)7 ItemStack (net.minecraft.item.ItemStack)6 BlockPos (net.minecraft.util.math.BlockPos)4 IGrowable (net.minecraft.block.IGrowable)3 Item (net.minecraft.item.Item)3 CABlock (convenientadditions.base.block.CABlock)2 BlockLeaves (net.minecraft.block.BlockLeaves)2 IInventory (net.minecraft.inventory.IInventory)2 ItemBlock (net.minecraft.item.ItemBlock)2 World (net.minecraft.world.World)2 IShearable (net.minecraftforge.common.IShearable)2 Affinity (am2.api.spell.enums.Affinity)1 AMParticle (am2.particles.AMParticle)1 ParticleFloatUpward (am2.particles.ParticleFloatUpward)1 InventoryItem (com.bluepowermod.container.inventory.InventoryItem)1 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)1 HashMap (java.util.HashMap)1 Filter (mcjty.rftoolsdim.config.Filter)1