From 0d07fa3cd496a797ee48ffc4f43454619dcb1ae4 Mon Sep 17 00:00:00 2001 From: HybridDog Date: Wed, 20 May 2015 21:01:10 +0200 Subject: [PATCH] use the weierstrass function to decorate the nether forest top (similar to http://a.pomf.se/niypzy.png) --- README.txt | 3 ++- nether/init.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index 570b021..8c2f490 100644 --- a/README.txt +++ b/README.txt @@ -7,4 +7,5 @@ http://i.imgur.com/pMZYqt9.png TODO: -— finish nether forest +— care about nether torches +— find out why the nether forests top is sometimes flat diff --git a/nether/init.lua b/nether/init.lua index f883b0b..5dd0862 100644 --- a/nether/init.lua +++ b/nether/init.lua @@ -125,6 +125,36 @@ local function table_contains(t, v) return false end +-- Weierstrass function stuff from https://github.com/slemonide/gen +local SIZE = 1000 +local ssize = math.ceil(math.abs(SIZE)) +local function do_ws_func(depth, a, x) + local n = x/(16*SIZE) + local y = 0 + for k=1,depth do + y = y + SIZE*(math.sin(math.pi * k^a * n)/(math.pi * k^a)) + end + return y +end + +local chunksize = minetest.setting_get("chunksize") or 5 +local ws_lists = {} +local function get_ws_list(a,x) + ws_lists[a] = ws_lists[a] or {} + local v = ws_lists[a][x] + if v then + return v + end + v = {} + for x=x,x + (chunksize*16 - 1) do + local y = do_ws_func(ssize, a, x) + v[x] = y + end + ws_lists[a][x] = v + return v +end + + local function dif(z1, z2) if z1 < 0 and z2 < 0 then @@ -367,10 +397,12 @@ minetest.register_on_generated(function(minp, maxp, seed) local forest_possible = maxp.y > f_h_min and minp.y < f_h_max --local pmap_f_bottom = minetest.get_perlin_map(perlins.forest_bottom, map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z}) - local perlin_f_bottom, pmap_f_top + local perlin_f_bottom, pmap_f_top, strassx, strassz if forest_possible then perlin_f_bottom = minetest.get_perlin(11, 3, 0.8, tmp2) pmap_f_top = minetest.get_perlin_map(perlins.forest_top, map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z}) + strassx = get_ws_list(2, minp.x) + strassz = get_ws_list(2, minp.z) end local num2, tab2 @@ -449,8 +481,8 @@ minetest.register_on_generated(function(minp, maxp, seed) if not f_perlins[pstr] then f_perlins[pstr] = math.floor(f_h_min+(math.abs(perlin_f_bottom:get2d({x=p.x, y=p.z})+1))*f_yscale_bottom+0.5) end + f_top = math.floor(f_h_max - (pmap_f_top[count]+1)*f_yscale_top + 0.5) f_bottom = f_perlins[pstr]+math.random(0,f_bottom_scale-1) - f_top = math.floor(f_h_max-(pmap_f_top[count]+1)*f_yscale_top+0.5) is_forest = f_bottom < f_top f_h_dirt = f_bottom-pr:next(0,1) end @@ -510,6 +542,18 @@ minetest.register_on_generated(function(minp, maxp, seed) ) then data[p_addpos] = c.air end + elseif is_forest + and y == f_top then + local sel = math.floor(strassx[x]+strassz[z]+0.5)%10 + if sel <= 5 then + data[p_addpos] = return_nether_ore(d_p_addp, true) + elseif sel == 6 then + data[p_addpos] = c.netherrack_black + elseif sel == 7 then + data[p_addpos] = c.glowstone + else + data[p_addpos] = c.air + end elseif y <= NETHER_BOTTOM then if y <= bottom then