forked from minetest-mods/nether
Respect protected areas when spawning remote portals (#27)
* respect protected areas when spawning remote portals * Use portal_shape to determine area to check for natural/protected * Log warning on deprecated function call
This commit is contained in:
18
mapgen.lua
18
mapgen.lua
@ -465,10 +465,15 @@ end
|
||||
|
||||
|
||||
-- use knowledge of the nether mapgen algorithm to return a suitable ground level for placing a portal.
|
||||
function nether.find_nether_ground_y(target_x, target_z, start_y)
|
||||
-- player_name is optional, allowing a player to spawn a remote portal in their own protected areas.
|
||||
function nether.find_nether_ground_y(target_x, target_z, start_y, player_name)
|
||||
local nobj_cave_point = minetest.get_perlin(np_cave)
|
||||
local air = 0 -- Consecutive air nodes found
|
||||
|
||||
local minp_schem, maxp_schem = nether.get_schematic_volume({x = target_x, y = 0, z = target_z}, nil, "nether_portal")
|
||||
local minp = {x = minp_schem.x, y = 0, z = minp_schem.z}
|
||||
local maxp = {x = maxp_schem.x, y = 0, z = maxp_schem.z}
|
||||
|
||||
for y = start_y, math_max(NETHER_FLOOR + BLEND, start_y - 4096), -1 do
|
||||
local nval_cave = nobj_cave_point:get3d({x = target_x, y = y, z = target_z})
|
||||
|
||||
@ -476,13 +481,14 @@ function nether.find_nether_ground_y(target_x, target_z, start_y)
|
||||
air = air + 1
|
||||
else -- Not cavern, check if 4 nodes of space above
|
||||
if air >= 4 then
|
||||
local portal_y = y + 1
|
||||
-- Check volume for non-natural nodes
|
||||
local minp = {x = target_x - 1, y = y , z = target_z - 2}
|
||||
local maxp = {x = target_x + 2, y = y + 4, z = target_z + 2}
|
||||
if nether.volume_is_natural(minp, maxp) then
|
||||
return y + 1
|
||||
minp.y = minp_schem.y + portal_y
|
||||
maxp.y = maxp_schem.y + portal_y
|
||||
if nether.volume_is_natural_and_unprotected(minp, maxp, player_name) then
|
||||
return portal_y
|
||||
else -- Restart search a little lower
|
||||
nether.find_nether_ground_y(target_x, target_z, y - 16)
|
||||
nether.find_nether_ground_y(target_x, target_z, y - 16, player_name)
|
||||
end
|
||||
else -- Not enough space, reset air to zero
|
||||
air = 0
|
||||
|
Reference in New Issue
Block a user