Check the type of block that was broken

20 views
Skip to first unread message

Alex Wegrzyn

unread,
Dec 3, 2022, 7:31:55 AM12/3/22
to ScriptCraft - Scripting Minecraft
Hi there!
I have some code that should be able to tell what type of block was broken when one is broken:

function blockbroken(event) {
const material = event.block.type
if (material  === "STONE") {
//do something
} else {
console.log(material)
console.log("not stone!")
}
}
events.blockBreak(blockbroken);

When I break stone, It logs "STONE" to the console just as written in the if statement, but it still says "not stone!". Does anyone know what I'm doing wrong?

Randy Friend

unread,
Dec 3, 2022, 10:11:59 AM12/3/22
to ScriptCraft - Scripting Minecraft

Where do you have your event?

Odds are it is firing when you don't think it should.  Remember Air is a block as well and thus your code could be firing after the block breaks and when your pick 'hits' air.
Reply all
Reply to author
Forward
0 new messages