Overgeneration

This commit is contained in:
paramat 2014-05-01 09:43:29 +01:00
parent 4b84ba825d
commit 8d923ca0d6
2 changed files with 63 additions and 49 deletions

View File

@ -1,4 +1,4 @@
riverdev 0.1.3 by paramat riverdev 0.1.4 by paramat
For latest stable Minetest back to 0.4.8 For latest stable Minetest back to 0.4.8
Depends default Depends default
Licenses: code WTFPL Licenses: code WTFPL

View File

@ -1,13 +1,8 @@
-- riverdev 0.1.3 by paramat -- riverdev 0.1.4 by paramat
-- For latest stable Minetest and back to 0.4.8 -- For latest stable Minetest and back to 0.4.8
-- Depends default -- Depends default
-- License: code WTFPL -- License: code WTFPL
-- thin dirt with altitude
-- dirt and grass
-- fine detail back to 24n
-- Add mixwater
-- Parameters -- Parameters
local YMIN = -33000 local YMIN = -33000
@ -277,35 +272,25 @@ minetest.register_on_generated(function(minp, maxp, seed)
local c_mixwater = minetest.get_content_id("riverdev:mixwater") local c_mixwater = minetest.get_content_id("riverdev:mixwater")
local sidelen = x1 - x0 + 1 local sidelen = x1 - x0 + 1
local chulens = {x=sidelen, y=sidelen, z=sidelen} local chulens = {x=sidelen, y=sidelen+2, z=sidelen}
local minposxyz = {x=x0, y=y0, z=z0} local minposxyz = {x=x0, y=y0-1, z=z0}
local minposxz = {x=x0, y=z0} local minposxz = {x=x0, y=z0}
local nvals_terrain = minetest.get_perlin_map(np_terrain, chulens):get3dMap_flat(minposxyz) local nvals_terrain = minetest.get_perlin_map(np_terrain, chulens):get3dMap_flat(minposxyz)
local nvals_mid = minetest.get_perlin_map(np_mid, chulens):get2dMap_flat(minposxz) local nvals_mid = minetest.get_perlin_map(np_mid, chulens):get2dMap_flat(minposxz)
local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat(minposxz) local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat(minposxz)
local ungen = false
if minetest.get_node({x=x0, y=y0-1, z=z0}).name == "ignore" then
ungen = true
end
local nixyz = 1 local nixyz = 1
local nixz = 1 local nixz = 1
local stable = {} local stable = {}
local under = {} local under = {}
for z = z0, z1 do for z = z0, z1 do
for x = x0, x1 do for y = y0 - 1, y1 + 1 do
local si = x - x0 + 1
under[si] = 0
local nodename = minetest.get_node({x=x,y=y0-1,z=z}).name
if nodename == "air"
or nodename == "default:water_source"
or nodename == "riverdev:freshwater"
or nodename == "riverdev:freshwaterflow"
or nodename == "riverdev:mixwater"
or nodename == "riverdev:mixwaterflow" then
stable[si] = 0
else
stable[si] = 2
end
end
for y = y0, y1 do
local vi = area:index(x0, y, z) local vi = area:index(x0, y, z)
local viu = area:index(x0, y-1, z) local viu = area:index(x0, y-1, z)
for x = x0, x1 do for x = x0, x1 do
@ -326,6 +311,28 @@ minetest.register_on_generated(function(minp, maxp, seed)
local tstream = TSTREAM * (1 - n_absmid) local tstream = TSTREAM * (1 - n_absmid)
local tssand = TSSAND * (1 - n_absmid) local tssand = TSSAND * (1 - n_absmid)
if y == y0 - 1 then -- overgeneration, initialise tables
under[si] = 0
if ungen then
if density >= 0 then
stable[si] = 2
else
stable[si] = 0
end
else
local nodename = minetest.get_node({x=x,y=y0-1,z=z}).name
if nodename == "air"
or nodename == "default:water_source"
or nodename == "riverdev:freshwater"
or nodename == "riverdev:freshwaterflow"
or nodename == "riverdev:mixwater"
or nodename == "riverdev:mixwaterflow" then
stable[si] = 0
else
stable[si] = 2
end
end
elseif y >= y0 and y <= y1 then -- chunk generation
if density >= tstone then -- stone if density >= tstone then -- stone
data[vi] = c_stone data[vi] = c_stone
stable[si] = stable[si] + 1 stable[si] = stable[si] + 1
@ -366,6 +373,13 @@ minetest.register_on_generated(function(minp, maxp, seed)
stable[si] = 0 stable[si] = 0
under[si] = 0 under[si] = 0
end end
elseif y == y1 + 1 then -- overgeneration, detect surface, add surface nodes
if density < 0 and under[si] ~= 0 then
if under[si] == 1 then
data[viu] = c_grass
end
end
end
nixyz = nixyz + 1 nixyz = nixyz + 1
nixz = nixz + 1 nixz = nixz + 1