#Replace block with another one after breaking it with a specific tool

13 messages · Page 1 of 1 (latest)

buoyant magnet
#

I'm trying to make a script where, when you break a grass block with a hoe, it sets the grass block to a coarse dirt, and if you do it again, it'll become a farmland.

it seems like most of the code is running fine, besides the block.set event which is the most important!!

BlockEvents.broken('grass_block', e => {
    const hoe = ['iron_hoe', 'diamond_hoe', 'netherite_hoe'];

    const { player, block, item, hand } = e;
    const { x, y, z } = block;
    if (hand != 'OFF_HAND' || item == hoe) {
        player.server.runCommandSilent(`playsound minecraft:block.rooted_dirt.step player @p ${x} ${y} ${z}`);
        block.set("coarse_dirt");
        player.potionEffects.add("mining_fatigue", 3, 0, false, false)
        player.addExhaustion(2)
    } else return;

})```
wild novaBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

buoyant magnet
#

I've used block.set before with the rightClick event and it worked fine, I don't know why it isn't working now?

#

I've tried multiple alternatives, like giving it "facing" properties

#

Changing the block

#

I even tried using runCommandSilent with the setblock command and it didn't seem to work?

#

Maybe I'm missing something, I just need an outside view of the issue!

eternal pond
#

block.set is probably a function for something else, I don't think you can do that with KubeJS, maybe an addon can make this work?

buoyant magnet
#

what?

buoyant magnet
#

Still havent found a solution, really any help is appreciated !!!

buoyant magnet
#

I have switched from "broken" to "leftClicked", it's not exactly what I aimed for initially, but now block.set works as intended

#

the script also has a lot of problems I haven't accounted for

#

I'll be closing the ticket and revamping it