Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
102 additions
and 2 deletions.
- +6 −0 builtin/game/register.lua
- +10 −0 doc/lua_api.txt
- +2 −0 games/devtest/mods/unittests/init.lua
- +44 −0 games/devtest/mods/unittests/itemdescription.lua
- +14 −0 src/inventory.cpp
- +1 −0 src/inventory.h
- +7 −2 src/itemdef.cpp
- +1 −0 src/itemdef.h
- +3 −0 src/script/common/c_content.cpp
- +11 −0 src/script/lua_api/l_item.cpp
- +3 −0 src/script/lua_api/l_item.h
@@ -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 |