pos iter cleanup

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

View File

@ -97,30 +97,31 @@ 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
local is_free = check_free(offset_mapblock_pos) break
if not is_free then end
return false, "Space already occupied at " .. minetest.pos_to_string(offset_mapblock_pos)
end
local success local is_free = check_free(offset_mapblock_pos)
if y == mapblock_pos.y then if not is_free then
-- check ground conditions return false, "Space already occupied at " .. minetest.pos_to_string(offset_mapblock_pos)
success, message = building_lib.check_conditions(offset_mapblock_pos, building_def.ground_conditions, building_def) end
if not success then
return false, message
end
end
success, message = building_lib.check_conditions(offset_mapblock_pos, building_def.conditions, building_def) local success
if not success then if offset_mapblock_pos.y == mapblock_pos.y then
return false, message -- check ground conditions
end success, message = building_lib.check_conditions(offset_mapblock_pos, building_def.ground_conditions, building_def)
if not success then
return false, message
end end
end end
success, message = building_lib.check_conditions(offset_mapblock_pos, building_def.conditions, building_def)
if not success then
return false, message
end
end end
-- all checks ok -- all checks ok
@ -146,27 +147,21 @@ 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 if vector.equals(offset_mapblock_pos, mapblock_pos) then
for z=mapblock_pos.z,mapblock_pos.z+size.z-1 do -- origin
local offset_mapblock_pos = {x=x, y=y, z=z} building_lib.store:merge(offset_mapblock_pos, {
building = {
if vector.equals(offset_mapblock_pos, mapblock_pos) then name = building_def.name,
-- origin size = size,
building_lib.store:merge(offset_mapblock_pos, { rotation = rotation
building = { }
name = building_def.name, })
size = size, else
rotation = rotation -- link to origin
} building_lib.store:merge(offset_mapblock_pos, mapblock_lib.create_data_link(mapblock_pos))
})
else
-- link to origin
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)