Add per-stack descriptions using ItemStack Metadata 5154/head
authorrubenwardy <rubenwardy@gmail.com>
Fri, 3 Feb 2017 22:28:09 +0000 (22:28 +0000)
committerrubenwardy <rubenwardy@gmail.com>
Sat, 4 Feb 2017 22:07:55 +0000 (22:07 +0000)
doc/lua_api.txt
src/guiFormSpecMenu.cpp

index 2f5e3706c56436eda13d1c564a699b2b81347325..dd20ae9041ac8baa533561eb7276a8e91c7966db 100644 (file)
@@ -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()
index 45b0e9c113d5eb02b25ee283a6ddf9985515dd08..67b3a9ad0d66c14ae97604f965ed82cabbbbd146 100644 (file)
@@ -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');