#player block break before events

1 messages · Page 1 of 1 (latest)

frosty talon
#

Hello, when I try to use console.warn(block.typeId) in block break before, it returns "minecraft:air", is it possible to fix that?

frosty talon
#

yes

#

I'm in phone, so I'll try to write the script

smoky otter
#

please dont

frosty talon
#

🤕

smoky otter
#

can you just copy and paste

frosty talon
#

I can't open the account now on the laptop

smoky otter
#

well I need to see the code atleast, but I dont want you rewriting because it might not be accurate

frosty talon
#

wait me pls, I'm going to have to open discord bao_doggo_happy

#
world.beforeEvents.playerBreakBlock.subscribe(({ player, block, itemStack: item }) => {
    system.run(() => {
            console.warn(block.typeId)
    })
})
#

It's here @smoky otter

smoky otter
#

the system.run is doing that

#

because it probably cant callback to block

frosty talon
#

But is it necessary for other things it does, or how can it be fixed by removing it?

frosty talon
smoky otter
#

well you can use afterevents

#

but instead of block.typeId you use .brokenBlockPermutation.type.Id

frosty talon
#

This is my complete code, I did not send it to avoid confusion but I think it can help you understand

smoky otter
#

you can probably do that with brokenBlockPermutation

#

nvm

frosty talon
#
world.beforeEvents.playerBreakBlock.subscribe( ({ player, block, itemStack: item }) => {
    system.run(() => {
        const silk = item?.getComponent("enchantments").enchantments.getEnchantment("silk_touch")?.level ?? undefined
            console.warn(block.typeId)
        if (silk) {
             const xp = mc.BlockPermutation.resolve(`${block.typeId}`, {
                 "test:xp": "no",
             }):
             block.setPermutation(xp);
        }
    })
})
frosty talon
smoky otter
#

I said nvm.

frosty talon
smoky otter
#

this is weird

#

Ive tried to fix it but its still doing that

#

if thats only the issue of getting the typeId, you dont need system.run

frosty talon
#

I put it in to get the enchantments, it wouldn't let me because it said I didn't have the privileges

smoky otter
#

the console warn of the block.typeid, doesnt need system.run

#

you can put it above it

frosty talon
#

ah, yes

smoky otter
#

oh wait, you are still trying to get the block id

frosty talon
#

yes

smoky otter
#

im sorry dude

#

I dont know what to do here

frosty talon
#

no problema

smoky otter
#

this doesnt mean others dont though, im not a master at script api clearly

frosty talon
#

thanks anyways

smoky otter
#

you can wait for someone else

#

np