5 biomes, trees, grasses, flowers. tune params

This commit is contained in:
paramat 2014-02-19 01:16:19 +00:00
parent 6f8f13f4a7
commit e580ce7730
4 changed files with 325 additions and 116 deletions

View File

@ -1,4 +1,4 @@
watershed 0.1.1 by paramat watershed 0.2.0 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

126
functions.lua Normal file
View File

@ -0,0 +1,126 @@
function watershed_appletree(x, y, z, area, data)
local c_tree = minetest.get_content_id("default:tree")
local c_apple = minetest.get_content_id("default:apple")
local c_leaves = minetest.get_content_id("default:leaves")
for j = -2, 4 do
if j >= 1 then
for i = -2, 2 do
for k = -2, 2 do
local vil = area:index(x + i, y + j + 1, z + k)
if math.random(48) == 2 then
data[vil] = c_apple
elseif math.random(3) ~= 2 then
data[vil] = c_leaves
end
end
end
end
local vit = area:index(x, y + j, z)
data[vit] = c_tree
end
end
function watershed_pinetree(x, y, z, area, data)
local c_tree = minetest.get_content_id("default:tree")
local c_wsneedles = minetest.get_content_id("watershed:needles")
local c_snowblock = minetest.get_content_id("default:snowblock")
for j = -4, 13 do
if j == 3 or j == 6 or j == 9 or j == 12 then
for i = -2, 2 do
for k = -2, 2 do
if math.abs(i) == 2 or math.abs(k) == 2 then
if math.random(5) ~= 2 then
local vil = area:index(x + i, y + j, z + k)
data[vil] = c_wsneedles
local vila = area:index(x + i, y + j + 1, z + k)
data[vila] = c_snowblock
end
end
end
end
elseif j == 4 or j == 7 or j == 10 or j == 13 then
for i = -1, 1 do
for k = -1, 1 do
if not (i == 0 and j == 0) then
if math.random(7) ~= 2 then
local vil = area:index(x + i, y + j, z + k)
data[vil] = c_wsneedles
local vila = area:index(x + i, y + j + 1, z + k)
data[vila] = c_snowblock
end
end
end
end
end
local vit = area:index(x, y + j, z)
data[vit] = c_tree
end
local vil = area:index(x, y + 14, z)
local vila = area:index(x, y + 15, z)
local vilaa = area:index(x, y + 16, z)
data[vil] = c_wsneedles
data[vila] = c_wsneedles
data[vilaa] = c_snowblock
end
function watershed_jungletree(x, y, z, area, data)
local c_juntree = minetest.get_content_id("default:jungletree")
local c_wsjunleaf = minetest.get_content_id("watershed:jungleleaf")
for j = -5, 17 do
if j == 11 or j == 17 then
for i = -2, 2 do
for k = -2, 2 do
local vil = area:index(x + i, y + j + math.random(0, 1), z + k)
if math.random(5) ~= 2 then
data[vil] = c_wsjunleaf
end
end
end
end
local vit = area:index(x, y + j, z)
data[vit] = c_juntree
end
end
function watershed_grass(data, vi)
local c_grass1 = minetest.get_content_id("default:grass_1")
local c_grass2 = minetest.get_content_id("default:grass_2")
local c_grass3 = minetest.get_content_id("default:grass_3")
local c_grass4 = minetest.get_content_id("default:grass_4")
local c_grass5 = minetest.get_content_id("default:grass_5")
local rand = math.random(5)
if rand == 1 then
data[vi] = c_grass1
elseif rand == 2 then
data[vi] = c_grass2
elseif rand == 3 then
data[vi] = c_grass3
elseif rand == 4 then
data[vi] = c_grass4
else
data[vi] = c_grass5
end
end
function watershed_flower(data, vi)
local c_danwhi = minetest.get_content_id("flowers:dandelion_white")
local c_danyel = minetest.get_content_id("flowers:dandelion_yellow")
local c_rose = minetest.get_content_id("flowers:rose")
local c_tulip = minetest.get_content_id("flowers:tulip")
local c_geranium = minetest.get_content_id("flowers:geranium")
local c_viola = minetest.get_content_id("flowers:viola")
local rand = math.random(6)
if rand == 1 then
data[vi] = c_danwhi
elseif rand == 2 then
data[vi] = c_rose
elseif rand == 3 then
data[vi] = c_tulip
elseif rand == 4 then
data[vi] = c_danyel
elseif rand == 5 then
data[vi] = c_geranium
else
data[vi] = c_viola
end
end

205
init.lua
View File

@ -1,22 +1,34 @@
-- watershed 0.1.1 by paramat -- watershed 0.2.0 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
-- TODO
-- Faults and strata
-- Arctan gradient?
-- Parameters -- Parameters
local YMIN = 6000 local YMIN = 6000
local YMAX = 8000 local YMAX = 8000
local TERCEN = 7008 -- Terrain centre local TERCEN = 7008 -- Terrain centre
local YWAT = 7024 -- Sea level local YWAT = 7024 -- Sea level
local TERSCA = 512 -- Vertical terrain scale local TERSCA = 384 -- Vertical terrain scale
local BASAMP = 0.3 -- Base terrain amplitude
local CANAMP = 0.7 -- Canyon terrain amplitude
local CANEXP = 1.33 -- Canyon shape exponent
local TSTONE = 0.02 -- Density threshold for stone local TSTONE = 0.02 -- Density threshold for stone
local TDIRT = 0.01 -- Density threshold for dirt local TDIRT = 0.01 -- Density threshold for dirt
local BASAMP = 0.5 -- Base terrain amplitude local TRIV = -0.016 -- Maximum densitybase threshold for river water
local BASEXP = 0.8 -- Base terrain exponent local TSAND = -0.02 -- Maximum densitybase threshold for sand
local CANAMP = 0.5 -- Canyon terrain amplitude
local TRIV = -0.012 -- Maximum densitybase threshold for river water local PINCHA = 47
local TSAND = -0.015 -- Maximum densitybase threshold for sand local APTCHA = 47
local FLOCHA = 36
local FOGCHA = 9
local GRACHA = 5
local JUTCHA = 16
local JUGCHA = 9
-- 3D noise for rough terrain -- 3D noise for rough terrain
@ -26,7 +38,7 @@ local np_rough = {
spread = {x=512, y=512, z=512}, spread = {x=512, y=512, z=512},
seed = 593, seed = 593,
octaves = 6, octaves = 6,
persist = 0.6 persist = 0.63
} }
-- 3D noise for smooth terrain -- 3D noise for smooth terrain
@ -40,15 +52,15 @@ local np_smooth = {
persist = 0.4 persist = 0.4
} }
-- 2D noise for base terrain / riverbed height, terrain blend, river and river sand depth -- 2D noise for base terrain / riverbed height / mountain ranges, terrain blend, river and river sand depth
local np_base = { local np_base = {
offset = 0, offset = 0,
scale = 1, scale = 1,
spread = {x=4096, y=4096, z=4096}, spread = {x=4096, y=4096, z=4096},
seed = 8890, seed = 8890,
octaves = 3, octaves = 4,
persist = 0.5 persist = 0.4
} }
-- 2D noise for biomes -- 2D noise for biomes
@ -56,7 +68,7 @@ local np_base = {
local np_biome = { local np_biome = {
offset = 0, offset = 0,
scale = 1, scale = 1,
spread = {x=2048, y=2048, z=2048}, spread = {x=512, y=512, z=512},
seed = -677772, seed = -677772,
octaves = 3, octaves = 3,
persist = 0.5 persist = 0.5
@ -66,95 +78,8 @@ local np_biome = {
watershed = {} watershed = {}
-- Nodes dofile(minetest.get_modpath("watershed").."/nodes.lua")
dofile(minetest.get_modpath("watershed").."/functions.lua")
minetest.register_node("watershed:grass", {
description = "WS Grass",
tiles = {"default_grass.png", "default_dirt.png", "default_grass.png"},
is_ground_content = false,
groups = {crumbly=3,soil=1},
drop = "default:dirt",
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.25},
}),
})
minetest.register_node("watershed:redstone", {
description = "WS Red Stone",
tiles = {"default_desert_stone.png"},
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("watershed:stone", {
description = "WS Stone",
tiles = {"default_stone.png"},
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("watershed:water", {
description = "WS Water Source",
inventory_image = minetest.inventorycube("default_water.png"),
drawtype = "liquid",
tiles = {
{name="default_water_source_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}}
},
alpha = WATER_ALPHA,
paramtype = "light",
is_ground_content = false,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
drowning = 1,
liquidtype = "source",
liquid_alternative_flowing = "watershed:waterflow",
liquid_alternative_source = "watershed:water",
liquid_viscosity = WATER_VISC,
liquid_renewable = false,
liquid_range = 3,
post_effect_color = {a=64, r=100, g=100, b=200},
groups = {water=3, liquid=3, puts_out_fire=1},
})
minetest.register_node("watershed:waterflow", {
description = "WS Flowing Water",
inventory_image = minetest.inventorycube("default_water.png"),
drawtype = "flowingliquid",
tiles = {"default_water.png"},
special_tiles = {
{
image="default_water_flowing_animated.png",
backface_culling=false,
animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.8}
},
{
image="default_water_flowing_animated.png",
backface_culling=true,
animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.8}
},
},
alpha = WATER_ALPHA,
paramtype = "light",
paramtype2 = "flowingliquid",
is_ground_content = false,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
drowning = 1,
liquidtype = "flowing",
liquid_alternative_flowing = "watershed:waterflow",
liquid_alternative_source = "watershed:water",
liquid_viscosity = WATER_VISC,
liquid_renewable = false,
liquid_range = 3,
post_effect_color = {a=64, r=100, g=100, b=200},
groups = {water=3, liquid=3, puts_out_fire=1, not_in_creative_inventory=1},
})
-- On generated function -- On generated function
@ -183,6 +108,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
local c_desand = minetest.get_content_id("default:desert_sand") local c_desand = minetest.get_content_id("default:desert_sand")
local c_snowblock = minetest.get_content_id("default:snowblock") local c_snowblock = minetest.get_content_id("default:snowblock")
local c_dirt = minetest.get_content_id("default:dirt") local c_dirt = minetest.get_content_id("default:dirt")
local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
local c_jungrass = minetest.get_content_id("default:junglegrass")
local c_wswater = minetest.get_content_id("watershed:water") local c_wswater = minetest.get_content_id("watershed:water")
local c_wsstone = minetest.get_content_id("watershed:stone") local c_wsstone = minetest.get_content_id("watershed:stone")
@ -203,9 +130,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nixyz = 1 local nixyz = 1
local nixz = 1 local nixz = 1
local stable = {} local stable = {}
local under = {}
for z = z0, z1 do -- for each xy plane progressing northwards for z = z0, z1 do -- for each xy plane progressing northwards
for x = x0, x1 do for x = x0, x1 do
local si = x - x0 + 1 local si = x - x0 + 1
under[si] = 0
local nodename = minetest.get_node({x=x,y=y0-1,z=z}).name local nodename = minetest.get_node({x=x,y=y0-1,z=z}).name
if nodename == "air" if nodename == "air"
or nodename == "default:water_source" then or nodename == "default:water_source" then
@ -216,19 +145,19 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
for y = y0, y1 do -- for each x row progressing upwards for y = y0, y1 do -- for each x row progressing upwards
local vi = area:index(x0, y, z) local vi = area:index(x0, y, z)
local viu = area:index(x0, y-1, z)
for x = x0, x1 do -- for each node do for x = x0, x1 do -- for each node do
local si = x - x0 + 1 local si = x - x0 + 1
local grad = (TERCEN - y) / TERSCA local grad = (TERCEN - y) / TERSCA
local n_base = nvals_base[nixz] local n_base = nvals_base[nixz]
local terblen = math.max(1 - math.abs(n_base) ^ BASEXP, 0) local terblen = 1 - math.abs(n_base)
local densitybase = terblen * BASAMP local densitybase = terblen * BASAMP
+ grad + grad
local triv = TRIV * (1 - terblen) local triv = TRIV * (1 - terblen * 1.1) -- 1.1 river disappears before ridge top
local tsand = TSAND * (1 - terblen) local tsand = TSAND * (1 - terblen * 1.1)
local tstone = TSTONE -- by height not terblen local tstone = TSTONE * (1 + grad * 1.5)
local canexp = 1.2
local density = densitybase local density = densitybase
+ math.abs(nvals_rough[nixyz] * terblen + nvals_smooth[nixyz] * (1 - terblen)) ^ canexp * CANAMP + math.abs(nvals_rough[nixyz] * terblen + nvals_smooth[nixyz] * (1 - terblen)) ^ CANEXP * CANAMP
local n_biome = nvals_biome[nixz] local n_biome = nvals_biome[nixz]
if density >= tstone then -- stone if density >= tstone then -- stone
@ -239,32 +168,80 @@ minetest.register_on_generated(function(minp, maxp, seed)
end end
stable[si] = stable[si] + 1 stable[si] = stable[si] + 1
elseif density >= 0 and density < tstone and stable[si] >= 2 then -- fine materials elseif density >= 0 and density < tstone and stable[si] >= 2 then -- fine materials
if densitybase >= tsand or y <= YWAT + math.random(3) then if densitybase >= tsand or y <= YWAT + 1 + math.random(2) then
data[vi] = c_sand -- riverbed, seabed data[vi] = c_sand -- riverbed, seabed
else else
if n_biome > 0.5 then if n_biome > 0.7 then
data[vi] = c_desand data[vi] = c_desand
elseif density > TDIRT then under[si] = 5 -- desert
elseif n_biome > 0.2 then
data[vi] = c_dirt data[vi] = c_dirt
elseif n_biome < -0.5 then under[si] = 4 -- rainforest
data[vi] = c_snowblock elseif n_biome > -0.2 then
data[vi] = c_dirt
under[si] = 3 -- grassland
elseif n_biome > -0.7 then
data[vi] = c_dirt
under[si] = 2 -- forest
else else
data[vi] = c_wsgrass data[vi] = c_dirt
under[si] = 1 -- taiga
end end
end end
elseif y <= YWAT then -- sea level water elseif y <= YWAT then -- sea level water
data[vi] = c_water data[vi] = c_water
stable[si] = 0 stable[si] = 0
under[si] = 0
elseif densitybase >= triv then -- river water elseif densitybase >= triv then -- river water
data[vi] = c_wswater data[vi] = c_wswater
stable[si] = 0 stable[si] = 0
under[si] = 0
else -- possible above surface air node
if y >= YWAT and under[si] ~= 0 then
if under[si] == 1 then
if trees and math.random(PINCHA) == 2 then
watershed_pinetree(x, y, z, area, data)
else else
data[vi] = c_air data[viu] = c_dirtsnow
data[vi] = c_snowblock
end
elseif under[si] == 2 then -- surface node turned to grass
if trees and math.random(APTCHA) == 2 then
watershed_appletree(x, y, z, area, data)
elseif math.random(FLOCHA) == 2 then
data[viu] = c_wsgrass
watershed_flower(data, vi)
elseif math.random(FOGCHA) == 2 then
data[viu] = c_wsgrass
watershed_grass(data, vi)
end
elseif under[si] == 3 then
data[viu] = c_wsgrass
if math.random(GRACHA) == 2 then
if math.random(3) == 2 then
watershed_grass(data, vi)
else
data[vi] = c_jungrass
end
end
elseif under[si] == 4 then
if math.random(JUTCHA) == 2 then
watershed_jungletree(x, y, z, area, data)
else
data[viu] = c_wsgrass
if math.random(JUGCHA) == 2 then
data[vi] = c_jungrass
end
end
end
end
stable[si] = 0 stable[si] = 0
under[si] = 0
end end
nixyz = nixyz + 1 -- increment 3D noise index nixyz = nixyz + 1 -- increment 3D noise index
nixz = nixz + 1 -- increment 2D noise index nixz = nixz + 1 -- increment 2D noise index
vi = vi + 1 vi = vi + 1
viu = viu + 1
end end
nixz = nixz - 80 -- rewind 2D noise index by 80 nodes for next x row above nixz = nixz - 80 -- rewind 2D noise index by 80 nodes for next x row above
end end

106
nodes.lua Normal file
View File

@ -0,0 +1,106 @@
minetest.register_node("watershed:needles", {
description = "WS Pine Needles",
tiles = {"paragen_needles.png"},
is_ground_content = false,
groups = {snappy=3, leafdecay=3},
sounds = default.node_sound_leaves_defaults(),
})
minetest.register_node("watershed:jungleleaf", {
description = "WS Jungletree Leaves",
drawtype = "allfaces_optional",
visual_scale = 1.3,
tiles = {"default_jungleleaves.png"},
paramtype = "light",
is_ground_content = false,
groups = {snappy=3, leafdecay=4, flammable=2, leaves=1},
sounds = default.node_sound_leaves_defaults(),
})
minetest.register_node("watershed:grass", {
description = "WS Grass",
tiles = {"default_grass.png", "default_dirt.png", "default_grass.png"},
is_ground_content = false,
groups = {crumbly=3,soil=1},
drop = "default:dirt",
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.25},
}),
})
minetest.register_node("watershed:redstone", {
description = "WS Red Stone",
tiles = {"default_desert_stone.png"},
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("watershed:stone", {
description = "WS Stone",
tiles = {"default_stone.png"},
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("watershed:water", {
description = "WS Water Source",
inventory_image = minetest.inventorycube("default_water.png"),
drawtype = "liquid",
tiles = {
{name="default_water_source_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}}
},
alpha = WATER_ALPHA,
paramtype = "light",
is_ground_content = false,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
drowning = 1,
liquidtype = "source",
liquid_alternative_flowing = "watershed:waterflow",
liquid_alternative_source = "watershed:water",
liquid_viscosity = WATER_VISC,
liquid_renewable = false,
liquid_range = 3,
post_effect_color = {a=64, r=100, g=100, b=200},
groups = {water=3, liquid=3, puts_out_fire=1},
})
minetest.register_node("watershed:waterflow", {
description = "WS Flowing Water",
inventory_image = minetest.inventorycube("default_water.png"),
drawtype = "flowingliquid",
tiles = {"default_water.png"},
special_tiles = {
{
image="default_water_flowing_animated.png",
backface_culling=false,
animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.8}
},
{
image="default_water_flowing_animated.png",
backface_culling=true,
animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.8}
},
},
alpha = WATER_ALPHA,
paramtype = "light",
paramtype2 = "flowingliquid",
is_ground_content = false,
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
drowning = 1,
liquidtype = "flowing",
liquid_alternative_flowing = "watershed:waterflow",
liquid_alternative_source = "watershed:water",
liquid_viscosity = WATER_VISC,
liquid_renewable = false,
liquid_range = 3,
post_effect_color = {a=64, r=100, g=100, b=200},
groups = {water=3, liquid=3, puts_out_fire=1, not_in_creative_inventory=1},
})