on Item Used
Runs code when you interact with, or use, an item in the game.
player.onItemInteracted(IRON_SHOVEL, function () {
})
When using the keyboard and mouse, an item is used if you right-click with the mouse while having the item equipped. For touch, an item is used when you press on the screen and hold.
Parameters
- item: the type of item used that will cause the code to run, such as:
TRIDENT
- handler: the code to run when the item is used by the current player
Example
The following code makes lightning strike near the player when they use a Diamond Sword. Unlimited power!
player.onItemInteracted(DIAMOND_SWORD, function () {
mobs.spawn(LIGHTNING_BOLT, pos(10, 0, 0))
})