From 835f97a61e91f535aadd4c6d5281fd7aa5e276ff Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 28 Nov 2024 11:23:34 -0600 Subject: [PATCH] Add mcl_burning.is_affected_by_sunlight(), rework mob light/sunlight damage and burning code --- mods/ENTITIES/mcl_burning/api.lua | 11 +++++++++ mods/ENTITIES/mcl_burning/mod.conf | 2 +- mods/ENTITIES/mcl_mobs/physics.lua | 38 ++++++++++-------------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/mods/ENTITIES/mcl_burning/api.lua b/mods/ENTITIES/mcl_burning/api.lua index c3348e6c4..2a4c6cc4d 100644 --- a/mods/ENTITIES/mcl_burning/api.lua +++ b/mods/ENTITIES/mcl_burning/api.lua @@ -18,6 +18,17 @@ function mcl_burning.is_affected_by_rain(obj) return mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) and mcl_weather.has_rain(pos) end +function mcl_burning.is_affected_by_sunlight(obj, threshold) + threshold = threshold or core.LIGHT_MAX + + local pos = obj:get_pos() + local _,dim = mcl_worlds.y_to_layer(pos.y) + if dim ~= "overworld" then return false end + + local sunlight = mcl_util.get_natural_light(pos, core.get_timeofday()) or 0 + if sunlight > threshold then return true end +end + function mcl_burning.get_collisionbox(obj, smaller, storage) local cache = storage.collisionbox_cache if cache then diff --git a/mods/ENTITIES/mcl_burning/mod.conf b/mods/ENTITIES/mcl_burning/mod.conf index 8a3d6ea00..bac9a1c10 100644 --- a/mods/ENTITIES/mcl_burning/mod.conf +++ b/mods/ENTITIES/mcl_burning/mod.conf @@ -1,4 +1,4 @@ name = mcl_burning description = Burning Objects for VoxeLibre author = Fleckenstein -depends = mcl_weather +depends = mcl_weather, mcl_worlds diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index b07cfcbeb..7cbbfe08b 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -634,36 +634,24 @@ function mob_class:do_env_damage() return true end - local node = minetest.get_node(pos) - if node then - if node.name ~= "ignore" then - -- put below code in this block if we can prove that unloaded maps are causing crash. - -- it should warn then error - else - --minetest.log("warning", "Pos is ignored: " .. dump(pos)) + -- Simple light damage + if self.light_damage or 0 > 0 and mcl_burning.is_affected_by_sunlight(self.object, 12) then + if self:deal_light_damage(pos, self.light_damage) then + return true end + end - local sunlight = mcl_util.get_natural_light(pos, self.time_of_day) - - if self.light_damage ~= 0 and (sunlight or 0) > 12 then - if self:deal_light_damage(pos, self.light_damage) then - return true - end - end - local _, dim = mcl_worlds.y_to_layer(pos.y) - if (self.sunlight_damage ~= 0 or self.ignited_by_sunlight) and (sunlight or 0) >= minetest.LIGHT_MAX and dim == "overworld" then - if self.armor_list and not self.armor_list.helmet or not self.armor_list or self.armor_list and self.armor_list.helmet and self.armor_list.helmet == "" then - if self.ignited_by_sunlight and not mcl_burning.is_affected_by_rain(self.object) then - if (#mcl_burning.get_touching_nodes(self.object, "group:puts_out_fire", self) == 0) then - mcl_burning.set_on_fire(self.object, 10) - end - else - self:deal_light_damage(pos, self.sunlight_damage) - return true + -- Sunlight burning/igniting mobs + if (self.sunlight_damage ~= 0 or self.ignited_by_sunlight) and mcl_burning.is_affected_by_sunlight(self.object) then + if not (self.armor_list and (self.armor_list.helmet or "") ~= "") then + if self.ignited_by_sunlight and not mcl_burning.is_affected_by_rain(self.object) then + if (#mcl_burning.get_touching_nodes(self.object, "group:puts_out_fire", self) == 0) then + mcl_burning.set_on_fire(self.object, 10) end + else + self:deal_light_damage(pos, self.sunlight_damage) end end - end local y_level = self.collisionbox[2]