mojira.dev
MC-1555

Items get deleted when the crafting recipe overflows the inventory

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)

[media]

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

[media]

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

Related issues

MC-2571 When crafting from Metal Block form to ingots or diamonds there is a possiblity of losing some of said block. MC-10237 Deleting item when crafting several at the same time and shift-clicking. MC-25282 Loss Of Block MC-44291 Shift-clicking with full inventory destroys some items MC-52198 Crafting loss MC-54200 Some materials are lost when shift-clicking with full inventory MC-54654 When your inventory is full and your crafting with somthing that gives you multiple items back (e.g. a redstone block) you can loose some of the redstone. MC-56475 Conversion of ingots loss MC-71316 Crafting Multiple Items Deletion Bug MC-71813 Crafting multible items deletes overflow MC-72399 1.8 Mineral Block Deletion bug MC-76496 Crafting with shift-right-click destroys fractional outputs (e.g. 1-3 planks) when overfilling inventory MC-77319 When breaking down storage block (iron, emerald, gold, etc.) with a full inventory, any more than 64 get deleted MC-94841 Item loss crafting 8 hay bales into wheat with nearly full inventory MC-94987 Converting a stack of iron blocks to ingots loses some iron MC-100639 Inventory items disappear while crafting MC-102809 Crafting Bone Meal MC-103558 Items are lost when shift-click crafting. MC-104799 Item Loss With Shift-Click From Crafting MC-106818 Incorrect breakdown of full stack stack of Blocks of Redstone when insufficient space in inventory

Attachments

Comments

migrated
[media][media][media][media]
migrated

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"

migrated

Affects 1.6.4 and snapshot 13w38c.

migrated

Still a bug in 1.7.2.

migrated

I can verify that this bug still exists in 1.7.2.

migrated

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.

migrated

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

migrated

Confirmed for snapshot 14w18b.

Jeremy

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.

AgentM

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

migrated

Confirmed for 14w27a.

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

migrated

And it's still in 14w28a...

migrated

Confirmed for 14w28a

migrated

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".

migrated

Confirmed for 14w33a.

migrated

Affects version 14w34a.

migrated

and 14w34b

migrated

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

migrated

Confirmed for 1.8-pre1.

migrated

and 1.8-pre2 & 3

migrated

Confirmed for 1.8 official release

migrated

Confirmed for 1.8.1-pre2

migrated

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.

migrated

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 😃

migrated

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".

[Mod] Neko

Confirmed in 1.8.1-pre5

migrated

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).

migrated

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

migrated

Confirmed in 1.8.7.

migrated

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

migrated

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

migrated

It's in 15w33c

migrated

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...

Panda4994

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

migrated

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).

migrated

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.

migrated

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.

CubeTheThird

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

kumasasa

Changed reporter to @unknown

migrated

Still in 15w42a

rydian

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

migrated

Confirmed for 15w46a

rydian

Still happening in 15w47a.

migrated

Confirmed for 15w51b.

migrated

Confirmed for 16w02a.

migrated

Confirmed for 16w03a.

CubeTheThird

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

migrated

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

migrated

Affects 16w04a.

migrated

Still in 16w05b

migrated

Affects 16w06a.

migrated

Affects 16w07a.

migrated

Affects 16w07b.

migrated

Confirmed for 1.9-pre1

migrated

Affects 1.9-pre2

marcono1234

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

migrated

Affects 1.9-pre4.

migrated

Confirmed for 1.9.1-pre3.

migrated

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

migrated

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

kumasasa

@unknown: 1.RV-pre1 is not tracked here.

migrated
migrated

@unknown you can also just say "confirmed for 1.9.2".

migrated

Confirmed for 1.9.3-pre3.

migrated

Confirmed for 1.9.4.

migrated

Confirmed for 16w20a.

FaRo1

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)

migrated

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

migrated

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

migrated

Confirmed for 16w21a.

migrated

Confirmed for 16w21b.

migrated

Confirmed for 1.10-pre1.

migrated

Confirmed for 1.10-pre2.

migrated

Confirmed for 1.10.

migrated

Confirmed for 1.10.1.

marcono1234

Confirmed fixed for 16w32a

Panda4994

Agnes Larsson

Confirmed

Minecraft 1.4.2, Minecraft 1.4.5, Minecraft 1.4.7, Snapshot 13w04a, Snapshot 13w07a, ..., Minecraft 1.10 Pre-Release 1, Minecraft 1.10 Pre-Release 2, Minecraft 1.10, Minecraft 1.10.1, Minecraft 1.10.2

Minecraft 16w32a

Retrieved