From 7a870d0eadd51b1eabb9608f0bc7dfa384073ed6 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 6 Jan 2020 13:46:43 +0100 Subject: [PATCH] Message when trying to spawn forbidden hostile mob --- mods/ENTITIES/mcl_mobs/api.lua | 14 ++++++++++---- mods/ENTITIES/mcl_mobs/locale/mcl_mobs.de.tr | 1 + mods/ENTITIES/mcl_mobs/locale/template.txt | 1 + mods/MISC/mcl_commands/init.lua | 16 ++++++++++++++++ mods/MISC/mcl_commands/locale/mcl_commands.de.tr | 1 + mods/MISC/mcl_commands/locale/template.txt | 1 + 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index fb823270a3..9be2152010 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -50,8 +50,8 @@ end -- Load settings local damage_enabled = minetest.settings:get_bool("enable_damage") -local mobs_spawn = minetest.settings:get_bool("mobs_spawn") ~= false -local peaceful_only = minetest.settings:get_bool("only_peaceful_mobs") +local mobs_spawn = minetest.settings:get_bool("mobs_spawn", true) ~= false + local disable_blood = minetest.settings:get_bool("mobs_disable_blood") local mobs_drop_items = minetest.settings:get_bool("mobs_drop_items") ~= false local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false @@ -65,7 +65,7 @@ local max_per_block = tonumber(minetest.settings:get("max_objects_per_block") or local mobs_spawn_chance = tonumber(minetest.settings:get("mobs_spawn_chance") or 2.5) -- Peaceful mode message so players will know there are no monsters -if peaceful_only then +if minetest.settings:get_bool("only_peaceful_mobs", false) then minetest.register_on_joinplayer(function(player) minetest.chat_send_player(player:get_player_name(), S("Peaceful mode active! No monsters will spawn.")) @@ -2756,7 +2756,7 @@ local mob_activate = function(self, staticdata, def, dtime) -- remove monsters in peaceful mode if self.type == "monster" - and peaceful_only then + and minetest.settings:get_bool("only_peaceful_mobs", false) then self.object:remove() @@ -3754,6 +3754,12 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) return itemstack end + if minetest.settings:get_bool("only_peaceful_mobs", false) + and minetest.registered_entities[mob].type == "monster" then + minetest.chat_send_player(name, S("Only peaceful mobs allowed!")) + return itemstack + end + pos.y = pos.y + 1 local mob = minetest.add_entity(pos, mob) diff --git a/mods/ENTITIES/mcl_mobs/locale/mcl_mobs.de.tr b/mods/ENTITIES/mcl_mobs/locale/mcl_mobs.de.tr index 59f65eae82..027c166493 100644 --- a/mods/ENTITIES/mcl_mobs/locale/mcl_mobs.de.tr +++ b/mods/ENTITIES/mcl_mobs/locale/mcl_mobs.de.tr @@ -6,3 +6,4 @@ You need the “maphack” privilege to change the mob spawner.=Sie brauchen das Name Tag=Namensschild A name tag is an item to name a mob.=Ein Namensschild ist ein Gegenstand, um einen Mob zu benennen. Before you use the name tag, you need to set a name at an anvil. Then you can use the name tag to name a mob. This uses up the name tag.=Bevor Sie ein Namensschild benutzen können, müssen Sie ihn an einem Amboss benennen. Dann können können Sie das Namensschild benutztn, um einen Mob zu benennen. Das wird das Namensschild verbrauchen. +Only peaceful mobs allowed!=Nur friedliche Mobs erlaubt! diff --git a/mods/ENTITIES/mcl_mobs/locale/template.txt b/mods/ENTITIES/mcl_mobs/locale/template.txt index db0c4d53ac..1751be38ba 100644 --- a/mods/ENTITIES/mcl_mobs/locale/template.txt +++ b/mods/ENTITIES/mcl_mobs/locale/template.txt @@ -6,3 +6,4 @@ You need the “maphack” privilege to change the mob spawner.= Name Tag= A name tag is an item to name a mob.= Before you use the name tag, you need to set a name at an anvil. Then you can use the name tag to name a mob. This uses up the name tag.= +Only peaceful mobs allowed!= diff --git a/mods/MISC/mcl_commands/init.lua b/mods/MISC/mcl_commands/init.lua index 0532108f98..8b931d0b8b 100644 --- a/mods/MISC/mcl_commands/init.lua +++ b/mods/MISC/mcl_commands/init.lua @@ -126,6 +126,21 @@ local function register_chatcommand_alias(alias, cmd) minetest.register_chatcommand(alias, def) end +-- Replace spawnentity cmd to disallow spawning of hostile mobs if disabled +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 + return false, S("Only peaceful mobs allowed!") + else + local bool, msg = orig_func(name, param) + return bool, msg + end +end +minetest.unregister_chatcommand("spawnentity") +minetest.register_chatcommand("spawnentity", cmd) + if minecraftaliases then register_chatcommand_alias("?", "help") register_chatcommand_alias("who", "list") @@ -145,3 +160,4 @@ if minecraftaliases then end, }) end + diff --git a/mods/MISC/mcl_commands/locale/mcl_commands.de.tr b/mods/MISC/mcl_commands/locale/mcl_commands.de.tr index 98f1e6a0d4..68d2675179 100644 --- a/mods/MISC/mcl_commands/locale/mcl_commands.de.tr +++ b/mods/MISC/mcl_commands/locale/mcl_commands.de.tr @@ -20,3 +20,4 @@ List bans=Bannliste anzeigen Ban list: @1=Bannliste: @1 Show who is logged on=Anzeigen, wer eingeloggt ist Displays the world seed=Den Seed der Welt anzeigen +Only peaceful mobs allowed!=Nur friedliche Mobs erlaubt! diff --git a/mods/MISC/mcl_commands/locale/template.txt b/mods/MISC/mcl_commands/locale/template.txt index fc979be6fd..5b4370b8fb 100644 --- a/mods/MISC/mcl_commands/locale/template.txt +++ b/mods/MISC/mcl_commands/locale/template.txt @@ -20,3 +20,4 @@ List bans= Ban list: @1= Show who is logged on= Displays the world seed= +Only peaceful mobs allowed!=