Update mod.conf
[minetest_pep.git] / init.lua
blob57690f5e1deea4e5e8f1cf764c0489333883352a
1 local S = minetest.get_translator("pep")
2 local ppa = minetest.get_modpath("playerphysics")
4 pep = {}
5 function pep.register_potion(potiondef)
6 local on_use
7 if(potiondef.effect_type ~= nil) then
8 on_use = function(itemstack, user, pointed_thing)
9 playereffects.apply_effect_type(potiondef.effect_type, potiondef.duration, user)
10 itemstack:take_item()
11 return itemstack
12 end
13 else
14 on_use = function(itemstack, user, pointed_thing)
15 itemstack:take_item()
16 return itemstack
17 end
18 end
19 minetest.register_craftitem("pep:"..potiondef.basename, {
20 description = S("Glass Bottle (@1)", potiondef.contentstring),
21 _doc_items_longdesc = potiondef.longdesc,
22 _doc_items_usagehelp = S("Hold it in your hand, then left-click to drink it."),
23 inventory_image = "pep_"..potiondef.basename..".png",
24 wield_image = "pep_"..potiondef.basename..".png",
25 on_use = on_use,
27 end
29 pep.moles = {}
31 function pep.enable_mole_mode(playername)
32 pep.moles[playername] = true
33 end
35 function pep.disable_mole_mode(playername)
36 pep.moles[playername] = false
37 end
39 function pep.yaw_to_vector(yaw)
40 local tau = math.pi*2
42 yaw = yaw % tau
43 if yaw < tau/8 then
44 return { x=0, y=0, z=1}
45 elseif yaw < (3/8)*tau then
46 return { x=-1, y=0, z=0 }
47 elseif yaw < (5/8)*tau then
48 return { x=0, y=0, z=-1 }
49 elseif yaw < (7/8)*tau then
50 return { x=1, y=0, z=0 }
51 else
52 return { x=0, y=0, z=1}
53 end
54 end
56 function pep.moledig(playername)
57 local player = minetest.get_player_by_name(playername)
59 local yaw = player:get_look_yaw()
60 -- fix stupid oddity of Minetest, adding pi/2 to the actual player's look yaw...
61 -- TODO: Remove this code as soon as Minetest fixes this.
62 yaw = yaw - math.pi/2
64 local pos = vector.round(player:getpos())
66 local v = pep.yaw_to_vector(yaw)
68 local digpos1 = vector.add(pos, v)
69 local digpos2 = { x = digpos1.x, y = digpos1.y+1, z = digpos1.z }
71 local try_dig = function(pos)
72 local n = minetest.get_node(pos)
73 local ndef = minetest.registered_nodes[n.name]
74 if ndef.walkable and ndef.diggable then
75 if ndef.can_dig ~= nil then
76 if ndef.can_dig() then
77 return true
78 else
79 return false
80 end
81 else
82 return true
83 end
84 else
85 return false
86 end
87 end
89 local dig = function(pos)
90 if try_dig(pos) then
91 local n = minetest.get_node(pos)
92 local ndef = minetest.registered_nodes[n.name]
93 if ndef.sounds ~= nil then
94 minetest.sound_play(ndef.sounds.dug, { pos = pos })
95 end
96 -- TODO: Replace this code as soon Minetest removes support for this function
97 local drops = minetest.get_node_drops(n.name, "default:pick_steel")
98 minetest.dig_node(pos)
99 local inv = player:get_inventory()
100 local leftovers = {}
101 for i=1,#drops do
102 table.insert(leftovers, inv:add_item("main", drops[i]))
104 for i=1,#leftovers do
105 minetest.add_item(pos, leftovers[i])
110 dig(digpos1)
111 dig(digpos2)
114 pep.timer = 0
116 minetest.register_globalstep(function(dtime)
117 pep.timer = pep.timer + dtime
118 if pep.timer > 0.5 then
119 for playername, is_mole in pairs(pep.moles) do
120 if is_mole then
121 pep.moledig(playername)
124 pep.timer = 0
126 end)
128 local add_physic = function(player, attribute, value)
129 if ppa then
130 playerphysics.add_physics_factor(player, attribute, "pep:"..attribute, value)
131 else
132 player:set_physics_override({[attribute]=value})
135 local remove_physic = function(player, attribute)
136 if ppa then
137 playerphysics.remove_physics_factor(player, attribute, "pep:"..attribute)
138 else
139 player:set_physics_override({[attribute]=1})
143 playereffects.register_effect_type("pepspeedplus", S("High speed"), "pep_speedplus.png", {"speed"},
144 function(player)
145 add_physic(player, "speed", 2)
146 end,
147 function(effect, player)
148 remove_physic(player, "speed")
151 playereffects.register_effect_type("pepspeedminus", S("Low speed"), "pep_speedminus.png", {"speed"},
152 function(player)
153 add_physic(player, "speed", 0.5)
154 end,
155 function(effect, player)
156 remove_physic(player, "speed")
159 playereffects.register_effect_type("pepspeedreset", S("Speed neutralizer"), "pep_speedreset.png", {"speed"},
160 function() end, function() end)
161 playereffects.register_effect_type("pepjumpplus", S("High jump"), "pep_jumpplus.png", {"jump"},
162 function(player)
163 add_physic(player, "jump", 2)
164 end,
165 function(effect, player)
166 remove_physic(player, "jump")
169 playereffects.register_effect_type("pepjumpminus", S("Low jump"), "pep_jumpminus.png", {"jump"},
170 function(player)
171 add_physic(player, "jump", 0.5)
172 end,
173 function(effect, player)
174 remove_physic(player, "jump")
177 playereffects.register_effect_type("pepjumpreset", S("Jump height neutralizer"), "pep_jumpreset.png", {"jump"},
178 function() end, function() end)
179 playereffects.register_effect_type("pepgrav0", S("No gravity"), "pep_grav0.png", {"gravity"},
180 function(player)
181 add_physic(player, "gravity", 0)
182 end,
183 function(effect, player)
184 remove_physic(player, "gravity")
187 playereffects.register_effect_type("pepgravreset", S("Gravity neutralizer"), "pep_gravreset.png", {"gravity"},
188 function() end, function() end)
189 playereffects.register_effect_type("pepregen", S("Regeneration"), "pep_regen.png", {"health"},
190 function(player)
191 player:set_hp(player:get_hp()+1)
192 end,
193 nil, nil, nil, 2
195 playereffects.register_effect_type("pepregen2", S("Strong regeneration"), "pep_regen2.png", {"health"},
196 function(player)
197 player:set_hp(player:get_hp()+2)
198 end,
199 nil, nil, nil, 1
202 if minetest.get_modpath("mana") ~= nil then
203 playereffects.register_effect_type("pepmanaregen", S("Weak mana boost"), "pep_manaregen.png", {"mana"},
204 function(player)
205 local name = player:get_player_name()
206 mana.setregen(name, mana.getregen(name) + 0.5)
207 end,
208 function(effect, player)
209 local name = player:get_player_name()
210 mana.setregen(name, mana.getregen(name) - 0.5)
213 playereffects.register_effect_type("pepmanaregen2", S("Strong mana boost"), "pep_manaregen2.png", {"mana"},
214 function(player)
215 local name = player:get_player_name()
216 mana.setregen(name, mana.getregen(name) + 1)
217 end,
218 function(effect, player)
219 local name = player:get_player_name()
220 mana.setregen(name, mana.getregen(name) - 1)
226 playereffects.register_effect_type("pepbreath", S("Perfect breath"), "pep_breath.png", {"breath"},
227 function(player)
228 player:set_breath(player:get_breath()+2)
229 end,
230 nil, nil, nil, 1
232 playereffects.register_effect_type("pepmole", S("Mole mode"), "pep_mole.png", {"autodig"},
233 function(player)
234 pep.enable_mole_mode(player:get_player_name())
235 end,
236 function(effect, player)
237 pep.disable_mole_mode(player:get_player_name())
240 playereffects.register_effect_type("pepglow", S("Glow"), "pep_glow.png", {"glow"},
241 function(player)
242 player:set_properties({glow=minetest.LIGHT_MAX})
243 end,
244 function(effect, player)
245 player:set_properties({glow=0})
249 pep.register_potion({
250 basename = "speedplus",
251 contentstring = S("Running Potion"),
252 longdesc = S("Drinking it will make you run faster for 30 seconds."),
253 effect_type = "pepspeedplus",
254 duration = 30,
256 pep.register_potion({
257 basename = "speedminus",
258 contentstring = S("Slug Potion"),
259 longdesc = S("Drinking it will make you walk slower for 30 seconds."),
260 effect_type = "pepspeedminus",
261 duration = 30,
263 pep.register_potion({
264 basename = "speedreset",
265 contentstring = S("Speed Neutralizer"),
266 longdesc = S("Drinking it will stop all speed effects you may currently have."),
267 effect_type = "pepspeedreset",
268 duration = 0
270 pep.register_potion({
271 basename = "breath",
272 contentstring = S("Air Potion"),
273 longdesc = S("Drinking it gives you breath underwater for 30 seconds."),
274 effect_type = "pepbreath",
275 duration = 30,
277 pep.register_potion({
278 basename = "regen",
279 contentstring = S("Weak Healing Potion"),
280 longdesc = S("Drinking it makes you regenerate health. Every 2 seconds, you get 1 HP, 10 times in total."),
281 effect_type = "pepregen",
282 duration = 10,
284 pep.register_potion({
285 basename = "regen2",
286 contentstring = S("Strong Healing Potion"),
287 longdesc = S("Drinking it makes you regenerate health quickly. Every second you get 2 HP, 10 times in total."),
288 effect_type = "pepregen2",
289 duration = 10,
291 pep.register_potion({
292 basename = "grav0",
293 contentstring = S("Non-Gravity Potion"),
294 longdesc = S("When you drink this potion, gravity stops affecting you, as if you were in space. The effect lasts for 20 seconds."),
295 effect_type = "pepgrav0",
296 duration = 20,
298 pep.register_potion({
299 basename = "gravreset",
300 contentstring = S("Gravity Neutralizer"),
301 longdesc = S("Drinking it will stop all gravity effects you currently have."),
302 effect_type = "pepgravreset",
303 duration = 0,
305 pep.register_potion({
306 basename = "jumpplus",
307 contentstring = S("High Jumping Potion"),
308 longdesc = S("Drinking it will make you jump higher for 30 seconds."),
309 effect_type = "pepjumpplus",
310 duration = 30,
312 pep.register_potion({
313 basename = "jumpminus",
314 contentstring = S("Low Jumping Potion"),
315 longdesc = S("Drinking it will make you jump lower for 30 seconds."),
316 effect_type = "pepjumpminus",
317 duration = 30,
319 pep.register_potion({
320 basename = "jumpreset",
321 contentstring = S("Jump Neutralizer"),
322 longdesc = S("Drinking it will stop all jumping effects you may currently have."),
323 effect_type = "pepjumpreset",
324 duration = 0,
326 pep.register_potion({
327 basename = "mole",
328 contentstring = S("Mole Potion"),
329 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."),
330 effect_type = "pepmole",
331 duration = 18,
333 pep.register_potion({
334 basename = "glow",
335 contentstring = S("Glow Potion"),
336 longdesc = S("Drinking it will make you glow. The effect lasts for 60 seconds."),
337 effect_type = "pepglow",
338 duration = 60,
340 if(minetest.get_modpath("mana")~=nil) then
341 pep.register_potion({
342 basename = "manaregen",
343 contentstring = S("Weak Mana Potion"),
344 effect_type = "pepmanaregen",
345 duration = 10,
346 longdesc = S("Drinking it will increase your mana regeneration rate by 0.5 for 10 seconds."),
348 pep.register_potion({
349 basename = "manaregen2",
350 contentstring = S("Strong Mana Potion"),
351 effect_type = "pepmanaregen2",
352 duration = 10,
353 longdesc = S("Drinking it will increase your mana regeneration rate by 1 for 10 seconds."),
358 --[=[ register crafts ]=]
359 --[[ normal potions ]]
360 if(minetest.get_modpath("vessels")~=nil) then
361 if(minetest.get_modpath("default")~=nil) then
362 minetest.register_craft({
363 type = "shapeless",
364 output = "pep:breath",
365 recipe = { "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus",
366 "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus", "vessels:glass_bottle" }
368 minetest.register_craft({
369 type = "shapeless",
370 output = "pep:speedminus",
371 recipe = { "default:dry_grass_1", "default:ice", "vessels:glass_bottle" }
373 if(minetest.get_modpath("flowers") ~= nil) then
374 minetest.register_craft({
375 type = "shapeless",
376 output = "pep:jumpplus",
377 recipe = { "flowers:flower_tulip", "default:grass_1", "default:mese_crystal_fragment",
378 "default:mese_crystal_fragment", "vessels:glass_bottle" }
380 minetest.register_craft({
381 type = "shapeless",
382 output = "pep:poisoner",
383 recipe = { "flowers:mushroom_red", "flowers:mushroom_red", "flowers:mushroom_red", "vessels:glass_bottle" }
386 if(minetest.get_modpath("farming") ~= nil) then
387 minetest.register_craft({
388 type = "shapeless",
389 output = "pep:regen",
390 recipe = { "default:cactus", "farming:flour", "flowers:mushroom_brown", "vessels:glass_bottle" }
394 if(minetest.get_modpath("farming") ~= nil) then
395 minetest.register_craft({
396 type = "shapeless",
397 output = "pep:regen2",
398 recipe = { "default:gold_lump", "farming:flour", "pep:regen" }
400 if minetest.get_modpath("mana") ~= nil then
401 minetest.register_craft({
402 type = "shapeless",
403 output = "pep:manaregen",
404 recipe = { "default:dry_shrub", "default:dry_shrub", "farming:seed_cotton", "default:mese_crystal_fragment",
405 "vessels:glass_bottle" }
409 if minetest.get_modpath("mana") ~= nil then
410 minetest.register_craft({
411 type = "shapeless",
412 output = "pep:manaregen2",
413 recipe = { "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:junglesapling",
414 "default:acacia_sapling", "default:mese_crystal_fragment", "pep:manaregen" }
418 minetest.register_craft({
419 type = "shapeless",
420 output = "pep:jumpminus",
421 recipe = { "default:leaves", "default:jungleleaves", "default:iron_lump", "flowers:dandelion_yellow", "vessels:glass_bottle" }
423 minetest.register_craft({
424 type = "shapeless",
425 output = "pep:grav0",
426 recipe = { "default:mese_crystal", "vessels:glass_bottle" }
428 minetest.register_craft({
429 type = "shapeless",
430 output = "pep:mole",
431 recipe = { "default:pick_steel", "default:shovel_steel", "vessels:glass_bottle" },
433 minetest.register_craft({
434 type = "shapeless",
435 output = "pep:gravreset" ,
436 recipe = { "pep:grav0", "default:iron_lump" }
439 if(minetest.get_modpath("flowers") ~= nil) then
440 minetest.register_craft({
441 type = "shapeless",
442 output = "pep:speedplus",
443 recipe = { "default:pine_sapling", "default:cactus", "flowers:dandelion_yellow", "default:junglegrass", "vessels:glass_bottle" }
448 --[[ independent crafts ]]
450 minetest.register_craft({
451 type = "shapeless",
452 output = "pep:speedreset",
453 recipe = { "pep:speedplus", "pep:speedminus" }
455 minetest.register_craft({
456 type = "shapeless",
457 output = "pep:jumpreset",
458 recipe = { "pep:jumpplus", "pep:jumpminus" }