Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-120643

Picking up an incomplete stack of items is not correctly detected



    • Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.12.1, Minecraft 1.12.2 Pre-Release 1, Minecraft 1.12.2 Pre-Release 2, Minecraft 1.12.2, Minecraft 17w43a, Minecraft 17w43b, Minecraft 17w45a, Minecraft 17w45b, Minecraft 17w46a, Minecraft 17w48a, Minecraft 17w50a, Minecraft 18w01a, Minecraft 18w03b, Minecraft 18w06a, Minecraft 18w07b, Minecraft 18w09a, Minecraft 18w10d, Minecraft 18w14b, Minecraft 1.13-pre1, Minecraft 1.13-pre3, Minecraft 1.13-pre6, Minecraft 1.13-pre10, Minecraft 1.13, Minecraft 18w30b, Minecraft 18w31a, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 19w04b, Minecraft 19w05a, Minecraft 19w06a, 1.14.4, 1.15 Pre-release 6, 1.15.1, 20w21a, 1.16 Pre-release 4, 1.16 Pre-release 6, 1.16, 1.16.4, 20w48a, 20w51a, 1.16.5, 21w05b, 1.17, 1.17.1 Pre-release 1, 1.17.1 Pre-release 2, 1.17.1, 21w41a, 21w42a, 21w43a, 21w44a, 1.18 Pre-release 1, 1.18 Pre-release 4, 1.18 Pre-release 5, 1.18 Pre-release 6, 1.18 Pre-release 8, 1.18 Release Candidate 1, 1.18 Release Candidate 3, 1.18.1, 1.19, 1.19.1
    • Confirmed
    • Networking
    • Normal


      The bug

      Picking up only a part of an item stack of an item entity because your inventory is nearly full is not correctly detected by the server causing:

      • Server-side:
        • Missing statistics change
      • Client-side:
        • Missing sound and animation
        • Item stack of item entity not updated

      How to reproduce

      It's easiest to reproduce this by starting in creative mode and then switching to survival partway through.

      1. Fill all of your inventory except for the first hotbar slot with one item (e.g. wooden swords), fill the hotbar slot with a nearly full stack of for example stone
        /give @s wooden_sword 36
        /item replace entity @s hotbar.0 with minecraft:stone 63
      2. Switch to survival mode (This is needed because in creative you can pick items up even when the inventory is full.)
        /gamemode survival
      3. Summon an item entity containing two stone items
        /summon item ~ ~ ~ {Item:{id:"stone",Count:2b}}

        The item entity still shows two items, there was no sound, no animation, etc.

      Code analysis

      Based on 1.12.2 decompiled using MCP 9.40

      The method net.minecraft.entity.item.EntityItem.onCollideWithPlayer(EntityPlayer) tests if net.minecraft.entity.player.InventoryPlayer.addItemStackToInventory(ItemStack) returns true. Since this is only the case if the complete stack was picked up, it should instead test if the stack size decreased.

      The following shows the problems with the current code:

      ItemStack itemstack = this.getItem();
      Item item = itemstack.getItem();
      int i = itemstack.getCount();
      // Don't test for entityIn.inventory.addItemStackToInventory(itemstack) == true
      if (this.pickupDelay == 0 && (this.owner == null || 6000 - this.age <= 200 || this.owner.equals(entityIn.getName())) && entityIn.inventory.addItemStackToInventory(itemstack))
          // Change this, picked up count can be < i
          entityIn.onItemPickup(this, i);
          if (itemstack.isEmpty())
          // Change this, picked up count can be < i
          entityIn.addStat(StatList.getObjectsPickedUpStats(item), i);


        Issue Links



              Unassigned Unassigned
              pokechu22 [Mod] Pokechu22
              18 Vote for this issue
              14 Start watching this issue