add place-schematic variant that aborts if the schematic doesn't fit
This commit is contained in:
parent
32f48430f2
commit
970defba65
@ -38,4 +38,17 @@ end
|
||||
mapgen_helper.intersect_exists_xz = function(minpos1, maxpos1, minpos2, maxpos2)
|
||||
return (minpos1.x <= maxpos2.x and maxpos1.x >= minpos2.x and
|
||||
minpos1.z <= maxpos2.z and maxpos1.z >= minpos2.z)
|
||||
end
|
||||
|
||||
-- Simply tests whether pos is within the bounding box defined by minpos and maxpos
|
||||
local intersect_exists = mapgen_helper.intersect_exists
|
||||
mapgen_helper.is_pos_within_box = function(pos, minpos, maxpos)
|
||||
return intersect_exists(pos, pos, minpos, maxpos)
|
||||
end
|
||||
|
||||
-- Tests whether box 1 is entirely contained within box 2
|
||||
mapgen_helper.is_box_within_box = function(minpos1, maxpos1, minpos2, maxpos2)
|
||||
return (minpos1.x >= minpos2.x and maxpos1.x <= maxpos2.x and
|
||||
minpos1.z >= minpos2.z and maxpos1.z <= maxpos2.z and
|
||||
minpos1.y >= minpos2.y and maxpos1.y <= maxpos2.y)
|
||||
end
|
@ -292,6 +292,16 @@ mapgen_helper.place_schematic_on_data = function(data, data_param2, area, pos, s
|
||||
return contained_in_area
|
||||
end
|
||||
|
||||
-- aborts schematic placement if it won't fit into the provided data
|
||||
mapgen_helper.place_schematic_on_data_if_it_fits = function(data, data_param2, area, pos, schematic, rotation, replacements, force_placement, flags)
|
||||
local minbound, maxbound = mapgen_helper.get_schematic_bounding_box(pos, schematic, rotation, flags)
|
||||
if mapgen_helper.is_box_within_box(minbound, maxbound, area.MinEdge, area.MaxEdge) then
|
||||
return mapgen_helper.place_schematic_on_data(data, data_param2, area, pos, schematic, rotation, replacements, force_placement, flags)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
-- wraps the above for convenience, so you can use this style of schematic in non-mapgen contexts as well
|
||||
mapgen_helper.place_schematic = function(pos, schematic, rotation, replacements, force_placement, flags)
|
||||
local minpos, maxpos = mapgen_helper.get_schematic_bounding_box(pos, schematic, rotation, flags)
|
||||
|
Loading…
x
Reference in New Issue
Block a user