1
0
mirror of https://github.com/HybridDog/nether-pack.git synced 2024-12-26 18:50:24 +01:00
nether-pack/nether/weird_mapgen_noise.lua

89 lines
2.0 KiB
Lua
Raw Normal View History

2014-04-18 22:02:24 +02:00
--V2
local function get_random(a, b, seed)
return PseudoRandom(math.abs(a+b*5)+seed)
end
local r_chs = {}
2015-02-18 18:34:03 +01:00
function nether_weird_noise(minp, fct, s, seed, range, scale)
2014-04-18 22:02:24 +02:00
if not r_chs[s] then
r_chs[s] = math.floor(s/3+0.5)
end
2015-02-18 18:34:03 +01:00
scale = scale or 15
2014-04-18 22:02:24 +02:00
local r_ch = r_chs[s]
2015-02-18 18:34:03 +01:00
local maxp = vector.add(minp, scale)
2014-04-18 22:02:24 +02:00
local tab,n = {},1
local sm = range or (s+r_ch)*2
2015-02-18 18:34:03 +01:00
for z = -sm, scale+sm do
2014-04-18 22:02:24 +02:00
local pz = z+minp.z
if pz%s == 0 then
2015-02-18 18:34:03 +01:00
for x = -sm, scale+sm do
2014-04-18 22:02:24 +02:00
local px = x+minp.x
if px%s == 0 then
local pr = get_random(px, pz, seed)
tab[n] = {x=px+pr:next(-r_ch, r_ch), y=0, z=pz+pr:next(-r_ch, r_ch)}
n = n+1
end
end
end
end
local tab2,n = {},1
for z = minp.z, maxp.z do
for x = minp.x, maxp.x do
local h = sm
for _,i in ipairs(tab) do
h = math.min(h, fct(x, i.x, z, i.z))
end
tab2[n] = {x=x, y=maxp.y-h, z=z}
n = n+1
end
end
return tab2
end
--[[
local function dif(z1, z2)
return math.abs(z1-z2)
end
local function pymg(x1, x2, z1, z2)
return math.max(dif(x1, x2), dif(z1, z2))
end
local function romg(x1, x2, z1, z2)
return math.hypot(dif(x1, x2), dif(z1, z2))
end
local function py2mg(x1, x2, z1, z2)
return dif(x1, x2) + dif(z1, z2)
end
minetest.register_node("ac:wmg", {
description = "wmg",
tiles = {"ac_block.png"},
groups = {snappy=1,bendy=2,cracky=1},
2015-02-18 18:34:03 +01:00
sounds = default.node_sound_stone_defaults(),
2014-04-18 22:02:24 +02:00
on_construct = function(pos)
local minp = vector.chunkcorner(pos)
for _,p in ipairs(weird_noise(minp, pymg, 20, 8, 4)) do
local p2 = {x=p.x, y=p.y+1, z=p.z}
if p.y <= minp.y+7 then
local p2 = {x=p.x, y=minp.y+6, z=p.z}
local p3 = {x=p.x, y=p2.y+1, z=p.z}
if minetest.get_node(p2).name ~= "default:desert_stone" then
minetest.set_node(p2, {name="default:desert_stone"})
end
if minetest.get_node(p3).name ~= "default:desert_sand" then
minetest.set_node(p3, {name="default:desert_sand"})
end
else
if minetest.get_node(p).name ~= "default:desert_stone" then
minetest.set_node(p, {name="default:desert_stone"})
end
end
end
end,
})]]