#Make item drop/put in inventory on rightClicked

3 messages · Page 1 of 1 (latest)

slim hatch
#

I'm trying to make it so that when a player strips a log, a "Bark" item is placed in their inventory (or, preferably, dropped on the ground). I know mods exist for this, but they add bark of every type, and often lack compatibility.

Here's what I'm trying to make work:


    if (event.player.getMainHandItem.hasTag("forge:tools/axes)) 
        event.player.give('kubejs:tree_bark')
    else
        return
})```

I made one iteration work where I had to explicitly specific acacia log and stone axe, and then foolishly didn't save it, so I don't even know how to make *that* work again.
spice daggerBOT
#

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

slim hatch
#

Solved, here's the functional script, including an nbt check, in case this is helpful for anyone else in the future:


    let heldItem = event.getItem();
    
    let isAxe = heldItem.hasTag("minecraft:axes");
    
    if (!isAxe) {
        let nbt = heldItem.nbt;
        if (nbt) {
            for (let key in nbt) {
                let value = nbt[key];
                if (typeof value === 'string' && value.includes('_axe_')) {
                    isAxe = true;
                    break;
                }
            }
        }
    }
    
    if (!isAxe) return;
    
    let blockId = event.block.id;
    if (!event.block.hasTag("minecraft:logs")) return;
    if (blockId.includes('stripped')) return;
    
    event.block.popItem('kubejs:tree_bark');

})```