Advertisement
Ganeesya

rdig

Nov 24th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. nglist = {}
  2. oklist = {}
  3.  
  4.  
  5. function init()
  6.     if fs.exists("OK.lst") then
  7.         local ngf = fs.open("OK.lst","r")
  8.  
  9.         local lname = ngf.readLine()
  10.         while ngf ~= nil do
  11.             nglist[#nglist+1] = lname
  12.         end
  13.         ngf.close()
  14.     end
  15.  
  16.     if fs.exists("NG.lst") then
  17.         local okf = fs.open("NG.lst","r")
  18.  
  19.         local lname = okf.readLine()
  20.         while okf ~= nil do
  21.             oklist[#oklist+1] = lname
  22.         end
  23.         okf.close()
  24.     end
  25. end
  26.  
  27. function addlist(fname,code)
  28.     local af = fs.open(fname,"a")
  29.     af.writeLine(code)
  30.     af.close()
  31. end
  32.  
  33. function checkNG(side)
  34.     if side == nil then
  35.         side = ""
  36.     end
  37.  
  38.     local ok,data = turtle["inspect"..side]()
  39.     if not ok then
  40.         return false
  41.     end
  42.  
  43.     local checkname = data["name"]
  44.     for i, v in ipairs(nglist) do
  45.         if v == checkname then
  46.             return true
  47.         end
  48.     end
  49.  
  50.     return false
  51. end
  52.  
  53. function checkOK(side)
  54.     if side == nil then
  55.         side = ""
  56.     end
  57.  
  58.     local ok,data = turtle["inspect"..side]()
  59.     if not ok then
  60.         return false
  61.     end
  62.  
  63.     local checkname = data["name"]
  64.     for i, v in ipairs(oklist) do
  65.         if v == checkname then
  66.             return true
  67.         end
  68.     end
  69.  
  70.     return false
  71. end
  72.  
  73. function digoutWait(side)
  74.     term.clear()
  75.     term.setCursorPos(1,1)
  76.     write("Plz DigOut NG Blocks")
  77.     repeat
  78.         sleep(1)
  79.     until not turtle["detect"..side]()
  80. end
  81.  
  82. function colorWrite(str,color)
  83.     if term.isColor() then
  84.         term.setTextColor(color)
  85.     end
  86.     write(str)
  87.     if term.isColor() then
  88.         term.setTextColor(colors.white)
  89.     end
  90. end
  91.  
  92. function cdig(side)
  93.     if side == nil then
  94.         side = ""
  95.     end
  96.     if checkNG(side) then
  97.         digoutWait(side)
  98.     end
  99.     if not checkOK(side) then
  100.  
  101.         term.clear()
  102.         term.setCursorPos(1,1)
  103.         local ok,data = turtle["inspect"..side]()
  104.         colorWrite( data["name"], colors.red)
  105.         if side == "" then
  106.             write(" on ")
  107.             colorWrite("Front",colors.orange)
  108.         else
  109.             write(" on ")
  110.             colorWrite(side,colors.orange)
  111.         end
  112.         write(" is unknown block...\nI can dig it?(y/n)\n")
  113.  
  114.         while true do
  115.             local mes = {os.pullEvent("key")}
  116.  
  117.             if mes[2] == 21 then ---y
  118.                 oklist[#oklist+1] = data["name"]
  119.                 addlist("OK.lst",data["name"])
  120.                 colorWrite("add list",colours.green)
  121.                 break
  122.             end
  123.  
  124.             if mes[2] == 49 then ---n
  125.                 nglist[#nglist+1] = data["name"]
  126.                 addlist("NG.lst",data["name"])
  127.                 digoutWait(side)
  128.                 break
  129.             end
  130.         end
  131.     end
  132.     turtle["dig"..side]()
  133. end
  134.  
  135. init()
  136. while true do
  137.     cdig()
  138.     turtle.forward()
  139.     cdig("Up")
  140.     cdig("Down")
  141.     if not turtle.detect() then
  142.         turtle.turnLeft()
  143.         if not turtle.detect() then
  144.             break
  145.         end
  146.     end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement