Skip to content

Commit

Permalink
Add per-stack descriptions using ItemStack Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Feb 4, 2017
1 parent f2aa2c6 commit f2f9a92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/lua_api.txt
Expand Up @@ -1473,6 +1473,10 @@ Item stacks can store metadata too. See `ItemStackMetaRef`.

Item metadata only contains a key-value store.

Some of the values in the key-value store are handled specially:

* `description`: Set the itemstack's description. Defaults to idef.description

Example stuff:

local meta = stack:get_meta()
Expand Down
7 changes: 6 additions & 1 deletion src/guiFormSpecMenu.cpp
Expand Up @@ -2303,7 +2303,12 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase,
// Draw tooltip
std::wstring tooltip_text = L"";
if (hovering && !m_selected_item) {
tooltip_text = utf8_to_wide(item.getDefinition(m_client->idef()).description);
const std::string &desc = item.metadata.getString("description");
if (desc.empty())
tooltip_text =
utf8_to_wide(item.getDefinition(m_client->idef()).description);
else
tooltip_text = utf8_to_wide(desc);
}
if (tooltip_text != L"") {
std::vector<std::wstring> tt_rows = str_split(tooltip_text, L'\n');
Expand Down

0 comments on commit f2f9a92

Please sign in to comment.