1 local S
= minetest
.get_translator("mcl_potions")
2 local GRAVITY
= tonumber(minetest
.settings
:get("movement_gravity"))
4 local splash_image
= function(colorstring
, opacity
)
8 return "mcl_potions_splash_overlay.png^[colorize:"..colorstring
..":"..tostring(opacity
).."^mcl_potions_splash_bottle.png"
12 function mcl_potions
.register_splash(name
, descr
, color
, def
)
14 local id
= "mcl_potions:"..name
.."_splash"
15 local longdesc
= def
.longdesc
16 if not def
.no_effect
then
17 longdesc
= S("A throwable potion that will shatter on impact, where it gives all nearby players and mobs a status effect.")
19 longdesc
= longdesc
.. "\n" .. def
.longdesc
22 minetest
.register_craftitem(id
, {
25 _doc_items_longdesc
= longdesc
,
26 _doc_items_usagehelp
= S("Use the “Punch” key to throw it."),
27 inventory_image
= splash_image(color
),
28 groups
= {brewitem
=1, not_in_creative_inventory
=0},
29 on_use
= function(item
, placer
, pointed_thing
)
31 local dir
= placer
:get_look_dir();
32 local pos
= placer
:get_pos();
33 local obj
= minetest
.add_entity({x
=pos
.x
+dir
.x
,y
=pos
.y
+2+dir
.y
,z
=pos
.z
+dir
.z
}, id
.."_flying")
34 obj
:set_velocity({x
=dir
.x
*velocity
,y
=dir
.y
*velocity
,z
=dir
.z
*velocity
})
35 obj
:set_acceleration({x
=dir
.x
*-3, y
=-9.8, z
=dir
.z
*-3})
36 obj
:get_luaentity()._thrower
= placer
:get_player_name()
37 if not minetest
.is_creative_enabled(placer
:get_player_name()) then
43 _on_dispense
= function(stack
, dispenserpos
, droppos
, dropnode
, dropdir
)
44 local s_pos
= vector
.add(dispenserpos
, vector
.multiply(dropdir
, 0.51))
45 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")
47 obj
:set_velocity({x
=dropdir
.x
*velocity
,y
=dropdir
.y
*velocity
,z
=dropdir
.z
*velocity
})
48 obj
:set_acceleration({x
=dropdir
.x
*-3, y
=-9.8, z
=dropdir
.z
*-3})
54 minetest
.register_entity(id
.."_flying",{
55 textures
= {splash_image(color
)},
57 visual_size
= {x
=w
/2,y
=w
/2},
58 collisionbox
= {-0.1,-0.1,-0.1,0.1,0.1,0.1},
60 on_step
= function(self
, dtime
)
61 local pos
= self
.object
:get_pos()
62 local node
= minetest
.get_node(pos
)
65 local redux_map
= {7/8,0.5,0.25}
66 if n
~= "air" and n
~= "mcl_portals:portal" and n
~= "mcl_portals:portal_end" or mcl_potions
.is_obj_hit(self
, pos
) then
67 minetest
.sound_play("mcl_potions_breaking_glass", {pos
= pos
, max_hear_distance
= 16, gain
= 1})
69 if name
== "water" then
70 texture
= "mcl_potions_droplet.png"
71 acc
= {x
=0, y
=-GRAVITY
, z
=0}
73 texture
= "mcl_potions_sprite.png"
76 minetest
.add_particlespawner({
79 minpos
= {x
=pos
.x
-d
, y
=pos
.y
+0.5, z
=pos
.z
-d
},
80 maxpos
= {x
=pos
.x
+d
, y
=pos
.y
+0.5+d
, z
=pos
.z
+d
},
81 minvel
= {x
=-2, y
=0, z
=-2},
82 maxvel
= {x
=2, y
=2, z
=2},
89 collisiondetection
= true,
91 texture
= texture
.."^[colorize:"..color
..":127"
94 if name
== "water" then
95 mcl_potions
._extinguish_nearby_fire(pos
)
98 for _
,obj
in pairs(minetest
.get_objects_inside_radius(pos
, 4)) do
100 local entity
= obj
:get_luaentity()
101 if obj
:is_player() or entity
._cmi_is_mob
then
103 local pos2
= obj
:get_pos()
104 local rad = math
.floor(math
.sqrt((pos2
.x
-pos
.x
)^
2 + (pos2
.y
-pos
.y
)^
2 + (pos2
.z
-pos
.z
)^
2))
105 if rad > 0 then def
.potion_fun(obj
, redux_map
[rad]) else def
.potion_fun(obj
, 1) end
115 local function time_string(dur
)
116 return math
.floor(dur
/60)..string.format(":%02d",math
.floor(dur
% 60))
119 local splash_DUR
= mcl_potions
.DURATION
*mcl_potions
.SPLASH_FACTOR
120 local splash_DUR_2
= mcl_potions
.DURATION_2
*mcl_potions
.SPLASH_FACTOR
121 local splash_DUR_pl
= mcl_potions
.DURATION_PLUS
*mcl_potions
.SPLASH_FACTOR
125 -- register_splash("weakness", S("Weakness Splash Potion"), "#6600AA", {
126 -- potion_fun = function(player, redx) mcl_potions.weakness_func(player, -4, splash_DUR*mcl_potions.INV_FACTOR*redx) end,
127 -- -- TODO: Fix tooltip
128 -- tt = time_string(splash_DUR*mcl_potions.INV_FACTOR)
131 -- register_splash("weakness_plus", S("Weakness Splash Potion +"), "#7700BB", {
132 -- potion_fun = function(player, redx) mcl_potions.weakness_func(player, -4, splash_DUR_pl*mcl_potions.INV_FACTOR*redx) end,
133 -- -- TODO: Fix tooltip
134 -- tt = time_string(splash_DUR_pl*mcl_potions.INV_FACTOR)
137 -- register_splash("strength", S("Strength Splash Potion"), "#D444D4", {
138 -- potion_fun = function(player, redx) mcl_potions.strength_func(player, 3, splash_DUR*redx) end,
139 -- -- TODO: Fix tooltip
140 -- tt = time_string(splash_DUR)
143 -- register_splash("strength_2", S("Strength Splash Potion II"), "#D444F4", {
144 -- potion_fun = function(player, redx) mcl_potions.strength_func(player, 6, splash_DUR_2*redx) end,
145 -- -- TODO: Fix tooltip
146 -- tt = time_string(splash_DUR_2)
149 -- register_splash("strength_plus", S("Strength Splash Potion +"), "#D444E4", {
150 -- potion_fun = function(player, redx) mcl_potions.strength_func(player, 3, splash_DUR_pl*redx) end,
151 -- -- TODO: Fix tooltip
152 -- tt = time_string(splash_DUR_pl)