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.
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
Switch to survival mode (This is needed because in creative you can pick items up even when the inventory is full.)
/gamemode survival
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())
{
this.setDead();
itemstack.setCount(i);
}
// Change this, picked up count can be < i
entityIn.addStat(StatList.getObjectsPickedUpStats(item), i);
}
Linked issues
discovered while testing 1
is duplicated by 7
Attachments
Comments 10
Here's the updated command for the first reproduction step:
/item replace entity @s hotbar.0 with minecraft:stone 63
Can confirm in 20w48a. For Step 2, since the /replaceitem command was replaced with /item, here's the updated use.