diff options
author | SmallJoker <mk939@ymail.com> | 2016-09-06 19:13:52 +0200 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2016-09-08 03:37:03 -0400 |
commit | 2de8c22a9971153d594b2bb4736eb293753f1212 (patch) | |
tree | 65427e44febaa2211107991c2ce006f6fe3ffcfb | |
parent | aa33166386f737f213f1f3005ffd6a6adfd2d97f (diff) | |
download | minetest-2de8c22a9971153d594b2bb4736eb293753f1212.tar.gz minetest-2de8c22a9971153d594b2bb4736eb293753f1212.tar.bz2 minetest-2de8c22a9971153d594b2bb4736eb293753f1212.zip |
Make getStackMax return the correct maximal stack size
-rw-r--r-- | src/inventory.h | 5 | ||||
-rw-r--r-- | src/itemdef.h | 2 | ||||
-rw-r--r-- | src/script/common/c_content.cpp | 5 |
3 files changed, 5 insertions, 7 deletions
diff --git a/src/inventory.h b/src/inventory.h index a690eb5ae..7d7e58d61 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -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; } diff --git a/src/itemdef.h b/src/itemdef.h index b14ed41f7..dcb98e8a9 100644 --- a/src/itemdef.h +++ b/src/itemdef.h @@ -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 diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index c664101ea..19873abc5 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -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); |