forked from Kimapr/nodecore-skyblock
bulk island generation, better island distribution algorhythm
This commit is contained in:
parent
1e2e9721e6
commit
17bef30b02
|
@ -121,10 +121,13 @@ local function island(pos,r)
|
|||
end)
|
||||
end
|
||||
local f,abs = math.floor, math.abs
|
||||
local function spawn_island(name,pos)
|
||||
local ref = minetest.get_player_by_name(name)
|
||||
local function raw_spawn_island(pos)
|
||||
pos = {x=f(pos.x),y=f(pos.y),z=f(pos.z)}
|
||||
island(pos,48,name)
|
||||
end
|
||||
local function spawn_island(name,pos)
|
||||
local ref = minetest.get_player_by_name(name)
|
||||
raw_spawn_island(pos)
|
||||
ref:set_pos({x=pos.x,y=pos.y+256,z=pos.z})
|
||||
end
|
||||
local store = minetest.get_mod_storage()
|
||||
|
@ -284,37 +287,56 @@ local function get_standing_island(name)
|
|||
return closesti
|
||||
end
|
||||
|
||||
local function gen_island_pos(name)
|
||||
local x,y,z = 0,0,0
|
||||
x,z = x+math.random(-64,64),z+math.random(-64,64)
|
||||
y=256+math.random(-32,32)
|
||||
for k,isl in ipairs(cells) do
|
||||
if isl and isl.valid then
|
||||
table.remove(cells,k)
|
||||
local ip = isl.pos
|
||||
local ref = minetest.get_player_by_name(name)
|
||||
local pos = ip
|
||||
players[name] = {pos = pos, valid = false}
|
||||
local function gen_island_pos(name,fgen)
|
||||
for n=1,fgen or 1 do
|
||||
minetest.after((n-1)*30,function()
|
||||
local x,y,z = 0,0,0
|
||||
x,z = x+math.random(-96,96),z+math.random(-96,96)
|
||||
y=256+math.random(-32,32)
|
||||
if not fgen then
|
||||
for k,isl in pairs(cells) do
|
||||
if isl and isl.valid then
|
||||
table.remove(cells,k)
|
||||
local ip = isl.pos
|
||||
local ref = minetest.get_player_by_name(name)
|
||||
local pos = ip
|
||||
players[name] = {pos = pos, valid = true}
|
||||
save()
|
||||
pos = {x=f(pos.x),y=f(pos.y),z=f(pos.z)}
|
||||
ref:set_pos({x=pos.x,y=pos.y+256,z=pos.z})
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
local ok = checkpos(x,y,z)
|
||||
while not ok do
|
||||
local sx,sz = math.random(-96,96),math.random(-96,96)
|
||||
if ((x+sx)^2+(z+sz)^2)^0.5 < (x^2+z^2)^0.5 then
|
||||
sx=-sx
|
||||
sz=-sz
|
||||
end
|
||||
x,z = x+sx,z+sz
|
||||
y=256+math.random(-32,32)
|
||||
ok = checkpos(x,y,z)
|
||||
end
|
||||
local ip = {x=x,y=y,z=z}
|
||||
if not fgen then
|
||||
spawn_island(name,ip)
|
||||
else
|
||||
raw_spawn_island(ip)
|
||||
end
|
||||
local pl = {
|
||||
pos = ip,
|
||||
valid = true
|
||||
}
|
||||
if not fgen then
|
||||
players[name] = pl
|
||||
else
|
||||
table.insert(cells,pl)
|
||||
end
|
||||
save()
|
||||
pos = {x=f(pos.x),y=f(pos.y),z=f(pos.z)}
|
||||
ref:set_pos({x=pos.x,y=pos.y+256,z=pos.z})
|
||||
return
|
||||
end
|
||||
end)
|
||||
end
|
||||
local ok = checkpos(x,y,z)
|
||||
while not ok do
|
||||
x,z = x+math.random(-64,64),z+math.random(-64,64)
|
||||
y=256+math.random(-32,32)
|
||||
ok = checkpos(x,y,z)
|
||||
end
|
||||
local ip = {x=x,y=y,z=z}
|
||||
spawn_island(name,ip)
|
||||
local pl = {
|
||||
pos = ip,
|
||||
valid = false
|
||||
}
|
||||
players[name] = pl
|
||||
save()
|
||||
end
|
||||
local updrate = 0.5
|
||||
local to_upd = updrate
|
||||
|
@ -515,6 +537,14 @@ minetest.register_chatcommand("reset",{
|
|||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("islandgen",{
|
||||
description = S"Bulk island generation",
|
||||
privs = {interact = true, server = true},
|
||||
func = function(name,param)
|
||||
gen_island_pos(name,tonumber(param) or 1)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_joinplayer(function(ref)
|
||||
local meta = ref:get_meta()
|
||||
local name = ref:get_player_name()
|
||||
|
|
Loading…
Reference in New Issue