Make picked item stack not drop when clicking Curios inventory button
apace100 opened this issue ยท 4 comments
Please describe the new feature or change.
The picked item stack should not drop out of the inventory when clicking the button to open the Curios inventory screen.
Please describe why you want this feature.
Occasionally, players might want to equip a Curio and then realize that the Curios inventory wasn't open, which leads to them trying to click the button to open that screen. It works, but simultaneously, the item stack will be dropped.
I haven't even thought about that before, but that would be really quite useful. Hope @TheIllusiveC4 will implement this feature.
Spent some time trying to figure out a way to get this to work. Unfortunately, Minecraft really doesn't want players to carry over stacks to different GUIs. I tried some workarounds but none of them worked right, so this probably won't be implemented.
It's definitely trickier than I expected. I managed to create a working workaround, however it seems very hacky. There's definitely room for improvement.
It basically saves the held item stack in a variable both on the server and the client before it changes the GUI, sets the held stack to empty (such that the inventory doesn't drop the item when closed) and then restores the object both client- and server-side after the new GUI has been opened.
However, client-side this can't be done in the constructor, because it has to be done after mc.displayGuiScreen
has been called. Therefore, I'm doing this on the first render frame of the CuriosScreen.
Server side it's done before and after the NetworkHooks are called in the packet classes sent from the client to the server.
Here's a link to the branch of my work where I implemented this, if you're interested:
https://github.com/apace100/Curios/tree/no-stack-drop-button
Affected classes:
GuiButtonCurios, CuriosScreen, CPacketOpenCurios, CPacketOpenVanilla