PlayerInteractEvent

Link to playerinteractevent

This event is the superclass of all other PlayerInteract events. Generally, you want to use the subtypes of this event.

The event is not cancelable.

The event does not have a result.

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

ZenScript
Copy
import crafttweaker.api.event.entity.player.interact.PlayerInteractEvent;

Extending PlayerEvent

Link to extending-playerevent

PlayerInteractEvent extends PlayerEvent. That means all methods available in PlayerEvent are also available in PlayerInteractEvent

Name: getBlockPos

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.

Return Type: BlockPos

ZenScript
Copy
// PlayerInteractEvent.getBlockPos() as BlockPos

myPlayerInteractEvent.getBlockPos();

Link to getCancellationResult

Name: 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 PASS, meaning cancelled events will cause the client to keep trying more interactions until something works.
Return Type: InteractionResult

ZenScript
Copy
// PlayerInteractEvent.getCancellationResult() as InteractionResult

myPlayerInteractEvent.getCancellationResult();

Name: getFace

The face involved in this interaction. For all non-block interactions, this will return null

Return Type: Direction

ZenScript
Copy
// PlayerInteractEvent.getFace() as Direction

myPlayerInteractEvent.getFace();

Name: getHand

Return Type: InteractionHand

ZenScript
Copy
// PlayerInteractEvent.getHand() as InteractionHand

myPlayerInteractEvent.getHand();

Name: getItemStack

The stack involved in this interaction. May be empty, but will never be null.

Return Type: IItemStack

ZenScript
Copy
// PlayerInteractEvent.getItemStack() as IItemStack

myPlayerInteractEvent.getItemStack();

Link to setCancellationResult

Name: setCancellationResult

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 RightClickBlockEvent, RightClickItemEvent, EntityInteractEvent.

Return Type: void

ZenScript
Copy
PlayerInteractEvent.setCancellationResult(result as InteractionResult) as void
参数类型描述
参数
result
类型
InteractionResult
描述
No Description Provided
名称类型可获得可设置描述
名称
blockPos
类型
BlockPos
可获得
true
可设置
false
描述
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.
名称
cancellationResult
类型
InteractionResult
可获得
true
可设置
true
描述
名称
face
类型
Direction
可获得
true
可设置
false
描述
The face involved in this interaction.
For all non-block interactions, this will return null
名称
hand
类型
InteractionHand
可获得
true
可设置
false
描述
No Description Provided
名称
物品应用
类型
IItemStack
可获得
true
可设置
false
描述
The stack involved in this interaction.
May be empty, but will never be null.