The Spice of Life

The Spice of Life

16M Downloads

Lunchbag / lunchbox item duplication

copygirl opened this issue ยท 3 comments

commented

While looking inside a lunchbox, it's still possible to move it around the inventory. This sometimes allows for items to be duplicated. To reproduce:

  • Open lunchbag / lunchbox.
  • Move lunchbag / lunchbox to a different slot.
  • Take out item(s).
  • Close GUI.
  • Check lunchbox.

I suggest these changes to fix this:

  • In the container class, use a special slot for where the container item is and don't allow modifying it.
  • Automatically close container / GUI when item is not in the slot anymore. This would prevent issues when the item is removed through other means (like player inventory accessing mods).
commented

Thanks for including the steps to reproduce it.

In looking at the code, I might just have overlooked that the ItemStack instance changes if the item changes slots on the server. On the client, I re-find the lunch bag/lunch box using a UUID before any changes are written to it because the ItemStack instance changes any time the server syncs. Shouldn't be too much trouble to apply that logic server-side as well.

Relevant code:

commented

I assume it's the item stack that's storing the food in NBT, is that correct? In this case, there will still be issues when the item stack is cloned, which a lot of inventory related code does. You can't trust that the same item stack instance is being reused.

commented

You can't trust that the same item stack instance is being reused.

Right. I knew this was the case on the client-side, but I mistakenly thought it wasn't the case on the server-side.