Make getStackMax return the correct maximal stack size
authorSmallJoker <mk939@ymail.com>
Tue, 6 Sep 2016 17:13:52 +0000 (19:13 +0200)
committerkwolekr <kwolekr@minetest.net>
Thu, 8 Sep 2016 07:37:03 +0000 (03:37 -0400)
src/inventory.h
src/itemdef.h
src/script/common/c_content.cpp

index a690eb5ae29d825b4635888d23d1a0aa407fb738..7d7e58d610d9f5ae48ce7d65dd208748f07022d1 100644 (file)
@@ -80,15 +80,14 @@ struct ItemStack
        // Maximum size of a stack
        u16 getStackMax(IItemDefManager *itemdef) const
        {
-               s16 max = itemdef->get(name).stack_max;
-               return (max >= 0) ? max : 0;
+               return itemdef->get(name).stack_max;
        }
 
        // Number of items that can be added to this stack
        u16 freeSpace(IItemDefManager *itemdef) const
        {
                u16 max = getStackMax(itemdef);
-               if(count > max)
+               if (count >= max)
                        return 0;
                return max - count;
        }
index b14ed41f7f2a5a0b21acea8a436c98db4f454585..dcb98e8a945d01c49e2e3bb1010d6493516765ab 100644 (file)
@@ -61,7 +61,7 @@ struct ItemDefinition
        /*
                Item stack and interaction properties
        */
-       s16 stack_max;
+       u16 stack_max;
        bool usable;
        bool liquids_pointable;
        // May be NULL. If non-NULL, deleted by destructor
index c664101eaba6825acd21251a1cdb55fe9b91f6af..19873abc552e5d5c92199c4db34497579fd04571 100644 (file)
@@ -65,9 +65,8 @@ ItemDefinition read_item_definition(lua_State* L,int index,
        }
        lua_pop(L, 1);
 
-       def.stack_max = getintfield_default(L, index, "stack_max", def.stack_max);
-       if(def.stack_max == 0)
-               def.stack_max = 1;
+       int stack_max = getintfield_default(L, index, "stack_max", def.stack_max);
+       def.stack_max = rangelim(stack_max, 1, U16_MAX);
 
        lua_getfield(L, index, "on_use");
        def.usable = lua_isfunction(L, -1);