scanner.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. minetest.register_node("potions:scanner_endpoint", {
  2. description = "Scanner Endpoint",
  3. tiles = {"default_stone.png^default_tool_steelsword.png"},
  4. groups = {cracky = 3},
  5. sounds = default.node_sound_stone_defaults(),
  6. })
  7. minetest.register_node("potions:scanner_noreplace", {
  8. description = "Scanner NoReplace",
  9. drawtype = "glasslike",
  10. tiles = {"default_glass.png^default_tool_diamondsword.png"},
  11. groups = {cracky = 3},
  12. sounds = default.node_sound_stone_defaults(),
  13. })
  14. minetest.register_node("potions:scanner_center", {
  15. description = "Scanner Center",
  16. tiles = {"default_stone.png^default_tool_bronzesword.png"},
  17. groups = {cracky = 3},
  18. sounds = default.node_sound_stone_defaults(),
  19. on_punch = function(pos)
  20. local path = minetest.get_worldpath().."/potions_testfile.txt"
  21. local ends = minetest.find_nodes_in_area(
  22. vector.subtract(pos, 51),
  23. vector.add(pos, 51),
  24. {"potions:scanner_endpoint"})
  25. if #ends < 2 then
  26. return
  27. end
  28. local e1 = {
  29. x = math.min(ends[1].x, ends[2].x)+1,
  30. y = math.min(ends[1].y, ends[2].y)+1,
  31. z = math.min(ends[1].z, ends[2].z)+1,
  32. }
  33. local e2 = {
  34. x = math.max(ends[1].x, ends[2].x)-1,
  35. y = math.max(ends[1].y, ends[2].y)-1,
  36. z = math.max(ends[1].z, ends[2].z)-1,
  37. }
  38. local data = {}
  39. for x = e1.x,e2.x do
  40. for y = e1.y,e2.y do
  41. for z = e1.z,e2.z do
  42. local p = {x=x, y=y, z=z}
  43. local n = minetest.get_node(p)
  44. if n.name ~= "air" then
  45. local nn = { name=n.name, }
  46. if n.param2 and n.param2 > 0 then
  47. nn.param2 = n.param2
  48. end
  49. table.insert(data, {p=vector.subtract(p, pos), n=nn})
  50. end
  51. end
  52. end
  53. end
  54. local f = io.open(path, "w")
  55. f:write(dump(data))
  56. f:close()
  57. end,
  58. })