#Bedrock Add On Scripting Help

1 messages · Page 1 of 1 (latest)

ornate flame
#

Hello, I am trying to create my own add on, and I want to have my own custom item that you can right click with and it will run the function command I assign it to, but I don't know how to do that. This is my current code.

wintry harness
#
// Import the world object from Minecraft API
// This event listens for when a player uses an item
import {world,system} from "@minecraft/server"
world.beforeEvents.itemUse.subscribe((eventData)=>{
const player = eventData.source; // Get the player who is using the item 
const itemInHand = eventData.itemStack; // Get the item that the player in using 
const playerPosition = player.location// Get the player's current position let playerPosition player.location:
if (itemInHand.typeId == "minecraft:diamond_sword") { // Check if the player is using minecraft:diamond_sword
    // Spawn lightning at the player's position
    system.run(()=>{world.getDimension("overworld").spawnEntity("minecraft:lightning_bolt", playerPosition)})
    }
})
steel forge