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

ItemUseOn afterEvents(not working) & beforeEvents(Repeatedly executes code block)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.20.62 Hotfix
    • Confirmed
    • Windows
    • 1203475

      afterEvents Behaviour

      when i use the diamond sword the script is supposed  to execute this code:

      import { world } from '@minecraft/server'
      world.afterEvents.itemUseOn.subscribe((data) => {    
      const Block = data.block    
      const Item = data.itemStack    
      const Player = data.source
          if (Item.typeId === "minecraft:diamond_sword" && Block.permutation.matches("minecraft:grass")) {        Player.sendMessage("works")    }}) 

      You will find attached a video titled "itemUseOn afterEvents Video" to show that this is not Woking correctly.

      beforeEvents Behaviour 

      when this same code is switched to a beforeEvents method. The code will Repeatedly execute the code block in the if statement. You will find attached a video titled "itemUseOn beforeEvents Video" to show this in-game. here is the code for this :

      import { world } from '@minecraft/server'
      world.beforeEvents.itemUseOn.subscribe((data) => {    
      const Block = data.block    
      const Item = data.itemStack    
      const Player = data.source
          if (Item.typeId === "minecraft:diamond_sword" && Block.permutation.matches("minecraft:grass")) {        Player.sendMessage("works")    }}) 

      my main.js code 

      import "item_use_on.js" 

      i will also attach a screen grab of my world settings, my manifest.json and two example addons containing the altered scripts 

            _Minecrafter_12 _Minecrafter_12
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              CHK: