Clean up mob settings, add mobs_spawn

This commit is contained in:
Wuzzy 2023-03-07 20:07:46 +01:00
parent 63f4116cf2
commit 0c97c13796
2 changed files with 33 additions and 9 deletions

View File

@ -8,15 +8,25 @@ mobs.mod = "redo"
-- Initial settings check
local damage_enabled = minetest.settings:get_bool("enable_damage") or false
local peaceful_only = minetest.settings:get_bool("only_peaceful_mobs") or false
local enable_blood = minetest.settings:get_bool("mobs_enable_blood") or false
local spawn_mobs = minetest.settings:get_bool("mobs_spawn", true)
local damage_enabled = minetest.settings:get_bool("enable_damage", true)
local peaceful_only = minetest.settings:get_bool("only_peaceful_mobs", false)
local enable_blood = minetest.settings:get_bool("mobs_enable_blood", false)
local setting_protected = minetest.settings:get("mobs_spawn_protected")
-- numeric value 1 or false means it's disabled
-- (the odd numeric value is supported for backwards-compability)
if tonumber(setting_protected) == 1 or setting_protected == "false" then
mobs.protected = 1 -- mobs can not spawn naturally in protected areas
-- any other value means it's enabled
else
mobs.protected = 0 -- mobs can spawn naturally in protected areas
end
mobs.protected = tonumber(minetest.settings:get("mobs_spawn_protected")) or 0
mobs.remove = false
local function is_too_near_spawn(pos)
if minetest.is_singleplayer() or not minetest.settings:get_bool("mobs_safe_spawn") then
if minetest.is_singleplayer() or not minetest.settings:get_bool("mobs_safe_spawn", true) then
return false
end
@ -1490,6 +1500,11 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
interval = interval,
chance = chance,
action = function(pos, node, _, active_object_count_wider)
-- do not spawn if mob spawning is disabled
if not spawn_mobs then
return
end
-- do not spawn if too many active entities in area
if active_object_count_wider > active_object_count or not mobs.spawning_mobs[name] then
--or not pos then
@ -1534,7 +1549,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
return
end
if minetest.settings:get_bool("display_mob_spawn") then
if minetest.settings:get_bool("display_mob_spawn", false) then
minetest.chat_send_all("[mobs] "..S("Spawned @1 at @2", name, minetest.pos_to_string(pos)))
end

View File

@ -67,19 +67,28 @@ locks_all_unlocked (Unlock all locks) bool false
locks_picked_time (Picked lock time) float 15 1.0
[Mobs]
# If enabled, only peaceful, non-hostile mobs will appear. Hostile mobs will disappear and cannot be spawned at all.
# If enabled, mobs will appear/spawn naturally in the world.
# If disabled, mobs won't spawn naturally, but they can still spawn by other means.
# This setting is only read at startup.
mobs_spawn (Mobs spawn) bool true
# If enabled, only peaceful, non-hostile mobs are able to appear/spawn. Hostile mobs will disappear and cannot be spawned at all.
# This setting is only read at startup.
only_peaceful_mobs (Only peaceful mobs) bool false
# If enabled, mobs can naturally spawn in areas that are protected by someone (e.g. using a protection mod).
# This setting is only read at startup.
mobs_spawn_protected (Mobs spawn in protected area) bool true
# If enabled, hostile mobs will not attack near the player spawn on multiplayer servers. This setting is ignored in singleplayer, mobs will attack regardless.
# The safety radius is set in static_spawn_radius.
mobs_safe_spawn (Safe spawn from mobs) bool true
# Radius around the player spawn point in which mobs don't attack.
# This is only the case in multiplayer servers and if the setting mobs_safe_spawn is enabled. In singleplayer, mobs will attack regardless.
# This is only the case in multiplayer servers and if the setting 'mobs_safe_spawn' is enabled. In singleplayer, mobs will attack regardless.
#
# Additionally, this radius also specifies the radius around
# spawn in which villages don't generate.
# the spawn point in which villages don't generate.
static_spawn_radius (Spawn point safety radius) int 256 0
[Graphics and audio]