-
Bug
-
Resolution: Unresolved
-
None
-
1.21.20.21 Preview, 1.21.2 Hotfix, 1.21.41 Hotfix, 1.21.44 Hotfix
-
None
-
Community Consensus
-
Windows
Hello! This is my first time using this site, so please forgive me if the text is confusing.
I'm making an add-on for the Bedrock Edition, and I'm trying to use ItemCustomComponent's onUseOn to trigger additional events for my homemade items such as shovels, axes, and hoes that are activated by right-clicking, but the onUseOn event itself doesn't occur for blocks that can be used because they are tagged as shovels, axes, or hoes.
Is this by design? Or is it a bug?
I'll show you the code just in case (some names have been hidden)
Please let me know if there is any other information you would like to know.
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); } } }); });
Added 2024/10/24
I'm sorry for the late response.
I'll add a comment.
Using "world.afterEvents.playerInteractWithBlock.subscribe" got me closer to the behavior I expected, but I'll send you a file and a video to show you what happens when you use OnUseOn just to solve the problem.
This is a simplified add-on made using only tools to send to Mojang. There may be some issues, but I believe I can reproduce them, so thank you for your cooperation.
Don't mind the "Error" in the name... it's just a name.
- is duplicated by
-
MCPE-188501 Trigger onUseOn and Item Tags conflict
- Resolved