From 71881154e9cda78bf167b2120aa11777582d5648 Mon Sep 17 00:00:00 2001 From: kno10 Date: Mon, 9 Sep 2024 20:05:59 +0200 Subject: [PATCH] use vector.in_area instead of own code in mapgen (#4562) `between` and `in_cube` duplicate functionality already in minetest `vector`. Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4562 Reviewed-by: the-real-herowl Co-authored-by: kno10 Co-committed-by: kno10 --- mods/CORE/mcl_util/init.lua | 9 ++++++++ mods/MAPGEN/mcl_mapgen_core/init.lua | 33 +--------------------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 783f5031b..1f53feef7 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1108,3 +1108,12 @@ function mcl_util.to_bool(val) if not val then return false end return true 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 diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 09bf1d8f5..7f6413fb8 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -136,37 +136,6 @@ if string.len(mg_flags_str) > 0 then end 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 -- regards to MapBlocks. -- 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 elseif struct.static_pos then 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) end end