1 local S
= minetest
.get_translator("pep")
2 local ppa
= minetest
.get_modpath("playerphysics")
5 function pep
.register_potion(potiondef
)
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
)
14 on_use
= function(itemstack
, user
, pointed_thing
)
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",
31 function pep
.enable_mole_mode(playername
)
32 pep
.moles
[playername
] = true
35 function pep
.disable_mole_mode(playername
)
36 pep
.moles
[playername
] = false
39 function pep
.yaw_to_vector(yaw
)
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 }
52 return { x
=0, y
=0, z
=1}
56 function pep
.moledig(playername
)
57 local player
= minetest
.get_player_by_name(playername
)
59 local yaw
= player
:get_look_horizontal()
61 local pos
= vector
.round(player
:get_pos())
63 local v
= pep
.yaw_to_vector(yaw
)
65 local digpos1
= vector
.add(pos
, v
)
66 local digpos2
= { x
= digpos1
.x
, y
= digpos1
.y
+1, z
= digpos1
.z
}
68 local try_dig
= function(pos
)
69 local n
= minetest
.get_node(pos
)
70 local ndef
= minetest
.registered_nodes
[n
.name
]
71 if ndef
.walkable
and ndef
.diggable
then
72 if ndef
.can_dig
~= nil then
73 if ndef
.can_dig() then
86 local dig
= function(pos
)
88 local n
= minetest
.get_node(pos
)
89 local ndef
= minetest
.registered_nodes
[n
.name
]
90 if ndef
.sounds
~= nil then
91 minetest
.sound_play(ndef
.sounds
.dug
, { pos
= pos
})
93 -- TODO: Replace this code as soon Minetest removes support for this function
94 local drops
= minetest
.get_node_drops(n
.name
, "default:pick_steel")
95 minetest
.dig_node(pos
)
96 local inv
= player
:get_inventory()
99 table.insert(leftovers
, inv
:add_item("main", drops
[i
]))
101 for i
=1,#leftovers
do
102 minetest
.add_item(pos
, leftovers
[i
])
113 minetest
.register_globalstep(function(dtime
)
114 pep
.timer
= pep
.timer
+ dtime
115 if pep
.timer
> 0.5 then
116 for playername
, is_mole
in pairs(pep
.moles
) do
118 pep
.moledig(playername
)
125 local add_physic
= function(player
, attribute
, value
)
127 playerphysics
.add_physics_factor(player
, attribute
, "pep:"..attribute
, value
)
129 player
:set_physics_override({[attribute
]=value
})
132 local remove_physic
= function(player
, attribute
)
134 playerphysics
.remove_physics_factor(player
, attribute
, "pep:"..attribute
)
136 player
:set_physics_override({[attribute
]=1})
140 playereffects
.register_effect_type("pepspeedplus", S("High speed"), "pep_speedplus.png", {"speed"},
142 add_physic(player
, "speed", 2)
144 function(effect
, player
)
145 remove_physic(player
, "speed")
148 playereffects
.register_effect_type("pepspeedminus", S("Low speed"), "pep_speedminus.png", {"speed"},
150 add_physic(player
, "speed", 0.5)
152 function(effect
, player
)
153 remove_physic(player
, "speed")
156 playereffects
.register_effect_type("pepspeedreset", S("Speed neutralizer"), "pep_speedreset.png", {"speed"},
157 function() end, function() end)
158 playereffects
.register_effect_type("pepjumpplus", S("High jump"), "pep_jumpplus.png", {"jump"},
160 add_physic(player
, "jump", 2)
162 function(effect
, player
)
163 remove_physic(player
, "jump")
166 playereffects
.register_effect_type("pepjumpminus", S("Low jump"), "pep_jumpminus.png", {"jump"},
168 add_physic(player
, "jump", 0.5)
170 function(effect
, player
)
171 remove_physic(player
, "jump")
174 playereffects
.register_effect_type("pepjumpreset", S("Jump height neutralizer"), "pep_jumpreset.png", {"jump"},
175 function() end, function() end)
176 playereffects
.register_effect_type("pepgrav0", S("No gravity"), "pep_grav0.png", {"gravity"},
178 add_physic(player
, "gravity", 0)
180 function(effect
, player
)
181 remove_physic(player
, "gravity")
184 playereffects
.register_effect_type("pepgravreset", S("Gravity neutralizer"), "pep_gravreset.png", {"gravity"},
185 function() end, function() end)
186 playereffects
.register_effect_type("pepregen", S("Regeneration"), "pep_regen.png", {"health"},
188 player
:set_hp(player
:get_hp()+1)
192 playereffects
.register_effect_type("pepregen2", S("Strong regeneration"), "pep_regen2.png", {"health"},
194 player
:set_hp(player
:get_hp()+2)
199 if minetest
.get_modpath("mana") ~= nil then
200 playereffects
.register_effect_type("pepmanaregen", S("Weak mana boost"), "pep_manaregen.png", {"mana"},
202 local name
= player
:get_player_name()
203 mana
.setregen(name
, mana
.getregen(name
) + 0.5)
205 function(effect
, player
)
206 local name
= player
:get_player_name()
207 mana
.setregen(name
, mana
.getregen(name
) - 0.5)
210 playereffects
.register_effect_type("pepmanaregen2", S("Strong mana boost"), "pep_manaregen2.png", {"mana"},
212 local name
= player
:get_player_name()
213 mana
.setregen(name
, mana
.getregen(name
) + 1)
215 function(effect
, player
)
216 local name
= player
:get_player_name()
217 mana
.setregen(name
, mana
.getregen(name
) - 1)
223 playereffects
.register_effect_type("pepbreath", S("Perfect breath"), "pep_breath.png", {"breath"},
225 player
:set_breath(player
:get_breath()+2)
229 playereffects
.register_effect_type("pepmole", S("Mole mode"), "pep_mole.png", {"autodig"},
231 pep
.enable_mole_mode(player
:get_player_name())
233 function(effect
, player
)
234 pep
.disable_mole_mode(player
:get_player_name())
237 playereffects
.register_effect_type("pepglow", S("Glow"), "pep_glow.png", {"glow"},
239 player
:set_properties({glow
=minetest
.LIGHT_MAX
})
241 function(effect
, player
)
242 player
:set_properties({glow
=0})
246 pep
.register_potion({
247 basename
= "speedplus",
248 contentstring
= S("Running Potion"),
249 longdesc
= S("Drinking it will make you run faster for 30 seconds."),
250 effect_type
= "pepspeedplus",
253 pep
.register_potion({
254 basename
= "speedminus",
255 contentstring
= S("Slug Potion"),
256 longdesc
= S("Drinking it will make you walk slower for 30 seconds."),
257 effect_type
= "pepspeedminus",
260 pep
.register_potion({
261 basename
= "speedreset",
262 contentstring
= S("Speed Neutralizer"),
263 longdesc
= S("Drinking it will stop all speed effects you may currently have."),
264 effect_type
= "pepspeedreset",
267 pep
.register_potion({
269 contentstring
= S("Air Potion"),
270 longdesc
= S("Drinking it gives you breath underwater for 30 seconds."),
271 effect_type
= "pepbreath",
274 pep
.register_potion({
276 contentstring
= S("Weak Healing Potion"),
277 longdesc
= S("Drinking it makes you regenerate health. Every 2 seconds, you get 1 HP, 10 times in total."),
278 effect_type
= "pepregen",
281 pep
.register_potion({
283 contentstring
= S("Strong Healing Potion"),
284 longdesc
= S("Drinking it makes you regenerate health quickly. Every second you get 2 HP, 10 times in total."),
285 effect_type
= "pepregen2",
288 pep
.register_potion({
290 contentstring
= S("Non-Gravity Potion"),
291 longdesc
= S("When you drink this potion, gravity stops affecting you, as if you were in space. The effect lasts for 20 seconds."),
292 effect_type
= "pepgrav0",
295 pep
.register_potion({
296 basename
= "gravreset",
297 contentstring
= S("Gravity Neutralizer"),
298 longdesc
= S("Drinking it will stop all gravity effects you currently have."),
299 effect_type
= "pepgravreset",
302 pep
.register_potion({
303 basename
= "jumpplus",
304 contentstring
= S("High Jumping Potion"),
305 longdesc
= S("Drinking it will make you jump higher for 30 seconds."),
306 effect_type
= "pepjumpplus",
309 pep
.register_potion({
310 basename
= "jumpminus",
311 contentstring
= S("Low Jumping Potion"),
312 longdesc
= S("Drinking it will make you jump lower for 30 seconds."),
313 effect_type
= "pepjumpminus",
316 pep
.register_potion({
317 basename
= "jumpreset",
318 contentstring
= S("Jump Neutralizer"),
319 longdesc
= S("Drinking it will stop all jumping effects you may currently have."),
320 effect_type
= "pepjumpreset",
323 pep
.register_potion({
325 contentstring
= S("Mole Potion"),
326 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."),
327 effect_type
= "pepmole",
330 pep
.register_potion({
332 contentstring
= S("Glow Potion"),
333 longdesc
= S("Drinking it will make you glow. The effect lasts for 60 seconds."),
334 effect_type
= "pepglow",
337 if(minetest
.get_modpath("mana")~=nil) then
338 pep
.register_potion({
339 basename
= "manaregen",
340 contentstring
= S("Weak Mana Potion"),
341 effect_type
= "pepmanaregen",
343 longdesc
= S("Drinking it will increase your mana regeneration rate by 0.5 for 10 seconds."),
345 pep
.register_potion({
346 basename
= "manaregen2",
347 contentstring
= S("Strong Mana Potion"),
348 effect_type
= "pepmanaregen2",
350 longdesc
= S("Drinking it will increase your mana regeneration rate by 1 for 10 seconds."),
355 --[=[ register crafts ]=]
356 --[[ normal potions ]]
357 if(minetest
.get_modpath("vessels")~=nil) then
358 if(minetest
.get_modpath("default")~=nil) then
359 minetest
.register_craft({
361 output
= "pep:breath",
362 recipe
= { "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus",
363 "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus", "vessels:glass_bottle" }
365 minetest
.register_craft({
367 output
= "pep:speedminus",
368 recipe
= { "default:dry_grass_1", "default:ice", "vessels:glass_bottle" }
370 if(minetest
.get_modpath("flowers") ~= nil) then
371 minetest
.register_craft({
373 output
= "pep:jumpplus",
374 recipe
= { "flowers:flower_tulip", "default:grass_1", "default:mese_crystal_fragment",
375 "default:mese_crystal_fragment", "vessels:glass_bottle" }
377 minetest
.register_craft({
379 output
= "pep:poisoner",
380 recipe
= { "flowers:mushroom_red", "flowers:mushroom_red", "flowers:mushroom_red", "vessels:glass_bottle" }
383 if(minetest
.get_modpath("farming") ~= nil) then
384 minetest
.register_craft({
386 output
= "pep:regen",
387 recipe
= { "default:cactus", "farming:flour", "flowers:mushroom_brown", "vessels:glass_bottle" }
391 if(minetest
.get_modpath("farming") ~= nil) then
392 minetest
.register_craft({
394 output
= "pep:regen2",
395 recipe
= { "default:gold_lump", "farming:flour", "pep:regen" }
397 if minetest
.get_modpath("mana") ~= nil then
398 minetest
.register_craft({
400 output
= "pep:manaregen",
401 recipe
= { "default:dry_shrub", "default:dry_shrub", "farming:seed_cotton", "default:mese_crystal_fragment",
402 "vessels:glass_bottle" }
406 if minetest
.get_modpath("mana") ~= nil then
407 minetest
.register_craft({
409 output
= "pep:manaregen2",
410 recipe
= { "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:junglesapling",
411 "default:acacia_sapling", "default:mese_crystal_fragment", "pep:manaregen" }
415 minetest
.register_craft({
417 output
= "pep:jumpminus",
418 recipe
= { "default:leaves", "default:jungleleaves", "default:iron_lump", "flowers:dandelion_yellow", "vessels:glass_bottle" }
420 minetest
.register_craft({
422 output
= "pep:grav0",
423 recipe
= { "default:mese_crystal", "vessels:glass_bottle" }
425 minetest
.register_craft({
428 recipe
= { "default:pick_steel", "default:shovel_steel", "vessels:glass_bottle" },
430 minetest
.register_craft({
432 output
= "pep:gravreset" ,
433 recipe
= { "pep:grav0", "default:iron_lump" }
436 if(minetest
.get_modpath("flowers") ~= nil) then
437 minetest
.register_craft({
439 output
= "pep:speedplus",
440 recipe
= { "default:pine_sapling", "default:cactus", "flowers:dandelion_yellow", "default:junglegrass", "vessels:glass_bottle" }
445 --[[ independent crafts ]]
447 minetest
.register_craft({
449 output
= "pep:speedreset",
450 recipe
= { "pep:speedplus", "pep:speedminus" }
452 minetest
.register_craft({
454 output
= "pep:jumpreset",
455 recipe
= { "pep:jumpplus", "pep:jumpminus" }