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 Details

    • player

      @Nullable private final @Nullable Player player
    • level

      private final Level level
    • pos

      private final BlockPos pos
    • state

      private final BlockState state
    • stack

      private final ItemStack stack
    • isValidBonemealTarget

      private final boolean isValidBonemealTarget
    • isSuccess

      private boolean isSuccess
  • Constructor Details

  • Method Details

    • getPlayer

      @Nullable public @Nullable Player getPlayer()
      Returns the player who used the bone meal, if any.
      Returns:
      the player who used the bone meal, if any
    • getLevel

      public Level getLevel()
      Returns the level.
      Returns:
      the level
    • getPos

      public BlockPos getPos()
      Returns the position of the bone mealed block.
      Returns:
      the position of the bone mealed block
    • getState

      public BlockState getState()
      Returns the state of the bone mealed block.
      Returns:
      the state of the bone mealed block
    • getStack

      public ItemStack getStack()
      Returns the bone meal item stack.

      Changes to this stack will write-back to the consumer.

    • isValidBonemealTarget

      public boolean isValidBonemealTarget()
    • 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 event ICancellableEvent.isCanceled().
      See Also:
    • setCanceled

      public void setCanceled(boolean canceled)
      Cancels the event, preventing vanilla handling from being applied.
      Specified by:
      setCanceled in interface net.neoforged.bus.api.ICancellableEvent
      See Also: