is_area_empty.lua 1010 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. local c_ignore = minetest.get_content_id("ignore")
  2. local buildable_to_nodes = {}
  3. minetest.after(4, function()
  4. local count = 0
  5. for name, node in pairs(minetest.registered_nodes) do
  6. if node.buildable_to then
  7. count = count + 1
  8. local id = minetest.get_content_id(name)
  9. buildable_to_nodes[id] = true
  10. end
  11. end
  12. minetest.log("action", "[jumpdrive] collected " .. count .. " nodes that are buildable_to")
  13. end)
  14. jumpdrive.is_area_empty = function(pos1, pos2)
  15. local manip = minetest.get_voxel_manip()
  16. local e1, e2 = manip:read_from_map(pos1, pos2)
  17. local area = VoxelArea:new({MinEdge=e1, MaxEdge=e2})
  18. local data = manip:get_data()
  19. for z=pos1.z, pos2.z do
  20. for y=pos1.y, pos2.y do
  21. for x=pos1.x, pos2.x do
  22. local index = area:index(x, y, z)
  23. local id = data[index]
  24. if id == c_ignore then
  25. return false, "Uncharted"
  26. end
  27. if not buildable_to_nodes[id] then
  28. -- not buildable_to
  29. return false, "Occupied"
  30. end
  31. end
  32. end
  33. end
  34. -- only buildable_to nodes found
  35. return true, ""
  36. end