From e0f70b54ec9c6ac0ef22f4585b88531b95663651 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 25 May 2022 14:02:10 +0200 Subject: [PATCH] Remove _cmi_is_mob --- mods/CORE/mcl_damage/init.lua | 2 +- mods/CORE/mcl_util/init.lua | 4 ++-- mods/ENTITIES/mcl_boats/init.lua | 2 +- mods/ENTITIES/mcl_mobs/api.lua | 17 +++++++---------- mods/ENTITIES/mcl_mobs/spawning.lua | 2 +- mods/HUD/mcl_bossbars/init.lua | 2 +- .../REDSTONE/mesecons_pressureplates/init.lua | 2 +- mods/ITEMS/mcl_beds/functions.lua | 2 +- mods/ITEMS/mcl_bows/arrow.lua | 4 ++-- mods/ITEMS/mcl_bows/rocket.lua | 6 +++--- mods/ITEMS/mcl_potions/functions.lua | 6 +++--- mods/ITEMS/mcl_potions/init.lua | 2 +- mods/ITEMS/mcl_potions/lingering.lua | 2 +- mods/ITEMS/mcl_potions/splash.lua | 2 +- mods/ITEMS/mcl_potions/tipped_arrow.lua | 4 ++-- mods/ITEMS/mcl_throwing/register.lua | 2 +- mods/MISC/mcl_commands/summon.lua | 2 +- mods/PLAYER/mcl_playerplus/init.lua | 2 +- 18 files changed, 31 insertions(+), 34 deletions(-) diff --git a/mods/CORE/mcl_damage/init.lua b/mods/CORE/mcl_damage/init.lua index 8b2acbb355..2a53ee21a1 100644 --- a/mods/CORE/mcl_damage/init.lua +++ b/mods/CORE/mcl_damage/init.lua @@ -78,7 +78,7 @@ function mcl_damage.from_punch(mcl_reason, object) mcl_reason.type = "arrow" elseif luaentity._is_fireball then mcl_reason.type = "fireball" - elseif luaentity._cmi_is_mob then + elseif luaentity.is_mob then mcl_reason.type = "mob" end mcl_reason.source = mcl_reason.source or luaentity._source_object diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 0d1cb45dc9..30d63fd32f 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -524,7 +524,7 @@ function mcl_util.deal_damage(target, damage, mcl_reason) if luaentity.deal_damage then luaentity:deal_damage(damage, mcl_reason or {type = "generic"}) return - elseif luaentity._cmi_is_mob then + elseif luaentity.is_mob then -- local puncher = mcl_reason and mcl_reason.direct or target -- target:punch(puncher, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy = damage}}, vector.direction(puncher:get_pos(), target:get_pos()), damage) if luaentity.health > 0 then @@ -544,7 +544,7 @@ end function mcl_util.get_hp(obj) local luaentity = obj:get_luaentity() - if luaentity and luaentity._cmi_is_mob then + if luaentity and luaentity.is_mob then return luaentity.health else return obj:get_hp() diff --git a/mods/ENTITIES/mcl_boats/init.lua b/mods/ENTITIES/mcl_boats/init.lua index 72664b1dfb..b7cc92775f 100644 --- a/mods/ENTITIES/mcl_boats/init.lua +++ b/mods/ENTITIES/mcl_boats/init.lua @@ -314,7 +314,7 @@ function boat.on_step(self, dtime, moveresult) for _, obj in pairs(minetest.get_objects_inside_radius(self.object:get_pos(), 1.3)) do local entity = obj:get_luaentity() - if entity and entity._cmi_is_mob then + if entity and entity.is_mob then attach_object(self, obj) break end diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index a2f00c54a9..7b9c6f5aaa 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -78,10 +78,6 @@ local node_snowblock = "mcl_core:snowblock" local node_snow = "mcl_core:snow" mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "mcl_core:dirt" ---Helper function to clear all mobs because /clearobjects removes too much -local function is_mob(o) - return o.type == "ambient" or o.type == "animal" or o.type == "monster" or o.type == "npc" -end minetest.register_chatcommand("clearmobs",{ privs={maphack=true}, params = "||", @@ -90,7 +86,7 @@ minetest.register_chatcommand("clearmobs",{ local p = minetest.get_player_by_name(n) local num=tonumber(param) for _,o in pairs(minetest.luaentities) do - if is_mob(o) then + if o.is_mob then if param == "all" or ( param == "nametagged" and o.nametag ) or ( param == "" and not o.nametag and not o.tamed ) or @@ -223,7 +219,7 @@ local collision = function(self) for _,object in pairs(minetest.get_objects_inside_radius(pos, width)) do local ent = object:get_luaentity() - if object:is_player() or (ent and ent._cmi_is_mob and object ~= self.object) then + if object:is_player() or (ent and ent.is_mob and object ~= self.object) then local pos2 = object:get_pos() local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z} @@ -3951,7 +3947,7 @@ minetest.register_entity(name, { runaway_from = def.runaway_from, owner_loyal = def.owner_loyal, facing_fence = false, - _cmi_is_mob = true, + is_mob = true, pushable = def.pushable or true, @@ -3999,6 +3995,7 @@ minetest.register_entity(name, { --this is a temporary hack so mobs stop --glitching and acting really weird with the --default built in engine collision detection + self.is_mob = true self.object:set_properties({ collide_with_objects = false, }) @@ -4123,7 +4120,7 @@ function mobs:register_arrow(name, def) if entity and self.hit_mob - and entity._cmi_is_mob == true + and entity.is_mob == true and tostring(player) ~= self.owner_id and entity.name ~= self.object:get_luaentity().name then self.hit_mob(self, player) @@ -4133,7 +4130,7 @@ function mobs:register_arrow(name, def) if entity and self.hit_object - and (not entity._cmi_is_mob) + and (not entity.is_mob) and tostring(player) ~= self.owner_id and entity.name ~= self.object:get_luaentity().name then self.hit_object(self, player) @@ -4452,7 +4449,7 @@ minetest.register_globalstep(function(dtime) local pos = player:get_pos() for _, obj in pairs(minetest.get_objects_inside_radius(pos, 47)) do local lua = obj:get_luaentity() - if lua and lua._cmi_is_mob then + if lua and lua.is_mob then lua.lifetimer = math.max(20, lua.lifetimer) lua.despawn_immediately = false end diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/spawning.lua index b5c93b451c..cce509729e 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/spawning.lua @@ -195,7 +195,7 @@ local list_of_all_biomes = { local function count_mobs(pos) local num = 0 for _,object in pairs(get_objects_inside_radius(pos, aoc_range)) do - if object and object:get_luaentity() and object:get_luaentity()._cmi_is_mob then + if object and object:get_luaentity() and object:get_luaentity().is_mob then num = num + 1 end end diff --git a/mods/HUD/mcl_bossbars/init.lua b/mods/HUD/mcl_bossbars/init.lua index f1d99e0139..96b6b4896b 100644 --- a/mods/HUD/mcl_bossbars/init.lua +++ b/mods/HUD/mcl_bossbars/init.lua @@ -78,7 +78,7 @@ end function mcl_bossbars.update_boss(object, name, color) local props = object:get_luaentity() - if not props or not props._cmi_is_mob then + if not props or not props.is_mob then props = object:get_properties() props.health = object:get_hp() end diff --git a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua index c0894224c6..495fbd0484 100644 --- a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua @@ -28,7 +28,7 @@ local function pp_on_timer(pos, elapsed) local obj_does_activate = function(obj, activated_by) if activated_by.any then return true - elseif activated_by.mob and obj:get_luaentity() and obj:get_luaentity()._cmi_is_mob == true then + elseif activated_by.mob and obj:get_luaentity() and obj:get_luaentity().is_mob == true then return true elseif activated_by.player and obj:is_player() then return true diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index b8478fc1fb..c1e76c90a3 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -106,7 +106,7 @@ local function lay_down(player, pos, bed_pos, state, skip) local mobname = ent.name local def = minetest.registered_entities[mobname] -- Approximation of monster detection range - if def._cmi_is_mob and ((mobname ~= "mobs_mc:pigman" and def.type == "monster" and not monster_exceptions[mobname]) or (mobname == "mobs_mc:pigman" and ent.state == "attack")) then + if def.is_mob and ((mobname ~= "mobs_mc:pigman" and def.type == "monster" and not monster_exceptions[mobname]) or (mobname == "mobs_mc:pigman" and ent.state == "attack")) then if math.abs(bed_pos.y - obj:get_pos().y) <= 5 then return false, S("You can't sleep now, monsters are nearby!") end diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index cda8dcc6d6..1816184bba 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -203,7 +203,7 @@ function ARROW_ENTITY.on_step(self, dtime) if obj:is_player() then ok = true elseif obj:get_luaentity() then - if (obj:get_luaentity()._cmi_is_mob or obj:get_luaentity()._hittable_by_projectile) then + if (obj:get_luaentity().is_mob or obj:get_luaentity()._hittable_by_projectile) then ok = true end end @@ -226,7 +226,7 @@ function ARROW_ENTITY.on_step(self, dtime) local obj = closest_object local is_player = obj:is_player() local lua = obj:get_luaentity() - if obj == self._shooter and self._time_in_air > 1.02 or obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then + if obj == self._shooter and self._time_in_air > 1.02 or obj ~= self._shooter and (is_player or (lua and (lua.is_mob or lua._hittable_by_projectile))) then if obj:get_hp() > 0 then -- Check if there is no solid node between arrow and object local ray = minetest.raycast(self.object:get_pos(), obj:get_pos(), true) diff --git a/mods/ITEMS/mcl_bows/rocket.lua b/mods/ITEMS/mcl_bows/rocket.lua index 2c1d30dcd4..9eb8ab8c4f 100644 --- a/mods/ITEMS/mcl_bows/rocket.lua +++ b/mods/ITEMS/mcl_bows/rocket.lua @@ -24,7 +24,7 @@ local function damage_explosion(self, damagemulitplier) for _,obj in pairs(objects) do if obj:is_player() then mcl_util.deal_damage(obj, damagemulitplier - vector.distance(self.object:get_pos(), obj:get_pos()), {type = "explosion"}) - elseif obj:get_luaentity()._cmi_is_mob then + elseif obj:get_luaentity().is_mob then obj:punch(self.object, 1.0, { full_punch_interval=1.0, damage_groups={fleshy=damagemulitplier - vector.distance(self.object:get_pos(), obj:get_pos())}, @@ -415,7 +415,7 @@ function ARROW_ENTITY.on_step(self, dtime) if obj:is_player() then ok = true elseif obj:get_luaentity() then - if (obj:get_luaentity()._cmi_is_mob or obj:get_luaentity()._hittable_by_projectile) then + if (obj:get_luaentity().is_mob or obj:get_luaentity()._hittable_by_projectile) then ok = true end end @@ -438,7 +438,7 @@ function ARROW_ENTITY.on_step(self, dtime) local obj = closest_object local is_player = obj:is_player() local lua = obj:get_luaentity() - if obj == self._shooter and self._time_in_air > 1.02 or obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then + if obj == self._shooter and self._time_in_air > 1.02 or obj ~= self._shooter and (is_player or (lua and (lua.is_mob or lua._hittable_by_projectile))) then if obj:get_hp() > 0 then -- Check if there is no solid node between arrow and object local ray = minetest.raycast(self.object:get_pos(), obj:get_pos(), true) diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index fdf565d178..2c47d50d1b 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -167,7 +167,7 @@ minetest.register_globalstep(function(dtime) if is_player then player:set_hp(math.min(player:get_properties().hp_max or 20, player:get_hp() + 1), { type = "set_hp", other = "regeneration" }) EF.regenerating[player].heal_timer = 0 - elseif entity and entity._cmi_is_mob then + elseif entity and entity.is_mob then entity.health = math.min(entity.hp_max, entity.health + 1) EF.regenerating[player].heal_timer = 0 else -- stop regenerating if not a player or mob @@ -545,7 +545,7 @@ function mcl_potions.is_obj_hit(self, pos) if entity and entity.name ~= self.object:get_luaentity().name then - if entity._cmi_is_mob then + if entity.is_mob then return true end @@ -686,7 +686,7 @@ function mcl_potions.healing_func(player, hp) hp = 1 end - if obj and obj._cmi_is_mob then + if obj and obj.is_mob then obj.health = math.max(obj.health + hp, obj.hp_max) elseif player:is_player() then player:set_hp(math.min(player:get_hp() + hp, player:get_properties().hp_max), { type = "set_hp", other = "healing" }) diff --git a/mods/ITEMS/mcl_potions/init.lua b/mods/ITEMS/mcl_potions/init.lua index 36f45b01ae..5b9f1fab35 100644 --- a/mods/ITEMS/mcl_potions/init.lua +++ b/mods/ITEMS/mcl_potions/init.lua @@ -281,7 +281,7 @@ local function water_splash(obj, damage) end -- Damage mobs that are vulnerable to water local lua = obj:get_luaentity() - if lua and lua._cmi_is_mob then + if lua and lua.is_mob then obj:punch(obj, 1.0, { full_punch_interval = 1.0, damage_groups = {water_vulnerable=damage}, diff --git a/mods/ITEMS/mcl_potions/lingering.lua b/mods/ITEMS/mcl_potions/lingering.lua index 64f846cb61..17088ad130 100644 --- a/mods/ITEMS/mcl_potions/lingering.lua +++ b/mods/ITEMS/mcl_potions/lingering.lua @@ -66,7 +66,7 @@ minetest.register_globalstep(function(dtime) for _, obj in pairs(minetest.get_objects_inside_radius(pos, d)) do local entity = obj:get_luaentity() - if obj:is_player() or entity._cmi_is_mob then + if obj:is_player() or entity.is_mob then vals.def.potion_fun(obj) -- TODO: Apply timer penalty only if the potion effect was acutally applied diff --git a/mods/ITEMS/mcl_potions/splash.lua b/mods/ITEMS/mcl_potions/splash.lua index 4a820e4672..730796952a 100644 --- a/mods/ITEMS/mcl_potions/splash.lua +++ b/mods/ITEMS/mcl_potions/splash.lua @@ -110,7 +110,7 @@ function mcl_potions.register_splash(name, descr, color, def) for _,obj in pairs(minetest.get_objects_inside_radius(pos, 4)) do local entity = obj:get_luaentity() - if obj:is_player() or entity._cmi_is_mob then + if obj:is_player() or entity.is_mob then local pos2 = obj:get_pos() local rad = math.floor(math.sqrt((pos2.x-pos.x)^2 + (pos2.y-pos.y)^2 + (pos2.z-pos.z)^2)) diff --git a/mods/ITEMS/mcl_potions/tipped_arrow.lua b/mods/ITEMS/mcl_potions/tipped_arrow.lua index 880dff9562..e6da04dff5 100644 --- a/mods/ITEMS/mcl_potions/tipped_arrow.lua +++ b/mods/ITEMS/mcl_potions/tipped_arrow.lua @@ -216,7 +216,7 @@ function mcl_potions.register_arrow(name, desc, color, def) if obj ~= self._shooter and obj:is_player() then ok = true elseif obj:get_luaentity() then - if obj ~= self._shooter and obj:get_luaentity()._cmi_is_mob then + if obj ~= self._shooter and obj:get_luaentity().is_mob then ok = true end end @@ -238,7 +238,7 @@ function mcl_potions.register_arrow(name, desc, color, def) local obj = closest_object local is_player = obj:is_player() local lua = obj:get_luaentity() - if obj ~= self._shooter and (is_player or (lua and lua._cmi_is_mob)) then + if obj ~= self._shooter and (is_player or (lua and lua.is_mob)) then if obj:get_hp() > 0 then -- Check if there is no solid node between arrow and object diff --git a/mods/ITEMS/mcl_throwing/register.lua b/mods/ITEMS/mcl_throwing/register.lua index 8683eea0a7..413bc9d5fc 100644 --- a/mods/ITEMS/mcl_throwing/register.lua +++ b/mods/ITEMS/mcl_throwing/register.lua @@ -64,7 +64,7 @@ local function check_object_hit(self, pos, dmg) -- TODO: Deal knockback self.object:remove() return true - elseif (entity._cmi_is_mob == true or entity._hittable_by_projectile) and (self._thrower ~= object) then + elseif (entity.is_mob == true or entity._hittable_by_projectile) and (self._thrower ~= object) then -- FIXME: Knockback is broken object:punch(self.object, 1.0, { full_punch_interval = 1.0, diff --git a/mods/MISC/mcl_commands/summon.lua b/mods/MISC/mcl_commands/summon.lua index 69da0a66cc..118d3e23b9 100644 --- a/mods/MISC/mcl_commands/summon.lua +++ b/mods/MISC/mcl_commands/summon.lua @@ -4,7 +4,7 @@ local orig_func = minetest.registered_chatcommands["spawnentity"].func local cmd = table.copy(minetest.registered_chatcommands["spawnentity"]) cmd.func = function(name, param) local ent = minetest.registered_entities[param] - if minetest.settings:get_bool("only_peaceful_mobs", false) and ent and ent._cmi_is_mob and ent.type == "monster" then + if minetest.settings:get_bool("only_peaceful_mobs", false) and ent and ent.is_mob and ent.type == "monster" then return false, S("Only peaceful mobs allowed!") else local bool, msg = orig_func(name, param) diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 38e39f7dc3..924b60c97d 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -36,7 +36,7 @@ local function player_collision(player) for _,object in pairs(minetest.get_objects_inside_radius(pos, width)) do local ent = object:get_luaentity() - if (object:is_player() or (ent and ent._cmi_is_mob and object ~= player)) then + if (object:is_player() or (ent and ent.is_mob and object ~= player)) then local pos2 = object:get_pos() local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z}