save_schematics.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. local S = minetest.get_translator("map_making_toolkit")
  2. local function save_cmd_func(name, param)
  3. --parse arguments and get the corners of the box with
  4. --minimal/maximal coordinates
  5. local worked, pos1, offset = map_making_toolkit.parse_args(param)
  6. if not worked or offset.x == 0 or offset.y == 0 or offset.z == 0
  7. then
  8. return true, S("Invalid coordinates or offset")
  9. end
  10. minpos = {}
  11. for k, v in pairs(pos1)
  12. do
  13. minpos[k] = math.min(v, v + (offset[k] - 1) * 16)
  14. offset[k] = math.abs(offset[k])
  15. end
  16. local mapid = math.random()
  17. local path = minetest.get_worldpath()
  18. path = path .. "/schematics/map" .. mapid .. "/"
  19. minetest.mkdir(path)
  20. for i = 0, offset.x - 1
  21. do
  22. local ix = minpos.x + i * 16
  23. for ii = 0, offset.y - 1
  24. do
  25. local iy = minpos.y + ii * 16
  26. for iii = 0, offset.z - 1
  27. do
  28. local iz = minpos.z + iii * 16
  29. local pos1 = vector.new(ix, iy, iz)
  30. local pos2 = vector.add(pos1, vector.new(15, 15, 15))
  31. local filename = path..i.."_"..ii.."_"..iii..".mts"
  32. minetest.create_schematic(pos1, pos2, nil, filename)
  33. end
  34. end
  35. end
  36. return true, S("Saved schematic files to:\n@1", path)
  37. end
  38. minetest.register_chatcommand("savemap",
  39. {
  40. params = S("<x> <y> <z> <offset x> <offset y> <offset z>"),
  41. privs = {server = true},
  42. description = S("Saves a map as a bunch of 16x16x16 schematics " ..
  43. "in the world directory.\n" ..
  44. "Offset is in map blocks."),
  45. func = save_cmd_func,
  46. })