#Bedrock Add On Scripting Help
1 messages · Page 1 of 1 (latest)
Please read the documentation, chatgpt is worse than lecture
// 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)})
}
})