nodecore-skyblock/mods/nc_sky/init.lua

116 lines
2.9 KiB
Lua
Raw Normal View History

2019-10-23 03:57:37 +02:00
--nothing--
local grass = "nc_terrain:dirt_with_grass"
local dirt = "nc_terrain:dirt"
local stone = "nc_terrain:stone"
local queue = {}
minetest.register_globalstep(function(dt)
for f,_ in pairs(queue) do
if not coroutine.resume(f) then
queue[f]=nil
end
end
end)
local function maxval(octaves,persistence,scale)
local m = scale
local poc = scale
if octaves > 1 then
for n=2,octaves do
poc = poc*persistence
m=m+poc
end
end
return m
end
local function island(pos,r)
minetest.after(2,function()--queue[coroutine.create(function()
local noise = PerlinNoise({
seed = math.random(10000),
octaves = 3,
spread = {x=r/2,y=r/2,z=r/2},
lacunarity = 2,
persistence = 0.5,
flags = "absvalue"
})
local n = 0
local c = 0
local cm = (r*2+1)^3
local function geto(x,y,z)
local dist = (x*x+y*y+z*z)^0.5
local uvdist = (y+r)/(r*2)
local hdist = (x*x+z*z)^0.5
local uhdist = (math.max(0,r-hdist)/r)^((1-uvdist)^3*5)
local udist = math.max(0,r-dist)/r
if math.min(1,math.max(0,uhdist^2)) ~= uhdist^2 then
print(uhdist^2)
end
local m = ((math.max(r-(hdist),0)/r)^0.1*(uhdist^2))-uhdist*uvdist^3
return m
end
for x=-r,r do
for z=-r,r do
for y=-r,r do
local xx,yy,zz = pos.x+x,pos.y+y,pos.z+z
o,o2 = geto(x,y,z),geto(x,y+1,z)
local oc = (o > 0.4)
local oc2 = o2 > 0.4
local og = (o > 0.6)
if oc then
n=n+1
local nam = dirt
if not og and not oc2 then
nam = grass
end
if og then
nam = stone
end
minetest.set_node({x=xx,y=yy,z=zz},{name=nam})
else
n=n+0.01
end
if n > 1000 then
n=0
--coroutine.yield()
end
end
end
end
minetest.set_node({x=pos.x,y=pos.y+10,z=pos.z},{name="nc_tree:eggcorn_planted"})
end)--end)] = true
end
local f = math.floor
local function spawn_island(name,pos)
local ref = minetest.get_player_by_name(name)
pos = {x=f(pos.x),y=f(pos.y),z=f(pos.z)}
island(pos,16,name)
ref:set_pos({x=pos.x,y=pos.y+30,z=pos.z})
end
local store = minetest.get_mod_storage()
local function pid(x,z)
return "i"..x.."_"..z
end
local function checkpos(x,z)
if store:get_string(pid(x,z)) == "" then
return true
end
end
local function gen_island_pos(name)
local x,z = 0,0
local ok = checkpos(x,z)
while not ok do
x,z = x+math.random(-1,1),z+math.random(-1,1)
ok = checkpos(x,z)
end
store:set_string(pid(x,z),name)
spawn_island(name,{x=x*128,y=256,z=z*128})
return pid(x,z)
end
minetest.register_on_joinplayer(function(ref)
local meta = ref:get_meta()
local name = ref:get_player_name()
if meta:get_string("island") == "" then
meta:set_string("island",gen_island_pos(name))
end
end)