From 0e339472585064bacd7851ad7be1a031af6640b7 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Tue, 23 Jan 2024 01:18:07 +0100 Subject: [PATCH] Renamed some functions and variables * changed names referring to player where it does support mobs * also added an is_player() check in one function --- mods/ENVIRONMENT/mcl_raids/init.lua | 8 ++++---- mods/ITEMS/mcl_campfires/api.lua | 2 +- mods/ITEMS/mcl_nether/init.lua | 2 +- mods/ITEMS/mcl_potions/functions.lua | 23 ++++++++++++----------- mods/PLAYER/mcl_hunger/hunger.lua | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_raids/init.lua b/mods/ENVIRONMENT/mcl_raids/init.lua index 8e7c644ae..208ee93e0 100644 --- a/mods/ENVIRONMENT/mcl_raids/init.lua +++ b/mods/ENVIRONMENT/mcl_raids/init.lua @@ -104,7 +104,7 @@ function mcl_raids.promote_to_raidcaptain(c) -- object mcl_raids.drop_obanner(pos) if cmi_cause and cmi_cause.type == "punch" and cmi_cause.puncher:is_player() then awards.unlock(cmi_cause.puncher:get_player_name(), "mcl:voluntary_exile") - local lv = mcl_potions.player_get_effect(cmi_cause.puncher, "bad_omen") + local lv = mcl_potions.get_effect(cmi_cause.puncher, "bad_omen") if not lv then lv = 0 else lv = lv.factor end lv = math.max(5,lv + 1) @@ -296,7 +296,7 @@ mcl_events.register_event("raid",{ --minetest.log("Cond start raid") local r = {} for _,p in pairs(minetest.get_connected_players()) do - if mcl_potions.player_has_effect(p,"bad_omen") then + if mcl_potions.has_effect(p,"bad_omen") then local raid_pos = mcl_raids.find_village(p:get_pos()) if raid_pos then --minetest.log("We have a raid position. Start raid") @@ -310,7 +310,7 @@ mcl_events.register_event("raid",{ self.mobs = {} self.health_max = 1 self.health = 0 - local lv = mcl_potions.player_get_effect(minetest.get_player_by_name(self.player), "bad_omen") + local lv = mcl_potions.get_effect(minetest.get_player_by_name(self.player), "bad_omen") if lv and lv.factor and lv.factor > 1 then self.max_stage = 6 end end, cond_progress = function(self) @@ -331,7 +331,7 @@ mcl_events.register_event("raid",{ end, on_complete = function(self) awards.unlock(self.player,"mcl:hero_of_the_village") - mcl_potions.player_clear_effect(minetest.get_player_by_name(self.player),"bad_omen") + mcl_potions.clear_effect(minetest.get_player_by_name(self.player),"bad_omen") make_firework(self.pos,os.time()) end, }) diff --git a/mods/ITEMS/mcl_campfires/api.lua b/mods/ITEMS/mcl_campfires/api.lua index 7fa495edb..ba6a55960 100644 --- a/mods/ITEMS/mcl_campfires/api.lua +++ b/mods/ITEMS/mcl_campfires/api.lua @@ -380,7 +380,7 @@ minetest.register_globalstep(function(dtime) etime = 0 for _,pl in pairs(minetest.get_connected_players()) do local armor_feet = pl:get_inventory():get_stack("armor", 5) - if pl and pl:get_player_control().sneak or (minetest.global_exists("mcl_enchanting") and mcl_enchanting.has_enchantment(armor_feet, "frost_walker")) or (minetest.global_exists("mcl_potions") and mcl_potions.player_has_effect(pl, "fire_proof")) then + if pl and pl:get_player_control().sneak or (minetest.global_exists("mcl_enchanting") and mcl_enchanting.has_enchantment(armor_feet, "frost_walker")) or (minetest.global_exists("mcl_potions") and mcl_potions.has_effect(pl, "fire_proof")) then return end burn_in_campfire(pl) diff --git a/mods/ITEMS/mcl_nether/init.lua b/mods/ITEMS/mcl_nether/init.lua index 252768df5..3a57ae427 100644 --- a/mods/ITEMS/mcl_nether/init.lua +++ b/mods/ITEMS/mcl_nether/init.lua @@ -135,7 +135,7 @@ minetest.register_node("mcl_nether:magma", { -- From walkover mod on_walk_over = function(loc, nodeiamon, player) local armor_feet = player:get_inventory():get_stack("armor", 5) - if player and player:get_player_control().sneak or (minetest.global_exists("mcl_enchanting") and mcl_enchanting.has_enchantment(armor_feet, "frost_walker")) or (minetest.global_exists("mcl_potions") and mcl_potions.player_has_effect(player, "fire_proof")) then + if player and player:get_player_control().sneak or (minetest.global_exists("mcl_enchanting") and mcl_enchanting.has_enchantment(armor_feet, "frost_walker")) or (minetest.global_exists("mcl_potions") and mcl_potions.has_effect(player, "fire_proof")) then return end -- Hurt players standing on top of this block diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index b2d44432b..796e82ebe 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -1145,32 +1145,33 @@ function mcl_potions._load_player_effects(player) end end --- Returns true if player has given effect -function mcl_potions.player_has_effect(player, effect_name) +-- Returns true if object has given effect +function mcl_potions.has_effect(object, effect_name) if not EF[effect_name] then return false end - return EF[effect_name][player] ~= nil + return EF[effect_name][object] ~= nil end -function mcl_potions.player_get_effect(player, effect_name) - if not EF[effect_name] or not EF[effect_name][player] then +function mcl_potions.get_effect(object, effect_name) + if not EF[effect_name] or not EF[effect_name][object] then return false end - return EF[effect_name][player] + return EF[effect_name][object] end -function mcl_potions.player_get_effect_level(player, effect_name) +function mcl_potions.get_effect_level(object, effect_name) if not EF[effect_name] then return end - local effect = EF[effect_name][player] + local effect = EF[effect_name][object] if not effect then return 0 end if not registered_effects[effect_name].uses_factor then return 1 end return registered_effects[effect_name].factor_to_level(effect.factor) end -function mcl_potions.player_clear_effect(player,effect) - EF[effect][player] = nil - potions_set_hud(player) +function mcl_potions.clear_effect(object, effect) + EF[effect][object] = nil + if not object:is_player() then return end + potions_set_hud(object) end minetest.register_on_leaveplayer( function(player) diff --git a/mods/PLAYER/mcl_hunger/hunger.lua b/mods/PLAYER/mcl_hunger/hunger.lua index afca9553b..c0ba9fb91 100644 --- a/mods/PLAYER/mcl_hunger/hunger.lua +++ b/mods/PLAYER/mcl_hunger/hunger.lua @@ -186,7 +186,7 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso do_poison = true end if do_poison then - local level = mcl_potions.player_get_effect_level(user, "food_poisoning") + local level = mcl_potions.get_effect_level(user, "food_poisoning") mcl_potions.give_effect_by_level("food_poisoning", user, level+exhaust, poisontime) end end