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.