Initial commit (import from tt)
[minetest_tt_base.git] / init.lua
blob4ea8a00604da342646089aebf83d2c27b6542044
1 local S = minetest.get_translator("tt_base")
3 local function get_min_digtime(caps)
4 local mintime
5 local unique = true
6 local maxlevel = caps.maxlevel
7 if not maxlevel then
8 maxlevel = 1
9 end
10 if maxlevel > 1 then
11 unique = false
12 end
13 if caps.times then
14 for r=1,3 do
15 local time = caps.times[r]
16 if time and maxlevel > 1 then
17 time = time / maxlevel
18 end
19 if time and ((not mintime) or (time < mintime)) then
20 if mintime and (time < mintime) then
21 unique = false
22 end
23 mintime = time
24 end
25 end
26 end
27 return mintime, unique
28 end
30 local function newline(str)
31 if str ~= "" then
32 str = str .. "\n"
33 end
34 return str
35 end
37 -- Tool information (digging times, weapon stats)
38 tt.register_snippet(function(itemstring)
39 local def = minetest.registered_items[itemstring]
40 local desc = ""
41 if def.tool_capabilities then
42 -- Digging times
43 local digs = ""
44 local d
45 if def.tool_capabilities.groupcaps then
46 for group, caps in pairs(def.tool_capabilities.groupcaps) do
47 local mintime, unique_mintime
48 if caps.times then
49 mintime, unique_mintime = get_min_digtime(caps)
50 if mintime and (mintime > 0 or (not unique_mintime)) then
51 d = S("Digs @1 blocks", group) .. "\n"
52 d = d .. S("Minimum dig time: @1s", string.format("%.2f", mintime))
53 digs = newline(digs)
54 digs = digs .. d
55 elseif mintime and mintime == 0 then
56 d = S("Digs @1 blocks instantly", group)
57 digs = newline(digs)
58 digs = digs .. d
59 end
60 end
61 end
62 if digs ~= "" then
63 desc = desc .. digs
64 end
65 end
66 -- Weapon stats
67 if def.tool_capabilities.damage_groups then
68 for group, damage in pairs(def.tool_capabilities.damage_groups) do
69 local msg
70 if group == "fleshy" then
71 if damage >= 0 then
72 msg = S("Damage: @1", damage)
73 else
74 msg = S("Healing: @1", math.abs(damage))
75 end
76 else
77 if damage >= 0 then
78 msg = S("Damage (@1): @2", group, damage)
79 else
80 msg = S("Healing (@1): @2", group, math.abs(damage))
81 end
82 end
83 desc = newline(desc)
84 desc = desc .. msg
85 end
86 local full_punch_interval = def.tool_capabilities.full_punch_interval
87 if not full_punch_interval then
88 full_punch_interval = 1
89 end
90 desc = newline(desc)
91 desc = desc .. S("Full punch interval: @1s", string.format("%.2f", full_punch_interval))
92 end
93 end
94 if desc == "" then
95 desc = nil
96 end
97 return desc
98 end)
100 -- Food
101 tt.register_snippet(function(itemstring)
102 local def = minetest.registered_items[itemstring]
103 local desc
104 if def._tt_food then
105 desc = S("Food item")
106 if def._tt_food_hp then
107 local msg = S("+@1 food points", def._tt_food_hp)
108 desc = desc .. "\n" .. msg
111 return desc
112 end)
114 -- Node info
115 tt.register_snippet(function(itemstring)
116 local def = minetest.registered_items[itemstring]
117 local desc = ""
119 -- Health-related node facts
120 if def.damage_per_second then
121 if def.damage_per_second > 0 then
122 desc = newline(desc)
123 desc = desc .. minetest.colorize(tt.COLOR_DANGER, S("Contact damage: @1 per second", def.damage_per_second))
124 elseif def.damage_per_second < 0 then
125 desc = newline(desc)
126 desc = desc .. minetest.colorize(tt.COLOR_GOOD, S("Contact healing: @1 per second", math.abs(def.damage_per_second)))
129 if def.drowning and def.drowning ~= 0 then
130 desc = newline(desc)
131 desc = desc .. minetest.colorize(tt.COLOR_DANGER, S("Drowning damage: @1", def.drowning))
133 local tmp = minetest.get_item_group(itemstring, "fall_damage_add_percent")
134 if tmp > 0 then
135 desc = newline(desc)
136 desc = desc .. minetest.colorize(tt.COLOR_DANGER, S("Fall damage: +@1%", tmp))
137 elseif tmp == -100 then
138 desc = newline(desc)
139 desc = desc .. minetest.colorize(tt.COLOR_GOOD, S("No fall damage"))
140 elseif tmp < 0 then
141 desc = newline(desc)
142 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Fall damage: @1%", tmp))
145 -- Movement-related node facts
146 if minetest.get_item_group(itemstring, "disable_jump") == 1 and not def.climbable then
147 if def.liquidtype == "none" then
148 desc = newline(desc)
149 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("No jumping"))
150 elseif minetest.get_item_group(itemstring, "fake_liquid") == 0 then
151 desc = newline(desc)
152 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("No swimming upwards"))
153 else
154 desc = newline(desc)
155 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("No rising"))
158 if def.climbable then
159 if minetest.get_item_group(itemstring, "disable_jump") == 1 then
160 desc = newline(desc)
161 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Climbable (only downwards)"))
162 else
163 desc = newline(desc)
164 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Climbable"))
167 if minetest.get_item_group(itemstring, "slippery") >= 1 then
168 desc = newline(desc)
169 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Slippery"))
171 local tmp = minetest.get_item_group(itemstring, "bouncy")
172 if tmp >= 1 then
173 desc = newline(desc)
174 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Bouncy (@1%)", tmp))
177 -- Node appearance
178 tmp = def.light_source
179 if tmp and tmp >= 1 then
180 desc = newline(desc)
181 desc = desc .. minetest.colorize(tt.COLOR_DEFAULT, S("Luminance: @1", tmp))
185 if desc == "" then
186 desc = nil
188 return desc, false
189 end)