Fix bug: drop single item cause exception

This commit is contained in:
BruceChen 2022-07-25 17:08:59 +08:00
parent f0af851df8
commit cbe348555b

View file

@ -1537,12 +1537,17 @@ namespace MinecraftClient
break; break;
case WindowActionType.DropItem: case WindowActionType.DropItem:
if (inventory.Items.ContainsKey(slotId)) if (inventory.Items.ContainsKey(slotId))
{
inventory.Items[slotId].Count--; inventory.Items[slotId].Count--;
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
}
if (inventory.Items[slotId].Count <= 0) if (inventory.Items[slotId].Count <= 0)
{
inventory.Items.Remove(slotId); inventory.Items.Remove(slotId);
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
}
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
break; break;
case WindowActionType.DropItemStack: case WindowActionType.DropItemStack:
inventory.Items.Remove(slotId); inventory.Items.Remove(slotId);