pos iter cleanup

This commit is contained in:
BuckarooBanzay 2022-11-08 08:27:19 +01:00
parent 4ca4785744
commit bc810a40f1

View File

@ -97,17 +97,20 @@ function building_lib.can_build(mapblock_pos, building_name, rotation)
return false, message or "size check '" .. building_def.placement .. "' failed" return false, message or "size check '" .. building_def.placement .. "' failed"
end end
for x=mapblock_pos.x, mapblock_pos.x+size.x-1 do local it = mapblock_lib.pos_iterator(mapblock_pos, vector.add(mapblock_pos, vector.subtract(size, 1)))
for z=mapblock_pos.z, mapblock_pos.z+size.z-1 do while true do
for y=mapblock_pos.y, mapblock_pos.y+size.y-1 do local offset_mapblock_pos = it()
local offset_mapblock_pos = {x=x, y=y, z=z} if not offset_mapblock_pos then
break
end
local is_free = check_free(offset_mapblock_pos) local is_free = check_free(offset_mapblock_pos)
if not is_free then if not is_free then
return false, "Space already occupied at " .. minetest.pos_to_string(offset_mapblock_pos) return false, "Space already occupied at " .. minetest.pos_to_string(offset_mapblock_pos)
end end
local success local success
if y == mapblock_pos.y then if offset_mapblock_pos.y == mapblock_pos.y then
-- check ground conditions -- check ground conditions
success, message = building_lib.check_conditions(offset_mapblock_pos, building_def.ground_conditions, building_def) success, message = building_lib.check_conditions(offset_mapblock_pos, building_def.ground_conditions, building_def)
if not success then if not success then
@ -120,8 +123,6 @@ function building_lib.can_build(mapblock_pos, building_name, rotation)
return false, message return false, message
end end
end end
end
end
-- all checks ok -- all checks ok
return true return true
@ -146,11 +147,7 @@ function building_lib.do_build(mapblock_pos, building_name, rotation, callback)
local size = placement.get_size(placement, mapblock_pos, building_def, rotation) local size = placement.get_size(placement, mapblock_pos, building_def, rotation)
-- write new data -- write new data
for x=mapblock_pos.x,mapblock_pos.x+size.x-1 do mapblock_lib.for_each(mapblock_pos, vector.add(mapblock_pos, vector.subtract(size, 1)), function(offset_mapblock_pos)
for y=mapblock_pos.y,mapblock_pos.y+size.y-1 do
for z=mapblock_pos.z,mapblock_pos.z+size.z-1 do
local offset_mapblock_pos = {x=x, y=y, z=z}
if vector.equals(offset_mapblock_pos, mapblock_pos) then if vector.equals(offset_mapblock_pos, mapblock_pos) then
-- origin -- origin
building_lib.store:merge(offset_mapblock_pos, { building_lib.store:merge(offset_mapblock_pos, {
@ -164,9 +161,7 @@ function building_lib.do_build(mapblock_pos, building_name, rotation, callback)
-- link to origin -- link to origin
building_lib.store:merge(offset_mapblock_pos, mapblock_lib.create_data_link(mapblock_pos)) building_lib.store:merge(offset_mapblock_pos, mapblock_lib.create_data_link(mapblock_pos))
end end
end end)
end
end
placement.place(placement, mapblock_pos, building_def, rotation, callback) placement.place(placement, mapblock_pos, building_def, rotation, callback)