mojira.dev
MCPE-166945

BeforeItemUseOnEvent.getBlockLocation() returns undefined

As of 1.19.70.22, the property blockLocation in BeforeItemUseOnEvent is now a function. However, this new function is not functioning properly. It's supposed to return a Vector3 object but returns undefined instead. The other event, The same method in ItemUseOnEvent works fine though.

Linked issues

Attachments

Comments 5

 

The code below ran in preview 1.19.70.22 if the player uses on the block, for instance, x: 1, y: 2, z: 3. should output:

import { world } from "@minecraft/server";

world.events.beforeItemUseOn.subscribe((event) => {
    const blockLocation = event.getBlockLocation();
    let keys = [];
    for (const key in event) {
        keys.push(key);
    }
    const { x, y, z } = blockLocation ?? {};
    console.warn('hello, ', x, y, z, keys.join(', '));
});

[Scripting][warning]-hello, 1 2 3 getBlockLocation, item, source, blockFace, faceLocationX, faceLocationY, cancel

but instead outputs

[Scripting][warning]-hello,  undefined undefined undefined getBlockLocation, item, source, blockFace, faceLocationX, faceLocationY, cancel

As you can see the method getBlockLocation is defined on the BeforeItemUseOnEvent class instance passed as a parameter in the event callback so the method always returns undefined.

new code and console output to further prove getBlockLocation is defined on the BeforeItemUseOnEvent instance.

import { world } from "@minecraft/server";world.events.beforeItemUseOn.subscribe((event) => {
    const blockLocation = event.getBlockLocation();
    let eventClone = {};
    for (const key in event) {
        eventClone[key] = typeof event[key];
    }
    const { x = 'undefined', y = 'undefined', z = 'undefined' } = blockLocation ?? {};
    world.sendMessage(JSON.stringify({ t: 'test', blockLocation: { x, y, z }, eventClone }, null, 4));
});

 

[media]

Thanks for the report!

This is still happening in 1.19.70.24.

Hi @darknavi,

Are there any workaround to get block location in 1.19.70.x?

Thanks a lot.

@tobiaspm

you can use this:

event.block.location

SIsilicon

(Unassigned)

977809

Confirmed

Multiple

1.19.70.22 Preview, 1.19.70

Retrieved