Use new doc_items field names
[minetest_pep.git] / init.lua
blob699fb89985f13d8270b7198d6b4166d0ab723c28
1 -- Boilerplate to support localized strings if intllib mod is installed.
2 local S
3 if minetest.get_modpath("intllib") then
4 S = intllib.Getter()
5 else
6 S = function(s) return s end
7 end
9 pep = {}
10 function pep.register_potion(potiondef)
11 local on_use
12 if(potiondef.effect_type ~= nil) then
13 on_use = function(itemstack, user, pointed_thing)
14 playereffects.apply_effect_type(potiondef.effect_type, potiondef.duration, user)
15 itemstack:take_item()
16 return itemstack
17 end
18 else
19 on_use = function(itemstack, user, pointed_thing)
20 itemstack:take_item()
21 return itemstack
22 end
23 end
24 minetest.register_craftitem("pep:"..potiondef.basename, {
25 description = string.format(S("Glass Bottle (%s)"), potiondef.contentstring),
26 _doc_items_longdesc = potiondef.longdesc,
27 _doc_items_usagehelp = S("Hold it in your hand, then left-click to drink it."),
28 inventory_image = "pep_"..potiondef.basename..".png",
29 wield_image = "pep_"..potiondef.basename..".png",
30 on_use = on_use,
32 end
34 pep.moles = {}
36 function pep.enable_mole_mode(playername)
37 pep.moles[playername] = true
38 end
40 function pep.disable_mole_mode(playername)
41 pep.moles[playername] = false
42 end
44 function pep.yaw_to_vector(yaw)
45 local tau = math.pi*2
47 yaw = yaw % tau
48 if yaw < tau/8 then
49 return { x=0, y=0, z=1}
50 elseif yaw < (3/8)*tau then
51 return { x=-1, y=0, z=0 }
52 elseif yaw < (5/8)*tau then
53 return { x=0, y=0, z=-1 }
54 elseif yaw < (7/8)*tau then
55 return { x=1, y=0, z=0 }
56 else
57 return { x=0, y=0, z=1}
58 end
59 end
61 function pep.moledig(playername)
62 local player = minetest.get_player_by_name(playername)
64 local yaw = player:get_look_yaw()
65 -- fix stupid oddity of Minetest, adding pi/2 to the actual player's look yaw...
66 -- TODO: Remove this code as soon as Minetest fixes this.
67 yaw = yaw - math.pi/2
69 local pos = vector.round(player:getpos())
71 local v = pep.yaw_to_vector(yaw)
73 local digpos1 = vector.add(pos, v)
74 local digpos2 = { x = digpos1.x, y = digpos1.y+1, z = digpos1.z }
76 local try_dig = function(pos)
77 local n = minetest.get_node(pos)
78 local ndef = minetest.registered_nodes[n.name]
79 if ndef.walkable and ndef.diggable then
80 if ndef.can_dig ~= nil then
81 if ndef.can_dig() then
82 return true
83 else
84 return false
85 end
86 else
87 return true
88 end
89 else
90 return false
91 end
92 end
94 local dig = function(pos)
95 if try_dig(pos) then
96 local n = minetest.get_node(pos)
97 local ndef = minetest.registered_nodes[n.name]
98 if ndef.sounds ~= nil then
99 minetest.sound_play(ndef.sounds.dug, { pos = pos })
101 -- TODO: Replace this code as soon Minetest removes support for this function
102 local drops = minetest.get_node_drops(n.name, "default:pick_steel")
103 minetest.dig_node(pos)
104 local inv = player:get_inventory()
105 local leftovers = {}
106 for i=1,#drops do
107 table.insert(leftovers, inv:add_item("main", drops[i]))
109 for i=1,#leftovers do
110 minetest.add_item(pos, leftovers[i])
115 dig(digpos1)
116 dig(digpos2)
119 pep.timer = 0
121 minetest.register_globalstep(function(dtime)
122 pep.timer = pep.timer + dtime
123 if pep.timer > 0.5 then
124 for playername, is_mole in pairs(pep.moles) do
125 if is_mole then
126 pep.moledig(playername)
129 pep.timer = 0
131 end)
133 playereffects.register_effect_type("pepspeedplus", S("High speed"), "pep_speedplus.png", {"speed"},
134 function(player)
135 player:set_physics_override({speed=2})
136 end,
137 function(effect, player)
138 player:set_physics_override({speed=1})
141 playereffects.register_effect_type("pepspeedminus", S("Low speed"), "pep_speedminus.png", {"speed"},
142 function(player)
143 player:set_physics_override({speed=0.5})
144 end,
145 function(effect, player)
146 player:set_physics_override({speed=1})
149 playereffects.register_effect_type("pepspeedreset", S("Speed neutralizer"), "pep_speedreset.png", {"speed"},
150 function() end, function() end)
151 playereffects.register_effect_type("pepjumpplus", S("High jump"), "pep_jumpplus.png", {"jump"},
152 function(player)
153 player:set_physics_override({jump=2})
154 end,
155 function(effect, player)
156 player:set_physics_override({jump=1})
159 playereffects.register_effect_type("pepjumpminus", S("Low jump"), "pep_jumpminus.png", {"jump"},
160 function(player)
161 player:set_physics_override({jump=0.5})
162 end,
163 function(effect, player)
164 player:set_physics_override({jump=1})
167 playereffects.register_effect_type("pepjumpreset", S("Jump height neutralizer"), "pep_jumpreset.png", {"jump"},
168 function() end, function() end)
169 playereffects.register_effect_type("pepgrav0", S("No gravity"), "pep_grav0.png", {"gravity"},
170 function(player)
171 player:set_physics_override({gravity=0})
172 end,
173 function(effect, player)
174 player:set_physics_override({gravity=1})
177 playereffects.register_effect_type("pepgravreset", S("Gravity neutralizer"), "pep_gravreset.png", {"gravity"},
178 function() end, function() end)
179 playereffects.register_effect_type("pepregen", S("Regeneration"), "pep_regen.png", {"health"},
180 function(player)
181 player:set_hp(player:get_hp()+1)
182 end,
183 nil, nil, nil, 2
185 playereffects.register_effect_type("pepregen2", S("Strong regeneration"), "pep_regen2.png", {"health"},
186 function(player)
187 player:set_hp(player:get_hp()+2)
188 end,
189 nil, nil, nil, 1
192 if minetest.get_modpath("mana") ~= nil then
193 playereffects.register_effect_type("pepmanaregen", S("Weak mana boost"), "pep_manaregen.png", {"mana"},
194 function(player)
195 local name = player:get_player_name()
196 mana.setregen(name, mana.getregen(name) + 0.5)
197 end,
198 function(effect, player)
199 local name = player:get_player_name()
200 mana.setregen(name, mana.getregen(name) - 0.5)
203 playereffects.register_effect_type("pepmanaregen2", S("Strong mana boost"), "pep_manaregen2.png", {"mana"},
204 function(player)
205 local name = player:get_player_name()
206 mana.setregen(name, mana.getregen(name) + 1)
207 end,
208 function(effect, player)
209 local name = player:get_player_name()
210 mana.setregen(name, mana.getregen(name) - 1)
216 playereffects.register_effect_type("pepbreath", S("Perfect breath"), "pep_breath.png", {"breath"},
217 function(player)
218 player:set_breath(player:get_breath()+2)
219 end,
220 nil, nil, nil, 1
222 playereffects.register_effect_type("pepmole", S("Mole mode"), "pep_mole.png", {"autodig"},
223 function(player)
224 pep.enable_mole_mode(player:get_player_name())
225 end,
226 function(effect, player)
227 pep.disable_mole_mode(player:get_player_name())
231 pep.register_potion({
232 basename = "speedplus",
233 contentstring = S("Running Potion"),
234 longdesc = S("Drinking it will make you run faster for 30 seconds."),
235 effect_type = "pepspeedplus",
236 duration = 30,
238 pep.register_potion({
239 basename = "speedminus",
240 contentstring = S("Slug Potion"),
241 longdesc = S("Drinking it will make you walk slower for 30 seconds."),
242 effect_type = "pepspeedminus",
243 duration = 30,
245 pep.register_potion({
246 basename = "speedreset",
247 contentstring = S("Speed Neutralizer"),
248 longdesc = S("Drinking it will stop all speed effects you may currently have."),
249 effect_type = "pepspeedreset",
250 duration = 0
252 pep.register_potion({
253 basename = "breath",
254 contentstring = S("Air Potion"),
255 longdesc = S("Drinking it gives you breath underwater for 30 seconds."),
256 effect_type = "pepbreath",
257 duration = 30,
259 pep.register_potion({
260 basename = "regen",
261 contentstring = S("Weak Healing Potion"),
262 longdesc = S("Drinking it makes you regenerate health. Every 2 seconds, you get 1 HP, 10 times in total."),
263 effect_type = "pepregen",
264 duration = 10,
266 pep.register_potion({
267 basename = "regen2",
268 contentstring = S("Strong Healing Potion"),
269 longdesc = S("Drinking it makes you regenerate health quickly. Every second you get 2 HP, 10 times in total."),
270 effect_type = "pepregen2",
271 duration = 10,
273 pep.register_potion({
274 basename = "grav0",
275 contentstring = S("Non-Gravity Potion"),
276 longdesc = S("When you drink this potion, gravity stops affecting you, as if you were in space. The effect lasts for 20 seconds."),
277 effect_type = "pepgrav0",
278 duration = 20,
280 pep.register_potion({
281 basename = "gravreset",
282 contentstring = S("Gravity Neutralizer"),
283 longdesc = S("Drinking it will stop all gravity effects you currently have."),
284 effect_type = "pepgravreset",
285 duration = 0,
287 pep.register_potion({
288 basename = "jumpplus",
289 contentstring = S("High Jumping Potion"),
290 longdesc = S("Drinking it will make you jump higher for 30 seconds."),
291 effect_type = "pepjumpplus",
292 duration = 30,
294 pep.register_potion({
295 basename = "jumpminus",
296 contentstring = S("Low Jumping Potion"),
297 longdesc = S("Drinking it will make you jump lower for 30 seconds."),
298 effect_type = "pepjumpminus",
299 duration = 30,
301 pep.register_potion({
302 basename = "jumpreset",
303 contentstring = S("Jump Neutralizer"),
304 longdesc = S("Drinking it will stop all jumping effects you may currently have."),
305 effect_type = "pepjumpreset",
306 duration = 0,
308 pep.register_potion({
309 basename = "mole",
310 contentstring = S("Mole Potion"),
311 longdesc = S("Drinking it will start an effect which will magically attempt to mine any two blocks in front of you horizontally, as if you were using a steel pickaxe on them. The effect lasts for 18 seconds."),
312 effect_type = "pepmole",
313 duration = 18,
315 if(minetest.get_modpath("mana")~=nil) then
316 pep.register_potion({
317 basename = "manaregen",
318 contentstring = S("Weak Mana Potion"),
319 effect_type = "pepmanaregen",
320 duration = 10,
321 longdesc = S("Drinking it will increase your mana regeneration rate by 0.5 for 10 seconds."),
323 pep.register_potion({
324 basename = "manaregen2",
325 contentstring = S("Strong Mana Potion"),
326 effect_type = "pepmanaregen2",
327 duration = 10,
328 longdesc = S("Drinking it will increase your mana regeneration rate by 1 for 10 seconds."),
333 --[=[ register crafts ]=]
334 --[[ normal potions ]]
335 if(minetest.get_modpath("vessels")~=nil) then
336 if(minetest.get_modpath("default")~=nil) then
337 minetest.register_craft({
338 type = "shapeless",
339 output = "pep:breath",
340 recipe = { "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus",
341 "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus", "vessels:glass_bottle" }
343 minetest.register_craft({
344 type = "shapeless",
345 output = "pep:speedminus",
346 recipe = { "default:dry_grass_1", "default:ice", "vessels:glass_bottle" }
348 if(minetest.get_modpath("flowers") ~= nil) then
349 minetest.register_craft({
350 type = "shapeless",
351 output = "pep:jumpplus",
352 recipe = { "flowers:flower_tulip", "default:grass_1", "default:mese_crystal_fragment",
353 "default:mese_crystal_fragment", "vessels:glass_bottle" }
355 minetest.register_craft({
356 type = "shapeless",
357 output = "pep:poisoner",
358 recipe = { "flowers:mushroom_red", "flowers:mushroom_red", "flowers:mushroom_red", "vessels:glass_bottle" }
361 if(minetest.get_modpath("farming") ~= nil) then
362 minetest.register_craft({
363 type = "shapeless",
364 output = "pep:regen",
365 recipe = { "default:cactus", "farming:flour", "flowers:mushroom_brown", "vessels:glass_bottle" }
369 if(minetest.get_modpath("farming") ~= nil) then
370 minetest.register_craft({
371 type = "shapeless",
372 output = "pep:regen2",
373 recipe = { "default:gold_lump", "farming:flour", "pep:regen" }
375 if minetest.get_modpath("mana") ~= nil then
376 minetest.register_craft({
377 type = "shapeless",
378 output = "pep:manaregen",
379 recipe = { "default:dry_shrub", "default:dry_shrub", "farming:seed_cotton", "default:mese_crystal_fragment",
380 "vessels:glass_bottle" }
384 if minetest.get_modpath("mana") ~= nil then
385 minetest.register_craft({
386 type = "shapeless",
387 output = "pep:manaregen2",
388 recipe = { "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:junglesapling",
389 "default:acacia_sapling", "default:mese_crystal_fragment", "pep:manaregen" }
393 minetest.register_craft({
394 type = "shapeless",
395 output = "pep:jumpminus",
396 recipe = { "default:leaves", "default:jungleleaves", "default:iron_lump", "flowers:dandelion_yellow", "vessels:glass_bottle" }
398 minetest.register_craft({
399 type = "shapeless",
400 output = "pep:grav0",
401 recipe = { "default:mese_crystal", "vessels:glass_bottle" }
403 minetest.register_craft({
404 type = "shapeless",
405 output = "pep:mole",
406 recipe = { "default:pick_steel", "default:shovel_steel", "vessels:glass_bottle" },
408 minetest.register_craft({
409 type = "shapeless",
410 output = "pep:gravreset" ,
411 recipe = { "pep:grav0", "default:iron_lump" }
414 if(minetest.get_modpath("flowers") ~= nil) then
415 minetest.register_craft({
416 type = "shapeless",
417 output = "pep:speedplus",
418 recipe = { "default:pine_sapling", "default:cactus", "flowers:dandelion_yellow", "default:junglegrass", "vessels:glass_bottle" }
423 --[[ independent crafts ]]
425 minetest.register_craft({
426 type = "shapeless",
427 output = "pep:speedreset",
428 recipe = { "pep:speedplus", "pep:speedminus" }
430 minetest.register_craft({
431 type = "shapeless",
432 output = "pep:jumpreset",
433 recipe = { "pep:jumpplus", "pep:jumpminus" }