Move core snippets to snippets.lua
[minetest_tt.git] / snippets.lua
blob449cc9a70d6cd7c76d57ef3c3f1b65868a18987b
1 local S = minetest.get_translator("tt")
3 local function get_min_digtime(caps)
4 local mintime
5 local unique = true
6 if caps.maxlevel and caps.maxlevel > 1 then
7 unique = false
8 end
9 if caps.times then
10 for r=1,3 do
11 local time = caps.times[r]
12 if caps.maxlevel and caps.maxlevel > 1 then
13 time = time / caps.maxlevel
14 end
15 if (not mintime) or (time and time < mintime) then
16 if time and mintime and (time < mintime) then
17 unique = false
18 end
19 mintime = time
20 end
21 end
22 end
23 return mintime, unique
24 end
26 -- CORE SNIPPETS --
28 -- Custom text (_tt_help)
29 tt.register_snippet(function(itemstring)
30 local def = minetest.registered_items[itemstring]
31 if def._tt_help then
32 return def._tt_help, false
33 end
34 end)
36 -- Tool information (digging times, weapon stats)
37 tt.register_snippet(function(itemstring)
38 local def = minetest.registered_items[itemstring]
39 local desc = ""
40 if def.tool_capabilities then
41 -- Digging times
42 local digs = ""
43 local d
44 if def.tool_capabilities.groupcaps then
45 for group, caps in pairs(def.tool_capabilities.groupcaps) do
46 local mintime, unique_mintime
47 if caps.times then
48 mintime, unique_mintime = get_min_digtime(caps)
49 if mintime and (mintime > 0 and (not unique_mintime)) then
50 d = S("Digs @1 blocks", group) .. "\n"
51 d = d .. S("Minimum dig time: @1s", string.format("%.2f", mintime))
52 digs = digs .. "\n" .. d
53 elseif mintime and mintime == 0 then
54 d = S("Digs @1 blocks instantly", group)
55 digs = digs .. "\n" .. d
56 end
57 end
58 end
59 if digs ~= "" then
60 desc = desc .. digs
61 end
62 end
63 -- Weapon stats
64 if def.tool_capabilities.damage_groups then
65 for group, damage in pairs(def.tool_capabilities.damage_groups) do
66 local msg
67 if group == "fleshy" then
68 if damage >= 0 then
69 msg = S("Damage: @1", damage)
70 else
71 msg = S("Healing: @1", math.abs(damage))
72 end
73 else
74 if damage >= 0 then
75 msg = S("Damage (@1): @2", group, damage)
76 else
77 msg = S("Healing (@1): @2", group, math.abs(damage))
78 end
79 end
80 desc = desc .. "\n" .. msg
81 end
82 local full_punch_interval = def.tool_capabilities.full_punch_interval
83 if not full_punch_interval then
84 full_punch_interval = 1
85 end
86 desc = desc .. "\n" .. S("Full punch interval: @1s", full_punch_interval)
87 end
88 end
89 if desc == "" then
90 desc = nil
91 end
92 return desc
93 end)
95 -- Food
96 tt.register_snippet(function(itemstring)
97 local def = minetest.registered_items[itemstring]
98 local desc
99 if def._tt_food then
100 desc = S("Food item")
101 if def._tt_food_hp then
102 local msg = S("+@1 food points", def._tt_food_hp)
103 desc = desc .. "\n" .. msg
106 return desc
107 end)
109 -- Node info
110 tt.register_snippet(function(itemstring)
111 local def = minetest.registered_items[itemstring]
112 local desc = ""
114 -- Health-related node facts
115 if def.damage_per_second then
116 if def.damage_per_second > 0 then
117 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DANGER, S("Contact damage: @1 per second", def.damage_per_second))
118 elseif def.damage_per_second < 0 then
119 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_GOOD, S("Contact healing: @1 per second", math.abs(def.damage_per_second)))
122 if def.drowning and def.drowning ~= 0 then
123 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DANGER, S("Drowning damage: @1", def.drowning))
125 local tmp = minetest.get_item_group(itemstring, "fall_damage_add_percent")
126 if tmp > 0 then
127 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DANGER, S("Fall damage: +@1%", tmp))
128 elseif tmp == -100 then
129 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_GOOD, S("No fall damage"))
130 elseif tmp < 0 then
131 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DEFAULT, S("Fall damage: @1%", tmp))
134 -- Movement-related node facts
135 if minetest.get_item_group(itemstring, "disable_jump") == 1 and not def.climbable then
136 if def.liquidtype == "none" then
137 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DEFAULT, S("No jumping"))
138 else
139 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DEFAULT, S("No swimming upwards"))
142 if def.climbable then
143 if minetest.get_item_group(itemstring, "disable_jump") == 1 then
144 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DEFAULT, S("Climbable (only downwards)"))
145 else
146 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DEFAULT, S("Climbable"))
149 if minetest.get_item_group(itemstring, "slippery") >= 1 then
150 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DEFAULT, S("Slippery"))
152 local tmp = minetest.get_item_group(itemstring, "bouncy")
153 if tmp >= 1 then
154 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DEFAULT, S("Bouncy (@1%)", tmp))
157 -- Node appearance
158 tmp = def.light_source
159 if tmp and tmp >= 1 then
160 desc = desc .. "\n" .. minetest.colorize(tt.COLOR_DEFAULT, S("Luminance: @1", tmp))
164 if desc == "" then
165 desc = nil
167 return desc, false
168 end)