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())
238 pep
.register_potion({
239 basename
= "speedplus",
240 contentstring
= S("Running Potion"),
241 longdesc
= S("Drinking it will make you run faster for 30 seconds."),
242 effect_type
= "pepspeedplus",
245 pep
.register_potion({
246 basename
= "speedminus",
247 contentstring
= S("Slug Potion"),
248 longdesc
= S("Drinking it will make you walk slower for 30 seconds."),
249 effect_type
= "pepspeedminus",
252 pep
.register_potion({
253 basename
= "speedreset",
254 contentstring
= S("Speed Neutralizer"),
255 longdesc
= S("Drinking it will stop all speed effects you may currently have."),
256 effect_type
= "pepspeedreset",
259 pep
.register_potion({
261 contentstring
= S("Air Potion"),
262 longdesc
= S("Drinking it gives you breath underwater for 30 seconds."),
263 effect_type
= "pepbreath",
266 pep
.register_potion({
268 contentstring
= S("Weak Healing Potion"),
269 longdesc
= S("Drinking it makes you regenerate health. Every 2 seconds, you get 1 HP, 10 times in total."),
270 effect_type
= "pepregen",
273 pep
.register_potion({
275 contentstring
= S("Strong Healing Potion"),
276 longdesc
= S("Drinking it makes you regenerate health quickly. Every second you get 2 HP, 10 times in total."),
277 effect_type
= "pepregen2",
280 pep
.register_potion({
282 contentstring
= S("Non-Gravity Potion"),
283 longdesc
= S("When you drink this potion, gravity stops affecting you, as if you were in space. The effect lasts for 20 seconds."),
284 effect_type
= "pepgrav0",
287 pep
.register_potion({
288 basename
= "gravreset",
289 contentstring
= S("Gravity Neutralizer"),
290 longdesc
= S("Drinking it will stop all gravity effects you currently have."),
291 effect_type
= "pepgravreset",
294 pep
.register_potion({
295 basename
= "jumpplus",
296 contentstring
= S("High Jumping Potion"),
297 longdesc
= S("Drinking it will make you jump higher for 30 seconds."),
298 effect_type
= "pepjumpplus",
301 pep
.register_potion({
302 basename
= "jumpminus",
303 contentstring
= S("Low Jumping Potion"),
304 longdesc
= S("Drinking it will make you jump lower for 30 seconds."),
305 effect_type
= "pepjumpminus",
308 pep
.register_potion({
309 basename
= "jumpreset",
310 contentstring
= S("Jump Neutralizer"),
311 longdesc
= S("Drinking it will stop all jumping effects you may currently have."),
312 effect_type
= "pepjumpreset",
315 pep
.register_potion({
317 contentstring
= S("Mole Potion"),
318 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."),
319 effect_type
= "pepmole",
322 if(minetest
.get_modpath("mana")~=nil) then
323 pep
.register_potion({
324 basename
= "manaregen",
325 contentstring
= S("Weak Mana Potion"),
326 effect_type
= "pepmanaregen",
328 longdesc
= S("Drinking it will increase your mana regeneration rate by 0.5 for 10 seconds."),
330 pep
.register_potion({
331 basename
= "manaregen2",
332 contentstring
= S("Strong Mana Potion"),
333 effect_type
= "pepmanaregen2",
335 longdesc
= S("Drinking it will increase your mana regeneration rate by 1 for 10 seconds."),
340 --[=[ register crafts ]=]
341 --[[ normal potions ]]
342 if(minetest
.get_modpath("vessels")~=nil) then
343 if(minetest
.get_modpath("default")~=nil) then
344 minetest
.register_craft({
346 output
= "pep:breath",
347 recipe
= { "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus",
348 "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus", "vessels:glass_bottle" }
350 minetest
.register_craft({
352 output
= "pep:speedminus",
353 recipe
= { "default:dry_grass_1", "default:ice", "vessels:glass_bottle" }
355 if(minetest
.get_modpath("flowers") ~= nil) then
356 minetest
.register_craft({
358 output
= "pep:jumpplus",
359 recipe
= { "flowers:flower_tulip", "default:grass_1", "default:mese_crystal_fragment",
360 "default:mese_crystal_fragment", "vessels:glass_bottle" }
362 minetest
.register_craft({
364 output
= "pep:poisoner",
365 recipe
= { "flowers:mushroom_red", "flowers:mushroom_red", "flowers:mushroom_red", "vessels:glass_bottle" }
368 if(minetest
.get_modpath("farming") ~= nil) then
369 minetest
.register_craft({
371 output
= "pep:regen",
372 recipe
= { "default:cactus", "farming:flour", "flowers:mushroom_brown", "vessels:glass_bottle" }
376 if(minetest
.get_modpath("farming") ~= nil) then
377 minetest
.register_craft({
379 output
= "pep:regen2",
380 recipe
= { "default:gold_lump", "farming:flour", "pep:regen" }
382 if minetest
.get_modpath("mana") ~= nil then
383 minetest
.register_craft({
385 output
= "pep:manaregen",
386 recipe
= { "default:dry_shrub", "default:dry_shrub", "farming:seed_cotton", "default:mese_crystal_fragment",
387 "vessels:glass_bottle" }
391 if minetest
.get_modpath("mana") ~= nil then
392 minetest
.register_craft({
394 output
= "pep:manaregen2",
395 recipe
= { "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:junglesapling",
396 "default:acacia_sapling", "default:mese_crystal_fragment", "pep:manaregen" }
400 minetest
.register_craft({
402 output
= "pep:jumpminus",
403 recipe
= { "default:leaves", "default:jungleleaves", "default:iron_lump", "flowers:dandelion_yellow", "vessels:glass_bottle" }
405 minetest
.register_craft({
407 output
= "pep:grav0",
408 recipe
= { "default:mese_crystal", "vessels:glass_bottle" }
410 minetest
.register_craft({
413 recipe
= { "default:pick_steel", "default:shovel_steel", "vessels:glass_bottle" },
415 minetest
.register_craft({
417 output
= "pep:gravreset" ,
418 recipe
= { "pep:grav0", "default:iron_lump" }
421 if(minetest
.get_modpath("flowers") ~= nil) then
422 minetest
.register_craft({
424 output
= "pep:speedplus",
425 recipe
= { "default:pine_sapling", "default:cactus", "flowers:dandelion_yellow", "default:junglegrass", "vessels:glass_bottle" }
430 --[[ independent crafts ]]
432 minetest
.register_craft({
434 output
= "pep:speedreset",
435 recipe
= { "pep:speedplus", "pep:speedminus" }
437 minetest
.register_craft({
439 output
= "pep:jumpreset",
440 recipe
= { "pep:jumpplus", "pep:jumpminus" }