diff options
-rw-r--r-- | builtin/game/register.lua | 4 | ||||
-rw-r--r-- | doc/lua_api.txt | 13 | ||||
-rw-r--r-- | games/devtest/mods/unittests/itemdescription.lua | 11 | ||||
-rw-r--r-- | src/script/common/c_content.cpp | 6 |
4 files changed, 20 insertions, 14 deletions
diff --git a/builtin/game/register.lua b/builtin/game/register.lua index b006957e9..1cff85813 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -118,10 +118,6 @@ function core.register_item(name, itemdef) end itemdef.name = name - -- default short_description to first line of description - itemdef.short_description = itemdef.short_description or - (itemdef.description or ""):gsub("\n.*","") - -- Apply defaults and add to registered_* table if itemdef.type == "node" then -- Use the nodebox as selection box if it's not set manually diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 7b7825614..a09b98924 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6039,18 +6039,18 @@ an itemstring, a table or `nil`. stack). * `set_metadata(metadata)`: (DEPRECATED) Returns true. * `get_description()`: returns the description shown in inventory list tooltips. - * The engine uses the same as this function for item descriptions. + * The engine uses this when showing item descriptions in tooltips. * Fields for finding the description, in order: * `description` in item metadata (See [Item Metadata].) * `description` in item definition * item name -* `get_short_description()`: returns the short description. +* `get_short_description()`: returns the short description or nil. * Unlike the description, this does not include new lines. - * The engine uses the same as this function for short item descriptions. * Fields for finding the short description, in order: * `short_description` in item metadata (See [Item Metadata].) * `short_description` in item definition - * first line of the description (See `get_description()`.) + * first line of the description (From item meta or def, see `get_description()`.) + * Returns nil if none of the above are set * `clear()`: removes all items from the stack, making it empty. * `replace(item)`: replace the contents of this stack. * `item` can also be an itemstring or table. @@ -7171,8 +7171,9 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and short_description = "Steel Axe", -- Must not contain new lines. - -- Defaults to the first line of description. - -- See also: `get_short_description` in [`ItemStack`] + -- Defaults to nil. + -- Use an [`ItemStack`] to get the short description, eg: + -- ItemStack(itemname):get_short_description() groups = {}, -- key = name, value = rating; rating = 1..3. diff --git a/games/devtest/mods/unittests/itemdescription.lua b/games/devtest/mods/unittests/itemdescription.lua index 1d0826545..d6ee6551a 100644 --- a/games/devtest/mods/unittests/itemdescription.lua +++ b/games/devtest/mods/unittests/itemdescription.lua @@ -26,15 +26,22 @@ minetest.register_chatcommand("item_description", { }) function unittests.test_short_desc() + local function get_short_description(item) + return ItemStack(item):get_short_description() + end + local stack = ItemStack("unittests:colorful_pick") assert(stack:get_short_description() == "Colorful Pickaxe") - assert(stack:get_short_description() == minetest.registered_items["unittests:colorful_pick"].short_description) + assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe") + assert(minetest.registered_items["unittests:colorful_pick"].short_description == nil) assert(stack:get_description() == full_description) assert(stack:get_description() == minetest.registered_items["unittests:colorful_pick"].description) stack:get_meta():set_string("description", "Hello World") - assert(stack:get_short_description() == "Colorful Pickaxe") + assert(stack:get_short_description() == "Hello World") assert(stack:get_description() == "Hello World") + assert(get_short_description(stack) == "Hello World") + assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe") stack:get_meta():set_string("short_description", "Foo Bar") assert(stack:get_short_description() == "Foo Bar") diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index ecab7baa1..2f9fbd74b 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -140,8 +140,10 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i) lua_setfield(L, -2, "name"); lua_pushstring(L, i.description.c_str()); lua_setfield(L, -2, "description"); - lua_pushstring(L, i.short_description.c_str()); - lua_setfield(L, -2, "short_description"); + if (!i.short_description.empty()) { + lua_pushstring(L, i.short_description.c_str()); + lua_setfield(L, -2, "short_description"); + } lua_pushstring(L, type.c_str()); lua_setfield(L, -2, "type"); lua_pushstring(L, i.inventory_image.c_str()); |