Skip to content

Commit 2de8c22

Browse files
SmallJokerkwolekr
authored andcommittedSep 8, 2016
Make getStackMax return the correct maximal stack size
1 parent aa33166 commit 2de8c22

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed
 

‎src/inventory.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ struct ItemStack
8080
// Maximum size of a stack
8181
u16 getStackMax(IItemDefManager *itemdef) const
8282
{
83-
s16 max = itemdef->get(name).stack_max;
84-
return (max >= 0) ? max : 0;
83+
return itemdef->get(name).stack_max;
8584
}
8685

8786
// Number of items that can be added to this stack
8887
u16 freeSpace(IItemDefManager *itemdef) const
8988
{
9089
u16 max = getStackMax(itemdef);
91-
if(count > max)
90+
if (count >= max)
9291
return 0;
9392
return max - count;
9493
}

‎src/itemdef.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct ItemDefinition
6161
/*
6262
Item stack and interaction properties
6363
*/
64-
s16 stack_max;
64+
u16 stack_max;
6565
bool usable;
6666
bool liquids_pointable;
6767
// May be NULL. If non-NULL, deleted by destructor

‎src/script/common/c_content.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ ItemDefinition read_item_definition(lua_State* L,int index,
6565
}
6666
lua_pop(L, 1);
6767

68-
def.stack_max = getintfield_default(L, index, "stack_max", def.stack_max);
69-
if(def.stack_max == 0)
70-
def.stack_max = 1;
68+
int stack_max = getintfield_default(L, index, "stack_max", def.stack_max);
69+
def.stack_max = rangelim(stack_max, 1, U16_MAX);
7170

7271
lua_getfield(L, index, "on_use");
7372
def.usable = lua_isfunction(L, -1);

0 commit comments

Comments
 (0)