Skip to content

Commit a8f6bef

Browse files
authored
Fix short_description fallback order (#10943)
1 parent 7832b68 commit a8f6bef

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

builtin/game/register.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ function core.register_item(name, itemdef)
118118
end
119119
itemdef.name = name
120120

121-
-- default short_description to first line of description
122-
itemdef.short_description = itemdef.short_description or
123-
(itemdef.description or ""):gsub("\n.*","")
124-
125121
-- Apply defaults and add to registered_* table
126122
if itemdef.type == "node" then
127123
-- Use the nodebox as selection box if it's not set manually

doc/lua_api.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6039,18 +6039,18 @@ an itemstring, a table or `nil`.
60396039
stack).
60406040
* `set_metadata(metadata)`: (DEPRECATED) Returns true.
60416041
* `get_description()`: returns the description shown in inventory list tooltips.
6042-
* The engine uses the same as this function for item descriptions.
6042+
* The engine uses this when showing item descriptions in tooltips.
60436043
* Fields for finding the description, in order:
60446044
* `description` in item metadata (See [Item Metadata].)
60456045
* `description` in item definition
60466046
* item name
6047-
* `get_short_description()`: returns the short description.
6047+
* `get_short_description()`: returns the short description or nil.
60486048
* Unlike the description, this does not include new lines.
6049-
* The engine uses the same as this function for short item descriptions.
60506049
* Fields for finding the short description, in order:
60516050
* `short_description` in item metadata (See [Item Metadata].)
60526051
* `short_description` in item definition
6053-
* first line of the description (See `get_description()`.)
6052+
* first line of the description (From item meta or def, see `get_description()`.)
6053+
* Returns nil if none of the above are set
60546054
* `clear()`: removes all items from the stack, making it empty.
60556055
* `replace(item)`: replace the contents of this stack.
60566056
* `item` can also be an itemstring or table.
@@ -7171,8 +7171,9 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and
71717171

71727172
short_description = "Steel Axe",
71737173
-- Must not contain new lines.
7174-
-- Defaults to the first line of description.
7175-
-- See also: `get_short_description` in [`ItemStack`]
7174+
-- Defaults to nil.
7175+
-- Use an [`ItemStack`] to get the short description, eg:
7176+
-- ItemStack(itemname):get_short_description()
71767177

71777178
groups = {},
71787179
-- key = name, value = rating; rating = 1..3.

games/devtest/mods/unittests/itemdescription.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ minetest.register_chatcommand("item_description", {
2626
})
2727

2828
function unittests.test_short_desc()
29+
local function get_short_description(item)
30+
return ItemStack(item):get_short_description()
31+
end
32+
2933
local stack = ItemStack("unittests:colorful_pick")
3034
assert(stack:get_short_description() == "Colorful Pickaxe")
31-
assert(stack:get_short_description() == minetest.registered_items["unittests:colorful_pick"].short_description)
35+
assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe")
36+
assert(minetest.registered_items["unittests:colorful_pick"].short_description == nil)
3237
assert(stack:get_description() == full_description)
3338
assert(stack:get_description() == minetest.registered_items["unittests:colorful_pick"].description)
3439

3540
stack:get_meta():set_string("description", "Hello World")
36-
assert(stack:get_short_description() == "Colorful Pickaxe")
41+
assert(stack:get_short_description() == "Hello World")
3742
assert(stack:get_description() == "Hello World")
43+
assert(get_short_description(stack) == "Hello World")
44+
assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe")
3845

3946
stack:get_meta():set_string("short_description", "Foo Bar")
4047
assert(stack:get_short_description() == "Foo Bar")

src/script/common/c_content.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i)
140140
lua_setfield(L, -2, "name");
141141
lua_pushstring(L, i.description.c_str());
142142
lua_setfield(L, -2, "description");
143-
lua_pushstring(L, i.short_description.c_str());
144-
lua_setfield(L, -2, "short_description");
143+
if (!i.short_description.empty()) {
144+
lua_pushstring(L, i.short_description.c_str());
145+
lua_setfield(L, -2, "short_description");
146+
}
145147
lua_pushstring(L, type.c_str());
146148
lua_setfield(L, -2, "type");
147149
lua_pushstring(L, i.inventory_image.c_str());

0 commit comments

Comments
 (0)