#About OnUseOn for custom component events in custom tools

1 messages · Page 1 of 1 (latest)

blissful turretBOT
weak sedge
#

Hello, nice to meet you.
I have a question.
First of all, I am making an add-on that adds tools such as shovels, axes, and hoes to the preview version of BE (1.21.20.24).
To lower the durability of the tools, I used itemComponentRegistry.registerCustomComponent in world.beforeEvents.worldInitialize.subscribe of ScriptAPI, and used onUseOn, which triggers an event when you right-click on a block, to lower the durability while changing the block. However, if the tool has tags such as "minecraft:is_hoe", "minecraft:is_axe", or "minecraft:is_shovel", the onUseOn event itself does not seem to be triggered.
Is this a feature? Or is it a bug?
If it is a feature, I would appreciate it if you could tell me the solution.
By the way, no errors occurred.
I'm sorry for my poor English.

It's a code.

world.beforeEvents.worldInitialize.subscribe((event) => {
    // Example Hoe
    event.itemComponentRegistry.registerCustomComponent("test:hoe", {
        // Right_Click_On_Block
        onUseOn(e) {
            const { block, blockFace, source, itemStack } = e;
            if (!(source instanceof Player)) return;
            // Playsound
            source.playSound("use.gravel");
            // No durability loss in creative mode
            if (source.getGameMode() !== GameMode.creative && block.hasTag("grass") && blockFace == Direction.Up) {
                let item = itemStack.getComponent("durability");
                item.damage += 1;
                source.getComponent("equippable").setEquipment(EquipmentSlot.Mainhand, itemStack);
            }
        }
    });
});

By the way, I asked the question here too.
https://bugs.mojang.com/browse/MCPE-183957

weak sedge
#

I've just started, so I'm sorry for sending it several times m(_ _)m

jaunty hill
#

i had same problem here and there is not any fixes for this, last option is to use playerInteractWithBlock event or make custom functionality for hoe,shovel and axe