Uploaded image for project: 'Minecraft (Bedrock codebase)'
  1. Minecraft (Bedrock codebase)
  2. MCPE-183957

ScriptAPI's ItemCustomComponent's onUseOn conflicts with tool tags

XMLWordPrintable

    • Icon: Bug 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.

        1. image-2024-11-21-17-08-41-932.png
          image-2024-11-21-17-08-41-932.png
          14 kB
        2. image-2024-11-21-17-08-41-932-1.png
          image-2024-11-21-17-08-41-932-1.png
          14 kB
        3. image-2024-11-21-17-09-44-774.png
          image-2024-11-21-17-09-44-774.png
          3 kB
        4. image-2024-11-21-17-09-44-774-1.png
          image-2024-11-21-17-09-44-774-1.png
          3 kB
        5. image-2024-11-21-17-09-44-774-2.png
          image-2024-11-21-17-09-44-774-2.png
          3 kB
        6. SendMojang.mp4
          7.54 MB
        7. TestErrorTools.mcaddon
          987 kB
        8. TestErrorTools.zip
          987 kB
        9. TestTools.mcworld
          1.05 MB

            Yon4800 Yon4800
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              CHK: