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

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

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

      @Nonnull public 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 Direction getFace()
      Returns:
      The face involved in this interaction. For all non-block interactions, this will return null.
    • getWorld

      public World getWorld()
      Returns:
      Convenience method to get the world 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 ActionResultType getCancellationResult()
      Returns:
      The EnumActionResult that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event. By default, this is EnumActionResult#PASS, meaning cancelled events will cause the client to keep trying more interactions until something works.
    • setCancellationResult

      public void setCancellationResult(ActionResultType result)
      Set the EnumActionResult 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.