From 5de9d90569def5bc0ca86db32416315a004242dc Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 22 Feb 2021 10:55:14 +0100 Subject: [PATCH] Simplify mcl_burning API --- .../mcl_burning/{engine.lua => api.lua} | 19 +++---------------- mods/ENTITIES/mcl_burning/init.lua | 4 ++-- mods/ENTITIES/mcl_mobs/api.lua | 5 ++--- mods/ENTITIES/mobs_mc/blaze.lua | 4 ++-- mods/ITEMS/mcl_bows/arrow.lua | 2 +- mods/ITEMS/mcl_enchanting/enchantments.lua | 2 +- 6 files changed, 11 insertions(+), 25 deletions(-) rename mods/ENTITIES/mcl_burning/{engine.lua => api.lua} (94%) diff --git a/mods/ENTITIES/mcl_burning/engine.lua b/mods/ENTITIES/mcl_burning/api.lua similarity index 94% rename from mods/ENTITIES/mcl_burning/engine.lua rename to mods/ENTITIES/mcl_burning/api.lua index 5be11a254..a217d294d 100644 --- a/mods/ENTITIES/mcl_burning/engine.lua +++ b/mods/ENTITIES/mcl_burning/api.lua @@ -107,11 +107,7 @@ function mcl_burning.damage(obj) end if do_damage then - local damage = mcl_burning.get(obj, "float", "damage") - if damage == 0 then - damage = 1 - end - local new_hp = hp - damage + local new_hp = hp - 1 if health then luaentity.health = new_hp else @@ -120,7 +116,7 @@ function mcl_burning.damage(obj) end end -function mcl_burning.set_on_fire(obj, burn_time, damage, interval, reason) +function mcl_burning.set_on_fire(obj, burn_time, reason) local luaentity = obj:get_luaentity() if luaentity and luaentity.fire_resistant then return @@ -173,8 +169,6 @@ function mcl_burning.set_on_fire(obj, burn_time, damage, interval, reason) end end mcl_burning.set(obj, "float", "burn_time", burn_time) - mcl_burning.set(obj, "float", "damage", damage) - mcl_burning.set(obj, "float", "interval", interval) mcl_burning.set(obj, "string", "reason", reason) mcl_burning.set(obj, "int", "hud_id", hud_id) mcl_burning.set(obj, "int", "sound_id", sound_id) @@ -208,8 +202,6 @@ function mcl_burning.extinguish(obj) obj:hud_remove(hud_id) end - mcl_burning.set(obj, "float", "damage") - mcl_burning.set(obj, "float", "interval") mcl_burning.set(obj, "string", "reason") mcl_burning.set(obj, "float", "burn_time") mcl_burning.set(obj, "float", "damage_timer") @@ -240,12 +232,7 @@ function mcl_burning.tick(obj, dtime) local damage_timer = mcl_burning.get(obj, "float", "damage_timer") + dtime - local interval = mcl_burning.get(obj, "float", "interval") - if interval == 0 then - interval = 1 - end - - if damage_timer >= interval then + if damage_timer >= 1 then damage_timer = 0 mcl_burning.damage(obj) end diff --git a/mods/ENTITIES/mcl_burning/init.lua b/mods/ENTITIES/mcl_burning/init.lua index 1b341273e..61ed12837 100644 --- a/mods/ENTITIES/mcl_burning/init.lua +++ b/mods/ENTITIES/mcl_burning/init.lua @@ -5,7 +5,7 @@ mcl_burning = { animation_frames = tonumber(minetest.settings:get("fire_animation_frames")) or 8 } -dofile(modpath .. "/engine.lua") +dofile(modpath .. "/api.lua") minetest.register_entity("mcl_burning:fire", { initial_properties = { @@ -33,4 +33,4 @@ end) minetest.register_on_leaveplayer(function(player) mcl_burning.set(player, "int", "hud_id") -end) \ No newline at end of file +end) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 50e9eec76..6d74d9d78 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1059,7 +1059,7 @@ local do_env_damage = function(self) end if (self.sunlight_damage ~= 0 or self.ignited_by_sunlight) and (minetest.get_node_light(pos) or 0) >= minetest.LIGHT_MAX and dim == "overworld" then if self.ignited_by_sunlight then - mcl_burning.set_on_fire(self.object, 10, self.sunlight_damage or 1) + mcl_burning.set_on_fire(self.object, 10) else deal_light_damage(self, pos, self.sunlight_damage) return true @@ -2975,8 +2975,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) if weapon then local fire_aspect_level = mcl_enchanting.get_enchantment(weapon, "fire_aspect") if fire_aspect_level > 0 then - local damage = fire_aspect_level * 4 - 1 - mcl_burning.set_on_fire(self.object, 4, 1, 4 / damage) + mcl_burning.set_on_fire(self.object, fire_aspect_level * 4) end end diff --git a/mods/ENTITIES/mobs_mc/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index 2b9000de7..20fa86a1f 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -91,7 +91,7 @@ mobs:register_arrow("mobs_mc:blaze_fireball", { if rawget(_G, "armor") and armor.last_damage_types then armor.last_damage_types[player:get_player_name()] = "fireball" end - mcl_burning.set_on_fire(player, 5, 1, 5 / 4, "blaze") + mcl_burning.set_on_fire(player, 5, "blaze") player:punch(self.object, 1.0, { full_punch_interval = 1.0, damage_groups = {fleshy = 5}, @@ -99,7 +99,7 @@ mobs:register_arrow("mobs_mc:blaze_fireball", { end, hit_mob = function(self, mob) - mcl_burning.set_on_fire(mob, 5, 1, 5 / 4) + mcl_burning.set_on_fire(mob, 5) mob:punch(self.object, 1.0, { full_punch_interval = 1.0, damage_groups = {fleshy = 5}, diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index ba9158078..e8e3ec160 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -253,7 +253,7 @@ ARROW_ENTITY.on_step = function(self, dtime) end damage_particles(self.object:get_pos(), self._is_critical) if mcl_burning.is_burning(self.object) then - mcl_burning.set_on_fire(obj, 5, 1, 5 / 4) + mcl_burning.set_on_fire(obj, 5) end obj:punch(self.object, 1.0, { full_punch_interval=1.0, diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index 7e47dd60e..7056ba13b 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -215,7 +215,7 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, if wielditem then local fire_aspect_level = mcl_enchanting.get_enchantment(wielditem, "fire_aspect") if fire_aspect_level > 0 then - mcl_burning.set_on_fire(player, fire_aspect_level * 4, 1, 1, hitter:get_player_name()) + mcl_burning.set_on_fire(player, fire_aspect_level * 4, hitter:get_player_name()) end end end