Add EnumHand and ItemStack to BonemealEvent (#3736)

This commit is contained in:
Choonster TheMage authored and LexManos committed 2017-04-07 16:31:51 -07:00
1 parent fd0dabd60c
commit 5ffbbd3b9f
4 files changed
+107 -6

No files matched your search

@@ -361,9 +361,18 @@ public class ForgeEventFactory
return 0;
}
/**
* @deprecated Use {@link #onApplyBonemeal(EntityPlayer, World, BlockPos, IBlockState, ItemStack, EnumHand)} instead.
*/
@Deprecated
public static int onApplyBonemeal(EntityPlayer player, World world, BlockPos pos, IBlockState state, ItemStack stack)
{
BonemealEvent event = new BonemealEvent(player, world, pos, state);
return onApplyBonemeal(player, world, pos, state, stack, null);
}
public static int onApplyBonemeal(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull ItemStack stack, @Nullable EnumHand hand)
{
BonemealEvent event = new BonemealEvent(player, world, pos, state, hand, stack);
if (MinecraftForge.EVENT_BUS.post(event)) return -1;
if (event.getResult() == Result.ALLOW)
{
@@ -23,9 +23,14 @@ import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* This event is called when a player attempts to use Bonemeal on a block.
* It can be canceled to completely prevent any further processing.
@@ -43,13 +48,27 @@ public class BonemealEvent extends PlayerEvent
private final World world;
private final BlockPos pos;
private final IBlockState block;
private final EnumHand hand;
private final ItemStack stack;
/**
* @deprecated Use {@link #BonemealEvent(EntityPlayer, World, BlockPos, IBlockState, EnumHand, ItemStack)} instead.
*/
@Deprecated
public BonemealEvent(EntityPlayer player, World world, BlockPos pos, IBlockState block)
{
this(player, world, pos, block, null, ItemStack.EMPTY);
}
public BonemealEvent(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState block, @Nullable EnumHand hand,
@Nonnull ItemStack stack)
{
super(player);
this.world = world;
this.pos = pos;
this.block = block;
this.hand = hand;
this.stack = stack;
}
public World getWorld()
@@ -66,4 +85,16 @@ public class BonemealEvent extends PlayerEvent
{
return block;
}
@Nullable
public EnumHand getHand()
{
return hand;
}
@Nonnull
public ItemStack getStack()
{
return stack;
}
}