Initial commit
[minetest_tt.git] / init.lua
blob041c5d248b80d206f0bc065435f3da6ba0371bac
1 local S = minetest.get_translator("tt")
2 local COLOR_DEFAULT = "#d0ffd0"
3 local COLOR_DANGER = "#ffff00"
4 local COLOR_GOOD = "#00ff00"
6 tt = {}
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
14 -- Custom text
15 if def._tt_help then
16 desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, def._tt_help)
17 end
18 -- Tool info
19 if def.tool_capabilities then
20 -- Digging stats
21 if def.tool_capabilities.groupcaps then
22 -- TODO: Add more detail (such as digging speed)
23 --local groups = {}
24 --for group, caps in pairs(def.tool_capabilities.groupcaps) do
25 -- table.insert(groups, group)
26 --end
27 --desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Digs: @1", table.concat(groups, ", ")))
28 end
29 -- Weapon stats
30 if def.tool_capabilities.damage_groups then
31 for group, damage in pairs(def.tool_capabilities.damage_groups) do
32 local msg
33 if group == "fleshy" then
34 if damage >= 0 then
35 msg = S("Damage: @1", damage)
36 else
37 msg = S("Healing: @1", math.abs(damage))
38 end
39 else
40 if damage >= 0 then
41 msg = S("Damage (@1): @2", group, damage)
42 else
43 msg = S("Healing (@1): @2", group, math.abs(damage))
44 end
45 end
46 desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, msg)
47 end
48 local full_punch_interval = def.tool_capabilities.full_punch_interval
49 if not full_punch_interval then
50 full_punch_interval = 1
51 end
52 desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Full punch interval: @1s", full_punch_interval))
53 end
54 end
55 -- Food
56 if def._tt_food then
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)
61 end
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)
66 else
67 msg = S("@1 satiation", def._tt_food_satiation)
68 end
69 desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, msg)
70 end]]
71 end
72 -- Node info
73 -- Damage-related
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)))
80 end
81 end
82 if def.drowning and def.drowning ~= 0 then
83 desc = desc .. "\n" .. minetest.colorize(COLOR_DANGER, S("Drowning damage: @1", def.drowning))
84 end
85 local tmp = minetest.get_item_group(itemstring, "fall_damage_add_percent")
86 if tmp > 0 then
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"))
90 elseif tmp < 0 then
91 desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Fall damage: @1%", tmp))
92 end
93 end
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"))
98 else
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)"))
105 else
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")
113 if tmp >= 1 then
114 desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Bouncy (@1%)", tmp))
116 -- Node appearance
117 tmp = def.light_source
118 if tmp and tmp >= 1 then
119 desc = desc .. "\n" .. minetest.colorize(COLOR_DEFAULT, S("Luminance: @1", tmp))
121 -- Custom functions
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
127 if str then
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)