InventoryManager: Defer opening new windows to the client until the window close handshake has been completed

fixes #5021 and probably a bunch of other inventory related glitches

When the server initiates a window close, it does so by sending a ContainerClose to the client, which causes the
client to behave as if it initiated the close itself. It responds by sending a ContainerClose back to the server,
which the server is then expected to respond to.

Sending the client a new window before sending this final response creates buggy behaviour on the client, which
is problematic when switching windows. Therefore, we defer sending any new windows until after the client
responds to our window close instruction, so that we can complete the window handshake correctly.

This is a pile of complicated garbage that only exists because Mojang overengineered the process of opening and
closing inventory windows.
This commit is contained in:
Dylan K. Taylor
2022-05-20 16:54:06 +01:00
parent 0ea3861d43
commit 554f96bc24
2 changed files with 65 additions and 38 deletions

View File

@ -2481,7 +2481,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
return false;
}
//TODO: client side race condition here makes the opening work incorrectly
$this->removeCurrentWindow();
if(($inventoryManager = $this->getNetworkSession()->getInvManager()) === null){