mojira.dev
MCPE-220433

PlayerHotbarSelectedSlotChangeAfterEvent is slow

In the latest Preview’s Beta v2 Scripting API, PlayerHotbarSelectedSlotChangeAfterEvent was introduced. The event fires if a player has changed their hotbar slot.
But the event fires slower compared to a hacky method using runInterval and .selectedSlotIndex check.

Steps to reproduce

Use this code snippet for reproducing the issue (2.1.0-beta version of ‘@minecraft/server’ module):

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        if ((player.selectedSlotIndex !== player.__lastSelectedSlot)) {
			console.log("interval check");
		}
        player.__lastSelectedSlot = player.selectedSlotIndex;
    }
});

world.afterEvents.playerHotbarSelectedSlotChange.subscribe(() => {
    console.log("hotbar change");
});

Actual result

Hotbar selected slot change event fires 1~3ms late than runInterval. Sometimes they fire at the same time, but runInterval always comes first.

Attachments

Comments 0

No comments.

Seawhite

(Unassigned)

Unconfirmed

Windows

Windows 11 24H2

1.21.90.26 Preview

Retrieved