Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4634

Offhand is in inventory iteration, but doesn't allow deletion.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • As this is an API bug this is not relevant.

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

    • git-Spigot-e5e5c7c-4e4cde4 (MC: 1.13.2)
    • Yes

      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.

            Unassigned Unassigned
            Photon Photon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: