Skip to content

PlayerInteractEvent


This fires each time you interact with a block in the world.

Cancellable = false

Parameter

PlayerInteractEvent

Properties

Action

  • LEFT_CLICK_BLOCK

  • RIGHT_CLICK_BLOCK

Methods

Action

Action getAction()

Returns current action as shown above.

Player

EntityPlayerSP getPlayer()

Returns EntityPlayerSP.

World

WorldClient getWorld()

Returns WorldClient.

Block position

BlockPos getPos()

Returns BlockPos.

Facing

EnumFacing getFacing()

Returns EnumFacing.

Example

/*
Sends a message when you right-click a chest.
*/
@EventTarget
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) return;

    final BlockPos blockPos = event.getPos();
    final TileEntity tileEntity = mc.theWorld.getTileEntity(blockPos);

    if (tileEntity instanceof TileEntityChest) {
        Meowtils.addMessage("Right clicked chest!");
    }
}