1
0
Fork 0

Add persistent particle spawner.

This commit is contained in:
Brandon 2020-06-20 09:00:53 -04:00
parent a5e3b259fa
commit d929ca19a8
4 changed files with 114 additions and 67 deletions

View File

@ -39,8 +39,9 @@ function mcl_potions.poison(player, toggle)
end
function mcl_potions._use_potion(item, pos, color)
function mcl_potions._use_potion(item, obj, color)
local d = 0.1
local pos = obj:get_pos()
item:replace("mcl_potions:glass_bottle")
minetest.sound_play("mcl_potions_drinking")
minetest.add_particlespawner({
@ -55,13 +56,37 @@ function mcl_potions._use_potion(item, pos, color)
minexptime = 1,
maxexptime = 5,
minsize = 0.5,
maxsize = 2,
maxsize = 1,
collisiondetection = true,
vertical = false,
texture = "mcl_potions_sprite.png^[colorize:"..color..":127",
})
end
function mcl_potions._add_spawner(obj, color)
local d = 0.2
local pos = obj:get_pos()
minetest.add_particlespawner({
amount = 5,
time = 1,
minpos = {x=pos.x-d, y=pos.y+1, z=pos.z-d},
maxpos = {x=pos.x+d, y=pos.y+2, z=pos.z+d},
minvel = {x=-0.1, y=0, z=-0.1},
maxvel = {x=0.1, y=0.1, z=0.1},
minacc = {x=-0.1, y=0, z=-0.1},
maxacc = {x=0.1, y=.1, z=0.1},
minexptime = 0.5,
maxexptime = 1,
minsize = 0.5,
maxsize = 1,
collisiondetection = false,
vertical = false,
texture = "mcl_potions_sprite.png^[colorize:"..color..":127",
})
end
local is_zombie = {}
for i, zombie in ipairs({"husk","zombie","pigman"}) do
@ -85,18 +110,27 @@ function mcl_potions.swiftness_func(player, factor, duration)
if not player:get_meta() then return false end
playerphysics.add_physics_factor(player, "speed", "swiftness", factor)
minetest.after(duration, function() playerphysics.remove_physics_factor(player, "speed", "swiftness") end )
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#009999") end)
end
end
function mcl_potions.leaping_func(player, factor, duration)
if player:get_meta() then return false end
playerphysics.add_physics_factor(player, "jump", "leaping", factor)
minetest.after(duration, function() playerphysics.remove_physics_factor(player, "jump", "leaping") end )
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#00CC33") end)
end
end
function mcl_potions.weakness_func(player, factor, duration)
player:set_attribute("weakness", tostring(factor))
-- print(player:get_player_name().." ".."weakness = "..player:get_attribute("weakness"))
minetest.after(duration, function() player:set_attribute("weakness", tostring(0)) end )
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#6600AA") end)
end
end
function mcl_potions.poison_func(player, factor, duration)
@ -110,6 +144,9 @@ function mcl_potions.poison_func(player, factor, duration)
end
end)
end
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#225533") end)
end
minetest.after(duration, function() mcl_potions.poison(player, false) end)
end
end
@ -122,12 +159,20 @@ function mcl_potions.regeneration_func(player, factor, duration)
end
end )
end
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#A52BB2") end)
end
end
function mcl_potions.invisiblility_func(player, duration)
mcl_potions.invisible(player, true)
minetest.after(duration, function() mcl_potions.invisible(player, false) end )
for i=1,math.floor(duration) do
minetest.after(i, function() mcl_potions._add_spawner(player, "#B0B0B0") end)
end
end
function mcl_potions.water_breathing_func(player, duration)
@ -138,8 +183,10 @@ function mcl_potions.water_breathing_func(player, duration)
if player:get_breath() < 10 then
player:set_breath(10)
end
mcl_potions._add_spawner(player, "#0000AA")
end )
end
end
end

View File

@ -50,7 +50,7 @@ local function register_lingering(name, descr, color, def)
minacc = {x=-0.2, y=0, z=-0.2},
maxacc = {x=0.2, y=.05, z=0.2},
minexptime = 1,
maxexptime = 5,
maxexptime = 2,
minsize = 2,
maxsize = 4,
collisiondetection = true,

View File

@ -73,13 +73,13 @@ minetest.register_craftitem("mcl_potions:healing", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.healing_func(user, 4)
mcl_potions._use_potion(itemstack, user:get_pos(), "#CC0000")
mcl_potions._use_potion(itemstack, user, "#CC0000")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.healing_func(user, 4)
mcl_potions._use_potion(itemstack, user:get_pos(), "#CC0000")
mcl_potions._use_potion(itemstack, user, "#CC0000")
return itemstack
end,
})
@ -94,13 +94,13 @@ minetest.register_craftitem("mcl_potions:healing_2", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.healing_func(user, 8)
mcl_potions._use_potion(itemstack, user:get_pos(), "#DD0000")
mcl_potions._use_potion(itemstack, user, "#DD0000")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.healing_func(user, 8)
mcl_potions._use_potion(itemstack, user:get_pos(), "#DD0000")
mcl_potions._use_potion(itemstack, user, "#DD0000")
return itemstack
end,
@ -116,13 +116,13 @@ minetest.register_craftitem("mcl_potions:harming", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.healing_func(user, -6)
mcl_potions._use_potion(itemstack, user:get_pos(), "#660099")
mcl_potions._use_potion(itemstack, user, "#660099")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.healing_func(user, -6)
mcl_potions._use_potion(itemstack, user:get_pos(), "#660099")
mcl_potions._use_potion(itemstack, user, "#660099")
return itemstack
end,
})
@ -137,13 +137,13 @@ minetest.register_craftitem("mcl_potions:harming_2", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.healing_func(user, -12)
mcl_potions._use_potion(itemstack, user:get_pos(), "#330066")
mcl_potions._use_potion(itemstack, user, "#330066")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.healing_func(user, -12)
mcl_potions._use_potion(itemstack, user:get_pos(), "#330066")
mcl_potions._use_potion(itemstack, user, "#330066")
return itemstack
end,
})
@ -169,13 +169,13 @@ minetest.register_craftitem("mcl_potions:swiftness", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 1.2, 180)
mcl_potions._use_potion(itemstack, user:get_pos(), "#009999")
mcl_potions._use_potion(itemstack, user, "#009999")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 1.2, 180)
mcl_potions._use_potion(itemstack, user:get_pos(), "#009999")
mcl_potions._use_potion(itemstack, user, "#009999")
return itemstack
end,
})
@ -190,13 +190,13 @@ minetest.register_craftitem("mcl_potions:swiftness_2", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 1.4, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00BBBB")
mcl_potions._use_potion(itemstack, user, "#00BBBB")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 1.4, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00BBBB")
mcl_potions._use_potion(itemstack, user, "#00BBBB")
return itemstack
end,
})
@ -211,13 +211,13 @@ minetest.register_craftitem("mcl_potions:swiftness_plus", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 1.2, 480)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00AAAA")
mcl_potions._use_potion(itemstack, user, "#00AAAA")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 1.2, 480)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00AAAA")
mcl_potions._use_potion(itemstack, user, "#00AAAA")
return itemstack
end,
})
@ -232,13 +232,13 @@ minetest.register_craftitem("mcl_potions:slowness", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 0.85, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#000080")
mcl_potions._use_potion(itemstack, user, "#000080")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 0.85, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#000080")
mcl_potions._use_potion(itemstack, user, "#000080")
return itemstack
end,
})
@ -253,13 +253,13 @@ minetest.register_craftitem("mcl_potions:slowness_plus", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 0.85, 240)
mcl_potions._use_potion(itemstack, user:get_pos(), "#000066")
mcl_potions._use_potion(itemstack, user, "#000066")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.swiftness_func(user, 0.85, 240)
mcl_potions._use_potion(itemstack, user:get_pos(), "#000066")
mcl_potions._use_potion(itemstack, user, "#000066")
return itemstack
end,
})
@ -275,13 +275,13 @@ minetest.register_craftitem("mcl_potions:leaping", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.leaping_func(user, 1.2, 180)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00CC33")
mcl_potions._use_potion(itemstack, user, "#00CC33")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.leaping_func(user, 1.2, 180)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00CC33")
mcl_potions._use_potion(itemstack, user, "#00CC33")
return itemstack
end,
})
@ -296,13 +296,13 @@ minetest.register_craftitem("mcl_potions:leaping_2", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.leaping_func(user, 1.4, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00EE33")
mcl_potions._use_potion(itemstack, user, "#00EE33")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.leaping_func(user, 1.4, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00EE33")
mcl_potions._use_potion(itemstack, user, "#00EE33")
return itemstack
end,
})
@ -317,13 +317,13 @@ minetest.register_craftitem("mcl_potions:leaping_plus", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.leaping_func(user, 1.2, 480)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00DD33")
mcl_potions._use_potion(itemstack, user, "#00DD33")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.leaping_func(user, 1.2, 480)
mcl_potions._use_potion(itemstack, user:get_pos(), "#00DD33")
mcl_potions._use_potion(itemstack, user, "#00DD33")
return itemstack
end,
})
@ -339,13 +339,13 @@ minetest.register_craftitem("mcl_potions:weakness", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.weakness_func(user, 1.2, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#6600AA")
mcl_potions._use_potion(itemstack, user, "#6600AA")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.weakness_func(user, 1.2, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#6600AA")
mcl_potions._use_potion(itemstack, user, "#6600AA")
return itemstack
end
})
@ -360,13 +360,13 @@ minetest.register_craftitem("mcl_potions:weakness_plus", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.weakness_func(user, 1.4, 240)
mcl_potions._use_potion(itemstack, user:get_pos(), "#7700BB")
mcl_potions._use_potion(itemstack, user, "#7700BB")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.weakness_func(user, 1.4, 240)
mcl_potions._use_potion(itemstack, user:get_pos(), "#7700BB")
mcl_potions._use_potion(itemstack, user, "#7700BB")
return itemstack
end
})
@ -382,13 +382,13 @@ minetest.register_craftitem("mcl_potions:poison", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.poison_func(user, 2.5, 45)
mcl_potions._use_potion(itemstack, user:get_pos(), "#225533")
mcl_potions._use_potion(itemstack, user, "#225533")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.poison_func(user, 2.5, 45)
mcl_potions._use_potion(itemstack, user:get_pos(), "#225533")
mcl_potions._use_potion(itemstack, user, "#225533")
return itemstack
end
})
@ -403,13 +403,13 @@ minetest.register_craftitem("mcl_potions:poison_2", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.poison_func(user, 1.2, 21)
mcl_potions._use_potion(itemstack, user:get_pos(), "#447755")
mcl_potions._use_potion(itemstack, user, "#447755")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.poison_func(user, 1.2, 21)
mcl_potions._use_potion(itemstack, user:get_pos(), "#447755")
mcl_potions._use_potion(itemstack, user, "#447755")
return itemstack
end
})
@ -424,13 +424,13 @@ minetest.register_craftitem("mcl_potions:poison_plus", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.poison_func(user, 2.5, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#336644")
mcl_potions._use_potion(itemstack, user, "#336644")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.poison_func(user, 2.5, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#336644")
mcl_potions._use_potion(itemstack, user, "#336644")
return itemstack
end
})
@ -446,13 +446,13 @@ minetest.register_craftitem("mcl_potions:regeneration", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.regeneration_func(user, 2.5, 45)
mcl_potions._use_potion(itemstack, user:get_pos(), "#A52BB2")
mcl_potions._use_potion(itemstack, user, "#A52BB2")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.regeneration_func(user, 2.5, 45)
mcl_potions._use_potion(itemstack, user:get_pos(), "#A52BB2")
mcl_potions._use_potion(itemstack, user, "#A52BB2")
return itemstack
end
})
@ -467,13 +467,13 @@ minetest.register_craftitem("mcl_potions:regeneration_2", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.regeneration_func(user, 1.2, 22)
mcl_potions._use_potion(itemstack, user:get_pos(), "#B52CC2")
mcl_potions._use_potion(itemstack, user, "#B52CC2")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.regeneration_func(user, 1.2, 22)
mcl_potions._use_potion(itemstack, user:get_pos(), "#B52CC2")
mcl_potions._use_potion(itemstack, user, "#B52CC2")
return itemstack
end
})
@ -488,13 +488,13 @@ minetest.register_craftitem("mcl_potions:regeneration_plus", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.regeneration_func(user, 2.5, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#C53DD3")
mcl_potions._use_potion(itemstack, user, "#C53DD3")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.regeneration_func(user, 2.5, 90)
mcl_potions._use_potion(itemstack, user:get_pos(), "#C53DD3")
mcl_potions._use_potion(itemstack, user, "#C53DD3")
return itemstack
end
})
@ -510,13 +510,13 @@ minetest.register_craftitem("mcl_potions:invisibility", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.invisiblility_func(user, 180)
mcl_potions._use_potion(itemstack, user:get_pos(), "#B0B0B0")
mcl_potions._use_potion(itemstack, user, "#B0B0B0")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.invisiblility_func(user, 180)
mcl_potions._use_potion(itemstack, user:get_pos(), "#B0B0B0")
mcl_potions._use_potion(itemstack, user, "#B0B0B0")
return itemstack
end
})
@ -531,13 +531,13 @@ minetest.register_craftitem("mcl_potions:invisibility_plus", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.invisiblility_func(user, 480)
mcl_potions._use_potion(itemstack, user:get_pos(), "#A0A0A0")
mcl_potions._use_potion(itemstack, user, "#A0A0A0")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.invisiblility_func(user, 480)
mcl_potions._use_potion(itemstack, user:get_pos(), "#A0A0A0")
mcl_potions._use_potion(itemstack, user, "#A0A0A0")
return itemstack
end
})
@ -560,13 +560,13 @@ minetest.register_craftitem("mcl_potions:water_breathing", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.water_breathing_func(user, 180)
mcl_potions._use_potion(itemstack, user:get_pos(), "#0000AA")
mcl_potions._use_potion(itemstack, user, "#0000AA")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.water_breathing_func(user, 180)
mcl_potions._use_potion(itemstack, user:get_pos(), "#0000AA")
mcl_potions._use_potion(itemstack, user, "#0000AA")
return itemstack
end
})
@ -581,13 +581,13 @@ minetest.register_craftitem("mcl_potions:water_breathing_plus", {
on_place = function(itemstack, user, pointed_thing)
mcl_potions.water_breathing_func(user, 480)
mcl_potions._use_potion(itemstack, user:get_pos(), "#0000CC")
mcl_potions._use_potion(itemstack, user, "#0000CC")
return itemstack
end,
on_secondary_use = function(itemstack, user, pointed_thing)
mcl_potions.water_breathing_func(user, 480)
mcl_potions._use_potion(itemstack, user:get_pos(), "#0000CC")
mcl_potions._use_potion(itemstack, user, "#0000CC")
return itemstack
end
})

View File

@ -49,7 +49,7 @@ local function register_splash(name, descr, color, def)
minacc = {x=-0.5, y=0, z=-0.5},
maxacc = {x=0.5, y=.2, z=0.5},
minexptime = 1,
maxexptime = 5,
maxexptime = 3,
minsize = 2,
maxsize = 4,
collisiondetection = true,