Fix biomegen offset_y

This commit is contained in:
cora 2022-03-26 01:47:12 +01:00
parent 4bd2f3aa93
commit c451a0fc75
1 changed files with 12 additions and 10 deletions

View File

@ -84,6 +84,8 @@ local function calculate_noises(minp)
end
local function calc_biome_from_noise(heat, humid, pos)
--water_level = multi_map.get_absolute_centerpoint(multi_map.get_layer(p.y))
local offsety= multi_map.get_offset_y(pos.y,multi_map.get_layer(pos.y))
local biome_closest = nil
local biome_closest_blend = nil
local dist_min = 31000
@ -91,14 +93,15 @@ local function calc_biome_from_noise(heat, humid, pos)
for i, biome in pairs(biomes) do
local min_pos, max_pos = biome.min_pos, biome.max_pos
if pos.y >= min_pos.y and pos.y <= max_pos.y+biome.vertical_blend
--if offsety >= min_pos.y and
if offsety <= max_pos.y+biome.vertical_blend
and pos.x >= min_pos.x and pos.x <= max_pos.x
and pos.z >= min_pos.z and pos.z <= max_pos.z then
local d_heat = heat - biome.heat_point
local d_humid = humid - biome.humidity_point
local dist = d_heat*d_heat + d_humid*d_humid -- Pythagorean distance
if pos.y <= max_pos.y then -- Within y limits of biome
if offsety <= max_pos.y then -- Within y limits of biome
if dist < dist_min then
dist_min = dist
biome_closest = biome
@ -289,7 +292,9 @@ local liquid = setmetatable({}, {
end,
})
local function can_place_deco(deco, data, vi, pattern)
local function can_place_deco(deco, data, vi, pattern,y)
local offsety= multi_map.get_offset_y(y,multi_map.get_layer(y))
if offsety < deco.y_min or offsety > deco.y_max then return false end
if not deco.place_on[data[vi]] then
return false
elseif deco.num_spawn_by <= 0 then
@ -395,7 +400,7 @@ local function place_deco(deco, data, a, vm, minp, maxp, blockseed)
for _, y in ipairs(floors) do
if y >= biome.y_min and y <= biome.y_max then
local pos = {x=x, y=y, z=z}
if can_place_deco(deco, data, vi, pattern) then
if can_place_deco(deco, data, vi, pattern,y) then
deco:generate(vm, ps, pos, false)
end
end
@ -406,7 +411,7 @@ local function place_deco(deco, data, a, vm, minp, maxp, blockseed)
for _, y in ipairs(ceilings) do
if y >= biome.y_min and y <= biome.y_max then
local pos = {x=x, y=y, z=z}
if can_place_deco(deco, data, vi, pattern) then
if can_place_deco(deco, data, vi, pattern,y) then
deco:generate(vm, ps, pos, true)
end
end
@ -449,7 +454,7 @@ local function place_deco(deco, data, a, vm, minp, maxp, blockseed)
if biome_ok then
local pos = {x=x, y=y, z=z}
if can_place_deco(deco, data, a:index(x,y,z), pattern) then
if can_place_deco(deco, data, a:index(x,y,z), pattern,y) then
deco:generate(vm, ps, pos, false)
end
end
@ -497,9 +502,6 @@ local dustable = setmetatable({}, {
local function dust_top_nodes(data, a, vm, minp, maxp)
water_level = multi_map.get_absolute_centerpoint()
if maxp.y < water_level then
return
end
local full_maxp = a.MaxEdge
@ -559,7 +561,7 @@ biomegen = {
}
function biomegen.generate_all(data, a, vm, minp, maxp, seed)
water_level = multi_map.get_absolute_centerpoint()
water_level = multi_map.get_absolute_centerpoint(multi_map.get_layer(minp.y))
generate_biomes(data, a, minp, maxp)
vm:set_data(data)
place_all_decos(data, a, vm, minp, maxp, seed)