[MC-1555] Items get deleted when the crafting recipe overflows the inventory Created: 01/Nov/12  Updated: 29/Jun/18  Resolved: 08/Aug/16

Status: Resolved
Project: Minecraft: Java Edition
Component/s: None
Affects Version/s: Minecraft 1.4.2, Minecraft 1.4.5, Minecraft 1.4.7, Snapshot 13w04a, Snapshot 13w07a, Minecraft 1.5, Minecraft 1.5.1, Minecraft 1.5.2, Snapshot 13w18b, Snapshot 13w18c, Minecraft 1.6.2, Minecraft 1.6.4, Minecraft 13w38a, Minecraft 13w38b, Minecraft 13w38c, Minecraft 13w42b, Minecraft 13w43a, Minecraft 1.7.1, Minecraft 1.7.2, Minecraft 13w48a, Minecraft 13w48b, Minecraft 13w49a, Minecraft 1.7.3, Minecraft 1.7.4, Minecraft 14w05b, Minecraft 14w06b, Minecraft 14w07a, Minecraft 14w08a, Minecraft 1.7.5, Minecraft 14w11b, Minecraft 1.7.9, Minecraft 14w17a, Minecraft 14w18b, Minecraft 14w26c, Minecraft 1.7.10, Minecraft 14w27a, Minecraft 14w28a, Minecraft 14w32a, Minecraft 14w33a, Minecraft 14w33c, Minecraft 14w34a, Minecraft 14w34b, Minecraft 14w34c, Minecraft 14w34d, Minecraft 1.8-pre1, Minecraft 1.8-pre3, Minecraft 1.8, Minecraft 1.8.1-pre2, Minecraft 1.8.1-pre5, Minecraft 1.8.1, Minecraft 1.8.2-pre1, Minecraft 1.8.2-pre2, Minecraft 1.8.2-pre3, Minecraft 1.8.2-pre4, Minecraft 1.8.6, Minecraft 1.8.7, Minecraft 1.8.8, Minecraft 15w31a, Minecraft 15w31c, Minecraft 15w32a, Minecraft 15w32b, Minecraft 15w32c, Minecraft 15w33c, Minecraft 15w36d, Minecraft 15w38a, Minecraft 15w38b, Minecraft 15w39b, Minecraft 15w39c, Minecraft 15w42a, Minecraft 15w45a, Minecraft 15w46a, Minecraft 15w47a, Minecraft 15w47b, Minecraft 15w47c, Minecraft 1.8.9, Minecraft 15w51b, Minecraft 16w02a, Minecraft 16w03a, Minecraft 16w04a, Minecraft 16w05b, Minecraft 16w06a, Minecraft 16w07a, Minecraft 16w07b, Minecraft 1.9 Pre-Release 1, Minecraft 1.9 Pre-Release 2, Minecraft 1.9 Pre-Release 3, Minecraft 1.9 Pre-Release 4, Minecraft 1.9, Minecraft 1.9.1 Pre-Release 1, Minecraft 1.9.1 Pre-Release 2, Minecraft 1.9.1 Pre-Release 3, Minecraft 1.9.1, Minecraft 1.9.2, Minecraft 16w14a, Minecraft 16w15a, Minecraft 16w15b, Minecraft 1.9.3 Pre-Release 1, Minecraft 1.9.3 Pre-Release 2, Minecraft 1.9.3 Pre-Release 3, Minecraft 1.9.3, Minecraft 1.9.4, Minecraft 16w20a, Minecraft 16w21a, Minecraft 16w21b, Minecraft 1.10 Pre-Release 1, Minecraft 1.10 Pre-Release 2, Minecraft 1.10, Minecraft 1.10.1, Minecraft 1.10.2
Fix Version/s: Minecraft 16w32a

Type: Bug
Reporter: [Mojang] Panda Assignee: [Mojang] Agnes Larsson
Resolution: Fixed Votes: 146
Labels: None

Attachments: PNG File 2014-11-19_20.24.45.png     PNG File 2014-11-19_20.24.48.png     PNG File 2014-11-19_20.25.28.png     PNG File 2014-11-19_20.25.32.png    
Issue Links:
Duplicate
is duplicated by MC-10237 Deleting item when crafting several a... Resolved
is duplicated by MC-25282 Loss Of Block Resolved
is duplicated by MC-44291 Shift-clicking with full inventory de... Resolved
is duplicated by MC-52198 Crafting loss Resolved
is duplicated by MC-54200 Some materials are lost when shift-cl... Resolved
is duplicated by MC-54654 When your inventory is full and your ... Resolved
is duplicated by MC-56475 Conversion of ingots loss Resolved
is duplicated by MC-71316 Crafting Multiple Items Deletion Bug Resolved
is duplicated by MC-71813 Crafting multible items deletes overflow Resolved
is duplicated by MC-72399 1.8 Mineral Block Deletion bug Resolved
is duplicated by MC-76496 Crafting with shift-right-click destr... Resolved
is duplicated by MC-77319 When breaking down storage block (iro... Resolved
is duplicated by MC-94841 Item loss crafting 8 hay bales into w... Resolved
is duplicated by MC-94987 Converting a stack of iron blocks to ... Resolved
is duplicated by MC-100639 Inventory items disappear while crafting Resolved
is duplicated by MC-102809 Crafting Bone Meal Resolved
is duplicated by MC-103558 Items are lost when shift-click craft... Resolved
is duplicated by MC-104799 Item Loss With Shift-Click From Crafting Resolved
is duplicated by MC-106818 Incorrect breakdown of full stack sta... Resolved
is duplicated by MC-2571 When crafting from Metal Block form t... Resolved
Relates
relates to MC-129515 Collecting items to cursor via double... Resolved
relates to MC-88929 Items lost when shift clicking in ful... Resolved
relates to MC-120622 Item loss with shift + click to fill ... Resolved
relates to MC-122000 Items get deleted when the inventory ... Resolved
CHK:
Confirmation Status: Confirmed
Game Mode: Survival

 Description   

When crafting something that gives more than one item as an result (e.g. diamond blocks to diamonds, stairs, slabs) and not all resulting items fit into the inventory, the overflow gets deleted.

Steps to reproduce
1. Prepare your inventory like this (Put the diamond blocks into the free spot, instead of the crafting field)

2. Make sure you are in survival (/gamemode 0)
3. Craft the 8 diamond blocks into diamonds.
4. The expected result would be 72 diamonds (8*9), but you only get 64 2014-11-19_20.24.48.png

Ways to fix
I mainly see two ways to fix this.
1. Check if there is enough space in the inventory before hand (This is probably a bit more work to implement as there is no such method, I think)
2. Drop the overflowing items.
While I personally prefer the first one, the second one should be easy to implement.
It is a one liner, but due to old copy paste code it would need to be change in several different spots (Villager, Player, Workbench, maybe also Furnace and Anvil).

So for a nice fix some more generic Inventory/Container code would be good.

Code analysis: https://bugs.mojang.com/browse/MC-1555?focusedCommentId=288028&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-288028


Fix note: https://twitter.com/_LadyAgnes/status/762734666042441730



 Comments   
Comment by Marcono1234 [ 10/Aug/16 ]

Confirmed fixed for 16w32a

Comment by null (Inactive) [ 22/Jun/16 ]

Confirmed for 1.10.1.

Comment by null (Inactive) [ 08/Jun/16 ]

Confirmed for 1.10.

Comment by null (Inactive) [ 07/Jun/16 ]

Confirmed for 1.10-pre2.

Comment by null (Inactive) [ 03/Jun/16 ]

Confirmed for 1.10-pre1.

Comment by null (Inactive) [ 26/May/16 ]

Confirmed for 16w21b.

Comment by null (Inactive) [ 25/May/16 ]

Confirmed for 16w21a.

Comment by [Mod] redstonehelper [ 23/May/16 ]

The third option wouldn't work, you can shift-craft while holding items with your cursor.

Comment by user-f2760 (Inactive) [ 19/May/16 ]

I'd say the second option, that seems the most logical.

Comment by Fabian Röling [ 19/May/16 ]

I don't see someone suggesting an intended behaviour yet in these comments. Should it...

  • ...drop the remaining items (in the example dropping 8 diamonds)
  • ...don't execute the crafting that overflows the inventory (in the example only craft 7 blocks to diamonds, leaving 1 in the crafting area)
  • ...give you the remaining items to your cursor (in the example the 8 diamonds, don't really see why it should)
Comment by null (Inactive) [ 18/May/16 ]

Confirmed for 16w20a.

Comment by null (Inactive) [ 11/May/16 ]

Confirmed for 1.9.4.

Comment by null (Inactive) [ 06/May/16 ]

Confirmed for 1.9.3-pre3.

Comment by user-f2760 (Inactive) [ 04/May/16 ]

Cha0sPudd1ng you can also just say "confirmed for 1.9.2".

Comment by Andreas Billmaier [ 04/May/16 ]

https://www.youtube.com/watch?v=Zh2jHCDhpsU

Comment by Kumasasa [ 01/Apr/16 ]

xxXmlgnosc0prXxx: 1.RV-pre1 is not tracked here.

Comment by John Samson [ 31/Mar/16 ]

Confirmed for 1.RV PreRelease 1 (I know its an April Fools joke but it still affects it)

Comment by Wululululu [ 30/Mar/16 ]

Affects 1.9.1 (and probably 1.9.2, as it will only be a fix for MC-100283)

Comment by James (inactive) [ 15/Mar/16 ]

Confirmed for 1.9.1-pre3.

Comment by Fenhl (Max Dominik Weber) [ 27/Feb/16 ]

Affects 1.9-pre4.

Comment by Marcono1234 [ 20/Feb/16 ]

Please link to this comment in the description of the report.

The following is based on decompiled version of Minecraft 1.8 using MCP. All method and class names are the names used in the decompiled version.

The reason why this happens is that the protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean useEndIndex) method of the net.minecraft.inventory.Container class assumes it can always take only a part of the stack. This works for containers but not for crafting GUIs where it is either all or nothing (in this case it thinks it should remove all). This could be fixed by using a parameter to indicate whether the item stack can be splitted or not.

The following shows one possible way to fix this.

Class: net.minecraft.inventory.Container
// This is the method with the parametes normally used
protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean useEndIndex) {
    return mergeItemStack(stack, startIndex, endIndex, useEndIndex, true);
}

/**
 * Merges provided ItemStack with the first avaliable one in the container/player inventor between minIndex
 * (included) and maxIndex (excluded). Args : stack, minIndex, maxIndex, negativDirection. /!\ the Container
 * implementation do not check if the item is valid for the slot
 */
// Added the parameter "canStackBeSplitted" (boolean)
//    protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean useEndIndex)
protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean useEndIndex, boolean canStackBeSplitted)
{
    boolean var5 = false;
    int var6 = startIndex;

    if (useEndIndex)
    {
        var6 = endIndex - 1;
    }

    Slot var7;
    ItemStack var8;

    if (stack.isStackable())
    {
        while (stack.stackSize > 0 && (!useEndIndex && var6 < endIndex || useEndIndex && var6 >= startIndex))
        {
            var7 = (Slot)this.inventorySlots.get(var6);
            var8 = var7.getStack();

            if (var8 != null && var8.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getMetadata() == var8.getMetadata()) && ItemStack.areItemStackTagsEqual(stack, var8))
            {
                int var9 = var8.stackSize + stack.stackSize;

                if (var9 <= stack.getMaxStackSize())
                {
                    stack.stackSize = 0;
                    var8.stackSize = var9;
                    var7.onSlotChanged();
                    var5 = true;
                }
                // Replaced this to test if the stack can be splitted
                //else if (var8.stackSize < stack.getMaxStackSize())
                else if (canStackBeSplitted && var8.stackSize < var8.getMaxStackSize())
                {
                    stack.stackSize -= stack.getMaxStackSize() - var8.stackSize;
                    var8.stackSize = stack.getMaxStackSize();
                    var7.onSlotChanged();
                    var5 = true;
                }
            }

            if (useEndIndex)
            {
                --var6;
            }
            else
            {
                ++var6;
            }
        }
    }

    //...

    return var5;
}
Class: net.minecraft.inventory.ContainerWorkbench
/**
 * Take a stack from the specified inventory slot.
 */
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
    ItemStack var3 = null;
    Slot var4 = (Slot)this.inventorySlots.get(index);
    
    if (var4 != null && var4.getHasStack())
    {
        ItemStack var5 = var4.getStack();
        var3 = var5.copy();

        if (index == 0)
        {
            // Index 0 is the crafting result which cannot be splitted
            //if (!this.mergeItemStack(var5, 10, 46, true))
            if (!this.mergeItemStack(var5, 10, 46, true, false))
            {
                return null;
            }

            var4.onSlotChange(var5, var3);
        }
        //...
    }

    return var3;
}
Class: net.minecraft.inventory.ContainerPlayer
/**
 * Take a stack from the specified inventory slot.
 */
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
    ItemStack var3 = null;
    Slot var4 = (Slot)this.inventorySlots.get(index);

    if (var4 != null && var4.getHasStack())
    {
        ItemStack var5 = var4.getStack();
        var3 = var5.copy();

        if (index == 0)
        {
            // Index 0 is the crafting result which cannot be splitted
            //if (!this.mergeItemStack(var5, 9, 45, true))
            if (!this.mergeItemStack(var5, 9, 45, true, false))
            {
                return null;
            }

            var4.onSlotChange(var5, var3);
        }
        //...
    }

    return var3;
}
Class: net.minecraft.inventory.ContainerMerchant
/**
 * Take a stack from the specified inventory slot.
 */
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
    ItemStack var3 = null;
    Slot var4 = (Slot)this.inventorySlots.get(index);

    if (var4 != null && var4.getHasStack())
    {
        ItemStack var5 = var4.getStack();
        var3 = var5.copy();

        if (index == 2)
        {
            // Index 2 is the item the player receives
            //if (!this.mergeItemStack(var5, 3, 39, true))
            if (!this.mergeItemStack(var5, 3, 39, true, false))
            {
                return null;
            }

            var4.onSlotChange(var5, var3);
        }
        //...
    }

    return var3;
}

Note: There might be other GUIs affected as well but I currently cannot think of any other ones

Comment by Wululululu [ 19/Feb/16 ]

Affects 1.9-pre2

Comment by 19Spleen [ 17/Feb/16 ]

Confirmed for 1.9-pre1

Comment by Fenhl (Max Dominik Weber) [ 16/Feb/16 ]

Affects 16w07b.

Comment by Fenhl (Max Dominik Weber) [ 15/Feb/16 ]

Affects 16w07a.

Comment by Fenhl (Max Dominik Weber) [ 10/Feb/16 ]

Affects 16w06a.

Comment by Wululululu [ 08/Feb/16 ]

Still in 16w05b

Comment by Fenhl (Max Dominik Weber) [ 29/Jan/16 ]

Affects 16w04a.

Comment by Mona Juntus [ 26/Jan/16 ]

@[Mod] CubeTheThird: Thanks, I'll keep it there in the future.

Comment by [Mod] CubeTheThird [ 26/Jan/16 ]

Unless providing additional information about the issue, please keep discussions on the Jira Subreddit.

Comment by Mona Juntus [ 22/Jan/16 ]

Confirmed for 16w03a.

Comment by James (inactive) [ 13/Jan/16 ]

Confirmed for 16w02a.

Comment by James (inactive) [ 21/Dec/15 ]

Confirmed for 15w51b.

Comment by George Gates [ 19/Nov/15 ]

Still happening in 15w47a.

Comment by 19Spleen [ 12/Nov/15 ]

Confirmed for 15w46a

Comment by George Gates [ 05/Nov/15 ]

Still happening in 15w45a. Did the same thing as in the images, 8 diamond blocks and the extra diamonds got erased.

Comment by Wululululu [ 14/Oct/15 ]

Still in 15w42a

Comment by Kumasasa [ 18/Sep/15 ]

Changed reporter to panda4994

Comment by [Mod] CubeTheThird [ 18/Sep/15 ]

@Maria, this issue and MC-88994 are different problems, which is why yourself (and several others) have experienced it only in the snapshot.

Comment by Maria Zuyeva [ 18/Sep/15 ]

Couldn't find it with search as was looking for "shift". Reported it again MC-88994.
I didn't have this happening to me in released versions though, snapshot 15w38b is the first one I saw this in.

Comment by Andrew hunter [ 18/Sep/15 ]

I don't know if this is part of this bug but if you Shift left click an item that is already in a full chest it just deletes it, which ties into the game not registering that your inventory is full.

Comment by branza [ 17/Sep/15 ]

The title should also say that this happens for any recipe, not just for splitting blocks into separate items (well, I assume it does, I didn't actually test it).

Comment by [Mojang] Panda [ 17/Sep/15 ]

Can confirm for 15w38b, also I agree with Wululululu that the title could be a bit more clear about the deletion of items

Comment by Wululululu [ 17/Sep/15 ]

Still in 15w38a, Can a mod label this Bug as "item deletion" or for the sake of it as "item duplication"?
I know it's not a duplication issue but item dupes are fixed fast. Loss of items due to a bug seems to be okay for years now...

Comment by Wululululu [ 16/Aug/15 ]

It's in 15w33c

Comment by Wululululu [ 05/Aug/15 ]

Another week, another version it's in. 15w32a.
Edit: and 15w32b
Edit2: and 15w32c

Comment by Wululululu [ 29/Jul/15 ]

Confirmed in 1.8.8 and 15w31a
Edit: and 15w31b
Edit2: and 15w31c

Comment by ChocolateChip Cookies [ 26/Jun/15 ]

Confirmed in 1.8.7.

Comment by Seurabimn [ 17/Jan/15 ]

Confirmed in 1.8.2-pre2, -pre3, and -pre4

Comment by Chris [ 13/Jan/15 ]

Confirmed in 1.8.2-pre1. Also affects wood planks. Can occur even when crafting more than a full stack (e.g. 22 diamond blocks + 3 empty slots -> 192 diamonds instead of 198).

Comment by [Mod] Neko [ 20/Nov/14 ]

Confirmed in 1.8.1-pre5

Comment by branza [ 20/Nov/14 ]

Since this bug affects all recipes that give multiple items, the title should be changed to something like "Recipes that give multiple items not properly checking for full inventory".

Comment by Clint Kennedy [ 20/Nov/14 ]

It's basically just destroying the remainder of 1 block. It's not completely destroying all blocks. Although this is still obviously an issue, it's not as bad as it would seem, but still of course bad! Essentially it sees that there is one slot open, so it fills it with the first 7 blocks to 63. Then it sees that it can fill one more item, it does so, but doesn't know what to do with the remainder, so apparently it just destroys it. If you have 8 blocks exactly then you wind up with no blocks left. If you have more than 8 blocks, then you wind up with how ever many blocks you had minus 8. This same effect happens where the last block loses its remainder all the way up to 8 free inventory slots. The good news is is that for each additional empty slot, you have less of a remainder that you're losing

Comment by Megabobster [ 20/Nov/14 ]

I attached proper screenshots of the issue (my skin is blacked out because it's terrible). First two are the buggy behavior when shift clicking, second two are the what happens under normal circumstances.

It's worth noting that this bug affects ALL mineral blocks.

I can provide more screenshots or even video if it is necessary.

Comment by Wululululu [ 16/Oct/14 ]

Confirmed for 1.8.1-pre2

Comment by ChocolateChip Cookies [ 02/Sep/14 ]

Confirmed for 1.8 official release

Comment by Wululululu [ 28/Aug/14 ]

and 1.8-pre2 & 3

Comment by [Mod] redstonehelper [ 24/Aug/14 ]

Confirmed for 1.8-pre1.

Comment by Wululululu [ 20/Aug/14 ]

still in 14w34c and d ... I guess we'll have this bug in 1.8

Comment by Wululululu [ 18/Aug/14 ]

and 14w34b

Comment by ChocolateChip Cookies [ 18/Aug/14 ]

Affects version 14w34a.

Comment by Wululululu [ 14/Aug/14 ]

Confirmed for 14w33a.

Comment by Wululululu [ 06/Aug/14 ]

Confirmed for 14w32a,
I'd suggest changing Environment to All OS, although I can only confirm this on Windows 7 64 bit with Java 8u11.
I'd also suggest adding the labels "item" "items" "inventory" "item deletion" "block" and "full".

Comment by Andrew Thomas [ 10/Jul/14 ]

Confirmed for 14w28a

Comment by Wululululu [ 10/Jul/14 ]

And it's still in 14w28a...

Comment by ChocolateChip Cookies [ 02/Jul/14 ]

Confirmed for 14w27a.

C'mon mojang, this would take like 5 minutes to fix, and it's been around for almost 2 years.

Comment by AgentM [ 28/Jun/14 ]

Confirmed for the latest snapshot 14w26a/b/c
Happens on windows too.
happened with crafting torches
I had 63 and I expected to drop the 3 other torches I crafted... but it didn't.

Btw vote for this bug If you want it fixed and keep updating the Affects Versions.
and maybe even bother the mojangsters by tweeting them the major bugs
and add some more labels so people can find it easier

Comment by Jeremy [ 05/May/14 ]

This is a seriously bad bug. I am surprised to see it still in the game after all this time.

Edit: You may also want to add that this affects Windows users as well, not just Linux.

Comment by rsNeutrino [ 05/May/14 ]

Confirmed for snapshot 14w18b.

Comment by Wululululu [ 01/Mar/14 ]

Still exists in 1.7.5. Not really surprising as Amunak confirmed it for the current Snapshots.

Comment by Amunak [ 01/Mar/14 ]

This is true for all recipes that create more than one item per one input. Can confirm for 14w08a (latest snapshot as of now). It's a nasty bug and someone should fix it.

Comment by Jacob Petersen [ 27/Jan/14 ]

I can verify that this bug still exists in 1.7.2.

Comment by Anton Kudin [ 10/Nov/13 ]

Still a bug in 1.7.2.

Comment by Marios [ 26/Sep/13 ]

Affects 1.6.4 and snapshot 13w38c.

Comment by Chalmes (Jon) [ 01/Nov/12 ]

Confirmed. Nasty bug.

Edit: Can I suggest changing title of bug to something like "Splitting blocks into separate items not properly checking for full inventory"

Generated at Sun Jan 12 11:54:50 UTC 2025 using Jira 9.12.2#9120002-sha1:301bf498dd45d800842af0b84230f1bb58606c13.