From ec2d700c9529d650063c66a7f355f732aa43b778 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 20 Jun 2020 10:16:00 -0400 Subject: [PATCH] Prevent compound regeneration --- mods/ITEMS/mcl_potions/functions.lua | 44 ++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 9cdd3c2a66..cd1a8ace98 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -1,5 +1,8 @@ local invisibility = {} local poisoned = {} +local regenerating = {} +local strong = {} +local weak = {} -- reset player invisibility/poison if they go offline minetest.register_on_leaveplayer(function(player) @@ -14,6 +17,18 @@ minetest.register_on_leaveplayer(function(player) poisoned[name] = nil end + if regenerating[name] then + regenerating[name] = nil + end + + if strong[name] then + strong[name] = nil + end + + if weak[name] then + weak[name] = nil + end + end) function mcl_potions.invisible(player, toggle) @@ -39,6 +54,13 @@ function mcl_potions.poison(player, toggle) end +function mcl_potions.regenerate(player, toggle) + + if not player then return false end + regenerating[player:get_player_name()] = toggle + +end + function mcl_potions._use_potion(item, obj, color) local d = 0.1 local pos = obj:get_pos() @@ -152,15 +174,19 @@ function mcl_potions.poison_func(player, factor, duration) end function mcl_potions.regeneration_func(player, factor, duration) - for i=1,math.floor(duration/factor) do - minetest.after(i*factor, function() - if player:get_hp() < 20 then - player:set_hp(player:get_hp() + 1) - end - end ) - end - for i=1,math.floor(duration) do - minetest.after(i, function() mcl_potions._add_spawner(player, "#A52BB2") end) + if not regenerating[player:get_player_name()] then + mcl_potions.regenerate(player, true) + for i=1,math.floor(duration/factor) do + minetest.after(i*factor, function() + if player:get_hp() < 20 then + player:set_hp(player:get_hp() + 1) + end + end ) + end + for i=1,math.floor(duration) do + minetest.after(i, function() mcl_potions._add_spawner(player, "#A52BB2") end) + end + minetest.after(duration, function() mcl_potions.regenerate(player, false) end) end end