[SPIGOT-4634] Offhand is in inventory iteration, but doesn't allow deletion. Created: 24/Feb/19  Updated: 25/Feb/19  Resolved: 25/Feb/19

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

Type: Bug Priority: Minor
Reporter: Photon Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: Inventory, iteration, removal
Environment:

As this is an API bug this is not relevant.

However, it was tested on a Windows 10 PC with Java 8.


Attachments: File bugreport-1.0-SNAPSHOT.jar    
Version: git-Spigot-e5e5c7c-4e4cde4 (MC: 1.13.2)
Guidelines Read: Yes

 Description   

The iteration through the inventory of a player will contain the offhand item, but you cannot remove it from the inventory.

Below is some code fragment to show the problem for a simple item smelter.

// Code-Platzhalter
for (ItemStack itemStack : player.getInventory())
{
   player.getInventory().addItem(this.smelt(itemStack))
   player.getInventory().remove(itemStack);
}

In this case holding e.g. an iron ore in the offhand will supply an infinite supply of iron ingots as the offhand is contained in the Inventory iterator, but the removal will not remove the itemstack. This also throws no error causing me to think that this is not intentional behaviour.
 

Potential fixes:

Either remove the Offhand from the Inventory Iterator or allow removal of item stacks from the offhand.

 

Minimal reproduction plugin included, will clear the inventory on join, with the method mentioned above, thus causing the offhand not to be cleared.

As this bug can lead to infinite resource bugs with item smelters, etc. and requires additional code that is not really expected, I consider this bug as major.



 Comments   
Comment by md_5 [ 25/Feb/19 ]

Documentation made crystal clear.
This can't be changed for compat reasons.

Comment by md_5 [ 24/Feb/19 ]

https://hub.spigotmc.org/jira/browse/SPIGOT-4617

See storage contents

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