Class BonemealEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.player.BonemealEvent
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
public class BonemealEvent
extends net.neoforged.bus.api.Event
implements net.neoforged.bus.api.ICancellableEvent
This event is called when a player attempts to use bone meal on a block.
This event can be cancelled, preventing vanilla handling from occurring.
If you want to perform custom logic, cancel the event and perform your own handling.
Use setSuccessful(boolean)
to control if handling should believe bone meal was used.
This event is fired on both client and server.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final boolean
private final net.minecraft.world.level.Level
private final @Nullable net.minecraft.world.entity.player.Player
private final net.minecraft.core.BlockPos
private final net.minecraft.world.item.ItemStack
private final net.minecraft.world.level.block.state.BlockState
-
Constructor Summary
ConstructorsConstructorDescriptionBonemealEvent
(@Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.item.ItemStack stack) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.world.level.Level
getLevel()
Returns the level.@Nullable net.minecraft.world.entity.player.Player
Returns the player who used the bone meal, if any.net.minecraft.core.BlockPos
getPos()
Returns the position of the bone mealed block.net.minecraft.world.item.ItemStack
getStack()
Returns the bone meal item stack.net.minecraft.world.level.block.state.BlockState
getState()
Returns the state of the bone mealed block.boolean
Returns if the event is successful.boolean
Returns true if the block is a valid bone meal target.void
setCanceled
(boolean canceled) Cancels the event, preventing vanilla handling from being applied.void
setSuccessful
(boolean success) Cancels the event and changes the successful state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled
-
Field Details
-
player
@Nullable private final @Nullable net.minecraft.world.entity.player.Player player -
level
private final net.minecraft.world.level.Level level -
pos
private final net.minecraft.core.BlockPos pos -
state
private final net.minecraft.world.level.block.state.BlockState state -
stack
private final net.minecraft.world.item.ItemStack stack -
isValidBonemealTarget
private final boolean isValidBonemealTarget -
isSuccess
private boolean isSuccess
-
-
Constructor Details
-
BonemealEvent
public BonemealEvent(@Nullable @Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.item.ItemStack stack)
-
-
Method Details
-
getPlayer
@Nullable public @Nullable net.minecraft.world.entity.player.Player getPlayer()Returns the player who used the bone meal, if any.- Returns:
- the player who used the bone meal, if any
-
getLevel
public net.minecraft.world.level.Level getLevel()Returns the level.- Returns:
- the level
-
getPos
public net.minecraft.core.BlockPos getPos()Returns the position of the bone mealed block.- Returns:
- the position of the bone mealed block
-
getState
public net.minecraft.world.level.block.state.BlockState getState()Returns the state of the bone mealed block.- Returns:
- the state of the bone mealed block
-
getStack
public net.minecraft.world.item.ItemStack getStack()Returns the bone meal item stack.Changes to this stack will write-back to the consumer.
-
isValidBonemealTarget
public boolean isValidBonemealTarget()Returns true if the block is a valid bone meal target.This is determined by
BonemealableBlock.isValidBonemealTarget(net.minecraft.world.level.LevelReader, net.minecraft.core.BlockPos, net.minecraft.world.level.block.state.BlockState)
. -
setSuccessful
public void setSuccessful(boolean success) Cancels the event and changes the successful state.The state controls if handlers believe bone meal was successfully applied, and controls things like hand swings.
-
isSuccessful
public boolean isSuccessful()Returns if the event is successful. Only relevant if the eventICancellableEvent.isCanceled()
.- See Also:
-
setCanceled
public void setCanceled(boolean canceled) Cancels the event, preventing vanilla handling from being applied.- Specified by:
setCanceled
in interfacenet.neoforged.bus.api.ICancellableEvent
- See Also:
-