Larvix

map/radar

Dec 15th, 2023 (edited)
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.90 KB | None | 0 0
  1. tileset = {
  2. air = {" ",colors.black},
  3. water = {"~",colors.blue},
  4. lava = {"~",colors.red},
  5. flowing_lava = {"~",colors.red},
  6. computer = {"C",colors.lightGray},
  7. turtle_advanced = {"\2",colors.yellow},
  8. turtle_expanded = {"\2",colors.lightGray},
  9. turtle = {"\2",colors.lightGray},
  10. peripheral = {"+",colors.white},
  11. advanced_modem = {"+",colors.yellow},
  12. cable = {"+",colors.lightGray},
  13. audio_cable = {"+",colors.gray},
  14. tallgrass = {'"',colors.green},
  15. double_plant = {'"',colors.green},
  16. vine = {"|",colors.green},
  17. ladder = {"|",colors.brown},
  18. rope = {"|",colors.white},
  19. leaves = {"\153",colors.green},
  20. waterlily = {"\248",colors.green},
  21. reeds = {"\165",colors.green},
  22. cactus = {"\165",colors.green},
  23. yellow_flower = {"*",colors.yellow},
  24. red_flower = {"*",colors.red},
  25. sand = {"\127",colors.yellow},
  26. gravel = {"\127",colors.lightGray},
  27. grass = {"\143",colors.green},
  28. dirt = {"\143",colors.brown},
  29. stone = {"\143",colors.lightGray},
  30. cobblestone = {"\143",colors.gray},
  31. log = {"\143",colors.brown},
  32. planks = {"\143",colors.brown},
  33. obsidian = {"\143",colors.purple},
  34. stone_button = {"r",colors.lightGray},
  35. wooden_button = {"r",colors.brown},
  36. light_button = {"r",colors.white},
  37. lever = {"r",colors.brown},
  38. redstone_wire = {"r",colors.red},
  39. redstone_torch = {"r",colors.red},
  40. repeater = {"r",colors.red},
  41. comparator = {"r",colors.red},
  42. observer = {"r",colors.gray},
  43. piston = {"r",colors.brown},
  44. sticky_piston = {"r",colors.green},
  45. redstone_block = {"r",colors.red},
  46. noteblock = {"\15",colors.brown},
  47. speaker = {"\15",colors.lightGray},
  48. tape_reader = {"\15",colors.lightGray},
  49. iron_bars = {"#",colors.lightGray},
  50. ironpane = {"#",colors.lightGray},
  51. glass = {"#",colors.white},
  52. glass_pane = {"#",colors.white},
  53. glasspane = {"#",colors.white},
  54. glasspanedyedblack = {"#",colors.white},
  55. stained_glass = {"#",colors.white},
  56. stained_glass_pane = {"#",colors.white},
  57. space_glass_clear = {"#",colors.white},
  58. cobblestone_wall = {"#",colors.gray},
  59. editable_wall = {"#",colors.brown},
  60. editable_wall_reinforced = {"#",colors.brown},
  61. editable_fence = {"#",colors.brown},
  62. editable_fence_reinforced = {"#",colors.brown},
  63. rail = {"=",colors.brown},
  64. track_outfitted = {"=",colors.brown},
  65. track_flex_electric = {"=",colors.brown},
  66. track_flex_hs_electric = {"=",colors.brown},
  67. wall_sign = {"?",colors.brown},
  68. standing_sign = {"?",colors.brown},
  69. glowstone = {"i",colors.yellow},
  70. torch = {"i",colors.yellow},
  71. interdiction_torch = {"i",colors.green},
  72. lamp = {"i",colors.yellow},
  73. blaze_lantern = {"i",colors.yellow},
  74. redstone_lamp = {"i",colors.red},
  75. lit_redstone_lamp = {"i",colors.red},
  76. fire = {"i",colors.orange},
  77. wool = {"w",colors.white},
  78. furnace = {"f",colors.lightGray},
  79. brewing_stand = {"b",colors.yellow},
  80. cauldron = {"c",colors.blue},
  81. chest = {"c",colors.brown},
  82. custom_chest = {"c",colors.brown},
  83. alchemical_chest = {"c",colors.lightGray},
  84. ender_chest = {"c",colors.green},
  85. ender_storage = {"c",colors.white},
  86. condenser_mk1 = {"c",colors.red},
  87. condenser_mk2 = {"c",colors.red},
  88. crafting_table = {"\169",colors.brown},
  89. autoworkbench_item = {"\169",colors.brown},
  90. pipe = {"\177",colors.lightGray},
  91. portal = {"@",colors.purple},
  92. coal_ore = {"\4",colors.gray},
  93. iron_ore = {"\4",colors.lightGray},
  94. gold_ore = {"\4",colors.orange},
  95. redstone_ore = {"\4",colors.red},
  96. lapis_ore = {"\4",colors.blue},
  97. diamond_ore = {"\4",colors.lightBlue},
  98. emerald_ore = {"\4",colors.green},
  99. copper_ore = {"\4",colors.orange},
  100. tin_ore = {"\4",colors.white},
  101. silver_ore = {"\4",colors.white},
  102. lead_ore = {"\4",colors.white},
  103. nickel_ore = {"\4",colors.white},
  104. platinum_ore = {"\4",colors.white},
  105. uranium_ore = {"\4",colors.white},
  106. aluminum_ore = {"\4",colors.white},
  107. zinc_ore = {"\4",colors.white},
  108. osmium_ore = {"\4",colors.white},
  109. sulfur_ore = {"\4",colors.white},
  110. ruby_ore = {"\4",colors.white},
  111. sapphire_ore = {"\4",colors.white},
  112. peridot_ore = {"\4",colors.white},
  113. certus_quartz_ore = {"\4",colors.white},
  114. charged_certus_quartz_ore = {"\4",colors.white},
  115. amber_ore = {"\4",colors.white},
  116. topaz_ore = {"\4",colors.white},
  117. tanzanite_ore = {"\4",colors.white},
  118. malachite_ore = {"\4",colors.white},
  119. coal_block = {"\143",colors.gray},
  120. iron_block = {"\143",colors.lightGray},
  121. gold_block = {"\143",colors.orange},
  122. redstone_block = {"\143",colors.red},
  123. lapis_block = {"\143",colors.blue},
  124. diamond_block = {"\143",colors.lightBlue},
  125. emerald_block = {"\143",colors.green},
  126. }
  127.  
  128. mapPath = "./data/map"
  129.  
  130. yieldTime = os.clock()
  131. yield = function()
  132.     if os.clock()-yieldTime>2 then
  133.         os.queueEvent("yield")
  134.         os.pullEvent("yield")
  135.         yieldTime = os.clock()
  136.     end
  137. end
  138.  
  139. args={...}
  140. sX,sY = term.getSize()
  141.  
  142. radar = function()
  143.     level = {}
  144.     scanner = nil
  145.     if peripheral.find("neuralInterface") and peripheral.find("neuralInterface").hasModule("plethora:scanner") then
  146.         scanner = peripheral.wrap("back")
  147.         neural = true
  148.     else scanner = peripheral.find("plethora:scanner") end
  149.     if scanner == nil then
  150.         term.setCursorPos(1,sY)
  151.         term.clearLine()
  152.         print("Requires Plethora Block Scanner!")
  153.     else
  154.         scan = scanner.scan()
  155.             selected = tonumber(args[1])
  156.     if selected == nil then
  157.         selected = 0
  158.     elseif selected > 8 then
  159.         selected = 8
  160.     elseif selected < -8 then
  161.         selected = -8
  162.     end
  163.    
  164.     size = tonumber(args[2])
  165.     if size == nil then size = 13
  166.     elseif size > 17 then
  167.         size = 17
  168.     elseif size < 1 then
  169.         size = 1
  170.     end
  171.     indent = math.floor((17-size)/2)
  172.     offset = math.floor((11-size)/2)
  173.     if size < 11 then
  174.         for n = 1,offset do
  175.             write("\n")
  176.         end
  177.         offset = 0
  178.     end
  179.     margin = ""
  180.     for i = 1,indent do
  181.         margin = margin.."  "
  182.     end
  183.         if neural then
  184.             for n = 1,#scan do
  185.                 scan[n].y = math.floor(scan[n].y)
  186.                 scan[n].x = math.floor(scan[n].x)
  187.                 scan[n].z = math.floor(scan[n].z)
  188.             end
  189.         end
  190.         for i = 1,#scan do
  191.             if scan[i].y == selected then
  192.                 name = scan[i].name
  193.                 name = name:sub(string.find(name,":")+1, #name)
  194.                 scan[i].nameP = name
  195.                 table.insert(level,scan[i])
  196.             end
  197.         end
  198.  
  199.         for col = -8+indent,8-indent+offset do
  200.             write(margin)
  201.             for row = -8+indent,8-indent do
  202.                 for block = 1,#level do
  203.                     if level[block].z == col then
  204.                         if level[block].x == row then
  205.                             name = level[block].nameP
  206.                             tX, tY = term.getCursorPos()
  207.                             tY = tY + offset
  208.                             level[block].tX = tX
  209.                             level[block].tY = tY
  210.                             notFound = true
  211.                             for k,v in pairs(tileset) do
  212.                                 if k == name then
  213.                                     if (term.isColour()) and (v[2]~=nil) then
  214.                                         term.setTextColor(v[2])
  215.                                     end
  216.                                     write(v[1].." ")
  217.                                     term.setTextColor(colors.white)
  218.                                     notFound = false
  219.                                 end
  220.                             end
  221.                             if notFound then write("\143 ") end
  222.                         end
  223.                     end
  224.                 end
  225.             end
  226.             write("\n")
  227.         end  
  228.  
  229.         if selected < 0 then lPref = "Y:"
  230.         else lPref = "Y: " end
  231.         if size < 10 then sPref = "S: "
  232.         else sPref = "S:" end
  233.         levelString = lPref..tostring(selected)
  234.         scaleString = sPref..tostring(size)
  235.         term.setCursorPos(sX-#levelString+1,1)
  236.         write(levelString)
  237.         term.setCursorPos(sX-#scaleString+1,2)
  238.         write(scaleString)
  239.     end
  240. end
  241.  
  242. saveMap = function()
  243.     myX = nil
  244.     myX, myY, myZ = gps.locate()
  245.     if myX == nil then
  246.         term.setCursorPos(1,sY)
  247.         term.clearLine()
  248.         print("GPS not found!")
  249.     else
  250.         myX = math.floor(myX)
  251.         myY = math.floor(myY)
  252.         myZ = math.floor(myZ)
  253.         if fs.exists(mapPath) then
  254.             mapFile = fs.open(mapPath, "r")
  255.             map = mapFile.readAll()
  256.             map = textutils.unserialize(map)
  257.             mapFile.close()
  258.         else
  259.             mapFile = fs.open(mapPath, "w")
  260.             mapFile.close()
  261.             map = {} end
  262.             s = "Saving"
  263.             term.setCursorPos(sX-#s+1,sY)
  264.             write(s)
  265.             for i = 1,#scan do
  266.                 blockExists = false
  267.                 for n = 1,#map do
  268.                     yield()
  269.                     if ((scan[i].y+myY) == map[n].y) and ((scan[i].x+myX) == map[n].x) and ((scan[i].z+myZ) == map[n].z) then
  270.                         blockExists = true
  271.                         if scan[i].name ~= map[n].name then
  272.                             map[n].name = scan[i].name end
  273.                         if scan[i].name == ("computercraft:turtle_advanced" or "computercraft:turtle" or "computercraft:turtle_expanded") then
  274.                             map[n].name = "minecraft:air" end
  275.                         break
  276.                     end
  277.                 end
  278.             if not blockExists then
  279.                 table.insert(map,{y=(scan[i].y+myY), x=(scan[i].x+myX), z=(scan[i].z+myZ), name=scan[i].name})
  280.             end
  281.         end
  282.  
  283.         mapFile = fs.open(mapPath, "w")
  284.         mapString = "{"
  285.         for t = 1,#map do
  286.             item = tostring(textutils.serialise(map[t]))
  287.             mapString = mapString..item..","
  288.         end
  289.         mapString = mapString.."}"
  290.         mapFile.write(mapString)
  291.         mapFile.close()
  292.     end
  293. end
  294.  
  295. change = true
  296. while true do
  297.     if change then
  298.         shell.run("clear")
  299.         radar()
  300.         change = false
  301.     else yield() end
  302.     evt, e1, e2, e3 = os.pullEvent()
  303.     if evt == "key" then
  304.         if e1 == keys.up then
  305.             args[1] = selected + 1
  306.             change = true
  307.         elseif e1 == keys.down then
  308.             args[1] = selected - 1
  309.             change = true
  310.         elseif e1 == keys.right then
  311.             args[2] = size + 2
  312.             change = true
  313.         elseif e1 == keys.left then
  314.             args[2] = size - 2
  315.             change = true
  316.         elseif e1 == keys.enter then
  317.             saveMap()
  318.             change = true
  319.         elseif e1 == keys.space then
  320.             change = true
  321.         end
  322.     elseif evt == "mouse_scroll" then
  323.         if e1 == 1 then
  324.             args[1] = selected - 1
  325.             change = true
  326.         elseif e1 == -1 then
  327.             args[1] = selected + 1
  328.             change = true
  329.         end
  330.     elseif evt == "mouse_click" then
  331.         for i = 1,#level do
  332.             if (tonumber(level[i].tX) == tonumber(e2)) and (tonumber(level[i].tY) == tonumber(e3)) then
  333.                 selectedBlock = tostring(textutils.serialise(level[i].nameP))
  334.                 selectedBlock = string.sub(selectedBlock,2,#selectedBlock-1):gsub("_"," ")
  335.                 term.setCursorPos(1,sY)
  336.                 term.clearLine()
  337.                 if #selectedBlock < sX then
  338.                     write(selectedBlock)
  339.                 else write(string.sub(selectedBlock,1,sX-3).."...") end
  340.             end
  341.         end
  342.     end
  343. end
Advertisement
Add Comment
Please, Sign In to add comment