Class PlayerInteractEvent.LeftClickBlock

All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
Enclosing class:
PlayerInteractEvent

public static class PlayerInteractEvent.LeftClickBlock extends PlayerInteractEvent implements net.neoforged.bus.api.ICancellableEvent
This event is fired when a player left clicks while targeting a block. This event controls which of BlockBehaviour.attack(BlockState, Level, BlockPos, Player) and/or the item harvesting methods will be called Canceling the event will cause none of the above noted methods to be called. There are various results to this event, see the getters below. This event is fired at various points during left clicking on blocks, at both the start and end on the server, and at the start and while held down on the client. Use getAction() to check which type of action triggered this event. Note that if the event is canceled and the player holds down left mouse, the event will continue to fire. This is due to how vanilla calls the left click handler methods. Also note that creative mode directly breaks the block without running any other logic. Therefore, in creative mode, setUseBlock(net.minecraft.util.TriState) and setUseItem(net.minecraft.util.TriState) have no effect.
  • Field Details

  • Constructor Details

    • LeftClickBlock

      @Internal public LeftClickBlock(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction face, PlayerInteractEvent.LeftClickBlock.Action action)
  • Method Details

    • getUseBlock

      public net.minecraft.util.TriState getUseBlock()
      Returns:
      If BlockBehaviour.attack(BlockState, Level, BlockPos, Player) should be called. Changing this has no effect in creative mode
    • getUseItem

      public net.minecraft.util.TriState getUseItem()
      Returns:
      If the block should be attempted to be mined with the current item. Changing this has no effect in creative mode
    • getAction

      Returns:
      The action type for this interaction. Will never be null.
    • setUseBlock

      public void setUseBlock(net.minecraft.util.TriState triggerBlock)
    • setUseItem

      public void setUseItem(net.minecraft.util.TriState triggerItem)
    • setCanceled

      public void setCanceled(boolean canceled)
      Specified by:
      setCanceled in interface net.neoforged.bus.api.ICancellableEvent