I'm trying to get my Weee! Flowers to spawn on grass using bonemeal. The code below achieves this but it also seems to replace vanilla bonemeal code as grass, flowers, and biome specific blocks no longer spawn with bonemeal, just my flowers.
Anyone know how to fix this?
package com.pam.weeeflowers;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.BonemealEvent;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class PamFlowerBonemealEvent
{
@SubscribeEvent
public void onUseBonemeal(BonemealEvent event)
{
World world = event.world;
int x = event.x;
int y = event.y;
int z = event.z;
Block block = event.block;
@SuppressWarnings("unused")
int meta = event.world.getBlockMetadata(x, y, z);
Random rand = new Random();
int i = rand.nextInt(13);
if (block == Blocks.grass && event.world.getBlockMetadata(x, y, z) == 0)
{
int var14 = y + 1;
for (int i1 = 0; i1 < 128; ++i1)
{
for (int i2 = 0; i2 < i1 / 16; ++i2)
{
x += event.world.rand.nextInt(3) - 1;
var14 += (event.world.rand.nextInt(3) - 1) * event.world.rand.nextInt(3) / 2;
z += event.world.rand.nextInt(3) - 1;
}
if (event.world.getBlock(x, var14, z).isAir(world, x, var14, z))
{
if (weeeflowers.pamFlower.canReplace(world, x, var14, z, 0, new ItemStack(weeeflowers.pamFlower, 1, i)))
{
event.setResult(Result.ALLOW);
if (!event.world.isRemote)
{
event.world.setBlock(x, var14, z, weeeflowers.pamFlower, i, 2);
}
}
}
}
}
}
}
/**
* This event is called when a player attempts to use Bonemeal on a block.
* It can be canceled to completely prevent any further processing.
*
* You can also set the result to ALLOW to mark the event as processed
* and use up a bonemeal from the stack but do no further processing.
*
* setResult(ALLOW) is the same as the old setHandeled()
*/
So any time you click on grass with bonemeal, you are telling the event to ALLOW, meaning that the event was handled and shouldn't spawn any other blocks, but should still use a bonemeal.
/**
* This event is called when a player attempts to use Bonemeal on a block.
* It can be canceled to completely prevent any further processing.
*
* You can also set the result to ALLOW to mark the event as processed
* and use up a bonemeal from the stack but do no further processing.
*
* setResult(ALLOW) is the same as the old setHandeled()
*/
So any time you click on grass with bonemeal, you are telling the event to ALLOW, meaning that the event was handled and shouldn't spawn any other blocks, but should still use a bonemeal.
Anyone know how to fix this?
So any time you click on grass with bonemeal, you are telling the event to ALLOW, meaning that the event was handled and shouldn't spawn any other blocks, but should still use a bonemeal.
Awesome! Thanks so much for helping me out!