Short description of the issue
When the offhand item of a SimulatedPlayer (@minecraft/server-gametest) is changed after it has spawned, the change is applied on the server but is never shown to connected players. The offhand item is only visible if it is set in the same tick as spawnSimulatedPlayer.
Steps to reproduce the issue
1. Run a behavior pack with the script below on a dedicated server (Beta APIs on, @minecraft/server 2.12.0-beta, @minecraft/server-gametest 1.0.0-beta) and join with a client.
2. Run /scriptevent test:offhand and watch the left hand of OffhandBot.
import { world, system, GameMode, ItemStack, EquipmentSlot } from "@minecraft/server";
import { spawnSimulatedPlayer } from "@minecraft/server-gametest";
system.afterEvents.scriptEventReceive.subscribe((e) => {
if (e.id !== "test:offhand") return;
const p = e.sourceEntity;
const bot = spawnSimulatedPlayer({ dimension: p.dimension, x: p.location.x + 2, y: p.location.y, z: p.location.z }, "OffhandBot", GameMode.Survival);
const items = ["shield", "totem_of_undying", ""];
let i = 0;
system.runInterval(() => {
const id = items[i++ % items.length];
const eq = bot.getComponent("minecraft:equippable");
if (id) eq.setEquipment(EquipmentSlot.Offhand, new ItemStack("minecraft:" + id));
else eq.setEquipment(EquipmentSlot.Offhand);
}, 60);
});
Expected result
The offhand item of OffhandBot changes every 3 seconds (shield, totem, empty) on the client.
Actual result
Nothing is shown in the left hand on the client. On the server the item is set: getEquipment(Offhand) returns it, /testfor with hasitem location=slot.weapon.offhand finds it, and a shield in the offhand blocks attacks while sneaking.
Notes
- /replaceitem entity <name> slot.weapon.offhand 0 shield gives the same result.
- Changing the main hand (selectedSlotIndex), changing armor, /gamemode spectator then survival, or the client rejoining after the change does not make it appear.
- If the offhand item is set in the same tick as spawnSimulatedPlayer, it is shown.
- A normal zombie that gets a shield in its offhand 2 seconds after spawning (via /replaceitem) shows it correctly, so the problem seems specific to SimulatedPlayer.
- Main hand items and armor of the SimulatedPlayer are shown correctly.
Additional information:
1. Still reproduces on BDS 1.26.66.1 (client 26.66).
2. I logged outgoing packets with @minecraft/server-net (beforeEvents.packetSend, packet type + recipients only) while changing a SimulatedPlayer's equipment one step at a time. Results (recipient = the real player watching):
- SimulatedPlayer spawns: AddPlayerPacket, MobArmorEquipmentPacket, 2x MobEquipmentPacket (main hand + offhand) -> sent to the real player
- Offhand changed (setEquipment(Offhand, totem) or /replaceitem ... slot.weapon.offhand): NO packet to the real player (only InventoryContent/InventorySlot to the SimulatedPlayer itself)
- selectedSlotIndex changed (0 -> 8): MobEquipmentPacket -> sent to the real player
- Item in the currently selected hotbar slot replaced (container.setItem on the selected slot): NO packet to the real player
- Armor changed (/replaceitem ... slot.armor.head): MobArmorEquipmentPacket -> sent to the real player
So for SimulatedPlayers, MobEquipmentPacket is only broadcast on spawn and on a selected-slot change. Changes to the offhand, or to the item in the selected slot, are never broadcast, and other players keep seeing the old item.
Workaround: give the whole kit (main hand and offhand) in the same tick as spawnSimulatedPlayer. Those items are included in the spawn packets and render correctly.