2014-02-19 02:16:19 +01:00
|
|
|
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")
|
2014-03-31 06:16:20 +02:00
|
|
|
local c_wsappleaf = minetest.get_content_id("watershed:appleleaf")
|
2014-02-19 02:16:19 +01:00
|
|
|
for j = -2, 4 do
|
2014-04-15 09:03:32 +02:00
|
|
|
if j == 3 or j == 4 then
|
2014-02-19 02:16:19 +01:00
|
|
|
for i = -2, 2 do
|
|
|
|
for k = -2, 2 do
|
2014-04-15 09:03:32 +02:00
|
|
|
local vil = area:index(x + i, y + j, z + k)
|
|
|
|
if math.random(64) == 2 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vil] = c_apple
|
2014-03-31 06:16:20 +02:00
|
|
|
elseif math.random(5) ~= 2 then
|
|
|
|
data[vil] = c_wsappleaf
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-15 09:03:32 +02:00
|
|
|
elseif j == 2 then
|
2014-04-02 03:44:33 +02:00
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
2014-04-15 09:03:32 +02:00
|
|
|
if math.abs(i) + math.abs(k) == 2 then
|
|
|
|
local vit = area:index(x + i, y + j, z + k)
|
|
|
|
data[vit] = c_tree
|
2014-04-02 03:44:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-15 09:03:32 +02:00
|
|
|
else
|
|
|
|
local vit = area:index(x, y + j, z)
|
|
|
|
data[vit] = c_tree
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function watershed_pinetree(x, y, z, area, data)
|
2014-04-14 07:01:05 +02:00
|
|
|
local c_wspitree = minetest.get_content_id("watershed:pinetree")
|
2014-02-19 02:16:19 +01:00
|
|
|
local c_wsneedles = minetest.get_content_id("watershed:needles")
|
|
|
|
local c_snowblock = minetest.get_content_id("default:snowblock")
|
2014-03-30 08:34:18 +02:00
|
|
|
for j = -4, 14 do
|
2014-02-19 02:16:19 +01:00
|
|
|
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
|
2014-04-01 05:28:21 +02:00
|
|
|
if math.random(7) ~= 2 then
|
2014-02-19 02:16:19 +01:00
|
|
|
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
|
2014-03-30 08:34:18 +02:00
|
|
|
elseif j == 4 or j == 7 or j == 10 then
|
2014-02-19 02:16:19 +01:00
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
|
|
|
if not (i == 0 and j == 0) then
|
2014-04-01 05:28:21 +02:00
|
|
|
if math.random(11) ~= 2 then
|
2014-02-19 02:16:19 +01:00
|
|
|
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
|
2014-03-30 08:34:18 +02:00
|
|
|
elseif j == 13 then
|
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
|
|
|
if not (i == 0 and j == 0) then
|
2014-04-01 05:28:21 +02:00
|
|
|
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_wsneedles
|
|
|
|
local vilaa = area:index(x + i, y + j + 2, z + k)
|
|
|
|
data[vilaa] = c_snowblock
|
2014-03-30 08:34:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
local vit = area:index(x, y + j, z)
|
2014-04-14 07:01:05 +02:00
|
|
|
data[vit] = c_wspitree
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
2014-03-30 08:34:18 +02:00
|
|
|
local vil = area:index(x, y + 15, z)
|
|
|
|
local vila = area:index(x, y + 16, z)
|
|
|
|
local vilaa = area:index(x, y + 17, z)
|
2014-02-19 02:16:19 +01:00
|
|
|
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")
|
2014-03-24 03:38:56 +01:00
|
|
|
local c_vine = minetest.get_content_id("watershed:vine")
|
|
|
|
local top = math.random(17,23)
|
|
|
|
local branch = math.floor(top * 0.6)
|
|
|
|
for j = -5, top do
|
|
|
|
if j == top or j == top - 1 or j == branch + 1 or j == branch + 2 then
|
|
|
|
for i = -2, 2 do -- leaves
|
2014-02-19 02:16:19 +01:00
|
|
|
for k = -2, 2 do
|
2014-03-24 03:38:56 +01:00
|
|
|
local vi = area:index(x + i, y + j, z + k)
|
2014-02-19 02:16:19 +01:00
|
|
|
if math.random(5) ~= 2 then
|
2014-03-24 03:38:56 +01:00
|
|
|
data[vi] = c_wsjunleaf
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-11 06:57:49 +02:00
|
|
|
elseif j == top - 2 or j == branch then -- branches
|
2014-03-24 03:38:56 +01:00
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
|
|
|
if math.abs(i) + math.abs(k) == 2 then
|
|
|
|
local vi = area:index(x + i, y + j, z + k)
|
|
|
|
data[vi] = c_juntree
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if j >= 0 and j <= top - 3 then -- climbable nodes
|
2014-03-22 07:40:39 +01:00
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
|
|
|
if math.abs(i) + math.abs(k) == 1 then
|
2014-03-24 03:38:56 +01:00
|
|
|
local vi = area:index(x + i, y + j, z + k)
|
|
|
|
data[vi] = c_vine
|
2014-03-22 07:40:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
2014-04-11 06:57:49 +02:00
|
|
|
if j <= top - 3 then -- trunk
|
2014-03-24 03:38:56 +01:00
|
|
|
local vi = area:index(x, y + j, z)
|
|
|
|
data[vi] = c_juntree
|
|
|
|
end
|
2014-02-19 02:16:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-20 13:24:02 +01:00
|
|
|
function watershed_acaciatree(x, y, z, area, data)
|
2014-04-14 07:01:05 +02:00
|
|
|
local c_wsactree = minetest.get_content_id("watershed:acaciatree")
|
|
|
|
local c_wsacleaf = minetest.get_content_id("watershed:acacialeaf")
|
2014-03-31 06:16:20 +02:00
|
|
|
for j = -3, 6 do
|
|
|
|
if j == 6 then
|
2014-02-20 13:24:02 +01:00
|
|
|
for i = -4, 4 do
|
|
|
|
for k = -4, 4 do
|
|
|
|
if not (i == 0 or k == 0) then
|
2014-04-01 05:28:21 +02:00
|
|
|
if math.random(7) ~= 2 then
|
2014-02-20 13:24:02 +01:00
|
|
|
local vil = area:index(x + i, y + j, z + k)
|
2014-04-14 07:01:05 +02:00
|
|
|
data[vil] = c_wsacleaf
|
2014-02-20 13:24:02 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-03-31 06:16:20 +02:00
|
|
|
elseif j == 5 then
|
2014-02-20 13:24:02 +01:00
|
|
|
for i = -2, 2, 4 do
|
|
|
|
for k = -2, 2, 4 do
|
|
|
|
local vit = area:index(x + i, y + j, z + k)
|
2014-04-14 07:01:05 +02:00
|
|
|
data[vit] = c_wsactree
|
2014-02-20 13:24:02 +01:00
|
|
|
end
|
|
|
|
end
|
2014-03-31 06:16:20 +02:00
|
|
|
elseif j == 4 then
|
2014-02-20 13:24:02 +01:00
|
|
|
for i = -1, 1 do
|
|
|
|
for k = -1, 1 do
|
|
|
|
if math.abs(i) + math.abs(k) == 2 then
|
|
|
|
local vit = area:index(x + i, y + j, z + k)
|
2014-04-14 07:01:05 +02:00
|
|
|
data[vit] = c_wsactree
|
2014-02-20 08:18:40 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-02-20 13:24:02 +01:00
|
|
|
else
|
|
|
|
local vit = area:index(x, y + j, z)
|
2014-04-14 07:01:05 +02:00
|
|
|
data[vit] = c_wsactree
|
2014-02-20 08:18:40 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-22 07:40:39 +01:00
|
|
|
function watershed_flower(data, vi, noise)
|
2014-02-19 02:16:19 +01:00
|
|
|
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")
|
2014-03-22 07:40:39 +01:00
|
|
|
if noise > 0.8 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_danwhi
|
2014-03-22 07:40:39 +01:00
|
|
|
elseif noise > 0.4 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_rose
|
2014-03-22 07:40:39 +01:00
|
|
|
elseif noise > 0 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_tulip
|
2014-03-22 07:40:39 +01:00
|
|
|
elseif noise > -0.4 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_danyel
|
2014-03-22 07:40:39 +01:00
|
|
|
elseif noise > -0.8 then
|
2014-02-19 02:16:19 +01:00
|
|
|
data[vi] = c_geranium
|
|
|
|
else
|
|
|
|
data[vi] = c_viola
|
|
|
|
end
|
2014-02-20 08:18:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function watershed_cactus(x, y, z, area, data)
|
|
|
|
local c_wscactus = minetest.get_content_id("watershed:cactus")
|
|
|
|
for j = -2, 4 do
|
|
|
|
for i = -2, 2 do
|
|
|
|
if i == 0 or j == 2 or (j == 3 and math.abs(i) == 2) then
|
|
|
|
local vic = area:index(x + i, y + j, z)
|
|
|
|
data[vic] = c_wscactus
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function watershed_papyrus(x, y, z, area, data)
|
|
|
|
local c_papyrus = minetest.get_content_id("default:papyrus")
|
|
|
|
local ph = math.random(1, 4)
|
2014-04-13 11:03:51 +02:00
|
|
|
for j = 0, ph do
|
2014-02-20 08:18:40 +01:00
|
|
|
local vip = area:index(x, y + j, z)
|
|
|
|
data[vip] = c_papyrus
|
|
|
|
end
|
2014-03-30 08:34:18 +02:00
|
|
|
end
|
|
|
|
|
2014-04-09 07:06:10 +02:00
|
|
|
-- Singlenode option
|
2014-04-01 02:39:57 +02:00
|
|
|
|
2014-04-10 06:27:59 +02:00
|
|
|
local SINGLENODE = true
|
2014-04-01 02:39:57 +02:00
|
|
|
|
2014-04-10 06:27:59 +02:00
|
|
|
if SINGLENODE then
|
2014-04-01 11:12:30 +02:00
|
|
|
-- Set mapgen parameters
|
2014-04-01 02:39:57 +02:00
|
|
|
|
2014-04-01 11:12:30 +02:00
|
|
|
minetest.register_on_mapgen_init(function(mgparams)
|
2014-04-03 06:37:53 +02:00
|
|
|
minetest.set_mapgen_params({mgname="singlenode"})
|
2014-04-01 11:12:30 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- Spawn player
|
|
|
|
|
|
|
|
function spawnplayer(player)
|
|
|
|
local TERCEN = -160 -- Terrain 'centre', average seabed level
|
|
|
|
local TERSCA = 512 -- Vertical terrain scale
|
2014-04-04 03:34:26 +02:00
|
|
|
local ATANAMP = 1.2 -- Arctan function amplitude, smaller = more and larger floatlands above ridges
|
2014-04-01 11:12:30 +02:00
|
|
|
local XLSAMP = 0.2 -- Extra large scale height variation amplitude
|
|
|
|
local BASAMP = 0.4 -- Base terrain amplitude
|
|
|
|
local CANAMP = 0.4 -- Canyon terrain amplitude
|
|
|
|
local CANEXP = 1.33 -- Canyon shape exponent
|
|
|
|
local xsp
|
|
|
|
local ysp
|
|
|
|
local zsp
|
|
|
|
local np_rough = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=512, y=512, z=512},
|
|
|
|
seed = 593,
|
|
|
|
octaves = 6,
|
|
|
|
persist = 0.63
|
|
|
|
}
|
|
|
|
local np_smooth = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=512, y=512, z=512},
|
|
|
|
seed = 593,
|
|
|
|
octaves = 6,
|
2014-04-14 07:01:05 +02:00
|
|
|
persist = 0.4
|
2014-04-01 11:12:30 +02:00
|
|
|
}
|
|
|
|
local np_base = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=4096, y=4096, z=4096},
|
|
|
|
seed = 8890,
|
|
|
|
octaves = 4,
|
|
|
|
persist = 0.4
|
|
|
|
}
|
|
|
|
local np_xlscale = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=8192, y=8192, z=8192},
|
|
|
|
seed = -72,
|
|
|
|
octaves = 3,
|
|
|
|
persist = 0.4
|
|
|
|
}
|
2014-04-14 07:01:05 +02:00
|
|
|
for chunk = 1, 64 do
|
2014-04-02 03:44:33 +02:00
|
|
|
print ("[watershed] searching for spawn "..chunk)
|
2014-04-01 11:12:30 +02:00
|
|
|
local x0 = 80 * math.random(-24, 24) - 32
|
|
|
|
local z0 = 80 * math.random(-24, 24) - 32
|
|
|
|
local y0 = -32
|
|
|
|
local x1 = x0 + 79
|
|
|
|
local z1 = z0 + 79
|
|
|
|
local y1 = 47
|
2014-04-09 07:06:10 +02:00
|
|
|
|
2014-04-01 11:12:30 +02:00
|
|
|
local sidelen = 80
|
|
|
|
local chulens = {x=sidelen, y=sidelen, z=sidelen}
|
|
|
|
local minposxyz = {x=x0, y=y0, z=z0}
|
|
|
|
local minposxz = {x=x0, y=z0}
|
2014-04-09 07:06:10 +02:00
|
|
|
|
2014-04-01 11:12:30 +02:00
|
|
|
local nvals_rough = minetest.get_perlin_map(np_rough, chulens):get3dMap_flat(minposxyz)
|
|
|
|
local nvals_smooth = minetest.get_perlin_map(np_smooth, chulens):get3dMap_flat(minposxyz)
|
2014-04-09 07:06:10 +02:00
|
|
|
|
2014-04-01 11:12:30 +02:00
|
|
|
local nvals_base = minetest.get_perlin_map(np_base, chulens):get2dMap_flat(minposxz)
|
|
|
|
local nvals_xlscale = minetest.get_perlin_map(np_xlscale, chulens):get2dMap_flat(minposxz)
|
2014-04-09 07:06:10 +02:00
|
|
|
|
2014-04-01 11:12:30 +02:00
|
|
|
local nixz = 1
|
|
|
|
local nixyz = 1
|
|
|
|
for z = z0, z1 do
|
|
|
|
for y = y0, y1 do
|
|
|
|
for x = x0, x1 do
|
|
|
|
local n_base = nvals_base[nixz]
|
2014-04-14 07:01:05 +02:00
|
|
|
local grad = math.atan((TERCEN - y) / TERSCA) * ATANAMP
|
2014-04-01 11:12:30 +02:00
|
|
|
local densitybase = (1 - math.abs(n_base)) * BASAMP + nvals_xlscale[nixz] * XLSAMP + grad
|
2014-04-03 06:37:53 +02:00
|
|
|
local terblen = math.max(1 - math.abs(n_base), 0)
|
2014-04-14 07:01:05 +02:00
|
|
|
local density = densitybase
|
|
|
|
+ math.abs(nvals_rough[nixyz] * terblen + nvals_smooth[nixyz] * (1 - terblen)) ^ CANEXP * CANAMP
|
2014-04-01 11:12:30 +02:00
|
|
|
if y >= 1 and density > -0.01 and density < 0 then
|
2014-04-02 12:26:42 +02:00
|
|
|
ysp = y + 1
|
2014-04-01 11:12:30 +02:00
|
|
|
xsp = x
|
|
|
|
zsp = z
|
|
|
|
break
|
|
|
|
end
|
|
|
|
nixz = nixz + 1
|
|
|
|
nixyz = nixyz + 1
|
2014-04-01 02:39:57 +02:00
|
|
|
end
|
2014-04-01 11:12:30 +02:00
|
|
|
if ysp then
|
2014-04-01 02:39:57 +02:00
|
|
|
break
|
|
|
|
end
|
2014-04-01 11:12:30 +02:00
|
|
|
nixz = nixz - 80
|
2014-04-01 02:39:57 +02:00
|
|
|
end
|
|
|
|
if ysp then
|
|
|
|
break
|
|
|
|
end
|
2014-04-01 11:12:30 +02:00
|
|
|
nixz = nixz + 80
|
2014-04-01 02:39:57 +02:00
|
|
|
end
|
|
|
|
if ysp then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2014-04-01 11:12:30 +02:00
|
|
|
print ("[watershed] spawn player ("..xsp.." "..ysp.." "..zsp..")")
|
|
|
|
player:setpos({x=xsp, y=ysp, z=zsp})
|
2014-04-01 02:39:57 +02:00
|
|
|
end
|
|
|
|
|
2014-04-01 11:12:30 +02:00
|
|
|
minetest.register_on_newplayer(function(player)
|
|
|
|
spawnplayer(player)
|
|
|
|
end)
|
2014-04-01 02:39:57 +02:00
|
|
|
|
2014-04-01 11:12:30 +02:00
|
|
|
minetest.register_on_respawnplayer(function(player)
|
|
|
|
spawnplayer(player)
|
|
|
|
return true
|
|
|
|
end)
|
2014-04-10 06:27:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- ABM
|
|
|
|
|
2014-04-14 07:01:05 +02:00
|
|
|
-- update luxore light
|
|
|
|
|
2014-04-10 06:27:59 +02:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"watershed:luxoreoff"},
|
2014-04-14 07:01:05 +02:00
|
|
|
interval = 13,
|
2014-04-10 06:27:59 +02:00
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
minetest.place_node(pos, {name="watershed:luxoreon"})
|
|
|
|
end,
|
2014-04-15 09:03:32 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Lava water cooling
|
|
|
|
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"group:lava"},
|
|
|
|
neighbors = {"group:water"},
|
|
|
|
interval = 11,
|
|
|
|
chance = 64,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
minetest.add_node(pos, {name="default:obsidian"})
|
|
|
|
minetest.sound_play("default_cool_lava", {pos = pos, gain = 0.25})
|
|
|
|
end,
|
2014-04-10 06:27:59 +02:00
|
|
|
})
|