From 628686ce79c317efad5723031dd53a5aab4ec0c7 Mon Sep 17 00:00:00 2001 From: cora Date: Tue, 5 Apr 2022 22:43:37 +0200 Subject: [PATCH 1/3] Add a command to safely remove all mob objects --- mods/ENTITIES/mcl_mobs/api.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index ea9235391..914a919a1 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -101,6 +101,16 @@ local mod_worlds = minetest.get_modpath("mcl_worlds") ~= nil local mod_armor = minetest.get_modpath("mcl_armor") ~= nil local mod_experience = minetest.get_modpath("mcl_experience") ~= nil +--Helper function to clear all mobs because /clearobjects removes too much +minetest.register_chatcommand("clearmobs",{ + privs={maphack=true}, + description=S("Removes all spawned mobs"), + func=function() + for k,o in pairs(minetest.luaentities) do + if o.type == "ambient" or o.type == "animal" or o.type == "monster" or o.type == "npc" then o.object:remove() end + end +end}) + ----For Water Flowing: local enable_physics = function(object, luaentity, ignore_check) if luaentity.physical_state == false or ignore_check == true then From e5de4bba65e0607c727a920982f1d23d3d1ca766 Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 17 Apr 2022 12:10:10 +0200 Subject: [PATCH 2/3] keep nametagged mobs, add "all" argument --- mods/ENTITIES/mcl_mobs/api.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 914a919a1..0429c5ea5 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -104,10 +104,15 @@ local mod_experience = minetest.get_modpath("mcl_experience") ~= nil --Helper function to clear all mobs because /clearobjects removes too much minetest.register_chatcommand("clearmobs",{ privs={maphack=true}, - description=S("Removes all spawned mobs"), - func=function() + params = "", + description=S("Removes all spawned mobs except nametagged ones. Supply the optional all argument to remove all mobs"), + func=function(n,p) for k,o in pairs(minetest.luaentities) do - if o.type == "ambient" or o.type == "animal" or o.type == "monster" or o.type == "npc" then o.object:remove() end + if o.type == "ambient" or o.type == "animal" or o.type == "monster" or o.type == "npc" then + if p == "all" or not o.nametag then + o.object:remove() + end + end end end}) From 5282a63bcb52b1ab8b8936601f936217fac98e76 Mon Sep 17 00:00:00 2001 From: cora Date: Fri, 6 May 2022 21:33:27 +0200 Subject: [PATCH 3/3] add options for nametagged mobs and range --- mods/ENTITIES/mcl_mobs/api.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 0429c5ea5..a046a1205 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -102,14 +102,22 @@ local mod_armor = minetest.get_modpath("mcl_armor") ~= nil local mod_experience = minetest.get_modpath("mcl_experience") ~= nil --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 = "", - description=S("Removes all spawned mobs except nametagged ones. Supply the optional all argument to remove all mobs"), - func=function(n,p) - for k,o in pairs(minetest.luaentities) do - if o.type == "ambient" or o.type == "animal" or o.type == "monster" or o.type == "npc" then - if p == "all" or not o.nametag then + params = "||", + description=S("Removes all spawned mobs except nametagged and tamed ones. all removes all mobs, nametagged only nametagged ones and with the range paramter all mobs in a distance of the current player are removed."), + func=function(n,param) + 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 param == "all" or + ( param == "nametagged" and o.nametag ) or + ( param == "" and not o.nametag and not o.tamed ) or + ( num and num > 0 and vector.distance(p:get_pos(),o.object:get_pos()) <= num ) then o.object:remove() end end