From 8324bbe3b4afa75f93e98b22e1b1b17998e96b94 Mon Sep 17 00:00:00 2001 From: blaboing <56389853+blaboing@users.noreply.github.com> Date: Thu, 4 Apr 2024 06:06:15 +0200 Subject: [PATCH 1/2] Check registered entities after mod loading (#68) --- mobs.lua | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/mobs.lua b/mobs.lua index 09cd46b..40fc5eb 100644 --- a/mobs.lua +++ b/mobs.lua @@ -23,31 +23,32 @@ local increase_inflicted_damage = function(player, value) meta:set_int("inflicted_damage", count + value) end +minetest.register_on_mods_loaded(function() + for _,entity in pairs(minetest.registered_entities) do + if entity.on_punch ~= nil and entity.hp_min ~= nil and entity.hp_min > 0 then -for _,entity in pairs(minetest.registered_entities) do - if entity.on_punch ~= nil and entity.hp_min ~= nil and entity.hp_min > 0 then + local originalPunch = entity.on_punch - local originalPunch = entity.on_punch + entity.on_punch = function(self, hitter,time_from_last_punch, tool_capabilities, direction) - entity.on_punch = function(self, hitter,time_from_last_punch, tool_capabilities, direction) + if tool_capabilities.damage_groups ~= nil and + tool_capabilities.damage_groups.fleshy ~= nil and + self.health ~= nil then + local rest = tool_capabilities.damage_groups.fleshy - if tool_capabilities.damage_groups ~= nil and - tool_capabilities.damage_groups.fleshy ~= nil and - self.health ~= nil then - local rest = tool_capabilities.damage_groups.fleshy - - if hitter:is_player() then - -- xp_redo.add_xp(hitter:get_player_name(), rest * 2) - xp_redo.add_xp(hitter:get_player_name(), 1) - increase_inflicted_damage(hitter, rest * 2) - increment_punch_count(hitter) + if hitter:is_player() then + -- xp_redo.add_xp(hitter:get_player_name(), rest * 2) + xp_redo.add_xp(hitter:get_player_name(), 1) + increase_inflicted_damage(hitter, rest * 2) + increment_punch_count(hitter) + end end - end - -- print(tool_capabilities.damage_groups.fleshy) - -- print(self.health) + -- print(tool_capabilities.damage_groups.fleshy) + -- print(self.health) - return originalPunch(self, hitter, time_from_last_punch, tool_capabilities, direction) + return originalPunch(self, hitter, time_from_last_punch, tool_capabilities, direction) + end end end -end +end) From 143c088b99f7173291b9202096963e93c00ac1f4 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Wed, 17 Apr 2024 08:48:06 +0200 Subject: [PATCH 2/2] add public xp_redo.get_area_xp_limits(id) (#70) Mods like [glider] and [hangglider] can't be satisfied with minetest.is_protected() as they don't want to build but area might be FLAK protected against any who don't have certain amount of XP. --- areas.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/areas.lua b/areas.lua index 9d2e07a..3fed559 100644 --- a/areas.lua +++ b/areas.lua @@ -2,6 +2,10 @@ -- id -> { max=1000, min=100 } local xp_areas = {} +function xp_redo.get_area_xp_limits(id) + return xp_areas[id] or {} +end + -- protection check local old_is_protected = minetest.is_protected function minetest.is_protected(pos, name)