1 -- Boilerplate to support localized strings if intllib mod is installed.
3 if minetest
.get_modpath("intllib") then
6 S
= function(s
) return s
end
8 local ppa
= minetest
.get_modpath("playerphysics")
11 function pep
.register_potion(potiondef
)
13 if(potiondef
.effect_type
~= nil) then
14 on_use
= function(itemstack
, user
, pointed_thing
)
15 playereffects
.apply_effect_type(potiondef
.effect_type
, potiondef
.duration
, user
)
20 on_use
= function(itemstack
, user
, pointed_thing
)
25 minetest
.register_craftitem("pep:"..potiondef
.basename
, {
26 description
= string.format(S("Glass Bottle (%s)"), potiondef
.contentstring
),
27 _doc_items_longdesc
= potiondef
.longdesc
,
28 _doc_items_usagehelp
= S("Hold it in your hand, then left-click to drink it."),
29 inventory_image
= "pep_"..potiondef
.basename
..".png",
30 wield_image
= "pep_"..potiondef
.basename
..".png",
37 function pep
.enable_mole_mode(playername
)
38 pep
.moles
[playername
] = true
41 function pep
.disable_mole_mode(playername
)
42 pep
.moles
[playername
] = false
45 function pep
.yaw_to_vector(yaw
)
50 return { x
=0, y
=0, z
=1}
51 elseif yaw
< (3/8)*tau
then
52 return { x
=-1, y
=0, z
=0 }
53 elseif yaw
< (5/8)*tau
then
54 return { x
=0, y
=0, z
=-1 }
55 elseif yaw
< (7/8)*tau
then
56 return { x
=1, y
=0, z
=0 }
58 return { x
=0, y
=0, z
=1}
62 function pep
.moledig(playername
)
63 local player
= minetest
.get_player_by_name(playername
)
65 local yaw
= player
:get_look_yaw()
66 -- fix stupid oddity of Minetest, adding pi/2 to the actual player's look yaw...
67 -- TODO: Remove this code as soon as Minetest fixes this.
70 local pos
= vector
.round(player
:getpos())
72 local v
= pep
.yaw_to_vector(yaw
)
74 local digpos1
= vector
.add(pos
, v
)
75 local digpos2
= { x
= digpos1
.x
, y
= digpos1
.y
+1, z
= digpos1
.z
}
77 local try_dig
= function(pos
)
78 local n
= minetest
.get_node(pos
)
79 local ndef
= minetest
.registered_nodes
[n
.name
]
80 if ndef
.walkable
and ndef
.diggable
then
81 if ndef
.can_dig
~= nil then
82 if ndef
.can_dig() then
95 local dig
= function(pos
)
97 local n
= minetest
.get_node(pos
)
98 local ndef
= minetest
.registered_nodes
[n
.name
]
99 if ndef
.sounds
~= nil then
100 minetest
.sound_play(ndef
.sounds
.dug
, { pos
= pos
})
102 -- TODO: Replace this code as soon Minetest removes support for this function
103 local drops
= minetest
.get_node_drops(n
.name
, "default:pick_steel")
104 minetest
.dig_node(pos
)
105 local inv
= player
:get_inventory()
108 table.insert(leftovers
, inv
:add_item("main", drops
[i
]))
110 for i
=1,#leftovers
do
111 minetest
.add_item(pos
, leftovers
[i
])
122 minetest
.register_globalstep(function(dtime
)
123 pep
.timer
= pep
.timer
+ dtime
124 if pep
.timer
> 0.5 then
125 for playername
, is_mole
in pairs(pep
.moles
) do
127 pep
.moledig(playername
)
134 local add_physic
= function(player
, attribute
, value
)
136 playerphysics
.add_physics_factor(player
, attribute
, "pep:"..attribute
, value
)
138 player
:set_physics_override({[attribute
]=value
})
141 local remove_physic
= function(player
, attribute
)
143 playerphysics
.remove_physics_factor(player
, attribute
, "pep:"..attribute
)
145 player
:set_physics_override({[attribute
]=1})
149 playereffects
.register_effect_type("pepspeedplus", S("High speed"), "pep_speedplus.png", {"speed"},
151 add_physic(player
, "speed", 2)
153 function(effect
, player
)
154 remove_physic(player
, "speed")
157 playereffects
.register_effect_type("pepspeedminus", S("Low speed"), "pep_speedminus.png", {"speed"},
159 add_physic(player
, "speed", 0.5)
161 function(effect
, player
)
162 remove_physic(player
, "speed")
165 playereffects
.register_effect_type("pepspeedreset", S("Speed neutralizer"), "pep_speedreset.png", {"speed"},
166 function() end, function() end)
167 playereffects
.register_effect_type("pepjumpplus", S("High jump"), "pep_jumpplus.png", {"jump"},
169 add_physic(player
, "jump", 2)
171 function(effect
, player
)
172 remove_physic(player
, "jump")
175 playereffects
.register_effect_type("pepjumpminus", S("Low jump"), "pep_jumpminus.png", {"jump"},
177 add_physic(player
, "jump", 0.5)
179 function(effect
, player
)
180 remove_physic(player
, "jump")
183 playereffects
.register_effect_type("pepjumpreset", S("Jump height neutralizer"), "pep_jumpreset.png", {"jump"},
184 function() end, function() end)
185 playereffects
.register_effect_type("pepgrav0", S("No gravity"), "pep_grav0.png", {"gravity"},
187 add_physic(player
, "gravity", 0)
189 function(effect
, player
)
190 remove_physic(player
, "gravity")
193 playereffects
.register_effect_type("pepgravreset", S("Gravity neutralizer"), "pep_gravreset.png", {"gravity"},
194 function() end, function() end)
195 playereffects
.register_effect_type("pepregen", S("Regeneration"), "pep_regen.png", {"health"},
197 player
:set_hp(player
:get_hp()+1)
201 playereffects
.register_effect_type("pepregen2", S("Strong regeneration"), "pep_regen2.png", {"health"},
203 player
:set_hp(player
:get_hp()+2)
208 if minetest
.get_modpath("mana") ~= nil then
209 playereffects
.register_effect_type("pepmanaregen", S("Weak mana boost"), "pep_manaregen.png", {"mana"},
211 local name
= player
:get_player_name()
212 mana
.setregen(name
, mana
.getregen(name
) + 0.5)
214 function(effect
, player
)
215 local name
= player
:get_player_name()
216 mana
.setregen(name
, mana
.getregen(name
) - 0.5)
219 playereffects
.register_effect_type("pepmanaregen2", S("Strong mana boost"), "pep_manaregen2.png", {"mana"},
221 local name
= player
:get_player_name()
222 mana
.setregen(name
, mana
.getregen(name
) + 1)
224 function(effect
, player
)
225 local name
= player
:get_player_name()
226 mana
.setregen(name
, mana
.getregen(name
) - 1)
232 playereffects
.register_effect_type("pepbreath", S("Perfect breath"), "pep_breath.png", {"breath"},
234 player
:set_breath(player
:get_breath()+2)
238 playereffects
.register_effect_type("pepmole", S("Mole mode"), "pep_mole.png", {"autodig"},
240 pep
.enable_mole_mode(player
:get_player_name())
242 function(effect
, player
)
243 pep
.disable_mole_mode(player
:get_player_name())
247 pep
.register_potion({
248 basename
= "speedplus",
249 contentstring
= S("Running Potion"),
250 longdesc
= S("Drinking it will make you run faster for 30 seconds."),
251 effect_type
= "pepspeedplus",
254 pep
.register_potion({
255 basename
= "speedminus",
256 contentstring
= S("Slug Potion"),
257 longdesc
= S("Drinking it will make you walk slower for 30 seconds."),
258 effect_type
= "pepspeedminus",
261 pep
.register_potion({
262 basename
= "speedreset",
263 contentstring
= S("Speed Neutralizer"),
264 longdesc
= S("Drinking it will stop all speed effects you may currently have."),
265 effect_type
= "pepspeedreset",
268 pep
.register_potion({
270 contentstring
= S("Air Potion"),
271 longdesc
= S("Drinking it gives you breath underwater for 30 seconds."),
272 effect_type
= "pepbreath",
275 pep
.register_potion({
277 contentstring
= S("Weak Healing Potion"),
278 longdesc
= S("Drinking it makes you regenerate health. Every 2 seconds, you get 1 HP, 10 times in total."),
279 effect_type
= "pepregen",
282 pep
.register_potion({
284 contentstring
= S("Strong Healing Potion"),
285 longdesc
= S("Drinking it makes you regenerate health quickly. Every second you get 2 HP, 10 times in total."),
286 effect_type
= "pepregen2",
289 pep
.register_potion({
291 contentstring
= S("Non-Gravity Potion"),
292 longdesc
= S("When you drink this potion, gravity stops affecting you, as if you were in space. The effect lasts for 20 seconds."),
293 effect_type
= "pepgrav0",
296 pep
.register_potion({
297 basename
= "gravreset",
298 contentstring
= S("Gravity Neutralizer"),
299 longdesc
= S("Drinking it will stop all gravity effects you currently have."),
300 effect_type
= "pepgravreset",
303 pep
.register_potion({
304 basename
= "jumpplus",
305 contentstring
= S("High Jumping Potion"),
306 longdesc
= S("Drinking it will make you jump higher for 30 seconds."),
307 effect_type
= "pepjumpplus",
310 pep
.register_potion({
311 basename
= "jumpminus",
312 contentstring
= S("Low Jumping Potion"),
313 longdesc
= S("Drinking it will make you jump lower for 30 seconds."),
314 effect_type
= "pepjumpminus",
317 pep
.register_potion({
318 basename
= "jumpreset",
319 contentstring
= S("Jump Neutralizer"),
320 longdesc
= S("Drinking it will stop all jumping effects you may currently have."),
321 effect_type
= "pepjumpreset",
324 pep
.register_potion({
326 contentstring
= S("Mole Potion"),
327 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."),
328 effect_type
= "pepmole",
331 if(minetest
.get_modpath("mana")~=nil) then
332 pep
.register_potion({
333 basename
= "manaregen",
334 contentstring
= S("Weak Mana Potion"),
335 effect_type
= "pepmanaregen",
337 longdesc
= S("Drinking it will increase your mana regeneration rate by 0.5 for 10 seconds."),
339 pep
.register_potion({
340 basename
= "manaregen2",
341 contentstring
= S("Strong Mana Potion"),
342 effect_type
= "pepmanaregen2",
344 longdesc
= S("Drinking it will increase your mana regeneration rate by 1 for 10 seconds."),
349 --[=[ register crafts ]=]
350 --[[ normal potions ]]
351 if(minetest
.get_modpath("vessels")~=nil) then
352 if(minetest
.get_modpath("default")~=nil) then
353 minetest
.register_craft({
355 output
= "pep:breath",
356 recipe
= { "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus",
357 "default:papyrus", "default:papyrus", "default:papyrus", "default:papyrus", "vessels:glass_bottle" }
359 minetest
.register_craft({
361 output
= "pep:speedminus",
362 recipe
= { "default:dry_grass_1", "default:ice", "vessels:glass_bottle" }
364 if(minetest
.get_modpath("flowers") ~= nil) then
365 minetest
.register_craft({
367 output
= "pep:jumpplus",
368 recipe
= { "flowers:flower_tulip", "default:grass_1", "default:mese_crystal_fragment",
369 "default:mese_crystal_fragment", "vessels:glass_bottle" }
371 minetest
.register_craft({
373 output
= "pep:poisoner",
374 recipe
= { "flowers:mushroom_red", "flowers:mushroom_red", "flowers:mushroom_red", "vessels:glass_bottle" }
377 if(minetest
.get_modpath("farming") ~= nil) then
378 minetest
.register_craft({
380 output
= "pep:regen",
381 recipe
= { "default:cactus", "farming:flour", "flowers:mushroom_brown", "vessels:glass_bottle" }
385 if(minetest
.get_modpath("farming") ~= nil) then
386 minetest
.register_craft({
388 output
= "pep:regen2",
389 recipe
= { "default:gold_lump", "farming:flour", "pep:regen" }
391 if minetest
.get_modpath("mana") ~= nil then
392 minetest
.register_craft({
394 output
= "pep:manaregen",
395 recipe
= { "default:dry_shrub", "default:dry_shrub", "farming:seed_cotton", "default:mese_crystal_fragment",
396 "vessels:glass_bottle" }
400 if minetest
.get_modpath("mana") ~= nil then
401 minetest
.register_craft({
403 output
= "pep:manaregen2",
404 recipe
= { "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:dry_shrub", "default:junglesapling",
405 "default:acacia_sapling", "default:mese_crystal_fragment", "pep:manaregen" }
409 minetest
.register_craft({
411 output
= "pep:jumpminus",
412 recipe
= { "default:leaves", "default:jungleleaves", "default:iron_lump", "flowers:dandelion_yellow", "vessels:glass_bottle" }
414 minetest
.register_craft({
416 output
= "pep:grav0",
417 recipe
= { "default:mese_crystal", "vessels:glass_bottle" }
419 minetest
.register_craft({
422 recipe
= { "default:pick_steel", "default:shovel_steel", "vessels:glass_bottle" },
424 minetest
.register_craft({
426 output
= "pep:gravreset" ,
427 recipe
= { "pep:grav0", "default:iron_lump" }
430 if(minetest
.get_modpath("flowers") ~= nil) then
431 minetest
.register_craft({
433 output
= "pep:speedplus",
434 recipe
= { "default:pine_sapling", "default:cactus", "flowers:dandelion_yellow", "default:junglegrass", "vessels:glass_bottle" }
439 --[[ independent crafts ]]
441 minetest
.register_craft({
443 output
= "pep:speedreset",
444 recipe
= { "pep:speedplus", "pep:speedminus" }
446 minetest
.register_craft({
448 output
= "pep:jumpreset",
449 recipe
= { "pep:jumpplus", "pep:jumpminus" }