skypop

scan (computer)

Sep 11th, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local x,_,z = gps.locate()
  2.  
  3. if not (x and z) then
  4.   term.setCursorPos(1,1)
  5.   term.clear()
  6.   print("Set position.")
  7.   term.setCursorPos(1,2)
  8.   term.write("X=")
  9.   term.setCursorBlink(true)
  10.   x = tonumber(read())
  11.   term.setCursorPos(1,3)
  12.   term.write("Z=")
  13.   z = tonumber(read())
  14.   term.setCursorBlink(false)
  15. else
  16.   x = math.floor(x)
  17.   z = math.floor(z)
  18. end
  19.  
  20. local cx,cz = x-(x%16),z-(z%16)
  21.  
  22. local level,cur=2,string.char(26)
  23. while true do
  24.   term.setCursorPos(1,1)
  25.   term.clear()
  26.   print(string.format([[Scan to level
  27.  %s128 - coal
  28.  %s 64 - iron
  29.  %s 32 - gold
  30.  %s 16 - diamond, redstone, lapis]],
  31.   level==4 and cur or " ",
  32.   level==3 and cur or " ",
  33.   level==2 and cur or " ",
  34.   level==1 and cur or " ")
  35.  )
  36.   local e,p=os.pullEvent("key")
  37.   if p==keys.up then
  38.     level = math.min(4,level+1)
  39.   elseif p==keys.down then
  40.     level = math.max(1,level-1)
  41.   elseif p==keys.enter then
  42.     local ref = {16,32,64,128}
  43.     level = ref[level]
  44.     break
  45.   end
  46.   sleep(.1)
  47. end
  48.  
  49. term.setCursorPos(1,1)
  50. term.clear()
  51. print(string.format([[Scan from
  52.  X %d %s %d
  53.  Y 1 %s %d
  54.  Z %d %s %d
  55. Confirm ? Y/N (or F for Yes and Fast)]],
  56.   cx,cur,cx+16,
  57.   cur,level,
  58.   cz,cur,cz+16)
  59. )
  60. while true do
  61.   local e,p = os.pullEvent("key")
  62.   if p==keys.y or p==keys.f then
  63.     local fastMode=(p==keys.f)
  64.     break
  65.   elseif p==keys.n then
  66.     sleep(.5)
  67.     error("Terminated",0)
  68.     return
  69.   end
  70.   sleep(.2)
  71. end
  72.  
  73. local wi = peripheral.find("WorldInterface")
  74. local ref = {
  75. ["minecraft:stone"]={"7",colors.gray,0},
  76. ["minecraft:gravel"]={"7",colors.gray,0},
  77. ["minecraft:dirt"]={"",colors.brown,0},
  78. ["minecraft:coal_ore"]={"f",colors.black,1},
  79. ["minecraft:iron_ore"]={"8",colors.lightGray,2},
  80. ["minecraft:gold_ore"]={"1",colors.yellow,3},
  81. ["minecraft:diamond_ore"]={"0",colors.white,4},
  82. ["minecraft:emerald_ore"]={"d",colors.green,4},
  83. ["minecraft:lapis_ore"]={"b",colors.blue,3},
  84. ["minecraft:redstone_ore"]={"e",colors.red,2},
  85. ["minecraft:lit_redstone_ore"]={"e",colors.red,2},
  86. ["minecraft:air"]={" ",false,0},
  87. ["else"]={"a",colors.purple,0},
  88. }
  89. local count = {
  90.   ["minecraft:diamond_ore"]=0,
  91.   ["minecraft:gold_ore"]=0,
  92.   ["minecraft:iron_ore"]=0,
  93.   ["minecraft:lapis_ore"]=0,
  94.   ["minecraft:redstone_ore"]=0,
  95.   ["minecraft:coal_ore"]=0,
  96.   ["minecraft:emerald_ore"]=0,
  97. }
  98. local function displayCount()
  99.   term.setCursorPos(35,7)
  100.   term.setBackgroundColor(colors.lightGray)
  101.   term.setTextColor(colors.black)
  102.   term.write("I")
  103.   term.setCursorPos(35,8)
  104.   term.setBackgroundColor(colors.yellow)
  105.   term.write("G")
  106.   term.setCursorPos(35,9)
  107.   term.setBackgroundColor(colors.white)
  108.   term.write("D")
  109.   term.setCursorPos(35,10)
  110.   term.setBackgroundColor(colors.blue)
  111.   term.write("L")
  112.   term.setCursorPos(35,11)
  113.   term.setBackgroundColor(colors.red)
  114.   term.write("R")
  115.   term.setCursorPos(35,12)
  116.   term.setBackgroundColor(colors.green)
  117.   term.write("E")
  118.   term.setCursorPos(35,6)
  119.   term.setBackgroundColor(colors.black)
  120.   term.setTextColor(colors.white)
  121.   term.write("C "..count["minecraft:coal_ore"])
  122.   term.setCursorPos(37,7)
  123.   term.write(count["minecraft:iron_ore"])
  124.   term.setCursorPos(37,8)
  125.   term.write(count["minecraft:gold_ore"])
  126.   term.setCursorPos(37,9)
  127.   term.write(count["minecraft:diamond_ore"])
  128.   term.setCursorPos(37,10)
  129.   term.write(count["minecraft:lapis_ore"])
  130.   term.setCursorPos(37,11)
  131.   term.write(count["minecraft:redstone_ore"])
  132.   term.setCursorPos(37,12)
  133.   term.write(count["minecraft:emerald_ore"])
  134. end
  135. local report = {}
  136. local _x,_y,_z
  137. local function displayPos(nX,nY,nZ,nRX,nRY)
  138.   term.setBackgroundColor(colors.black)
  139.   term.setTextColor(colors.white)
  140.   term.setCursorPos(35,2)
  141.   term.write("X: "..nX.."("..nRX..")             ")
  142.   term.setCursorPos(35,3)
  143.   term.write("Y: "..nY.."                        ")
  144.   term.setCursorPos(35,4)
  145.   term.write("Z: "..nZ.."("..nRY..")             ")
  146. end
  147. term.setBackgroundColor(colors.black)
  148. term.clear()
  149. for _y=1,level do
  150.   term.setBackgroundColor(colors.black)
  151. --  term.clear()
  152.   local i
  153.   for i=1,16 do
  154.     term.setCursorPos(2,i+1)
  155.     term.write(string.rep(string.char(127),32))
  156.   end
  157.   if not fastMode then sleep(.5) end
  158.   local lay = ""
  159.   for _z=cz,cz+15 do
  160.     displayCount()
  161.     for _x=cx,cx+15 do
  162.       local rx,ry = _x%16,_z%16
  163.       displayPos(_x,_y,_z,rx,ry)
  164.       term.setCursorPos(1,19)
  165.       term.clearLine()
  166.       local o = wi.getBlockInfos(_x,_y,_z)
  167.       term.write(o.blockName)
  168.       local _t,_c,delay=" ",false,0
  169.       if type(ref[o.blockName])=="table"
  170.       and #ref[o.blockName]>=3 then
  171.         _t = ref[o.blockName][1]
  172.         _c = ref[o.blockName][2]
  173.         delay = ref[o.blockName][3]*.1
  174.         if ref[o.blockName][3]>0 then
  175.           table.insert(report,string.format(
  176.             "y:%d|%s|x:%d|z%d",
  177.             _y,o.blockName:sub(11,14),_x,_z)
  178.           )
  179.           if o.blockName=="minecraft:lit_redstone_ore" then
  180.             count["minecraft:redstone_ore"] = count["minecraft:redstone_ore"]+1
  181.           else
  182.             count[o.blockName] = count[o.blockName]+1
  183.           end
  184.         end
  185.       else
  186.         _t = ref["else"][1]
  187.         _c = ref["else"][2]
  188.       end
  189.       lay = lay.._t
  190.       if _c then
  191.         paintutils.drawPixel((rx*2)+2,ry+2,_c)
  192.         paintutils.drawPixel((rx*2)+3,ry+2,_c)
  193.         if not fastMode and delay>0 then
  194.           sleep(delay)
  195.         end
  196.       end
  197.       term.setBackgroundColor(colors.black)
  198.     end
  199. --    sleep(.2)
  200.     lay = lay.."\n"
  201.   end
  202.   local dir = "/scans/chunk_"..cx.."_"..cz
  203.   local filename = "level_".._y
  204.   local fh = fs.open(dir.."/"..filename,"w")
  205.   fh.write(lay)
  206.   fh.close()
  207.   sleep(.3)
  208. end
  209. os.pullEvent("key")
  210. term.setCursorPos(1,1)
  211. term.clear()
  212. print("Report "..#report.." lines, "..math.ceil(#report/21).." pages")
  213. local str,i,l = ""
  214. for i,l in pairs(report) do
  215.   str = (i==1) and l or str.."\n"..l
  216. end
  217. sleep(.3)
  218. os.pullEvent("key")
  219. --textutils.pagedPrint(str)
  220. fh = fs.open(".temp.scan","w")
  221. fh.write(str)
  222. fh.close()
  223. shell.run("edit .temp.scan")
  224. shell.run("rm .temp.scan")
Add Comment
Please, Sign In to add comment