Forceload blocks
parent
2a2854ad1e
commit
c30c6c90ae
36
init.lua
36
init.lua
|
@ -1,4 +1,4 @@
|
||||||
RADIUS = 128
|
RADIUS = 1280
|
||||||
SPAWN = {x=0, y=0, z=0}
|
SPAWN = {x=0, y=0, z=0}
|
||||||
|
|
||||||
local function findspawn(player)
|
local function findspawn(player)
|
||||||
|
@ -6,24 +6,26 @@ local function findspawn(player)
|
||||||
local pos = {x = SPAWN.x, y = SPAWN.y, z = SPAWN.z}
|
local pos = {x = SPAWN.x, y = SPAWN.y, z = SPAWN.z}
|
||||||
pos.x = SPAWN.x + math.random(-RADIUS, RADIUS)
|
pos.x = SPAWN.x + math.random(-RADIUS, RADIUS)
|
||||||
pos.z = SPAWN.z + math.random(-RADIUS, RADIUS)
|
pos.z = SPAWN.z + math.random(-RADIUS, RADIUS)
|
||||||
-- Find ground level (0...15)
|
if minetest.forceload_block(pos) then
|
||||||
local ground_y = nil
|
-- Find ground level (0...15)
|
||||||
for y=16, 0, -1 do
|
local ground_y = nil
|
||||||
print("pos = "..pos.x..", "..y..", "..pos.z.."")
|
for y=16, 0, -1 do
|
||||||
local nn = minetest.get_node({x=pos.x, y=y, z=pos.z}).name
|
local nn = minetest.get_node({x=pos.x, y=y, z=pos.z}).name
|
||||||
if nn ~= "air" and nn~= "ignore" then
|
if nn ~= "air" and nn~= "ignore" then
|
||||||
ground_y = y
|
ground_y = y
|
||||||
break
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
if ground_y then
|
||||||
if ground_y then
|
pos.y = ground_y
|
||||||
pos.y = ground_y
|
if minetest.registered_nodes[minetest.get_node(pos).name].walkable == true and
|
||||||
if minetest.registered_nodes[minetest.get_node(pos).name].walkable == true and
|
minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" and
|
||||||
minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" and
|
minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name == "air" then
|
||||||
minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name == "air" then
|
local pos_spawn = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||||
pos.y = pos.y+1
|
return pos_spawn
|
||||||
return pos
|
end
|
||||||
end
|
end
|
||||||
|
minetest.forceload_free_block(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue