Entity.setItemInHandSlot (stable in @minecraft/server 2.13.0, Preview 27.0.20) does not update the client when it is called on a non-player entity after the tick that entity was spawned in. The server has the item: Entity.getItemInHandSlot returns it. The client keeps the entity's previous hand item, so anything client-side that depends on it is wrong.
The same call made in the tick the entity is spawned does reach the client, and so does the same change made at the same later time with /replaceitem. Only the later API call is lost.
The attached pack shows this on a custom entity whose render controller tints it red while query.is_item_equipped('slot.weapon.mainhand') is true, and on vanilla armor stands, which draw the item they hold.
Steps to reproduce
Import the attached
script_api_entity_set_item_in_hand_slot_client_sync.mcaddonand create a flat creative world with both packs applied. No experiments are needed: the pack uses the stable@minecraft/server2.13.0 module.Run
/ss_ihs:bug_report. The script spawns two rows of three entities in front of you, armor stands in the first row and pig-shaped probes in the second, each with a name tag:A: given a diamond sword with
entity.setItemInHandSlot(HandSlot.Mainhand, item)in the same tick it is spawned.B: given the same sword with the same call 100 ticks (5 seconds) later.
C: given the same sword 100 ticks later with
/replaceitem entity @s slot.weapon.mainhand 0 diamond_sword.
Wait about 6 seconds, until the script prints its log, which reads every main hand back with
Entity.getItemInHandSlot.Look at the six entities.
Expected result
All six entities hold the sword on the client as well as on the server: the three armor stands show a diamond sword in hand, and the three probes are tinted red.
Observed result
The log reports minecraft:diamond_sword for all six entities, so the server state is correct in every case.
Probes (custom entity, client-side Molang):
A: (API in the spawn tick): red.
B: (API 5 seconds after spawning): not tinted. The client still evaluates
query.is_item_equipped('slot.weapon.mainhand')as false.C: (
/replaceitem5 seconds after spawning): red.
Armor stands:
A: Shows the sword
B: Empty Hand, Can right click to retrieve sword
C: Shows the sword
Thank you for helping us improve Minecraft! We saved your files: