Class PlayerInteractEvent.EntityInteract

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

public static class PlayerInteractEvent.EntityInteract extends PlayerInteractEvent implements net.neoforged.bus.api.ICancellableEvent

This event is fired on both sides when a non-spectator player right-clicks an entity. It is responsible for all entity interactions.

This event's state affects whether Entity.interact(Player, InteractionHand, Vec3) and Item.interactLivingEntity(ItemStack, Player, LivingEntity, InteractionHand) are called.

Let result be InteractionResult.SUCCESS if Entity.interact(Player, InteractionHand, Vec3) or Item.interactLivingEntity(ItemStack, Player, LivingEntity, InteractionHand) return true, or cancellationResult if the event is cancelled. If we are on the client and result is not InteractionResult.SUCCESS, the client will then try PlayerInteractEvent.RightClickItem.

  • Field Details

    • cancellationResult

      private InteractionResult cancellationResult
    • target

      private final Entity target
    • location

      private final Vec3 location
  • Constructor Details

  • Method Details

    • getTarget

      public Entity getTarget()
    • getLocation

      public Vec3 getLocation()
      Returns the local interaction position. This is a 3D vector, where (0, 0, 0) is centered exactly at the center of the entity's bounding box at their feet. This means the X and Z values will be in the range [-width / 2, width / 2] while Y values will be in the range [0, height].
      Returns:
      the local interaction position
    • 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.