}
-ItemStack ItemStack::addItem(const ItemStack &newitem_,
- IItemDefManager *itemdef)
+ItemStack ItemStack::addItem(ItemStack newitem, IItemDefManager *itemdef)
{
- ItemStack newitem = newitem_;
-
// If the item is empty or the position invalid, bail out
if(newitem.empty())
{
// If this is an empty item, it's an easy job.
else if(empty())
{
+ const u16 stackMax = newitem.getStackMax(itemdef);
+
*this = newitem;
- newitem.clear();
+
+ // If the item fits fully, delete it
+ if (count <= stackMax) {
+ newitem.clear();
+ } else { // Else the item does not fit fully. Return the rest.
+ count = stackMax;
+ newitem.remove(count);
+ }
}
// If item name or metadata differs, bail out
else if (name != newitem.name
return newitem;
}
-bool ItemStack::itemFits(const ItemStack &newitem_,
+bool ItemStack::itemFits(ItemStack newitem,
ItemStack *restitem,
IItemDefManager *itemdef) const
{
- ItemStack newitem = newitem_;
// If the item is empty or the position invalid, bail out
if(newitem.empty())
// If this is an empty item, it's an easy job.
else if(empty())
{
- newitem.clear();
+ const u16 stackMax = newitem.getStackMax(itemdef);
+
+ // If the item fits fully, delete it
+ if (newitem.count <= stackMax) {
+ newitem.clear();
+ } else { // Else the item does not fit fully. Return the rest.
+ newitem.remove(stackMax);
+ }
}
// If item name or metadata differs, bail out
else if (name != newitem.name
newitem.clear();
}
// Else the item does not fit fully. Return the rest.
- // the rest.
else
{
u16 freespace = freeSpace(itemdef);