Fix bugs
parent
0a11882395
commit
817889ef46
2
API.md
2
API.md
|
@ -41,7 +41,7 @@ The shapes are defined as follows:
|
|||
|
||||
func = function(pos, n)
|
||||
return 2 * n
|
||||
end
|
||||
end,
|
||||
-- Function to edit the NoiseParams based on some operation.
|
||||
-- Keep in mind that this function will be run many, many times, so it is
|
||||
-- best to keep this function as trivial as possible.
|
||||
|
|
|
@ -8,8 +8,8 @@ end
|
|||
local function from_flat_to_3d(i, nx, ny)
|
||||
return {
|
||||
dx = (i - 1) % nx,
|
||||
dy = (i - 1) // nx % ny,
|
||||
dz = (i - 1) // nx // ny
|
||||
dy = math.floor((i - 1) / nx) % ny,
|
||||
dz = math.floor((i - 1) / (nx * ny))
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -22,9 +22,9 @@ local function iter_3d_area(minp, maxp, callback)
|
|||
for i = 1, nx * ny * nz do
|
||||
local dpos = from_flat_to_3d(i, nx, ny)
|
||||
local pos = {
|
||||
x = minp.x + dpos.x,
|
||||
y = minp.y + dpos.y,
|
||||
z = minp.z + dpos.z,
|
||||
x = minp.x + dpos.dx,
|
||||
y = minp.y + dpos.dy,
|
||||
z = minp.z + dpos.dz,
|
||||
}
|
||||
|
||||
callback(i, pos)
|
||||
|
@ -185,8 +185,8 @@ local function get_threshold_flat(minp, maxp)
|
|||
for _, n in pairs(noise) do
|
||||
local v = n.noise[i]
|
||||
|
||||
local dx = math.abs(x - n.def.connectivity)
|
||||
local dy = math.abs(y - n.def.verticality)
|
||||
local dx = math.abs(x - n.def.connectivity_point)
|
||||
local dy = math.abs(y - n.def.verticality_point)
|
||||
|
||||
local w = math.abs(shape_distance_weight(
|
||||
#noordstar_caves.registered_shapes, dx, dy
|
||||
|
@ -231,7 +231,7 @@ noordstar_caves.set_world_depth(world_depth)
|
|||
-- - Make sure that the output changes VERY SLOWLY over time
|
||||
-- - This function will be run a LOT so it is very performance sensitive
|
||||
noordstar_caves.cave_vastness = function(pos)
|
||||
return math.abs(pos.y) / world_depth
|
||||
return pos.y / world_depth
|
||||
end
|
||||
|
||||
-- Secretly, we're using an internal function that also adds a safe layer for
|
||||
|
@ -240,28 +240,54 @@ local function cave_vastness(pos)
|
|||
if world_depth + 20 < pos.y then
|
||||
return noordstar_caves.cave_vastness(pos)
|
||||
elseif world_depth + 5 < pos.y then
|
||||
return noordstar_caves.cave_vastness(pos) * math.abs(y - world_depth - 5) / 15
|
||||
return noordstar_caves.cave_vastness(pos) * math.abs(pos.y - world_depth - 5) / 15
|
||||
else
|
||||
return -1000
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
local tpd_yet = false
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, blockseed)
|
||||
if maxp.y < world_depth then
|
||||
return
|
||||
end
|
||||
|
||||
-- Get voxelmanip
|
||||
local vm = minetest.get_mapgen_object("voxelmanip")
|
||||
local data = vm:get_data()
|
||||
|
||||
-- Get threshold values
|
||||
local thresholds = get_threshold_flat(minp, maxp)
|
||||
local air = minetest.get_content_id("air")
|
||||
local air = minetest.get_content_id("mcl_core:glass")
|
||||
|
||||
local count = 0
|
||||
|
||||
iter_3d_area(minp, maxp, function(i, pos)
|
||||
if thresholds[i] >= cave_vastness(pos) then
|
||||
data[i] = air
|
||||
local nx = maxp.x - minp.x + 1 + 32
|
||||
local ny = maxp.y - minp.y + 1 + 32
|
||||
|
||||
local dx = pos.x - minp.x
|
||||
local dy = pos.y - minp.y
|
||||
local dz = pos.z - minp.z
|
||||
|
||||
|
||||
local vi = from_3d_to_flat(dx + 16, dy + 16, dz + 16, nx, ny)
|
||||
|
||||
if not data[vi] then
|
||||
error("Vi is not in data (len " .. #data .. "): " .. vi .. " for (dx, dy, dz) = (" .. dx .. ", " .. dy .. ", " .. dz .. ") with minp = (" .. minp.x .. ", " .. minp.y .. ", " .. minp.z .. ") and maxp = (" .. maxp.x .. ", " .. maxp.y .. ", " .. maxp.z .. ") and pos = (" .. pos.x .. ", " .. pos.y .. ", " .. pos.z .. ")")
|
||||
end
|
||||
|
||||
if thresholds[i] >= (1 - cave_vastness(pos)) then
|
||||
data[vi] = air
|
||||
|
||||
count = count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
-- Write all changes to the Minetest world
|
||||
vm:set_data(data)
|
||||
vm:write_to_map()
|
||||
|
||||
minetest.chat_send_all("Updated " .. count .. " squares")
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue