Applied Energistics 2

Applied Energistics 2

137M Downloads

Sky stone chest closing sound plays too early, also plays if REI interface opened

saltyseadoggo opened this issue ยท 2 comments

commented

Describe the bug
Both variants of the sky stone chest play their closing sound immediately after the chest GUI is exited by any means. This means that it plays too early when closing the chest compared to the vanilla chest, and it also plays when the player views a recipe/uses in Roughly Enough Items when the chest GUI is open.

To Reproduce

  • Start Minecraft with the Fabric mod loader, with AE2, Roughly Enough Items and the Fabric API in the mods folder.
  • Create a new world in creative mode.
  • Place down a vanilla chest.
  • Open the chest, then close it. Note when the closing sound plays.
  • Place down either variant of the sky stone chest.
  • Open the chest, then close it. Note how much earlier the closing sound plays.
  • Open the chest once more, and left click any item in the REI interface on the right side of the screen with a crafting recipe to view its recipe. Note that the chest closing sound plays when the REI interface opens.

Expected behavior
The chest closing sound would play at the correct time for both variants of the sky stone chest, and would not play when the REI recipe interface is opened from within the chest.

Environment
Minecraft version: 1.16.5
Fabric Loader version: 0.11.1
AE2 version: 8.2.0 alpha 1
Fabric API version: 0.31.0
Roughly Enough Items version: 5.10.184

commented

Reproduced with Forge (+ JEI).

So there's two distinct issues you've identified here:

  1. AE2 chests will immediately play their closing sound when exiting the inventory. This is because we play sounds on openInventory and closeInventory rather than on tick updating, additionally our close sound isn't dependent on the lid angle whereas native MC chests are. I'm not sure why the difference, but I think it's something to do with us using the PlayerEntity in the playSound call which the tick method doesn't have access to. This is an easy fix since we can just remember the last interacting player - working on a PR.
  2. The chest physically closes whenever a recipe is interacted with in JEI, which is counter-intuitive because exiting a JEI recipe brings you back to the chest inventory GUI. Currently looking into what other mods do differently for this to not be an issue for them.
commented

I think I understand (2) more now.
Normally, client containers really just serve as dummy inventories that create server requests to open/close the server container (which will then as appropriate tell the client to open/close the container's gui). The server then is able to maintain a number of players using the chest, and tell the client to play open/close sounds as appropriate when the number of players using it goes >0 or = 0 (since if someone opens a chest you've already got open, it shouldn't open again).
In AE2, the client container is not a dummy and is linked directly to the TileEntity in the client's world. This means the client itself keeps track of how many players are using the chest rather than the server telling it how many.
This could seem fine - even if it doesn't really make sense - however, on the client, things like opening a new gui (such as with JEI) can change the player's current open container and hence tell the chest to close.
This is fixable by ignoring open/closeInventory calls on the client and reading the number of using players from the server block event via receiveClientEvent instead.

Will open a PR tomorrow.