Class BlockEvent.BlockToolModificationEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.BlockEvent
net.neoforged.neoforge.event.level.BlockEvent.BlockToolModificationEvent
All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
Enclosing class:
BlockEvent

public static class BlockEvent.BlockToolModificationEvent extends BlockEvent implements net.neoforged.bus.api.ICancellableEvent
Fired when a block is right-clicked by a tool to change its state. For example: Used to determine if an axe can strip, a shovel can path, or a hoe can till.

Care must be taken to ensure level-modifying events are only performed if isSimulated() returns false.

This event is ICancellableEvent. If canceled, this will prevent the tool from changing the block's state.

  • Field Details

    • context

      private final UseOnContext context
    • toolAction

      private final ToolAction toolAction
    • simulate

      private final boolean simulate
    • state

      private BlockState state
  • Constructor Details

  • Method Details

    • getPlayer

      @Nullable public @Nullable Player getPlayer()
      Returns:
      the player using the tool. May be null based on what was provided by the use on context.
    • getHeldItemStack

      public ItemStack getHeldItemStack()
      Returns:
      the tool being used
    • getToolAction

      public ToolAction getToolAction()
      Returns:
      the action being performed
    • isSimulated

      public boolean isSimulated()
      Returns true if this event should not perform any actions that modify the level. If false, then level-modifying actions can be performed.
      Returns:
      true if this event should not perform any actions that modify the level. If false, then level-modifying actions can be performed.
    • getContext

      public UseOnContext getContext()
      Returns the nonnull use on context that this event was performed in.
      Returns:
      the nonnull use on context that this event was performed in
    • setFinalState

      public void setFinalState(@Nullable @Nullable BlockState finalState)
      Sets the state to transform the block into after tool use.
      Parameters:
      finalState - the state to transform the block into after tool use
      See Also:
    • getFinalState

      public BlockState getFinalState()
      Returns the state to transform the block into after tool use. If setFinalState(BlockState) is not called, this will return the original state. If ICancellableEvent.isCanceled() is true, this value will be ignored and the tool action will be canceled.
      Returns:
      the state to transform the block into after tool use