Skip to content

Commit

Permalink
Fix wrong meta key in item meta on ItemStack construction
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy authored and sofar committed Feb 22, 2017
1 parent 01b2d2c commit 2d1fca5
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/script/common/c_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,29 +827,13 @@ ItemStack read_item(lua_State* L, int index,Server* srv)

ItemStack istack(name, count, wear, idef);

lua_getfield(L, index, "metadata");

// Support old metadata format by checking type
int fieldstable = lua_gettop(L);
if (lua_istable(L, fieldstable)) {
lua_pushnil(L);
while (lua_next(L, fieldstable) != 0) {
// key at index -2 and value at index -1
std::string key = lua_tostring(L, -2);
size_t value_len;
const char *value_cs = lua_tolstring(L, -1, &value_len);
std::string value(value_cs, value_len);
istack.metadata.setString(name, value);
lua_pop(L, 1); // removes value, keeps key for next iteration
}
} else {
// BACKWARDS COMPATIBLITY
std::string value = getstringfield_default(L, index, "metadata", "");
istack.metadata.setString("", value);
}
// BACKWARDS COMPATIBLITY
std::string value = getstringfield_default(L, index, "metadata", "");
istack.metadata.setString("", value);

// Get meta
lua_getfield(L, index, "meta");
fieldstable = lua_gettop(L);
int fieldstable = lua_gettop(L);
if (lua_istable(L, fieldstable)) {
lua_pushnil(L);
while (lua_next(L, fieldstable) != 0) {
Expand All @@ -858,7 +842,7 @@ ItemStack read_item(lua_State* L, int index,Server* srv)
size_t value_len;
const char *value_cs = lua_tolstring(L, -1, &value_len);
std::string value(value_cs, value_len);
istack.metadata.setString(name, value);
istack.metadata.setString(key, value);
lua_pop(L, 1); // removes value, keeps key for next iteration
}
}
Expand Down

0 comments on commit 2d1fca5

Please sign in to comment.