Search in sources :

Example 1 with BonemealEvent

use of net.minecraftforge.event.entity.player.BonemealEvent in project MineFactoryReloaded by powercrystals.

the class FertilizableForestryPods method fertilize.

@Override
public boolean fertilize(World world, Random rand, int x, int y, int z, FertilizerType fertilizerType) {
    if (world.getBlockId(x, y, z) == this.getFertilizableBlockId()) {
        BonemealEvent event = new BonemealEvent(null, world, 1, x, y, z);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.getResult().equals(BonemealEvent.Result.ALLOW)) {
            return true;
        }
    }
    return false;
}
Also used : BonemealEvent(net.minecraftforge.event.entity.player.BonemealEvent)

Example 2 with BonemealEvent

use of net.minecraftforge.event.entity.player.BonemealEvent in project MineFactoryReloaded by powercrystals.

the class FertilizableForestryLeaves method fertilize.

@Override
public boolean fertilize(World world, Random rand, int x, int y, int z, FertilizerType fertilizerType) {
    if (world.getBlockId(x, y, z) == this.getFertilizableBlockId()) {
        IFruitBearer f = ForestryUtils.getFruitBearer(world.getBlockTileEntity(x, y, z));
        if (f.hasFruit() && f.getRipeness() < 1.0f) {
            BonemealEvent event = new BonemealEvent(null, world, 1, x, y, z);
            MinecraftForge.EVENT_BUS.post(event);
            if (event.getResult().equals(BonemealEvent.Result.ALLOW)) {
                return true;
            }
        }
    }
    return false;
}
Also used : BonemealEvent(net.minecraftforge.event.entity.player.BonemealEvent) IFruitBearer(forestry.api.genetics.IFruitBearer)

Example 3 with BonemealEvent

use of net.minecraftforge.event.entity.player.BonemealEvent in project BloodMagic by WayofTime.

the class ItemSigilGreenGrove method applyBonemeal.

private boolean applyBonemeal(World worldIn, BlockPos target, EntityPlayer player, ItemStack sigilStack) {
    IBlockState iblockstate = worldIn.getBlockState(target);
    BonemealEvent event = new BonemealEvent(player, worldIn, target, iblockstate, EnumHand.MAIN_HAND, sigilStack);
    if (MinecraftForge.EVENT_BUS.post(event))
        return false;
    else if (event.getResult() == Result.ALLOW)
        return true;
    if (iblockstate.getBlock() instanceof IGrowable) {
        IGrowable igrowable = (IGrowable) iblockstate.getBlock();
        if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.isRemote)) {
            if (!worldIn.isRemote) {
                if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate))
                    igrowable.grow(worldIn, worldIn.rand, target, iblockstate);
            }
            return true;
        }
    }
    return false;
}
Also used : BonemealEvent(net.minecraftforge.event.entity.player.BonemealEvent) IBlockState(net.minecraft.block.state.IBlockState) IGrowable(net.minecraft.block.IGrowable)

Example 4 with BonemealEvent

use of net.minecraftforge.event.entity.player.BonemealEvent in project ArsMagica2 by Mithion.

the class Grow 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);
    BonemealEvent event = new BonemealEvent(DummyEntityPlayer.fromEntityLiving(caster), world, block, blockx, blocky, blockz);
    if (MinecraftForge.EVENT_BUS.post(event)) {
        return false;
    }
    if (event.getResult() == Result.ALLOW) {
        return true;
    }
    // EoD: Spawn AM2 flowers with 3% chance. This has to be the first one in the list to override all others
    if (world.rand.nextInt(100) < 3 && block.isNormalCube() && (world.getBlock(blockx, blocky + 1, blockz).isAir(null, 0, 0, 0) || world.getBlock(blockx, blocky + 1, blockz) == Blocks.tallgrass)) {
        // shuffle the flower list every time we want to try to find one.
        Collections.shuffle(growableAMflowers);
        for (AMFlower flower : growableAMflowers) {
            if (flower.canGrowOn(world, blockx, blocky + 1, blockz)) {
                if (!world.isRemote) {
                    world.setBlock(blockx, blocky + 1, blockz, flower, 0, 2);
                }
                return true;
            }
        }
    // We did not find a flower or we have been executed on the wrong block. Either way, we continue
    }
    // Grow huge mushrooms 10% of the time.
    if (block instanceof BlockMushroom) {
        if (!world.isRemote && world.rand.nextInt(10) < 1) {
            ((BlockMushroom) block).func_149884_c(world, blockx, blocky, blockz, world.rand);
        }
        return true;
    }
    // If the spell is executed in water, check if we have space for a wakebloom above and create one 3% of the time.
    if (block == Blocks.water) {
        if (world.getBlock(blockx, blocky + 1, blockz) == Blocks.air) {
            if (!world.isRemote && world.rand.nextInt(100) < 3) {
                world.setBlock(blockx, blocky + 1, blockz, BlocksCommonProxy.wakebloom);
            }
            return true;
        }
    }
    // EoD: If there is already tallgrass present, let's grow it further 20% of the time.
    if (block == Blocks.tallgrass) {
        if (Blocks.tallgrass.canBlockStay(world, blockx, blocky + 1, blockz)) {
            if (!world.isRemote && world.rand.nextInt(10) < 2) {
                world.setBlock(blockx, blocky, blockz, Blocks.tallgrass, 1, 2);
            }
            return true;
        }
    }
    // This works only on podzol in vanilla MC.
    if (block == Blocks.deadbush) {
        if (Blocks.tallgrass.canBlockStay(world, blockx, blocky, blockz)) {
            if (!world.isRemote && world.rand.nextInt(10) < 2) {
                world.setBlock(blockx, blocky, blockz, Blocks.tallgrass, 1, 2);
            }
            return true;
        }
    }
    // See ItemDye.applyBonemeal().
    if (block instanceof IGrowable) {
        IGrowable igrowable = (IGrowable) block;
        if (igrowable.func_149851_a(world, blockx, blocky, blockz, world.isRemote)) {
            if (!world.isRemote && world.rand.nextInt(10) < 3) {
                if (igrowable.func_149852_a(world, world.rand, blockx, blocky, blockz)) {
                    igrowable.func_149853_b(world, world.rand, blockx, blocky, blockz);
                }
            }
            return true;
        }
    }
    return true;
}
Also used : BonemealEvent(net.minecraftforge.event.entity.player.BonemealEvent) AMFlower(am2.blocks.AMFlower)

Aggregations

BonemealEvent (net.minecraftforge.event.entity.player.BonemealEvent)4 AMFlower (am2.blocks.AMFlower)1 IFruitBearer (forestry.api.genetics.IFruitBearer)1 IGrowable (net.minecraft.block.IGrowable)1 IBlockState (net.minecraft.block.state.IBlockState)1