Class PlayerInteractEvent

Direct Known Subclasses:
PlayerInteractEvent.EntityInteract, PlayerInteractEvent.EntityInteractSpecific, PlayerInteractEvent.LeftClickBlock, PlayerInteractEvent.LeftClickEmpty, PlayerInteractEvent.RightClickBlock, PlayerInteractEvent.RightClickEmpty, PlayerInteractEvent.RightClickItem

public class PlayerInteractEvent extends PlayerEvent
PlayerInteractEvent is fired when a player interacts in some way. All subclasses are fired on MinecraftForge.EVENT_BUS. See the individual documentation on each subevent for more details.
  • Field Details

  • Constructor Details

  • Method Details

    • getHand

      @NotNull public @NotNull InteractionHand getHand()
      Returns:
      The hand involved in this interaction. Will never be null.
    • getItemStack

      @NotNull public @NotNull ItemStack getItemStack()
      Returns:
      The itemstack involved in this interaction, ItemStack.EMPTY if the hand was empty.
    • getPos

      @NotNull public @NotNull BlockPos getPos()
      If the interaction was on an entity, will be a BlockPos centered on the entity. If the interaction was on a block, will be the position of that block. Otherwise, will be a BlockPos centered on the player. Will never be null.
      Returns:
      The position involved in this interaction.
    • getFace

      @Nullable public @Nullable Direction getFace()
      Returns:
      The face involved in this interaction. For all non-block interactions, this will return null.
    • getLevel

      public Level getLevel()
      Returns:
      Convenience method to get the level of this interaction.
    • getSide

      public LogicalSide getSide()
      Returns:
      The effective, i.e. logical, side of this interaction. This will be LogicalSide.CLIENT on the client thread, and LogicalSide.SERVER on the server thread.
    • getCancellationResult

      public InteractionResult getCancellationResult()
      Returns:
      The InteractionResult that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event. By default, this is InteractionResult.PASS, meaning cancelled events will cause the client to keep trying more interactions until something works.
    • setCancellationResult

      public void setCancellationResult(InteractionResult result)
      Set the InteractionResult that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event. Note that this only has an effect on PlayerInteractEvent.RightClickBlock, PlayerInteractEvent.RightClickItem, PlayerInteractEvent.EntityInteract, and PlayerInteractEvent.EntityInteractSpecific.