Skip to content

Commit

Permalink
Do not add group values of zero to group lists. (#8751)
Browse files Browse the repository at this point in the history
This fixes an issue where when the engine looked up groups (for example,
in ABM node names), NodeDefManager's m_group_to_items would contain nodes
with a group value of zero, resulting in nodes with flammable = 0 being
burned by a fire mod with a group:flammable checking ABM.

It brings consistency to the behaviour described in the api
documentation, where zero and nil groups should be the same.
  • Loading branch information
linewriter1024 authored and sfan5 committed Aug 7, 2019
1 parent 233cb86 commit 4d7f296
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/script/common/c_content.cpp
Expand Up @@ -1529,13 +1529,15 @@ void read_groups(lua_State *L, int index, ItemGroupList &result)
return;
result.clear();
lua_pushnil(L);
if(index < 0)
if (index < 0)
index -= 1;
while(lua_next(L, index) != 0){
while (lua_next(L, index) != 0) {
// key at index -2 and value at index -1
std::string name = luaL_checkstring(L, -2);
int rating = luaL_checkinteger(L, -1);
result[name] = rating;
// zero rating indicates not in the group
if (rating != 0)
result[name] = rating;
// removes value, keeps key for next iteration
lua_pop(L, 1);
}
Expand Down

0 comments on commit 4d7f296

Please sign in to comment.