From e9ff2ba32a356ddf3f29c744e465d433f613b3ed Mon Sep 17 00:00:00 2001 From: kabou Date: Thu, 3 Mar 2022 09:38:59 +0100 Subject: [PATCH 1/3] Minor changes to mcl_burning. * Remove animation_frame from fire entity state, it is now kept in the storage table of the parent entity. * Rename animation_timer in fire entity table to _mcl_animation_timer, in line with mineclone2 policy on adding custom members to minetest tables. * Comment out code that does nothing sensible. Scheduled for deletion at a later time. --- mods/ENTITIES/mcl_burning/api.lua | 2 ++ mods/ENTITIES/mcl_burning/init.lua | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_burning/api.lua b/mods/ENTITIES/mcl_burning/api.lua index 8093d45f9..3fcc7778f 100644 --- a/mods/ENTITIES/mcl_burning/api.lua +++ b/mods/ENTITIES/mcl_burning/api.lua @@ -132,6 +132,7 @@ function mcl_burning.set_on_fire(obj, burn_time) mcl_burning.update_hud(obj) end + --[[ -- FIXME: does this code make sense? It removes attached fire luaentities from -- another object that happen to be at the same position. local fire_luaentity = fire_entity:get_luaentity() @@ -142,6 +143,7 @@ function mcl_burning.set_on_fire(obj, burn_time) break end end + ]]-- end function mcl_burning.extinguish(obj) diff --git a/mods/ENTITIES/mcl_burning/init.lua b/mods/ENTITIES/mcl_burning/init.lua index 62bf3f69a..5ffc804a1 100644 --- a/mods/ENTITIES/mcl_burning/init.lua +++ b/mods/ENTITIES/mcl_burning/init.lua @@ -98,8 +98,7 @@ minetest.register_entity("mcl_burning:fire", { glow = -1, backface_culling = false, }, - animation_frame = 0, - animation_timer = 0, + _mcl_animation_timer = 0, on_activate = function(self) self.object:set_sprite({x = 0, y = 0}, animation_frames, 1.0 / animation_frames) end, @@ -115,9 +114,9 @@ minetest.register_entity("mcl_burning:fire", { return end if parent:is_player() then - self.animation_timer = self.animation_timer + dtime - if self.animation_timer >= 0.1 then - self.animation_timer = 0 + self._mcl_animation_timer = self._mcl_animation_timer + dtime + if self._mcl_animation_timer >= 0.1 then + self._mcl_animation_timer = 0 mcl_burning.update_hud(parent) end end From 90311da514973e5f6cd0bc05b6d9f549429a93d5 Mon Sep 17 00:00:00 2001 From: kabou Date: Thu, 3 Mar 2022 10:14:35 +0100 Subject: [PATCH 2/3] Preempt possible crash on nil in on_joinplayer. * In mineclone5 a crash was reported to occur when deserialization of storage returned nil in on_joinplayer. https://git.minetest.land/ MineClone5/MineClone5/commit/96c4fb60d8641b4181edb902ed24dbf173828d09 This commit uses a different, but equally effective fix. --- mods/ENTITIES/mcl_burning/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_burning/init.lua b/mods/ENTITIES/mcl_burning/init.lua index 5ffc804a1..8133a1fe3 100644 --- a/mods/ENTITIES/mcl_burning/init.lua +++ b/mods/ENTITIES/mcl_burning/init.lua @@ -57,7 +57,7 @@ minetest.register_on_joinplayer(function(player) local storage = {} local burn_data = player:get_meta():get_string("mcl_burning:data") if burn_data ~= "" then - storage = minetest.deserialize(burn_data) + storage = minetest.deserialize(burn_data) or storage end mcl_burning.storage[player] = storage if storage.burn_time and storage.burn_time > 0 then From 9eba0e4860f570363cfec992994b466521178a5b Mon Sep 17 00:00:00 2001 From: kabou Date: Fri, 18 Mar 2022 11:39:11 +0100 Subject: [PATCH 3/3] Remove unused code. * Remove unused code that was commented out. The code tried to find fire luaentities in the same spot as the newly created fire luaentity. It may have been intended to optimize getting set on fire multiple times, but it makes no sense as it does not discriminate between fire luaentities attached to the object set on fire and those attached to other objects. The function that this code was in also has a better way to prevent adding multiple fire luaentities in the first place. --- mods/ENTITIES/mcl_burning/api.lua | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/mods/ENTITIES/mcl_burning/api.lua b/mods/ENTITIES/mcl_burning/api.lua index 3fcc7778f..885875aca 100644 --- a/mods/ENTITIES/mcl_burning/api.lua +++ b/mods/ENTITIES/mcl_burning/api.lua @@ -131,19 +131,6 @@ function mcl_burning.set_on_fire(obj, burn_time) if obj:is_player() then mcl_burning.update_hud(obj) end - - --[[ - -- FIXME: does this code make sense? It removes attached fire luaentities from - -- another object that happen to be at the same position. - local fire_luaentity = fire_entity:get_luaentity() - for _, other in pairs(minetest.get_objects_inside_radius(fire_entity:get_pos(), 0)) do - local other_luaentity = other:get_luaentity() - if other_luaentity and other_luaentity.name == "mcl_burning:fire" and other_luaentity ~= fire_luaentity then - other:remove() - break - end - end - ]]-- end function mcl_burning.extinguish(obj)