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 get_min_digtime(caps
)
12 if caps
.maxlevel
and caps
.maxlevel
> 1 then
17 local time
= caps
.times
[r
]
18 if caps
.maxlevel
and caps
.maxlevel
> 1 then
19 time
= time
/ caps
.maxlevel
21 if (not mintime
) or (time
and time
< mintime
) then
22 if time
and mintime
and (time
< mintime
) then
29 return mintime
, unique
32 tt
.register_snippet
= function(func
)
33 table.insert(tt
.registered_snippets
, func
)
38 tt
.register_snippet(function(itemstring
)
39 local def
= minetest
.registered_items
[itemstring
]
42 return def
._tt_help
, false
46 tt
.register_snippet(function(itemstring
)
47 local def
= minetest
.registered_items
[itemstring
]
50 if def
.tool_capabilities
then
54 if def
.tool_capabilities
.groupcaps
then
55 for group
, caps
in pairs(def
.tool_capabilities
.groupcaps
) do
56 local mintime
, unique_mintime
58 mintime
, unique_mintime
= get_min_digtime(caps
)
59 if mintime
and (mintime
> 0 and (not unique_mintime
)) then
60 d
= S("Digs @1 blocks", group
) .. "\n"
61 d
= d
.. S("Minimum dig time: @1s", string.format("%.2f", mintime
))
62 digs
= digs
.. "\n" .. d
63 elseif mintime
and mintime
== 0 then
64 d
= S("Digs @1 blocks instantly", group
)
65 digs
= digs
.. "\n" .. d
70 desc
= desc
.. minetest
.colorize(COLOR_DEFAULT
, digs
)
74 if def
.tool_capabilities
.damage_groups
then
75 for group
, damage
in pairs(def
.tool_capabilities
.damage_groups
) do
77 if group
== "fleshy" then
79 msg
= S("Damage: @1", damage
)
81 msg
= S("Healing: @1", math
.abs(damage
))
85 msg
= S("Damage (@1): @2", group
, damage
)
87 msg
= S("Healing (@1): @2", group
, math
.abs(damage
))
90 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, msg
)
92 local full_punch_interval
= def
.tool_capabilities
.full_punch_interval
93 if not full_punch_interval
then
94 full_punch_interval
= 1
96 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Full punch interval: @1s", full_punch_interval
))
105 tt
.register_snippet(function(itemstring
)
106 local def
= minetest
.registered_items
[itemstring
]
110 desc
= S("Food item")
111 if def
._tt_food_hp
then
112 local msg
= S("+@1 food points", def
._tt_food_hp
)
113 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, msg
)
119 tt
.register_snippet(function(itemstring
)
120 local def
= minetest
.registered_items
[itemstring
]
123 if def
.damage_per_second
then
124 if def
.damage_per_second
> 0 then
125 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DANGER
, S("Contact damage: @1 per second", def
.damage_per_second
))
126 elseif def
.damage_per_second
< 0 then
127 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_GOOD
, S("Contact healing: @1 per second", math
.abs(def
.damage_per_second
)))
130 if def
.drowning
and def
.drowning
~= 0 then
131 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DANGER
, S("Drowning damage: @1", def
.drowning
))
133 local tmp
= minetest
.get_item_group(itemstring
, "fall_damage_add_percent")
135 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DANGER
, S("Fall damage: +@1%", tmp
))
136 elseif tmp
== -100 then
137 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_GOOD
, S("No fall damage"))
139 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Fall damage: @1%", tmp
))
141 -- Movement-related node facts
142 if minetest
.get_item_group(itemstring
, "disable_jump") == 1 and not def
.climbable
then
143 if def
.liquidtype
== "none" then
144 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("No jumping"))
146 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("No swimming upwards"))
149 if def
.climbable
then
150 if minetest
.get_item_group(itemstring
, "disable_jump") == 1 then
151 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Climbable (only downwards)"))
153 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Climbable"))
156 if minetest
.get_item_group(itemstring
, "slippery") >= 1 then
157 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Slippery"))
159 local tmp
= minetest
.get_item_group(itemstring
, "bouncy")
161 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Bouncy (@1%)", tmp
))
164 tmp
= def
.light_source
165 if tmp
and tmp
>= 1 then
166 desc
= desc
.. "\n" .. minetest
.colorize(COLOR_DEFAULT
, S("Luminance: @1", tmp
))
175 -- Apply item description update
177 local function append_descs()
178 for itemstring
, def
in pairs(minetest
.registered_items
) do
179 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
180 local desc
= def
.description
181 local orig_desc
= desc
184 for s
=1, #tt
.registered_snippets
do
185 local str
, snippet_color
= tt
.registered_snippets
[s
](itemstring
)
186 if snippet_color
== nil then
187 snippet_color
= COLOR_DEFAULT
188 elseif snippet_color
== false then
189 snipped_color
= false
197 if snippet_color
== false then
198 desc
= desc
.. minetest
.colorize(snippet_color
, str
)
204 if desc
~= def
.description
then
205 minetest
.override_item(itemstring
, { description
= desc
, _tt_original_description
= orig_desc
})
211 minetest
.register_on_mods_loaded(append_descs
)