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
-
Constructor Summary
ConstructorDescriptionBonemealEvent
(@Nullable Player player, Level level, BlockPos pos, BlockState state, ItemStack stack) -
Method Summary
Modifier and TypeMethodDescriptiongetLevel()
Returns the level.@Nullable Player
Returns the player who used the bone meal, if any.getPos()
Returns the position of the bone mealed block.getStack()
Returns the bone meal item stack.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
-
level
-
pos
-
state
-
stack
-
isValidBonemealTarget
private final boolean isValidBonemealTarget -
isSuccess
private boolean isSuccess
-
-
Constructor Details
-
BonemealEvent
public BonemealEvent(@Nullable @Nullable Player player, Level level, BlockPos pos, BlockState state, ItemStack stack)
-
-
Method Details
-
getPlayer
Returns the player who used the bone meal, if any.- Returns:
- the player who used the bone meal, if any
-
getLevel
Returns the level.- Returns:
- the level
-
getPos
Returns the position of the bone mealed block.- Returns:
- the position of the bone mealed block
-
getState
Returns the state of the bone mealed block.- Returns:
- the state of the bone mealed block
-
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:
-