import { system, world } from "@minecraft/server";
world.afterEvents.itemUse.subscribe((data) => {
const item = data.itemStack;
const player = data.source;
if (item.typeId === "minecraft:tnt") {
system.run(() => {
player.runCommand("clear @s tnt 0 1")
player.runCommand("playsound random.fuse @s ~~~ 1")
let location = { x: player.location.x + player.getViewDirection().x * 0.5, y: player.location.y + 1.5 + player.getViewDirection().y * 0.5, z: player.location.z + player.getViewDirection().z * 0.5 }
let tnt = player.dimension.spawnEntity("minecraft:tnt", location)
tnt.applyImpulse(player.getViewDirection())
})
}
})
world.afterEvents.playerPlaceBlock.subscribe(data => {
if (data.block.typeId == "minecraft:tnt") {
data.player.runCommandAsync(`setblock ${data.block.x} ${data.block.y} ${data.block.z} air`)
data.player.runCommandAsync(`summon tnt ${data.block.x} ${data.block.y} ${data.block.z}`)
}
})
i want make it like hive boom box .'