forked from VoxeLibre/VoxeLibre
use vector.in_area instead of own code in mapgen (#4562)
`between` and `in_cube` duplicate functionality already in minetest `vector`. Reviewed-on: VoxeLibre/VoxeLibre#4562 Reviewed-by: the-real-herowl <the-real-herowl@noreply.git.minetest.land> Co-authored-by: kno10 <erich.schubert@gmail.com> Co-committed-by: kno10 <erich.schubert@gmail.com>
This commit is contained in:
parent
6c38823606
commit
71881154e9
|
@ -1108,3 +1108,12 @@ function mcl_util.to_bool(val)
|
||||||
if not val then return false end
|
if not val then return false end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not vector.in_area then
|
||||||
|
-- backport from minetest 5.8, can be removed when the minimum version is 5.8
|
||||||
|
vector.in_area = function(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
|
||||||
|
|
|
@ -136,37 +136,6 @@ if string.len(mg_flags_str) > 0 then
|
||||||
end
|
end
|
||||||
minetest.set_mapgen_setting("mg_flags", mg_flags_str, true)
|
minetest.set_mapgen_setting("mg_flags", mg_flags_str, true)
|
||||||
|
|
||||||
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=wpos2.x
|
|
||||||
local xmin=wpos1.x
|
|
||||||
|
|
||||||
local ymax=wpos2.y
|
|
||||||
local ymin=wpos1.y
|
|
||||||
|
|
||||||
local zmax=wpos2.z
|
|
||||||
local zmin=wpos1.z
|
|
||||||
if wpos1.x > wpos2.x then
|
|
||||||
xmax=wpos1.x
|
|
||||||
xmin=wpos2.x
|
|
||||||
end
|
|
||||||
if wpos1.y > wpos2.y then
|
|
||||||
ymax=wpos1.y
|
|
||||||
ymin=wpos2.y
|
|
||||||
end
|
|
||||||
if wpos1.z > wpos2.z then
|
|
||||||
zmax=wpos1.z
|
|
||||||
zmin=wpos2.z
|
|
||||||
end
|
|
||||||
if between(tpos.x,xmin,xmax) and between(tpos.y,ymin,ymax) and between(tpos.z,zmin,zmax) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Helper function for converting a MC probability to MT, with
|
-- Helper function for converting a MC probability to MT, with
|
||||||
-- regards to MapBlocks.
|
-- regards to MapBlocks.
|
||||||
-- Some MC generated structures are generated on per-chunk
|
-- Some MC generated structures are generated on per-chunk
|
||||||
|
@ -497,7 +466,7 @@ mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blocks
|
||||||
end
|
end
|
||||||
elseif struct.static_pos then
|
elseif struct.static_pos then
|
||||||
for _,p in pairs(struct.static_pos) do
|
for _,p in pairs(struct.static_pos) do
|
||||||
if in_cube(p,minp,maxp) then
|
if vector.in_area(p,minp,maxp) then
|
||||||
mcl_structures.place_structure(p,struct,pr,blockseed)
|
mcl_structures.place_structure(p,struct,pr,blockseed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue