218 changes: 94 additions & 124 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
yappy = {}
yappy.mod_path = minetest.get_modpath("yappy")
yappy.settings_file = minetest.get_worldpath().."/yappy_settings.txt"
yappy.ores_table = {}
yappy.scale = 1
yappy.terrain_scale = 1
yappy.details = 0
Expand Down Expand Up @@ -37,7 +36,7 @@ yappy.np_trees = {
offset = 0,
scale = 1,
spread = {x=64, y=64, z=64},
octaves = 2,
octaves = 1,
seed = -5432,
persist = 0.6
}
Expand All @@ -62,18 +61,8 @@ yappy.np_temperature = {
}

dofile(yappy.mod_path.."/nodes.lua")

yappy.biomes = { -- 0 = default
--min temp, under (stone), middle (3), ground (1), top (1)
{45, yappy.c_desert_stone, yappy.c_desert_sand, yappy.c_desert_sand, 0},
{38, yappy.c_sandstone, yappy.c_sand, yappy.c_sand, 0},
{34, 0, yappy.c_sand, 0, 0},
{-5, 0, 0, 0, 0},
{-15, 0, 0, yappy.c_dirt_snow, 0},
{-20, 0, 0, yappy.c_snowblock, yappy.c_snow},
{-99, yappy.c_ice, yappy.c_snowblock, yappy.c_snowblock, yappy.c_snow},
}
dofile(yappy.mod_path.."/functions.lua")
dofile(yappy.mod_path.."/biomedef.lua")
dofile(yappy.mod_path.."/default_mapgen.lua")

local np_list = {"np_base", "np_mountains", "np_trees", "np_temperature"}
Expand Down Expand Up @@ -103,82 +92,104 @@ minetest.register_on_generated(function(minp, maxp, seed)
local t1 = os.clock()
local sidelen = maxp.x - minp.x + 1
local chulens = {x=sidelen, y=sidelen, z=sidelen}
local mid_chunk = minp.y + (sidelen / 2)

local terrain_scale = yappy.terrain_scale
local ores = yappy.ores
local trees = yappy.trees
local biomes = yappy.biomes
local decorations = yappy.decorations
local surface = {}
local mudflow_check = {}

local nvals_base, nvals_mountains, nvals_trees, nvals_temperature
local nvals_base, nvals_mountains, nvals_trees, nvals_temp
if is_surface then
nvals_base = minetest.get_perlin_map(yappy.np_base, chulens):get2dMap_flat({x=minp.x, y=minp.z})
nvals_mountains = minetest.get_perlin_map(yappy.np_mountains, chulens):get2dMap_flat({x=minp.x, y=minp.z})
nvals_trees = minetest.get_perlin_map(yappy.np_trees, chulens):get2dMap_flat({x=minp.x, y=minp.z})
nvals_temperature = minetest.get_perlin_map(yappy.np_temperature, chulens):get2dMap_flat({x=minp.x, y=minp.z})
nvals_temp = minetest.get_perlin_map(yappy.np_temperature, chulens):get2dMap_flat({x=minp.x, y=minp.z})
end

local nixz = 1
local surface = {}
local terrain_scale = yappy.terrain_scale
for i, v in ipairs(ores) do
if v.height_min <= maxp.y and v.height_max >= minp.y then
local chance = v.clust_scarcity
if chance >= 8*8 then
chance = v.clust_scarcity - ((v.height_max - mid_chunk) / 10)
chance = math.max(chance, v.clust_scarcity * 0.75)
end
v.current_chance = math.floor(chance)
end
end

local nixz = 1
if is_surface then
for z = minp.z, maxp.z do
for x = minp.x, maxp.x do
local surf = nvals_base[nixz] * 20 + 16
local mt_elev = nvals_mountains[nixz] - 0.2
local trees = nvals_trees[nixz] + 0.4
local temp = (nvals_temperature[nixz] + 0.3) * 38
local tree_chance = nvals_trees[nixz]
local temp = (nvals_temp[nixz] + 0.4) * 44
temp = math.floor((temp * 4) + 0.5) / 4
local r_temp, tree = temp, 0

if mt_elev > 0 then
surf = surf + (mt_elev * 75)
end

if trees > 0.85 then
trees = 0.85
end

if trees > 0.6 then
trees = yappy.tree_chance - (yappy.tree_chance * trees)
else
trees = yappy.tree_max_chance
end

if surf < 0 then
surf = surf * 2.5
end

surf = math.floor((surf * terrain_scale) + 0.5)
trees = math.floor(trees + 0.5)
temp = math.floor((temp * 4) + 0.5) / 4
temp = temp + math.random(-3, 3)
local c_stone, c_middle, c_cover, c_top

local c_stone = yappy.c_stone
local c_under = yappy.c_dirt
local c_above = yappy.c_grass
local c_top = 0
local noise = math.random(-3, 3)
for i, v in ipairs(biomes) do
if temp > v.temperature_min then
c_stone = v.stone
c_middle = v.middle
c_cover = v.cover
c_top = v.top
break
end
end

for _,v in ipairs(yappy.biomes) do
if temp + noise > v[1] then
if v[2] ~= 0 then
c_stone = v[2]
end
if v[3] ~= 0 then
c_under = v[3]
end
if v[4] ~= 0 then
c_above = v[4]
end
if v[5] ~= 0 then
c_top = v[5]
if c_top == 0 then
for i, v in ipairs(decorations) do
if temp >= v.temperature_min and
temp <= v.temperature_max and
(v.chance <= 1 or math.random(v.chance) == 1) then

if yappy.is_valid_ground(v.node_under, c_cover) then
c_top = v.name
break
end
end
break
end
end

local rand = math.random(5*5)
if temp > 33 and temp < 36 and rand == 2 then
c_top = yappy.c_jgrass
elseif temp > 0 and temp < 35 and rand == 3 then
c_top = yappy["grass_"..math.random(5)]
local tree_factor = 1
if tree_chance > 0.4 then
tree_factor = 0.5
elseif tree_chance < -0.4 then
tree_factor = 1.6
end

for i, v in ipairs(trees) do
if temp >= v.temperature_min and
temp <= v.temperature_max and
math.random(math.ceil(v.chance * tree_factor)) == 1 then

if yappy.is_valid_ground(v.node_under, c_cover) then
tree = i + 1
c_top = 0
break
end
end
end

surface[nixz] = {surf, trees, temp,
c_stone, c_under, c_above, c_top}
surface[nixz] = {surf, tree, r_temp,
c_stone, c_middle, c_cover, c_top}
nixz = nixz + 1
end
end
Expand All @@ -191,37 +202,24 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nvals_caves = minetest.get_perlin_map(yappy.np_caves, chulens):get3dMap_flat(minp)

local nixyz = 1
local mid_chunk = minp.y + (sidelen / 2)
local ores_table = yappy.ores_table
local mudflow_check = {}

for i, v in ipairs(ores_table) do
if v.height_min <= maxp.y and v.height_max >= minp.y then
local chance = v.clust_scarcity
if chance >= 8*8 then
chance = v.clust_scarcity - ((v.height_max - mid_chunk) / 10)
chance = math.max(chance, v.clust_scarcity * 0.75)
end
v.current_chance = math.floor(chance)
end
end

for z = minp.z, maxp.z do
for y = minp.y, maxp.y do
local vi = area:index(minp.x, y, z)
for x = minp.x, maxp.x do
local surf, trees, temp = 0, 0, 0
local surf, tree, temp = 0, 0, 0
local c_stone = yappy.c_stone
local c_under, c_above, c_top = 0, 0, 0
local c_middle, c_cover, c_top = 0, 0, 0

if is_surface then
local cache = surface[nixz]
surf = cache[1]
trees = cache[2]
tree = cache[2]
temp = cache[3]

c_stone = cache[4]
c_under = cache[5]
c_above = cache[6]
c_middle = cache[5]
c_cover = cache[6]
c_top = cache[7]
end
local cave = nvals_caves[nixyz]
Expand All @@ -235,63 +233,35 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
elseif y == surf and y < 0 then
-- Sea ground
data[vi] = c_under
data[vi] = c_middle
elseif y == surf then
local placed = false
if trees > 2 and math.random(trees) == 2 then
if temp > 39 then
if trees % 2 == 0 then
for i = 1, math.random(4, 6) do
data[area:index(x, y + i, z)] = yappy.c_cactus
end
data[vi] = yappy.c_desert_sand
placed = true
end
elseif x + 4 < maxp.x and
x - 4 > minp.x and
y + 10 < maxp.y and
z + 4 < maxp.z and
z - 4 > minp.z then
local tree_pos = vector.new(x, y + 1, z)
if temp > 32 then
default.grow_jungletree(data, area, tree_pos, trees)
data[vi] = yappy.c_dirt
placed = true
elseif temp > 0 then
local rand = math.random(20)
if rand > 2 then
default.grow_tree(data, area, tree_pos, rand % 3 == 0, trees)
else
yappy.gen_oak_tree(x, y, z, area, data)
end
data[vi] = yappy.c_dirt
placed = true
elseif temp > -20 then
yappy.gen_pine_tree(x, y, z, area, data)
data[vi] = yappy.c_dirt
placed = true
end
end
end
if not placed then
data[vi] = c_above
if tree > 0 and
x + 4 < maxp.x and
x - 4 > minp.x and
y + 10 < maxp.y and
z + 4 < maxp.z and
z - 4 > minp.z then
trees[tree - 1].action(vector.new(x, y + 1, z), data, area, seed)
data[vi] = c_middle
else
data[vi] = c_cover
end
elseif y == surf + 1 and y > 0 and c_top ~= 0 then
if data[vi] == yappy.c_air then
if data[area:index(x, y - 1, z)] == c_above then
if data[area:index(x, y - 1, z)] == c_cover then
data[vi] = c_top
end
end
elseif y - surf >= -3 and y < surf then
data[vi] = c_under
data[vi] = c_middle
elseif y > surf and y <= 0 then
-- Water
if temp + math.random(-2, 2) < -18 then
data[vi] = yappy.c_ice
elseif temp < 43 then
data[vi] = yappy.c_water
elseif temp >= 43 and temp <= 44 then
data[vi] = c_under
data[vi] = c_middle
end
elseif y < surf then
data[vi] = c_stone
Expand All @@ -300,7 +270,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
if y <= surf then
local node = data[vi]
local stones = yappy.stones
for i, v in ipairs(ores_table) do
for i, v in ipairs(ores) do
if v.height_min <= y and v.height_max >= y then
local valid = (math.random(v.current_chance) == 1)
if valid then
Expand Down Expand Up @@ -347,7 +317,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
local cache = surface[nixz]
local r_surf = cache[1]
local surf = r_surf + height
local c_stone, c_under, c_above = cache[4], cache[5], cache[6]
local c_stone, c_middle, c_cover = cache[4], cache[5], cache[6]

-- out of range
if r_surf - 16 > maxp.y then
Expand Down Expand Up @@ -388,12 +358,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
if ground ~= 6.66 and ground ~= surf then
vi = area:index(x, ground, z)
if ground >= 0 and not covered then
data[vi] = c_above
data[vi] = c_cover
else
data[vi] = c_under
data[vi] = c_middle
end
vi = area:index(x, ground - 1, z)
data[vi] = c_under
data[vi] = c_middle
end
end
nixz = nixz + 1
Expand Down
33 changes: 3 additions & 30 deletions nodes.lua
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
yappy.c_air = minetest.get_content_id("air")
yappy.c_grass = minetest.get_content_id("default:dirt_with_grass")
yappy.c_dirt = minetest.get_content_id("default:dirt")
yappy.c_gravel = minetest.get_content_id("default:gravel")
yappy.c_stone = minetest.get_content_id("default:stone")
yappy.c_water = minetest.get_content_id("default:water_source")
yappy.c_lava = minetest.get_content_id("default:lava_source")
yappy.c_clay = minetest.get_content_id("default:clay")
yappy.c_jgrass = minetest.get_content_id("default:junglegrass")

yappy.c_sdiamond = minetest.get_content_id("default:stone_with_diamond")
yappy.c_smese = minetest.get_content_id("default:stone_with_mese")
yappy.c_sgold = minetest.get_content_id("default:stone_with_gold")
yappy.c_scopper = minetest.get_content_id("default:stone_with_copper")
yappy.c_siron = minetest.get_content_id("default:stone_with_iron")
yappy.c_scoal = minetest.get_content_id("default:stone_with_coal")

yappy.c_snow = minetest.get_content_id("default:snow")
yappy.c_snowblock = minetest.get_content_id("default:snowblock")
yappy.c_ice = minetest.get_content_id("default:ice")
yappy.c_dirt_snow = minetest.get_content_id("default:dirt_with_snow")

yappy.c_sand = minetest.get_content_id("default:sand")
yappy.c_sandstone = minetest.get_content_id("default:sandstone")

yappy.c_desert_sand = minetest.get_content_id("default:desert_sand")
yappy.c_desert_stone = minetest.get_content_id("default:desert_stone")
yappy.c_cactus = minetest.get_content_id("default:cactus")
yappy.c_dry_shrub = minetest.get_content_id("default:dry_shrub")

for i = 1, 6 do
yappy["grass_"..i] = minetest.get_content_id("default:grass_"..i)
end
yappy.c_stone = minetest.get_content_id("default:stone")
yappy.c_ice = minetest.get_content_id("default:ice")
yappy.c_cactus = minetest.get_content_id("default:cactus")

local trees = {
pine = {"Pine sapling", "skylands_pine_sapling.png", "Pine needles", "skylands_needles.png", "pine_needles", "pine_sapling", 3},
Expand Down