Polyfill vector.in_area and use it instead of custom in_cube

This commit is contained in:
Elias Åström 2024-09-14 20:41:01 +02:00 committed by ryvnf
parent 127de8e4d6
commit a788f485ed
3 changed files with 11 additions and 15 deletions

View File

@ -197,12 +197,12 @@ globals = {
"mcl_armor_trims",
"mcl_villages",
"AreaStore",
"vector",
}
read_globals = {
"DIR_DELIM",
"dump", "dump2",
"vector",
"VoxelManip", "VoxelArea",
"PseudoRandom", "PcgRandom", "PerlinNoise", "PerlinNoiseMap",
"ItemStack",

View File

@ -1423,3 +1423,11 @@ if not minetest.objects_inside_radius then --polyfill for pre minetest 5.9
return valid_object_iterator(core.get_objects_in_area(min_pos, max_pos))
end
end
if not vector.in_area then
function vector.in_area(pos, min, max)
return (pos.x >= min.x) and (pos.x <= max.x) and
(pos.y >= min.y) and (pos.y <= max.y) and
(pos.z >= min.z) and (pos.z <= max.z)
end
end

View File

@ -286,21 +286,9 @@ if mg_name ~= "singlenode" or end_fixes_in_singlenode then
end
-- This should be moved to mcl_structures eventually if the dependencies can be sorted out.
local function between(x, y, z) -- x is between y and z (inclusive)
return y <= x and x <= z
end
local function in_cube(tpos, wpos1, wpos2)
local xmax = math.max(wpos1.x, wpos2.x)
local xmin = math.min(wpos1.x, wpos2.x)
local ymax = math.max(wpos1.y, wpos2.y)
local ymin = math.min(wpos1.y, wpos2.y)
local zmax = math.max(wpos1.z, wpos2.z)
local zmin = math.min(wpos1.z, wpos2.z)
return between(tpos.x, xmin, xmax) and between(tpos.y, ymin, ymax) and between(tpos.z, zmin, zmax)
local minp, maxp = vector.sort(wpos1, wpos2)
return vector.in_area(tpos, minp, maxp)
end
mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blockseed)