1 local S
= minetest
.get_translator("tt")
2 local COLOR_DEFAULT
= "#d0ffd0"
3 local COLOR_DANGER
= "#ffff00"
4 local COLOR_GOOD
= "#00ff00"
7 tt
.registered_snippets
= {}
9 local function append_descs()
10 for itemstring
, def
in pairs(minetest
.registered_items
) do
11 if itemstring
~= "" and itemstring
~= "air" and itemstring
~= "ignore" and itemstring
~= "unknown" and def
~= nil and def
.description
~= nil and def
.description
~= "" and def
._tt_ignore
~= true then
12 local desc
= def
.description
13 local orig_desc
= desc
16 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, def
._tt_help
)
19 if def
.tool_capabilities
then
21 if def
.tool_capabilities
.groupcaps
then
22 -- TODO: Add more detail (such as digging speed)
24 --for group, caps in pairs(def.tool_capabilities.groupcaps) do
25 -- table.insert(groups, group)
27 --desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Digs: @1", table.concat(groups, ", ")))
30 if def
.tool_capabilities
.damage_groups
then
31 for group
, damage
in pairs(def
.tool_capabilities
.damage_groups
) do
33 if group
== "fleshy" then
35 msg
= S("Damage: @1", damage
)
37 msg
= S("Healing: @1", math
.abs(damage
))
41 msg
= S("Damage (@1): @2", group
, damage
)
43 msg
= S("Healing (@1): @2", group
, math
.abs(damage
))
46 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, msg
)
48 local full_punch_interval
= def
.tool_capabilities
.full_punch_interval
49 if not full_punch_interval
then
50 full_punch_interval
= 1
52 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Full punch interval: @1s", full_punch_interval
))
57 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Food item"))
58 if def
._tt_food_hp
then
59 local msg
= S("+@1 food points", def
._tt_food_hp
)
60 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, msg
)
62 -- NOTE: This is unused atm
63 --[[if def._tt_food_satiation then
64 if def._tt_food_satiation >= 0 then
65 msg = S("+@1 satiation", def._tt_food_satiation)
67 msg = S("@1 satiation", def._tt_food_satiation)
69 desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, msg)
75 if def
.damage_per_second
then
76 if def
.damage_per_second
> 0 then
77 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DANGER
, S("Contact damage: @1 per second", def
.damage_per_second
))
78 elseif def
.damage_per_second
< 0 then
79 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_GOOD
, S("Contact healing: @1 per second", math
.abs(def
.damage_per_second
)))
82 if def
.drowning
and def
.drowning
~= 0 then
83 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DANGER
, S("Drowning damage: @1", def
.drowning
))
85 local tmp
= minetest
.get_item_group(itemstring
, "fall_damage_add_percent")
87 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DANGER
, S("Fall damage: +@1%", tmp
))
88 elseif tmp
== -100 then
89 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_GOOD
, S("No fall damage"))
91 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Fall damage: @1%", tmp
))
94 -- Movement-related node facts
95 if minetest
.get_item_group(itemstring
, "disable_jump") == 1 and not def
.climbable
then
96 if def
.liquidtype
== "none" then
97 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("No jumping"))
99 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("No swimming upwards"))
102 if def
.climbable
then
103 if minetest
.get_item_group(itemstring
, "disable_jump") == 1 then
104 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Climbable (only downwards)"))
106 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Climbable"))
109 if minetest
.get_item_group(itemstring
, "slippery") >= 1 then
110 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Slippery"))
112 local tmp
= minetest
.get_item_group(itemstring
, "bouncy")
114 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Bouncy (@1%)", tmp
))
117 tmp
= def
.light_source
118 if tmp
and tmp
>= 1 then
119 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Luminance: @1", tmp
))
122 for s
=1, #tt
.registered_snippets
do
123 local str
, snippet_color
= tt
.registered_snippets
[s
](itemstring
)
124 if not snippet_color
then
125 snippet_color
= COLOR_DEFAULT
128 desc
= desc
.. "\n" .. minetest
.colorize(snippet_color
, str
)
132 minetest
.override_item(itemstring
, { description
= desc
, _tt_original_description
= orig_desc
})
137 tt
.register_snippet
= function(func
)
138 table.insert(tt
.registered_snippets
, func
)
141 minetest
.register_on_mods_loaded(append_descs
)