2015-06-19 21:21:36 +02:00
|
|
|
-- https://github.com/paramat/meru/blob/master/init.lua#L52
|
|
|
|
-- Parameters must match mgv6 biome noise
|
2015-11-21 21:54:25 +01:00
|
|
|
|
2015-06-19 21:21:36 +02:00
|
|
|
local np_default = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=250, y=250, z=250},
|
|
|
|
seed = 9130,
|
|
|
|
octaves = 3,
|
|
|
|
persist = 0.5
|
|
|
|
}
|
|
|
|
|
2015-11-21 21:54:25 +01:00
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
-- 2D noise for coldness
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2015-06-21 12:49:27 +02:00
|
|
|
local mg = snow.mapgen
|
|
|
|
local scale = mg.perlin_scale
|
2014-09-21 08:47:45 +02:00
|
|
|
local np_cold = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
2015-06-21 12:49:27 +02:00
|
|
|
spread = {x=scale, y=scale, z=scale},
|
2014-09-21 08:47:45 +02:00
|
|
|
seed = 112,
|
|
|
|
octaves = 3,
|
|
|
|
persist = 0.5
|
|
|
|
}
|
2013-08-09 02:37:05 +02:00
|
|
|
|
2015-11-21 21:54:25 +01:00
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
-- 2D noise for icetype
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
local np_ice = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=80, y=80, z=80},
|
|
|
|
seed = 322345,
|
|
|
|
octaves = 3,
|
|
|
|
persist = 0.5
|
|
|
|
}
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2015-11-21 21:54:25 +01:00
|
|
|
|
2015-06-05 14:57:54 +02:00
|
|
|
local function do_ws_func(a, x)
|
2016-04-24 18:46:22 +02:00
|
|
|
local n = math.pi * x / 16000
|
2015-06-05 14:57:54 +02:00
|
|
|
local y = 0
|
2016-04-24 18:46:22 +02:00
|
|
|
for k = 1,1000 do
|
2016-07-16 21:54:31 +02:00
|
|
|
y = y + math.sin(k^a * n)/(k^a)
|
2015-06-05 14:57:54 +02:00
|
|
|
end
|
2016-07-16 21:54:31 +02:00
|
|
|
return 1000*y/math.pi
|
2015-06-05 14:57:54 +02:00
|
|
|
end
|
|
|
|
|
2015-06-13 15:53:10 +02:00
|
|
|
|
2015-11-21 21:54:25 +01:00
|
|
|
-- caching functions
|
|
|
|
|
2016-04-25 18:47:52 +02:00
|
|
|
local ws_values = {}
|
|
|
|
local function get_ws_value(a, x)
|
|
|
|
local v = ws_values[a]
|
2015-11-21 21:54:25 +01:00
|
|
|
if v then
|
2016-04-25 18:47:52 +02:00
|
|
|
v = v[x]
|
|
|
|
if v then
|
|
|
|
return v
|
|
|
|
end
|
|
|
|
else
|
|
|
|
ws_values[a] = {}
|
2016-04-29 17:58:13 +02:00
|
|
|
-- weak table, see https://www.lua.org/pil/17.1.html
|
2016-04-29 18:05:04 +02:00
|
|
|
setmetatable(ws_values[a], {__mode = "kv"})
|
2015-11-21 21:54:25 +01:00
|
|
|
end
|
2016-04-25 18:47:52 +02:00
|
|
|
v = do_ws_func(a, x)
|
|
|
|
ws_values[a][x] = v
|
2015-11-21 21:54:25 +01:00
|
|
|
return v
|
|
|
|
end
|
|
|
|
|
2015-06-13 15:53:10 +02:00
|
|
|
local plantlike_ids = {}
|
2016-04-29 18:05:04 +02:00
|
|
|
setmetatable(plantlike_ids, {__mode = "kv"})
|
2015-06-13 15:53:10 +02:00
|
|
|
local function is_plantlike(id)
|
|
|
|
if plantlike_ids[id] ~= nil then
|
|
|
|
return plantlike_ids[id]
|
|
|
|
end
|
|
|
|
local node = minetest.registered_nodes[minetest.get_name_from_content_id(id)]
|
|
|
|
if not node then
|
|
|
|
plantlike_ids[id] = false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local drawtype = node.drawtype
|
|
|
|
if not drawtype
|
|
|
|
or drawtype ~= "plantlike" then
|
|
|
|
plantlike_ids[id] = false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
plantlike_ids[id] = true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-06-19 21:21:36 +02:00
|
|
|
local snowable_ids = {}
|
2016-04-29 18:05:04 +02:00
|
|
|
setmetatable(snowable_ids, {__mode = "kv"})
|
2015-06-19 21:21:36 +02:00
|
|
|
local function is_snowable(id)
|
|
|
|
if snowable_ids[id] ~= nil then
|
|
|
|
return snowable_ids[id]
|
|
|
|
end
|
|
|
|
local node = minetest.registered_nodes[minetest.get_name_from_content_id(id)]
|
|
|
|
if not node then
|
|
|
|
snowable_ids[id] = false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local drawtype = node.drawtype
|
|
|
|
if drawtype
|
|
|
|
and drawtype ~= "normal"
|
|
|
|
and drawtype ~= "allfaces_optional"
|
|
|
|
and drawtype ~= "glasslike" then
|
|
|
|
snowable_ids[id] = false
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
snowable_ids[id] = true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-11-21 21:54:25 +01:00
|
|
|
|
2015-11-22 01:21:21 +01:00
|
|
|
local c, replacements, mg_debug, biome_to_string
|
2015-06-13 15:58:57 +02:00
|
|
|
local function define_contents()
|
|
|
|
c = {
|
|
|
|
dirt_with_grass = minetest.get_content_id("default:dirt_with_grass"),
|
|
|
|
dirt = minetest.get_content_id("default:dirt"),
|
|
|
|
tree = minetest.get_content_id("default:tree"),
|
|
|
|
apple = minetest.get_content_id("default:apple"),
|
|
|
|
snow = minetest.get_content_id("default:snow"),
|
|
|
|
snow_block = minetest.get_content_id("default:snowblock"),
|
|
|
|
dirt_with_snow = minetest.get_content_id("default:dirt_with_snow"),
|
|
|
|
air = minetest.get_content_id("air"),
|
|
|
|
ignore = minetest.get_content_id("ignore"),
|
|
|
|
stone = minetest.get_content_id("default:stone"),
|
|
|
|
dry_shrub = minetest.get_content_id("default:dry_shrub"),
|
2015-06-17 19:29:43 +02:00
|
|
|
snow_shrub = minetest.get_content_id("snow:shrub_covered"),
|
2015-06-13 15:58:57 +02:00
|
|
|
leaves = minetest.get_content_id("default:leaves"),
|
|
|
|
jungleleaves = minetest.get_content_id("default:jungleleaves"),
|
|
|
|
junglegrass = minetest.get_content_id("default:junglegrass"),
|
|
|
|
ice = minetest.get_content_id("default:ice"),
|
|
|
|
water = minetest.get_content_id("default:water_source"),
|
|
|
|
papyrus = minetest.get_content_id("default:papyrus"),
|
|
|
|
sand = minetest.get_content_id("default:sand"),
|
2015-06-19 22:03:59 +02:00
|
|
|
desert_sand = minetest.get_content_id("default:desert_sand"),
|
2015-06-13 15:58:57 +02:00
|
|
|
}
|
2015-06-19 21:21:36 +02:00
|
|
|
replacements = snow.known_plants or {}
|
2015-11-22 01:21:21 +01:00
|
|
|
|
|
|
|
mg_debug = snow.debug
|
2015-06-13 15:58:57 +02:00
|
|
|
end
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2015-06-21 11:42:32 +02:00
|
|
|
local smooth = snow.smooth_biomes
|
2015-06-21 12:49:27 +02:00
|
|
|
local smooth_rarity_max = mg.smooth_rarity_max
|
|
|
|
local smooth_rarity_min = mg.smooth_rarity_min
|
|
|
|
local smooth_rarity_dif = mg.smooth_rarity_dif
|
|
|
|
local nosmooth_rarity = mg.nosmooth_rarity
|
2015-06-21 11:42:32 +02:00
|
|
|
|
2015-11-22 01:21:21 +01:00
|
|
|
snow.register_on_configuring(function(name, v)
|
|
|
|
if name == "debug" then
|
|
|
|
mg_debug = v
|
|
|
|
elseif name == "mapgen_rarity"
|
|
|
|
or name == "mapgen_size"
|
|
|
|
or name == "smooth_biomes" then
|
|
|
|
minetest.after(0, function()
|
|
|
|
smooth = snow.smooth_biomes
|
|
|
|
smooth_rarity_max = mg.smooth_rarity_max
|
|
|
|
smooth_rarity_min = mg.smooth_rarity_min
|
|
|
|
smooth_rarity_dif = mg.smooth_rarity_dif
|
|
|
|
nosmooth_rarity = mg.nosmooth_rarity
|
|
|
|
local scale = mg.perlin_scale
|
|
|
|
np_cold = {
|
|
|
|
offset = 0,
|
|
|
|
scale = 1,
|
|
|
|
spread = {x=scale, y=scale, z=scale},
|
|
|
|
seed = 112,
|
|
|
|
octaves = 3,
|
|
|
|
persist = 0.5
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-09-17 11:38:38 +02:00
|
|
|
local perlin_objs, perlins_chulen
|
|
|
|
local function get_perlins(sidelen)
|
|
|
|
if perlins_chulen == sidelen then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
perlins_chulen = sidelen
|
2016-09-17 12:03:23 +02:00
|
|
|
local chulens = {x=sidelen, y=sidelen}
|
2016-09-17 11:38:38 +02:00
|
|
|
perlin_objs = {
|
|
|
|
default = minetest.get_perlin_map(np_default, chulens),
|
|
|
|
cold = minetest.get_perlin_map(np_cold, chulens),
|
|
|
|
ice = minetest.get_perlin_map(np_ice, chulens),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-09-17 22:03:53 +02:00
|
|
|
local nbuf_default, nbuf_cold, nbuf_ice
|
2014-09-21 08:47:45 +02:00
|
|
|
minetest.register_on_generated(function(minp, maxp, seed)
|
|
|
|
local t1 = os.clock()
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
local x0 = minp.x
|
|
|
|
local z0 = minp.z
|
|
|
|
local x1 = maxp.x
|
|
|
|
local z1 = maxp.z
|
2015-05-29 12:11:17 +02:00
|
|
|
|
2015-06-13 15:58:57 +02:00
|
|
|
if not c then
|
|
|
|
define_contents()
|
|
|
|
end
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2016-07-16 21:54:31 +02:00
|
|
|
local vm, emin, emax = minetest.get_mapgen_object"voxelmanip"
|
|
|
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
2014-09-21 08:47:45 +02:00
|
|
|
local data = vm:get_data()
|
2015-06-17 19:29:43 +02:00
|
|
|
local param2s = vm:get_param2_data()
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2016-07-16 21:54:31 +02:00
|
|
|
local heightmap = minetest.get_mapgen_object"heightmap"
|
2015-07-11 19:47:21 +02:00
|
|
|
|
2015-06-05 14:57:54 +02:00
|
|
|
local snow_tab,num = {},1
|
2015-06-19 19:49:31 +02:00
|
|
|
local pines_tab,pnum = {},1
|
2015-06-05 14:57:54 +02:00
|
|
|
|
2016-09-17 11:38:38 +02:00
|
|
|
get_perlins(x1 - x0 + 1)
|
2016-09-17 22:03:53 +02:00
|
|
|
local nvals_default = perlin_objs.default:get2dMap_flat({x=x0+150, y=z0+50}, nbuf_default)
|
2016-09-14 19:46:44 +02:00
|
|
|
local nvals_cold, nvals_ice, ndia
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
-- Choose biomes
|
|
|
|
local pr = PseudoRandom(seed+57)
|
|
|
|
-- Land biomes
|
2015-05-30 22:06:23 +02:00
|
|
|
local biome = pr:next(1, 5)
|
2015-06-12 23:21:43 +02:00
|
|
|
local snowy = biome == 1 -- spawns snow
|
2014-09-21 08:47:45 +02:00
|
|
|
local alpine = biome == 3 -- rocky terrain
|
|
|
|
-- Misc biome settings
|
|
|
|
local icy = pr:next(1, 2) == 2 -- if enabled spawns ice in sand instead of snow blocks
|
|
|
|
local shrubs = pr:next(1,2) == 1 -- spawns dry shrubs in snow
|
|
|
|
local pines = pr:next(1,2) == 1 -- spawns pines
|
|
|
|
-- Reseed random
|
|
|
|
pr = PseudoRandom(seed+68)
|
2013-08-06 08:25:01 +02:00
|
|
|
|
2016-02-13 19:11:01 +01:00
|
|
|
local nodes_added
|
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
-- Loop through columns in chunk
|
2015-06-21 11:42:32 +02:00
|
|
|
local smooth = smooth and not snowy
|
2014-09-21 08:47:45 +02:00
|
|
|
local write_to_map = false
|
|
|
|
local ni = 1
|
|
|
|
for z = z0, z1 do
|
|
|
|
for x = x0, x1 do
|
2015-06-21 11:42:32 +02:00
|
|
|
local in_biome = false
|
|
|
|
local test
|
|
|
|
if nvals_default[ni] < 0.35 then
|
2016-09-17 22:03:53 +02:00
|
|
|
nvals_cold = nvals_cold or perlin_objs.cold:get2dMap_flat({x=x0, y=z0}, nbuf_cold)
|
2015-06-19 21:21:36 +02:00
|
|
|
test = math.min(nvals_cold[ni], 1)
|
2015-06-21 11:42:32 +02:00
|
|
|
if smooth then
|
|
|
|
if test >= smooth_rarity_max
|
|
|
|
or (
|
|
|
|
test > smooth_rarity_min
|
|
|
|
and pr:next(1, 1000) <= ((test-smooth_rarity_min)/smooth_rarity_dif)*1000
|
|
|
|
) then
|
2015-06-19 21:21:36 +02:00
|
|
|
in_biome = true
|
|
|
|
end
|
2015-06-21 11:42:32 +02:00
|
|
|
elseif test > nosmooth_rarity then
|
2015-06-12 23:21:43 +02:00
|
|
|
in_biome = true
|
|
|
|
end
|
2015-06-19 21:21:36 +02:00
|
|
|
end
|
2013-08-09 02:37:05 +02:00
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
if not in_biome then
|
2015-06-19 22:03:59 +02:00
|
|
|
if alpine
|
|
|
|
and test
|
2015-06-21 11:42:32 +02:00
|
|
|
and test > smooth_rarity_min then
|
2015-06-12 23:21:43 +02:00
|
|
|
-- remove trees near alpine
|
2015-07-11 19:47:21 +02:00
|
|
|
local ground_y
|
2016-07-16 21:54:31 +02:00
|
|
|
if data[area:index(x, maxp.y, z)] == c.air then
|
2016-09-14 16:53:01 +02:00
|
|
|
local ytop = math.min(heightmap[ni]+20, maxp.y)
|
|
|
|
local vi = area:index(x, ytop, z)
|
|
|
|
for y = ytop, math.max(minp.y, heightmap[ni]-5), -1 do
|
|
|
|
if data[vi] ~= c.air then
|
2016-07-16 21:54:31 +02:00
|
|
|
ground_y = y
|
|
|
|
break
|
|
|
|
end
|
2016-09-14 16:53:01 +02:00
|
|
|
vi = vi - area.ystride
|
2014-09-21 08:47:45 +02:00
|
|
|
end
|
|
|
|
end
|
2013-08-06 08:25:01 +02:00
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
if ground_y then
|
|
|
|
local vi = area:index(x, ground_y, z)
|
2016-09-14 16:53:01 +02:00
|
|
|
for _ = minp.y - 16, ground_y do
|
|
|
|
local id = data[vi]
|
|
|
|
if id == c.leaves
|
|
|
|
or id == c.jungleleaves
|
|
|
|
or id == c.tree
|
|
|
|
or id == c.apple then
|
|
|
|
data[vi] = c.air
|
|
|
|
nodes_added = true
|
|
|
|
else
|
|
|
|
break
|
2014-06-05 08:58:56 +02:00
|
|
|
end
|
2016-09-14 16:53:01 +02:00
|
|
|
vi = vi - area.ystride
|
2015-05-29 12:11:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-06-12 23:21:43 +02:00
|
|
|
else
|
2016-09-17 22:03:53 +02:00
|
|
|
if not nvals_ice then
|
|
|
|
nvals_ice = perlin_objs.ice:get2dMap_flat({x=x0, y=z0}, nbuf_ice)
|
|
|
|
|
|
|
|
nodes_added = true
|
|
|
|
write_to_map = true
|
|
|
|
end
|
2015-11-21 21:54:25 +01:00
|
|
|
local icetype = nvals_ice[ni]
|
2015-05-30 22:06:23 +02:00
|
|
|
local cool = icetype > 0 -- only spawns ice on edge of water
|
2014-09-21 08:47:45 +02:00
|
|
|
local icebergs = icetype > -0.2 and icetype <= 0
|
2015-05-30 22:06:23 +02:00
|
|
|
local icehole = icetype > -0.4 and icetype <= -0.2 -- icesheet with holes
|
2014-09-21 08:47:45 +02:00
|
|
|
local icesheet = icetype > -0.6 and icetype <= -0.4
|
|
|
|
local icecave = icetype <= -0.6
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2015-07-11 19:47:21 +02:00
|
|
|
|
2015-06-12 23:21:43 +02:00
|
|
|
local ground_y
|
2016-07-16 21:54:31 +02:00
|
|
|
-- avoid generating underground
|
|
|
|
if data[area:index(x, maxp.y, z)] == c.air then
|
|
|
|
-- search for non air node from 20 m above ground down to 5 m below ground (confined by minp and maxp)
|
2016-09-14 16:53:01 +02:00
|
|
|
local ytop = math.min(heightmap[ni]+20, maxp.y)
|
|
|
|
local vi = area:index(x, ytop, z)
|
|
|
|
for y = ytop, math.max(minp.y, heightmap[ni]-5), -1 do
|
|
|
|
if data[vi] ~= c.air then
|
2016-07-16 21:54:31 +02:00
|
|
|
ground_y = y
|
|
|
|
break
|
|
|
|
end
|
2016-09-14 16:53:01 +02:00
|
|
|
vi = vi - area.ystride
|
2014-09-21 08:47:45 +02:00
|
|
|
end
|
|
|
|
end
|
2015-05-29 12:11:17 +02:00
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
if ground_y then
|
|
|
|
local node = area:index(x, ground_y, z)
|
2015-06-12 23:21:43 +02:00
|
|
|
local c_ground = data[node]
|
2013-12-09 04:56:35 +01:00
|
|
|
|
2015-06-13 15:58:57 +02:00
|
|
|
if c_ground == c.dirt_with_grass then
|
2015-06-12 23:21:43 +02:00
|
|
|
if alpine
|
2015-06-21 11:42:32 +02:00
|
|
|
and test > nosmooth_rarity then
|
2015-06-13 15:53:10 +02:00
|
|
|
snow_tab[num] = {ground_y, z, x, test}
|
2015-06-05 14:57:54 +02:00
|
|
|
num = num+1
|
2015-06-12 23:21:43 +02:00
|
|
|
-- generate stone ground
|
2016-09-14 16:53:01 +02:00
|
|
|
local vi = area:index(x, ground_y, z)
|
|
|
|
for _ = math.max(-6, minp.y-6), ground_y do
|
2015-06-13 15:58:57 +02:00
|
|
|
if data[vi] == c.stone then
|
2014-09-21 08:47:45 +02:00
|
|
|
break
|
2013-12-09 04:56:35 +01:00
|
|
|
end
|
2015-06-13 15:58:57 +02:00
|
|
|
data[vi] = c.stone
|
2016-09-14 16:53:01 +02:00
|
|
|
vi = vi - area.ystride
|
2014-09-21 08:47:45 +02:00
|
|
|
end
|
2015-06-12 23:21:43 +02:00
|
|
|
elseif pines
|
|
|
|
and pr:next(1,36) == 1 then
|
2015-06-19 19:49:31 +02:00
|
|
|
pines_tab[pnum] = {x=x, y=ground_y+1, z=z}
|
|
|
|
pnum = pnum+1
|
2015-06-17 18:57:11 +02:00
|
|
|
elseif shrubs
|
|
|
|
and pr:next(1,928) == 1 then
|
|
|
|
data[node] = c.dirt_with_snow
|
|
|
|
data[area:index(x, ground_y+1, z)] = c.dry_shrub
|
2014-09-21 08:47:45 +02:00
|
|
|
else
|
2015-06-19 22:03:59 +02:00
|
|
|
if snowy
|
2015-06-21 11:42:32 +02:00
|
|
|
or test > smooth_rarity_max then
|
2015-06-19 22:03:59 +02:00
|
|
|
-- more, deeper snow
|
|
|
|
data[node] = c.snow_block
|
|
|
|
else
|
|
|
|
data[node] = c.dirt_with_snow
|
|
|
|
end
|
2015-06-13 15:53:10 +02:00
|
|
|
snow_tab[num] = {ground_y, z, x, test}
|
2015-06-05 14:57:54 +02:00
|
|
|
num = num+1
|
2014-09-21 08:47:45 +02:00
|
|
|
end
|
2015-06-13 15:58:57 +02:00
|
|
|
elseif c_ground == c.water then
|
2015-05-30 22:06:23 +02:00
|
|
|
if not icesheet
|
|
|
|
and not icecave
|
|
|
|
and not icehole then
|
2016-09-14 19:46:44 +02:00
|
|
|
local y = data[node - area.ystride]
|
|
|
|
local ice = y ~= c.water and y ~= c.ice
|
|
|
|
|
2015-05-30 22:06:23 +02:00
|
|
|
if not ice then
|
2016-09-14 19:46:44 +02:00
|
|
|
ndia = ndia or {
|
|
|
|
area.zstride - 1,
|
|
|
|
1,
|
|
|
|
-2*area.zstride - 2,
|
|
|
|
area.zstride,
|
|
|
|
1 - area.zstride,
|
|
|
|
0
|
|
|
|
}
|
|
|
|
local vi = node + 1
|
|
|
|
for n = 1,6 do
|
|
|
|
local i = data[vi]
|
2015-06-13 15:58:57 +02:00
|
|
|
if i ~= c.water
|
|
|
|
and i ~= c.ice
|
|
|
|
and i ~= c.air
|
|
|
|
and i ~= c.ignore then
|
2015-05-30 22:06:23 +02:00
|
|
|
ice = true
|
|
|
|
break
|
|
|
|
end
|
2016-09-14 19:46:44 +02:00
|
|
|
vi = vi + ndia[n]
|
|
|
|
end
|
|
|
|
|
|
|
|
if not ice
|
|
|
|
and (cool or icebergs)
|
|
|
|
and pr:next(1,4) == 1 then
|
|
|
|
|
|
|
|
local vi = node + 1
|
|
|
|
for i = 1,6 do
|
|
|
|
if data[vi] == c.ice then
|
|
|
|
ice = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
vi = vi + ndia[i]
|
|
|
|
end
|
2015-05-30 22:06:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if ice
|
2015-03-05 17:36:02 +01:00
|
|
|
or (icebergs and pr:next(1,6) == 1) then
|
2015-06-13 15:58:57 +02:00
|
|
|
data[node] = c.ice
|
2014-09-21 08:47:45 +02:00
|
|
|
end
|
|
|
|
else
|
2015-06-12 23:21:43 +02:00
|
|
|
if icesheet
|
2015-05-30 22:06:23 +02:00
|
|
|
or icecave
|
2015-06-12 23:21:43 +02:00
|
|
|
or (icehole and pr:next(1,10) > 1) then
|
2015-06-13 15:58:57 +02:00
|
|
|
data[node] = c.ice
|
2014-09-21 08:47:45 +02:00
|
|
|
end
|
|
|
|
if icecave then
|
2016-09-14 16:53:01 +02:00
|
|
|
local vi = area:index(x, ground_y-1, z)
|
|
|
|
for _ = math.max(minp.y-16, -33), ground_y-1 do
|
2015-06-13 15:58:57 +02:00
|
|
|
if data[vi] ~= c.water then
|
2014-09-21 08:47:45 +02:00
|
|
|
break
|
2013-08-06 08:25:01 +02:00
|
|
|
end
|
2015-06-13 15:58:57 +02:00
|
|
|
data[vi] = c.air
|
2016-09-14 16:53:01 +02:00
|
|
|
vi = vi - area.ystride
|
2013-08-09 02:37:05 +02:00
|
|
|
end
|
2013-08-06 08:25:01 +02:00
|
|
|
end
|
2015-06-12 23:21:43 +02:00
|
|
|
if icesheet then
|
|
|
|
-- put snow onto icesheets
|
2015-06-13 15:53:10 +02:00
|
|
|
snow_tab[num] = {ground_y, z, x, test}
|
2015-06-12 23:21:43 +02:00
|
|
|
num = num+1
|
|
|
|
end
|
2013-08-06 08:25:01 +02:00
|
|
|
end
|
2015-06-13 15:58:57 +02:00
|
|
|
elseif c_ground == c.sand then
|
2015-06-13 15:53:10 +02:00
|
|
|
if icy then
|
2015-06-13 15:58:57 +02:00
|
|
|
data[node] = c.ice
|
2015-06-13 15:53:10 +02:00
|
|
|
end
|
|
|
|
snow_tab[num] = {ground_y, z, x, test}
|
|
|
|
num = num+1
|
2015-06-13 15:58:57 +02:00
|
|
|
elseif c_ground == c.papyrus then
|
2015-06-13 15:53:10 +02:00
|
|
|
snow_tab[num] = {ground_y, z, x, test}
|
|
|
|
num = num+1
|
|
|
|
-- replace papyrus plants with snowblocks
|
2016-09-14 16:53:01 +02:00
|
|
|
local vi = area:index(x, ground_y, z)
|
2015-06-13 15:53:10 +02:00
|
|
|
for _ = 1,7 do
|
2016-09-14 16:53:01 +02:00
|
|
|
if data[vi] ~= c.papyrus then
|
2015-06-13 15:53:10 +02:00
|
|
|
break
|
|
|
|
end
|
2016-09-14 16:53:01 +02:00
|
|
|
data[vi] = c.snow_block
|
|
|
|
vi = vi - area.ystride
|
2015-06-13 15:53:10 +02:00
|
|
|
end
|
2015-06-19 21:21:36 +02:00
|
|
|
elseif alpine then
|
|
|
|
-- make stone pillars out of trees and other stuff
|
2016-09-14 16:53:01 +02:00
|
|
|
local vi = area:index(x, ground_y, z)
|
|
|
|
for _ = 0, ground_y - math.max(-6, minp.y-6) do
|
|
|
|
if data[vi] == c.stone then
|
2015-06-19 21:21:36 +02:00
|
|
|
break
|
|
|
|
end
|
2016-09-14 16:53:01 +02:00
|
|
|
data[vi] = c.stone
|
|
|
|
vi = vi - area.ystride
|
2015-06-19 21:21:36 +02:00
|
|
|
end
|
|
|
|
-- put snow onto it
|
|
|
|
snow_tab[num] = {ground_y, z, x, test}
|
|
|
|
num = num+1
|
2015-06-19 22:03:59 +02:00
|
|
|
elseif c_ground ~= c.desert_sand then
|
2015-06-19 21:21:36 +02:00
|
|
|
if is_snowable(c_ground) then
|
|
|
|
-- put snow onto it
|
|
|
|
snow_tab[num] = {ground_y, z, x, test}
|
|
|
|
num = num+1
|
|
|
|
end
|
2016-09-14 16:53:01 +02:00
|
|
|
local vi = area:index(x, ground_y, z)
|
|
|
|
for _ = 0, 12 do
|
2015-06-19 21:21:36 +02:00
|
|
|
local nd = data[vi]
|
|
|
|
local plantlike = is_plantlike(nd)
|
|
|
|
if replacements[nd] then
|
|
|
|
data[vi] = replacements[nd]
|
|
|
|
if plantlike then
|
|
|
|
param2s[vi] = pr:next(0,179)
|
|
|
|
end
|
|
|
|
elseif nd == c.dirt_with_grass then
|
|
|
|
data[vi] = c.dirt_with_snow
|
|
|
|
break
|
|
|
|
elseif plantlike then
|
2016-09-14 16:53:01 +02:00
|
|
|
local under = vi - area.ystride
|
2015-06-19 21:21:36 +02:00
|
|
|
if data[under] == c.dirt_with_grass then
|
|
|
|
-- replace other plants with shrubs
|
|
|
|
data[vi] = c.snow_shrub
|
|
|
|
param2s[vi] = pr:next(0,179)
|
|
|
|
data[under] = c.dirt_with_snow
|
|
|
|
break
|
|
|
|
end
|
|
|
|
elseif nd == c.stone then
|
|
|
|
break
|
|
|
|
end
|
2016-09-14 16:53:01 +02:00
|
|
|
vi = vi - area.ystride
|
2015-06-13 15:53:10 +02:00
|
|
|
end
|
2014-09-21 08:47:45 +02:00
|
|
|
end
|
2013-08-09 02:37:05 +02:00
|
|
|
end
|
2013-08-06 08:25:01 +02:00
|
|
|
end
|
2014-09-21 08:47:45 +02:00
|
|
|
ni = ni + 1
|
|
|
|
end
|
|
|
|
end
|
2013-08-09 02:37:05 +02:00
|
|
|
|
2016-02-13 19:11:01 +01:00
|
|
|
-- abort if mapgen doesn't change sth
|
|
|
|
if not nodes_added then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-06-05 14:57:54 +02:00
|
|
|
if num ~= 1 then
|
2016-09-14 16:53:01 +02:00
|
|
|
for i = 1, num-1 do
|
|
|
|
i = snow_tab[i]
|
2015-06-17 18:20:03 +02:00
|
|
|
-- set snow
|
|
|
|
data[area:index(i[3], i[1]+1, i[2])] = c.snow
|
2015-06-13 15:53:10 +02:00
|
|
|
end
|
2016-09-14 16:53:01 +02:00
|
|
|
for i = 1, num-1 do
|
|
|
|
i = snow_tab[i]
|
2015-06-13 15:53:10 +02:00
|
|
|
local y,z,x,test = unpack(i)
|
2015-06-21 11:42:32 +02:00
|
|
|
test = (test-nosmooth_rarity)/(1-nosmooth_rarity) -- /(1-0.53)
|
2015-06-05 15:26:56 +02:00
|
|
|
if test > 0 then
|
2015-06-12 23:21:43 +02:00
|
|
|
local maxh = math.floor(test*10)%10+1
|
2015-06-11 18:40:51 +02:00
|
|
|
if maxh ~= 1 then
|
2016-04-25 18:47:52 +02:00
|
|
|
local h = math.floor(get_ws_value(2, x) + get_ws_value(5, z)*5)%10+1
|
2015-06-05 15:26:56 +02:00
|
|
|
if h ~= 1 then
|
2015-06-13 15:53:10 +02:00
|
|
|
-- search for nearby snow
|
|
|
|
y = y+1
|
|
|
|
for i = -1,1,2 do
|
|
|
|
for _,cord in pairs({{x+i,z}, {x,z+i}}) do
|
|
|
|
local nd = data[area:index(cord[1], y, cord[2])]
|
2015-06-13 15:58:57 +02:00
|
|
|
if nd == c.air
|
2015-06-13 16:51:14 +02:00
|
|
|
or is_plantlike(nd) then
|
2015-06-13 15:53:10 +02:00
|
|
|
h = h/2
|
|
|
|
end
|
|
|
|
end
|
2015-06-05 15:26:56 +02:00
|
|
|
end
|
2015-06-13 15:53:10 +02:00
|
|
|
h = math.floor(h+0.5)
|
|
|
|
if h > 1 then
|
|
|
|
-- make snowdrifts walkable
|
|
|
|
if h == 10 then
|
|
|
|
h = 5
|
|
|
|
end
|
|
|
|
h = math.min(maxh, h)
|
|
|
|
local vi = area:index(x, y, z)
|
|
|
|
if h == 9 then
|
|
|
|
-- replace the snow with a snowblock because its a full node
|
2015-06-13 15:58:57 +02:00
|
|
|
data[vi] = c.snow_block
|
2015-06-13 15:53:10 +02:00
|
|
|
else
|
|
|
|
-- set a specific snow height
|
|
|
|
param2s[vi] = h*7
|
2015-06-12 23:21:43 +02:00
|
|
|
end
|
|
|
|
end
|
2015-06-05 14:57:54 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-19 19:49:31 +02:00
|
|
|
-- spawn pines
|
|
|
|
if pines
|
|
|
|
and pnum ~= 1 then
|
|
|
|
local spawn_pine = snow.voxelmanip_pine
|
2016-09-14 16:53:01 +02:00
|
|
|
for i = 1, pnum-1 do
|
|
|
|
spawn_pine(pines_tab[i], area, data)
|
2015-06-19 19:49:31 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-21 08:47:45 +02:00
|
|
|
vm:set_data(data)
|
2015-06-17 19:29:43 +02:00
|
|
|
vm:set_param2_data(param2s)
|
2014-09-21 08:47:45 +02:00
|
|
|
vm:set_lighting({day=0, night=0})
|
|
|
|
vm:calc_lighting()
|
|
|
|
vm:write_to_map()
|
2013-08-09 02:37:05 +02:00
|
|
|
|
2015-05-26 20:55:13 +02:00
|
|
|
if write_to_map
|
2015-11-22 01:21:21 +01:00
|
|
|
and mg_debug then -- print if any column of mapchunk was snow biome
|
2015-05-30 22:06:23 +02:00
|
|
|
local biome_string = biome_to_string(biome)
|
2014-09-21 08:47:45 +02:00
|
|
|
local chugent = math.ceil((os.clock() - t1) * 1000)
|
2015-05-30 22:06:23 +02:00
|
|
|
print("[snow] "..biome_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms")
|
2014-09-21 08:47:45 +02:00
|
|
|
end
|
2013-12-09 04:56:35 +01:00
|
|
|
end)
|
2015-11-22 01:21:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- Debugging function
|
|
|
|
|
|
|
|
local biome_strings = {
|
|
|
|
{"snowy", "plain", "alpine", "normal", "normal"},
|
|
|
|
{"cool", "icebergs", "icesheet", "icecave", "icehole"}
|
|
|
|
}
|
|
|
|
function biome_to_string(num,num2)
|
|
|
|
local biome = biome_strings[1][num] or "unknown "..num
|
|
|
|
return biome
|
|
|
|
end
|