[SPIGOT-5635] Calling ItemStack#setType for items inside an Inventory will not update Created: 26/Mar/20  Updated: 27/Mar/20  Resolved: 26/Mar/20

Status: Closed
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Stef van Schie Assignee: Unassigned
Resolution: Invalid Votes: 0
Labels: 1.15.2, bug, inventory, itemstack
Environment:

OpenJDK 14 64-bit build 14+36 for Spigot 1.15.2 and CraftBukkit 1.15.2. OpenJDK 13 64-bit build 13+33 for Spigot 1.14.4 and CraftBukkit 1.14.4. Windows 7 Professional.


Attachments: File IF-Test-0.0.0.jar    
Version: This server is running CraftBukkit version git-Spigot-a03b1fd-fc318cc (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

When placing an ItemStack inside a custom Inventory (created by Bukkit.createInventory), the item is shown in the Inventory. If the same ItemStack is then updated via ItemStack#setType(Material) to a different type, then reopening the same Inventory, the item will still have its old type shown, instead of the new type.

I believe this is a bug, since the ItemStack updates itself (as per Javadocs: "Sets the type of this item" (italics of "this" not in original quote)), so readding the item to the inventory should not be necessary (since it's already in there). While having to reopen the Inventory for the viewer(s) is understandable, I would expect this action to show the new item, however the old item is still shown.

I have tested this on Spigot 1.15.2 (git-Spigot-a03b1fd-fc318cc (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)); CraftBukkit 1.15.2 (git-Bukkit-fc318cc (MC: 1.15.2) (Implementing API version 1.15.2-R0.1-SNAPSHOT)); Spigot 1.14.4 (git-Spigot-56f8741-3e3818b (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)); and CraftBukkit 1.14.4 (git-Bukkit-009d8af (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)) and this issue occurs on all of them.

To reproduce this issue make sure that the test plugin I attached below has been installed on a server. Start the server and login to the server as a player. Make sure that this player is an operator on the joined server. Then execute as this player via chat the command /gui open and notice the green wool in the top left corner of the now opened inventory. This is indeed as it should be. Now close the opened inventory and execute /gui change and no visible change should occur (as intended). Internally the ItemStack has been changed from green wool to red wool. Now execute /gui open yet again and notice how the item in the top-left corner of the again opened inventory is still green wool, instead of the expected red wool.

The code of the sample plugin along with its plugin.yml can be seen here: https://gist.github.com/stefvanschie/0d6d67d6425d665be7529a0769b8b9aa



 Comments   
Comment by Stef van Schie [ 27/Mar/20 ]

Could you elaborate on why the update packets would need to be send? I understand that changes to an open inventory aren't reflected immediately, which would indeed lead to this "packet spam", but that's not the issue. I find it strange (hence why I think this is a bug) that even after reopening the inventory, changed properties of the ItemStack are not reflected and that - as per your comment - I need to set the same item that was already in the inventory again, just to get the changes visible to the player.

Comment by Black Hole [ 26/Mar/20 ]

After changing properties of an item stack you have to set the changed slot again.
Imagine you will alter many properties of many item stacks in an inventory. Sending out hundreds of update packets would be very inefficiently.

Generated at Fri Mar 14 09:35:31 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.