1 local S
= minetest
.get_translator("mcl_potions")
3 local splash_image
= function(colorstring
, opacity
)
7 return "mcl_potions_splash_overlay.png^[colorize:"..colorstring
..":"..tostring(opacity
).."^mcl_potions_splash_bottle.png"
11 function mcl_potions
.register_splash(name
, descr
, color
, def
)
13 local id
= "mcl_potions:"..name
.."_splash"
14 local longdesc
= def
.longdesc
15 if not def
.no_effect
then
16 longdesc
= S("A throwable potion that will shatter on impact, where it gives all nearby players and mobs a status effect.")
18 longdesc
= longdesc
.. "\n" .. def
.longdesc
21 minetest
.register_craftitem(id
, {
24 _doc_items_longdesc
= longdesc
,
25 _doc_items_usagehelp
= S("Use the “Punch” key to throw it."),
26 inventory_image
= splash_image(color
),
27 groups
= {brewitem
=1, not_in_creative_inventory
=0},
28 on_use
= function(item
, placer
, pointed_thing
)
30 local dir
= placer
:get_look_dir();
31 local pos
= placer
:get_pos();
32 local obj
= minetest
.add_entity({x
=pos
.x
+dir
.x
,y
=pos
.y
+2+dir
.y
,z
=pos
.z
+dir
.z
}, id
.."_flying")
33 obj
:set_velocity({x
=dir
.x
*velocity
,y
=dir
.y
*velocity
,z
=dir
.z
*velocity
})
34 obj
:set_acceleration({x
=dir
.x
*-3, y
=-9.8, z
=dir
.z
*-3})
35 obj
:get_luaentity()._thrower
= placer
:get_player_name()
36 if not minetest
.is_creative_enabled(placer
:get_player_name()) then
42 _on_dispense
= function(stack
, dispenserpos
, droppos
, dropnode
, dropdir
)
43 local s_pos
= vector
.add(dispenserpos
, vector
.multiply(dropdir
, 0.51))
44 local obj
= minetest
.add_entity({x
=s_pos
.x
+dropdir
.x
,y
=s_pos
.y
+dropdir
.y
,z
=s_pos
.z
+dropdir
.z
}, id
.."_flying")
46 obj
:set_velocity({x
=dropdir
.x
*velocity
,y
=dropdir
.y
*velocity
,z
=dropdir
.z
*velocity
})
47 obj
:set_acceleration({x
=dropdir
.x
*-3, y
=-9.8, z
=dropdir
.z
*-3})
53 minetest
.register_entity(id
.."_flying",{
54 textures
= {splash_image(color
)},
56 visual_size
= {x
=w
/2,y
=w
/2},
57 collisionbox
= {0,0,0,0,0,0},
58 on_step
= function(self
, dtime
)
59 local pos
= self
.object
:getpos()
60 local node
= minetest
.get_node(pos
)
63 local redux_map
= {7/8,0.5,0.25}
64 if n
~= "air" and n
~= "mcl_portals:portal" and n
~= "mcl_portals:portal_end" or mcl_potions
.is_obj_hit(self
, pos
) then
65 minetest
.sound_play("mcl_potions_breaking_glass", {pos
= pos
, max_hear_distance
= 16, gain
= 1})
66 minetest
.add_particlespawner({
69 minpos
= {x
=pos
.x
-d
, y
=pos
.y
+0.5, z
=pos
.z
-d
},
70 maxpos
= {x
=pos
.x
+d
, y
=pos
.y
+d
, z
=pos
.z
+d
},
71 minvel
= {x
=-1, y
=0, z
=-1},
72 maxvel
= {x
=1, y
=0.5, z
=1},
73 minacc
= {x
=-0.5, y
=0, z
=-0.5},
74 maxacc
= {x
=0.5, y
=.2, z
=0.5},
79 collisiondetection
= true,
81 texture
= "mcl_potions_sprite.png^[colorize:"..color
..":127",
84 for _
,obj
in pairs(minetest
.get_objects_inside_radius(pos
, 4)) do
86 local entity
= obj
:get_luaentity()
87 if obj
:is_player() or entity
._cmi_is_mob
then
89 local pos2
= obj
:get_pos()
90 local rad = math
.floor(math
.sqrt((pos2
.x
-pos
.x
)^
2 + (pos2
.y
-pos
.y
)^
2 + (pos2
.z
-pos
.z
)^
2))
91 if rad > 0 then def
.potion_fun(obj
, redux_map
[rad]) else def
.potion_fun(obj
, 1) end
101 local function time_string(dur
)
102 return math
.floor(dur
/60)..string.format(":%02d",math
.floor(dur
% 60))
105 local splash_DUR
= mcl_potions
.DURATION
*mcl_potions
.SPLASH_FACTOR
106 local splash_DUR_2
= mcl_potions
.DURATION_2
*mcl_potions
.SPLASH_FACTOR
107 local splash_DUR_pl
= mcl_potions
.DURATION_PLUS
*mcl_potions
.SPLASH_FACTOR
111 -- register_splash("weakness", S("Weakness Splash Potion"), "#6600AA", {
112 -- potion_fun = function(player, redx) mcl_potions.weakness_func(player, -4, splash_DUR*mcl_potions.INV_FACTOR*redx) end,
113 -- -- TODO: Fix tooltip
114 -- tt = time_string(splash_DUR*mcl_potions.INV_FACTOR)
117 -- register_splash("weakness_plus", S("Weakness Splash Potion +"), "#7700BB", {
118 -- potion_fun = function(player, redx) mcl_potions.weakness_func(player, -4, splash_DUR_pl*mcl_potions.INV_FACTOR*redx) end,
119 -- -- TODO: Fix tooltip
120 -- tt = time_string(splash_DUR_pl*mcl_potions.INV_FACTOR)
123 -- register_splash("strength", S("Strength Splash Potion"), "#D444D4", {
124 -- potion_fun = function(player, redx) mcl_potions.strength_func(player, 3, splash_DUR*redx) end,
125 -- -- TODO: Fix tooltip
126 -- tt = time_string(splash_DUR)
129 -- register_splash("strength_2", S("Strength Splash Potion II"), "#D444F4", {
130 -- potion_fun = function(player, redx) mcl_potions.strength_func(player, 6, splash_DUR_2*redx) end,
131 -- -- TODO: Fix tooltip
132 -- tt = time_string(splash_DUR_2)
135 -- register_splash("strength_plus", S("Strength Splash Potion +"), "#D444E4", {
136 -- potion_fun = function(player, redx) mcl_potions.strength_func(player, 3, splash_DUR_pl*redx) end,
137 -- -- TODO: Fix tooltip
138 -- tt = time_string(splash_DUR_pl)