Mojira Archive
MCPE-179308

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

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 

Unresolved

_Minecrafter_12

2024-03-03, 12:30 AM

2024-03-13, 02:21 PM

0

1

Confirmed

1203475

scripting-api

1.20.62 Hotfix

-