When porting to 1.21 I noticed that my packets now experience race conditions (or just out of order, not sure yet):
Specifically the vanilla ClientboundContainerSetContentPacket arrives faster than my OpenGui packet, thus getting discarded.
My current hotfix is to just sleep 100ms but thats really not a permanent solution.
Old code, no longer works despite sending OpenGuiRequest first, then ClientboundContainerSetContentPacket through setSynchronizer.
public void openInventory(ServerPlayer player) {
((ServerPlayerEntityMixin)player).ic$nextContainerCounter();
AbstractContainerMenu screenHandler = createMenu(((ServerPlayerEntityMixin)player).getContainerCounter(), player.getInventory(), player);
if (screenHandler != null) {
NetworkHandler.sendToPlayer(new OpenGuiRequest(this, screenHandler.containerId), player);
// A sleep here would "fix" the issue.
player.containerMenu = screenHandler;
ServerPlayerEntityMixin playerAccessor = (ServerPlayerEntityMixin) player;
screenHandler.setSynchronizer(playerAccessor.getContainerSynchronizer());
}
}
