Skip to content

Commit

Permalink
Make getStackMax return the correct maximal stack size
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker authored and kwolekr committed Sep 8, 2016
1 parent aa33166 commit 2de8c22
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/inventory.h
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/itemdef.h
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/script/common/c_content.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 2de8c22

Please sign in to comment.