From 467ecc7c5883311c2f8bb5e1893ef17f87629f87 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 17 Sep 2022 00:58:03 +0200 Subject: [PATCH 1/3] Remove 5.3 check for get_natural_light function as 5.3 isn't supported anymore --- mods/ENTITIES/mcl_mobs/api.lua | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 91c8c6b61..88d6217ea 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1025,15 +1025,6 @@ local node_ok = function(pos, fallback) return minetest.registered_nodes[fallback] end -local function get_light(pos, tod) - if minetest.get_node_or_nil(pos) then - local lightfunc = minetest.get_natural_light or minetest.get_node_light - return lightfunc(pos, tod) - else - return 0 - end -end - -- environmental damage (water, lava, fire, light etc.) local do_env_damage = function(self) @@ -1076,9 +1067,7 @@ local do_env_damage = function(self) end end - -- Use get_node_light for Minetest version 5.3 where get_natural_light - -- does not exist yet. - local sunlight = get_light(pos, self.time_of_day) + local sunlight = minetest.get_natural_light(pos, self.time_of_day) -- bright light harms mob if self.light_damage ~= 0 and (sunlight or 0) > 12 then From df8c234def9b3c4b5b0bec41bce182d84307c59a Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 17 Sep 2022 13:55:00 +0200 Subject: [PATCH 2/3] Check map limits before get_natural_light --- mods/ENTITIES/mcl_mobs/api.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 88d6217ea..652bb9599 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1067,7 +1067,10 @@ local do_env_damage = function(self) end end - local sunlight = minetest.get_natural_light(pos, self.time_of_day) + local sunlight = 10 + if within_limits(pos,0) then + sunlight = minetest.get_natural_light(pos, self.time_of_day) + end -- bright light harms mob if self.light_damage ~= 0 and (sunlight or 0) > 12 then From 9a95557ec82dcfae43c1aa0868b4d514226ff948 Mon Sep 17 00:00:00 2001 From: cora Date: Sat, 17 Sep 2022 15:31:09 +0200 Subject: [PATCH 3/3] Simplify within_limits function so you don't need a cs degree to read it ^^ --- mods/ENTITIES/mcl_mobs/api.lua | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 652bb9599..e637fc673 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -915,23 +915,21 @@ end -- check if within physical map limits (-30911 to 30927) -local within_limits, wmin, wmax = nil, -30913, 30928 -within_limits = function(pos, radius) +local function within_limits(pos, radius) + local wmin, wmax = -30912, 30928 if mcl_vars then if mcl_vars.mapgen_edge_min and mcl_vars.mapgen_edge_max then wmin, wmax = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max - within_limits = function(pos, radius) - return pos - and (pos.x - radius) > wmin and (pos.x + radius) < wmax - and (pos.y - radius) > wmin and (pos.y + radius) < wmax - and (pos.z - radius) > wmin and (pos.z + radius) < wmax - end end end - return pos - and (pos.x - radius) > wmin and (pos.x + radius) < wmax - and (pos.y - radius) > wmin and (pos.y + radius) < wmax - and (pos.z - radius) > wmin and (pos.z + radius) < wmax + if radius then + wmin = wmin - radius + wmax = wmax + radius + end + for _,v in pairs(pos) do + if v < wmin or v > wmax then return false end + end + return true end