Mari023 / AE2WirelessTerminalLibrary

port of https://github.com/p455w0rd/AE2WirelessTerminalLibrary for fabric
MIT License
6 stars 26 forks source link

1.20.1 Items disappearing with in trinket slot #242

Closed Gamerbolts closed 6 months ago

Gamerbolts commented 7 months ago

Hello!

I am using my own modpack here https://www.curseforge.com/minecraft/modpacks/pxc-fabric-adventure

Noticed that when the wireless terminal is equipped into the head slot for trinkets that when opening it and putting items into the crafting grid then closing the terminal if you reopen it then the items are gone, no longer in the ME system just vanished. If you put the wireless terminal into the hotbar and right click then put items into the grid you can close and reopen and it works. Then you put the grid back into your head slot and open and try a crafting recipe, close, reopen and the items are there again from when it was on the hotbar. So it is essentially deleting the items and I am not sure what to do. I have no idea if this is due to this mod, AE2 or Trinkets. Hopefully it can be resolved. Thanks!

Mari023 commented 6 months ago

I think I know why this happens, but I am not sure if I can fix this

somehow the open terminal looses the reference to the terminal itemstack, thus being unable to save the inventory to it

Gamerbolts commented 6 months ago

Interesting, well I hope you can fix it if you can, if not is there way to prevent the wireless terminal from going into the trinket slot? I am created a modpack for others to play and would not like them to lose items.

Mari023 commented 6 months ago

is there way to prevent the wireless terminal from going into the trinket slot?

you can remove the items from the trinkets tags using a datapack or kubejs

Gamerbolts commented 6 months ago

Thank you, i'll do this

Mari023 commented 6 months ago

since the fix for this bug would be rather complicated, and only applies to 1.20.1, I won't be fixing this

lexi-the-cute commented 1 month ago

i presume this is the code that loses the reference to the ItemStack when in a trinket slot? https://github.com/Mari023/AE2WirelessTerminalLibrary/blob/53cc53c68e97ae0da51dd65110a4e7a8a2996645/src/main/java/de/mari_023/ae2wtlib/terminal/ItemWT.java#L154-L159

Mari023 commented 1 month ago

i presume this is the code that loses the reference to the ItemStack when in a trinket slot?

https://github.com/Mari023/AE2WirelessTerminalLibrary/blob/53cc53c68e97ae0da51dd65110a4e7a8a2996645/src/main/java/de/mari_023/ae2wtlib/terminal/ItemWT.java#L154-L159

no, that is just responsible to load data from an already present ItemStack

the issue is that the ItemStack instance in the slot changes, but WTMenuHost doesn't know about this, so WTMenuHost#getItemStack still returns the old instance, where all changes are then saved to (but lost, since that stack isn't stored anywhere else)

AE2 has a workaround for that, but it only works for the player inventory, but not trinkets. (see WirelessTerminalMenuHost#ensureItemStillInSlot) (in later minecraft versions this is fixed by just always directly getting the ItemStack from the slot, but in 1.20.1, we don't even know the slot if it is a trinkets slot)

lexi-the-cute commented 1 month ago

i presume this is the code that loses the reference to the ItemStack when in a trinket slot? https://github.com/Mari023/AE2WirelessTerminalLibrary/blob/53cc53c68e97ae0da51dd65110a4e7a8a2996645/src/main/java/de/mari_023/ae2wtlib/terminal/ItemWT.java#L154-L159

no, that is just responsible to load data from an already present ItemStack

the issue is that the ItemStack instance in the slot changes, but WTMenuHost doesn't know about this, so WTMenuHost#getItemStack still returns the old instance, where all changes are then saved to (but lost, since that stack isn't stored anywhere else)

AE2 has a workaround for that, but it only works for the player inventory, but not trinkets. (see WirelessTerminalMenuHost#ensureItemStillInSlot) (in later minecraft versions this is fixed by just always directly getting the ItemStack from the slot, but in 1.20.1, we don't even know the slot if it is a trinkets slot)

I wonder if we can assign each terminal a unique id in the nbt and scan all the non-inventory slots for it when attempting to save the data. Are we able to see the data if we check slots sequentially?

Also, if this is a trinkets specific issue, maybe posting an issue on the trinkets repo may help get a fix implemented?