mirror of
https://github.com/ElCeejo/creatura.git
synced 2025-04-30 13:51:41 -04:00
Spawning fixes:
1. Spawning radius fixed, we now have a cubic max radius mobs will spawn within, and a spherical min radius mobs won't spawn within. 2. Node light check fixed - we need to check the node above the spawn node, otherwise it always returns zero.
This commit is contained in:
parent
c251f07ae5
commit
cea6d15965
1 changed files with 11 additions and 6 deletions
17
spawning.lua
17
spawning.lua
|
@ -66,7 +66,7 @@ end
|
||||||
function creatura.register_mob_spawn(name, def)
|
function creatura.register_mob_spawn(name, def)
|
||||||
local spawn = {
|
local spawn = {
|
||||||
chance = def.chance or 5,
|
chance = def.chance or 5,
|
||||||
min_radius = def.min_height or nil,
|
min_radius = def.min_radius or nil,
|
||||||
max_radius = def.max_radius or nil,
|
max_radius = def.max_radius or nil,
|
||||||
min_height = def.min_height or 0,
|
min_height = def.min_height or 0,
|
||||||
max_height = def.max_height or 128,
|
max_height = def.max_height or 128,
|
||||||
|
@ -132,7 +132,7 @@ local spawn_queue = {}
|
||||||
|
|
||||||
local min_spawn_radius = 16
|
local min_spawn_radius = 16
|
||||||
|
|
||||||
local min_spawn_radius = 64
|
local max_spawn_radius = 64
|
||||||
|
|
||||||
function execute_spawns(player)
|
function execute_spawns(player)
|
||||||
if not player:get_pos() then return end
|
if not player:get_pos() then return end
|
||||||
|
@ -144,11 +144,16 @@ function execute_spawns(player)
|
||||||
local spawn = creatura.registered_mob_spawns[mob]
|
local spawn = creatura.registered_mob_spawns[mob]
|
||||||
if not spawn
|
if not spawn
|
||||||
or random(spawn.chance) > 1 then return end
|
or random(spawn.chance) > 1 then return end
|
||||||
|
local max_radius = spawn.max_radius or max_spawn_radius
|
||||||
|
local min_radius = spawn.min_radius or min_spawn_radius
|
||||||
local spawn_pos_center = {
|
local spawn_pos_center = {
|
||||||
x = pos.x + random(-min_spawn_radius, spawn.min_radius or min_spawn_radius),
|
x = pos.x + random(-max_radius, max_radius),
|
||||||
y = pos.y,
|
y = pos.y,
|
||||||
z = pos.z + random(-min_spawn_radius, spawn.max_radius or min_spawn_radius)
|
z = pos.z + random(-max_radius, max_radius)
|
||||||
}
|
}
|
||||||
|
if vector.distance(pos, spawn_pos_center) < min_radius then
|
||||||
|
return
|
||||||
|
end
|
||||||
local index_func
|
local index_func
|
||||||
if spawn.spawn_in_nodes then
|
if spawn.spawn_in_nodes then
|
||||||
index_func = minetest.find_nodes_in_area
|
index_func = minetest.find_nodes_in_area
|
||||||
|
@ -159,7 +164,7 @@ function execute_spawns(player)
|
||||||
if type(spawn_on) == "string" then
|
if type(spawn_on) == "string" then
|
||||||
spawn_on = {spawn_on}
|
spawn_on = {spawn_on}
|
||||||
end
|
end
|
||||||
local spawn_y_array = index_func(vec_raise(spawn_pos_center, -8), vec_raise(spawn_pos_center, 8), spawn_on)
|
local spawn_y_array = index_func(vec_raise(spawn_pos_center, -max_radius), vec_raise(spawn_pos_center, max_radius), spawn_on)
|
||||||
if spawn_y_array[1] then
|
if spawn_y_array[1] then
|
||||||
local spawn_pos = spawn_y_array[1]
|
local spawn_pos = spawn_y_array[1]
|
||||||
|
|
||||||
|
@ -168,7 +173,7 @@ function execute_spawns(player)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local light = minetest.get_node_light(spawn_pos) or 7
|
local light = minetest.get_node_light(vec_raise(spawn_pos, 1)) or 7
|
||||||
|
|
||||||
if light > spawn.max_light
|
if light > spawn.max_light
|
||||||
or light < spawn.min_light then
|
or light < spawn.min_light then
|
||||||
|
|
Loading…
Add table
Reference in a new issue