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_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.
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
89 local dig
= function(pos
)
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
})
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()
102 table.insert(leftovers
, inv
:add_item("main", drops
[i
]))
104 for i
=1,#leftovers
do
105 minetest
.add_item(pos
, leftovers
[i
])
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
121 pep
.moledig(playername
)
128 local add_physic
= function(player
, attribute
, value
)
130 playerphysics
.add_physics_factor(player
, attribute
, "pep:"..attribute
, value
)
132 player
:set_physics_override({[attribute
]=value
})
135 local remove_physic
= function(player
, attribute
)
137 playerphysics
.remove_physics_factor(player
, attribute
, "pep:"..attribute
)
139 player
:set_physics_override({[attribute
]=1})
143 playereffects
.register_effect_type("pepspeedplus", S("High speed"), "pep_speedplus.png", {"speed"},
145 add_physic(player
, "speed", 2)
147 function(effect
, player
)
148 remove_physic(player
, "speed")
151 playereffects
.register_effect_type("pepspeedminus", S("Low speed"), "pep_speedminus.png", {"speed"},
153 add_physic(player
, "speed", 0.5)
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"},
163 add_physic(player
, "jump", 2)
165 function(effect
, player
)
166 remove_physic(player
, "jump")
169 playereffects
.register_effect_type("pepjumpminus", S("Low jump"), "pep_jumpminus.png", {"jump"},
171 add_physic(player
, "jump", 0.5)
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"},
181 add_physic(player
, "gravity", 0)
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"},
191 player
:set_hp(player
:get_hp()+1)
195 playereffects
.register_effect_type("pepregen2", S("Strong regeneration"), "pep_regen2.png", {"health"},
197 player
:set_hp(player
:get_hp()+2)
202 if minetest
.get_modpath("mana") ~= nil then
203 playereffects
.register_effect_type("pepmanaregen", S("Weak mana boost"), "pep_manaregen.png", {"mana"},
205 local name
= player
:get_player_name()
206 mana
.setregen(name
, mana
.getregen(name
) + 0.5)
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"},
215 local name
= player
:get_player_name()
216 mana
.setregen(name
, mana
.getregen(name
) + 1)
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"},
228 player
:set_breath(player
:get_breath()+2)
232 playereffects
.register_effect_type("pepmole", S("Mole mode"), "pep_mole.png", {"autodig"},
234 pep
.enable_mole_mode(player
:get_player_name())
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"},
242 player
:set_properties({glow
=minetest
.LIGHT_MAX
})
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",
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",
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",
270 pep
.register_potion({
272 contentstring
= S("Air Potion"),
273 longdesc
= S("Drinking it gives you breath underwater for 30 seconds."),
274 effect_type
= "pepbreath",
277 pep
.register_potion({
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",
284 pep
.register_potion({
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",
291 pep
.register_potion({
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",
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",
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",
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",
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",
326 pep
.register_potion({
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",
333 pep
.register_potion({
335 contentstring
= S("Glow Potion"),
336 longdesc
= S("Drinking it will make you glow. The effect lasts for 60 seconds."),
337 effect_type
= "pepglow",
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",
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",
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({
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({
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({
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({
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({
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({
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({
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({
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({
420 output
= "pep:jumpminus",
421 recipe
= { "default:leaves", "default:jungleleaves", "default:iron_lump", "flowers:dandelion_yellow", "vessels:glass_bottle" }
423 minetest
.register_craft({
425 output
= "pep:grav0",
426 recipe
= { "default:mese_crystal", "vessels:glass_bottle" }
428 minetest
.register_craft({
431 recipe
= { "default:pick_steel", "default:shovel_steel", "vessels:glass_bottle" },
433 minetest
.register_craft({
435 output
= "pep:gravreset" ,
436 recipe
= { "pep:grav0", "default:iron_lump" }
439 if(minetest
.get_modpath("flowers") ~= nil) then
440 minetest
.register_craft({
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({
452 output
= "pep:speedreset",
453 recipe
= { "pep:speedplus", "pep:speedminus" }
455 minetest
.register_craft({
457 output
= "pep:jumpreset",
458 recipe
= { "pep:jumpplus", "pep:jumpminus" }