Fix lingering potion timer.
parent
2a29ec7827
commit
79e7f6849f
|
@ -12,25 +12,19 @@ local function add_lingering_effect(pos, color, def)
|
||||||
|
|
||||||
lingering_effect_at[pos] = {color = color, timer = 30, def = def}
|
lingering_effect_at[pos] = {color = color, timer = 30, def = def}
|
||||||
|
|
||||||
local timer = 0
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local lingering_timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
|
|
||||||
timer = timer + dtime
|
lingering_timer = lingering_timer + dtime
|
||||||
|
if lingering_timer >= 1 then
|
||||||
if timer >= 1 then
|
|
||||||
|
|
||||||
for pos, vals in pairs(lingering_effect_at) do
|
for pos, vals in pairs(lingering_effect_at) do
|
||||||
|
|
||||||
if lingering_effect_at[pos] then
|
vals.timer = vals.timer - lingering_timer
|
||||||
|
local d = 4 * (vals.timer / 30.0)
|
||||||
lingering_effect_at[pos].timer = lingering_effect_at[pos].timer - timer
|
|
||||||
|
|
||||||
-- print(lingering_effect_at[pos].timer)
|
|
||||||
|
|
||||||
if lingering_effect_at[pos].timer > 0 then
|
|
||||||
|
|
||||||
local d = 4 * (lingering_effect_at[pos].timer / 30.0)
|
|
||||||
|
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = 5 * d^2,
|
amount = 5 * d^2,
|
||||||
|
@ -47,7 +41,7 @@ local function add_lingering_effect(pos, color, def)
|
||||||
maxsize = 4,
|
maxsize = 4,
|
||||||
collisiondetection = true,
|
collisiondetection = true,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
texture = "mcl_potions_sprite.png^[colorize:"..lingering_effect_at[pos].color..":127",
|
texture = "mcl_potions_sprite.png^[colorize:"..vals.color..":127",
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, d)) do
|
for _, obj in pairs(minetest.get_objects_inside_radius(pos, d)) do
|
||||||
|
@ -55,26 +49,19 @@ local function add_lingering_effect(pos, color, def)
|
||||||
local entity = obj:get_luaentity()
|
local entity = obj:get_luaentity()
|
||||||
if obj:is_player() or entity._cmi_is_mob then
|
if obj:is_player() or entity._cmi_is_mob then
|
||||||
|
|
||||||
-- if obj:is_player() then print(obj:is_player()) print(obj:get_player_name()) end
|
vals.def.potion_fun(obj)
|
||||||
-- if entity then print(entity.name) print(entity._cmi_is_mob) end
|
vals.timer = vals.timer / 2
|
||||||
|
|
||||||
lingering_effect_at[pos].def.potion_fun(obj)
|
|
||||||
lingering_effect_at[pos].timer = lingering_effect_at[pos].timer / 2
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
if vals.timer <= 0 then lingering_effect_at[pos] = nil end
|
||||||
lingering_effect_at[pos] = nil
|
|
||||||
end
|
end
|
||||||
end
|
lingering_timer = 0
|
||||||
end
|
|
||||||
timer = 0
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function register_lingering(name, descr, color, def)
|
local function register_lingering(name, descr, color, def)
|
||||||
|
@ -114,7 +101,7 @@ local function register_lingering(name, descr, color, def)
|
||||||
minetest.sound_play("mcl_potions_breaking_glass", {pos = pos, max_hear_distance = 16, gain = 1})
|
minetest.sound_play("mcl_potions_breaking_glass", {pos = pos, max_hear_distance = 16, gain = 1})
|
||||||
add_lingering_effect(pos, color, def)
|
add_lingering_effect(pos, color, def)
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = 20,
|
amount = 40,
|
||||||
time = 1,
|
time = 1,
|
||||||
minpos = {x=pos.x-d, y=pos.y+0.5, z=pos.z-d},
|
minpos = {x=pos.x-d, y=pos.y+0.5, z=pos.z-d},
|
||||||
maxpos = {x=pos.x+d, y=pos.y+1, z=pos.z+d},
|
maxpos = {x=pos.x+d, y=pos.y+1, z=pos.z+d},
|
||||||
|
|
Loading…
Reference in New Issue