summaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorDS <vorunbekannt75@web.de>2020-10-09 20:11:21 +0200
committerGitHub <noreply@github.com>2020-10-09 19:11:21 +0100
commitf3ae45b2b245dd0aeb4a7d9b76afaf078871104c (patch)
treef9b0e27043bbe8f2b16e6f4917f6b9a92f273345 /games
parentb2f3f663858e6d2a2174066e425bb6f2edea910b (diff)
downloadminetest-f3ae45b2b245dd0aeb4a7d9b76afaf078871104c.tar.gz
minetest-f3ae45b2b245dd0aeb4a7d9b76afaf078871104c.tar.bz2
minetest-f3ae45b2b245dd0aeb4a7d9b76afaf078871104c.zip
Add a short_description to be used by mods (#8980)
Diffstat (limited to 'games')
-rw-r--r--games/devtest/mods/unittests/init.lua2
-rw-r--r--games/devtest/mods/unittests/itemdescription.lua44
2 files changed, 46 insertions, 0 deletions
diff --git a/games/devtest/mods/unittests/init.lua b/games/devtest/mods/unittests/init.lua
index 6c1728420..12c67f78b 100644
--- a/games/devtest/mods/unittests/init.lua
+++ b/games/devtest/mods/unittests/init.lua
@@ -5,10 +5,12 @@ dofile(modpath .. "/random.lua")
dofile(modpath .. "/player.lua")
dofile(modpath .. "/crafting_prepare.lua")
dofile(modpath .. "/crafting.lua")
+dofile(modpath .. "/itemdescription.lua")
if minetest.settings:get_bool("devtest_unittests_autostart", false) then
unittests.test_random()
unittests.test_crafting()
+ unittests.test_short_desc()
minetest.register_on_joinplayer(function(player)
unittests.test_player(player)
end)
diff --git a/games/devtest/mods/unittests/itemdescription.lua b/games/devtest/mods/unittests/itemdescription.lua
new file mode 100644
index 000000000..1d0826545
--- /dev/null
+++ b/games/devtest/mods/unittests/itemdescription.lua
@@ -0,0 +1,44 @@
+local full_description = "Colorful Pickaxe\nThe best pick."
+minetest.register_tool("unittests:colorful_pick", {
+ description = full_description,
+ inventory_image = "basetools_mesepick.png",
+ tool_capabilities = {
+ full_punch_interval = 1.0,
+ max_drop_level=3,
+ groupcaps={
+ cracky={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3},
+ crumbly={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3},
+ snappy={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=20, maxlevel=3}
+ },
+ damage_groups = {fleshy=4},
+ },
+})
+
+minetest.register_chatcommand("item_description", {
+ param = "",
+ description = "Show the short and full description of the wielded item.",
+ func = function(name)
+ local player = minetest.get_player_by_name(name)
+ local item = player:get_wielded_item()
+ return true, string.format("short_description: %s\ndescription: %s",
+ item:get_short_description(), item:get_description())
+ end
+})
+
+function unittests.test_short_desc()
+ 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(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_description() == "Hello World")
+
+ stack:get_meta():set_string("short_description", "Foo Bar")
+ assert(stack:get_short_description() == "Foo Bar")
+ assert(stack:get_description() == "Hello World")
+
+ return true
+end