Immersive Engineering

Immersive Engineering

152M Downloads

Engineer's toolbox voids items

KrutNA opened this issue ยท 8 comments

commented

Minecraft Version

1.21.1

Immersive Engineering Version

12,1.0-185

Expected Behavior

I have 33 (current count (32) + new count (1) minecraft:oak_log in the engineer's toolbox

Actual Behavior

I have 32 minecraft:oak_log in the engineer's toolbox
Or if you put more then 32 minecraft:oak_log (full stack - current count), for example 43, you will have 43 (current count (32) * 2 + new count (43) - full stack (64) = 43) of the same item
Another example: (current count (43) * 2 + new count (47) - full stack (64) = 69) of the same item

Steps to reproduce

  1. Open engineer's toolbox
  2. Put some (less then full stack) of "Anything", for example half a stack (32) minecraft:oak_log
  3. Put some more of the same item by shift-click, for example 1 minecraft:oak_log

Debug Crash Log

https://pastebin.com/RKem3CeL

commented

@CrysMia Did you ever find anything else out about this?

commented

Sorry for the delay on further investigating this.

I have tracked the reset of the stack down to the broadcastChanges function in AbstractContainerMenu.class which is called by broadcastChanges in IEContainerMenu on every tick. I assume that the broadcast will result to the old reference when quick stacking. I have yet to find out why this happens tho. I am not that familiar with minecraft modding tho so I am mainly going in blind on that.

Screenshot 1:
Image

Screenshot 2:
Image

Slot 18 is being read as "1 minecraft:oak_log" despite slot 18 holding 64 instead. Slot 18 was 1 before tho, so it's resulting to old data instead.
When the function is being called via "this.player.containerMenu.broadcastChanges()" in ServerGamePacketListenerImpl.class the slots are properly updated (first screenshot with properly updated slots, second screenshot with reset slots), the broadcast call from IE however resets it due to reading the old data on quick stacking. The reset only happens as soon as the index 20 is being handled in this case, tho this might just be breakpoint and rendering stuff delay. Maybe a forced update to the reference before calling the broadcast would fix it?

edited for better clarity on the screenshots

commented

Hey, just found out about this issue. It turns out that the voiding only happens when the toolbox was opened while holding it.
If it is placed on the ground beforehand then the issue does not appear.
Maybe it's missing the reference for shift+left click when being held?

I shouldn't respond to stuff while half asleep, disregard what I wrote earlier. I might look at the code later on, will take some time tho.

Edit:
The problem at a first glance seems to be that the toolbox is not properly updated on quick stack, resulting in the item(s) being voided. Stacks are all properly set until the point when the Toolbox should get updated in the player inventory. This would at least explain why it only affects the quick stack in the inventory but not when being placed in world. Stacking "normally" also calls other functions that handle the change just fine, my guess would be that the toolbox instance is either returned from it's previous state or the state is never properly updated. Mostly just assumptions from a few breakpoints and going through a few instructions as of now tho, need to fully get into all affected code first but I thought I'll share my findings so far. I'll see what else I can find.

commented

I can definitely reproduce it, but I am stumped on actually fixing this.
If anyone else is motivated to debug this deeper, any help is appreciated.

commented

initially I couldnt reproduce until I read it was with shift-click, and yea thats very wierd that it voids shift-click specifically

seems possible that its an ordering issue with the change being applied to the toolbox, and as far as I'm aware shift-moving doesnt hold a stack in the cursor whereas moving by hand does?

commented

oh and it also doesnt have the issue when the box is placed in-world, only specifically when the box is held in-hand and shift-insert is used

commented

and also also specifically when a stack merge is performed, if its its own stack or a new stack (ie any existing ones are full) it doesnt occur

commented

Yeah I know the conditions under when it happens, I just don't understand why it happens.

If someone else wants to step this through with a debugger to find out, be my guest.