From a4d29183836a60a62b1b2bb342c662815b442fe9 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Mon, 30 Nov 2020 14:43:49 +0000 Subject: [PATCH] add mob_area_spawn setting --- api.lua | 26 +++++++++++++++++++++++--- api.txt | 3 +++ settingtypes.txt | 3 +++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/api.lua b/api.lua index 72947ab..6484457 100644 --- a/api.lua +++ b/api.lua @@ -8,7 +8,7 @@ local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20201115", + version = "20201130", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {} } @@ -58,6 +58,7 @@ local mobs_drop_items = settings:get_bool("mobs_drop_items") ~= false local mobs_griefing = settings:get_bool("mobs_griefing") ~= false local spawn_protected = settings:get_bool("mobs_spawn_protected") ~= false local remove_far = settings:get_bool("remove_far_mobs") ~= false +local mob_area_spawn = settings:get_bool("mob_area_spawn") local difficulty = tonumber(settings:get("mob_difficulty")) or 1.0 local show_health = settings:get_bool("mob_show_health") ~= false local max_per_block = tonumber(settings:get("max_objects_per_block") or 99) @@ -3908,8 +3909,27 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter end end - -- returns position if we have enough space to spawn mob - pos = can_spawn(pos, name) + -- should we check mob area for obstructions ? + if mob_area_spawn ~= true then + + -- do we have enough height clearance to spawn mob? + local ent = minetest.registered_entities[name] + local height = max(1, math.ceil( + (ent.collisionbox[5] or 0.25) - (ent.collisionbox[2] or -0.25) - 1)) + + for n = 0, height do + + local pos2 = {x = pos.x, y = pos.y + n, z = pos.z} + + if minetest.registered_nodes[node_ok(pos2).name].walkable == true then +--print ("--- inside block", name, node_ok(pos2).name) + return + end + end + else + -- returns position if we have enough space to spawn mob + pos = can_spawn(pos, name) + end if pos then diff --git a/api.txt b/api.txt index e81b750..d78fd98 100644 --- a/api.txt +++ b/api.txt @@ -697,6 +697,9 @@ External Settings for "minetest.conf" function. 'mob_nospawn_range' Minimum range a mob can spawn near player (def: 12) 'mob_active_limit' Number of active mobs in game, 0 for unlimited + 'mob_area_spawn' When true will check surrounding area the size of the + mob for obstructions before spawning, otherwise it + defaults to checking the height of the mob only. Players can override the spawn chance for each mob registered by adding a line to their minetest.conf file with a new value, the lower the value the more each diff --git a/settingtypes.txt b/settingtypes.txt index 75bf111..49d2443 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -33,3 +33,6 @@ mob_nospawn_range (Mob no-spawn range) float 12.0 # Sets maximum number of active mobs in game (0 for unlimited) mob_active_limit (Mob Active Limit) float 0 + +# Enables area check when spawning mobs +mob_area_spawn (Mob Area Spawn) bool false