mojira.dev
MCPE-244728

Script API - Entity Set Item In Hand Slot Client Sync

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

  1. Import the attached script_api_entity_set_item_in_hand_slot_client_sync.mcaddon and create a flat creative world with both packs applied. No experiments are needed: the pack uses the stable @minecraft/server 2.13.0 module.

  2. 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:

    1. A: given a diamond sword with entity.setItemInHandSlot(HandSlot.Mainhand, item) in the same tick it is spawned.

    2. B: given the same sword with the same call 100 ticks (5 seconds) later.

    3. C: given the same sword 100 ticks later with /replaceitem entity @s slot.weapon.mainhand 0 diamond_sword.

  3. Wait about 6 seconds, until the script prints its log, which reads every main hand back with Entity.getItemInHandSlot.

  4. 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: (/replaceitem 5 seconds after spawning): red.

Armor stands:

  • A: Shows the sword

  • B: Empty Hand, Can right click to retrieve sword

  • C: Shows the sword

Attachments

Comments 2

Thank you for helping us improve Minecraft! We saved your files:

[media][media]

Can confirm in Android

SmokeyStack

(Unassigned)

Unconfirmed

Windows

11

27.0.20 Preview

Retrieved