Advertisement
johnnic431

TSM+FUEL

Aug 9th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. os.loadAPI("advTurtle")
  2. advTurtle.override()
  3.  
  4. safeFuel=500
  5. blocksMined=0;
  6.  
  7. local function incBM()
  8.     blocksMined=blocksMined+1
  9. end
  10.  
  11. function doDig(num)
  12.     for e=1, num do
  13.         if turtle.dig() then incBM() end
  14.         doForw(1)
  15.         if turtle.digUp() then incBM() end
  16.         if turtle.digDown() then incBM() end
  17.     end
  18. end
  19.  
  20. local function writeInfo()
  21.  
  22.     term.setCursorPos(1,1)
  23.     local ta=advTurtle.localPos()
  24.     if ta[4]==1 then facing="+x"
  25.     elseif ta[4]==-1 then facing="-x"
  26.     elseif ta[5]==1 then facing="+z"
  27.     elseif ta[5]==-1 then facing="-z" end
  28.     write(lpad("local x:"..ta[1].." y:"..ta[2].." z:"..ta[3],_x))
  29.     write(lpad("facing local "..facing,_x))
  30.     term.setCursorPos(1,4)
  31.     fL=turtle.getFuelLevel()
  32.     write(lpad("Fuel level: "..fL,_x))
  33.     if fL<safeFuel then
  34.         status="Refueling"
  35.         for y=1, 16 do
  36.             turtle.select(y)
  37.             if turtle.refuel(5) then break end
  38.         end
  39.     else
  40.         status="Mining"
  41.     end
  42.     term.setCursorPos(1,5)
  43.     write(lpad("Blocks Mined: "..blocksMined,_x))
  44.     term.setCursorPos(1,_y)
  45.     write(lpad("Status: "..status,_x))
  46. end
  47.  
  48. function doForw(num)
  49.     for e=1, num do
  50.         while not turtle.forward() do
  51.             if turtle.dig() then incBM() end
  52.             turtle.attack()
  53.         end
  54.         writeInfo()
  55.     end
  56. end
  57.  
  58. _x,_y=term.getSize()
  59.  
  60. function lpad(str, leng, charg)
  61.     if charg == nil then charg = ' ' end
  62.     return str .. string.rep(charg, leng - #str)
  63. end
  64.  
  65. term.clear()
  66.  
  67. m = 0
  68. while true do
  69.     for y=1, m do
  70.         turtle.forward()
  71.     end
  72.     doDig(1)
  73.     turtle.turnLeft()
  74.     doDig(60)
  75.     turtle.turnLeft()
  76.     turtle.turnLeft()
  77.     doDig(121)
  78.     turtle.turnLeft()
  79.     turtle.turnLeft()
  80.     doDig(61)
  81.     turtle.turnLeft()
  82.     doForw(m+1)
  83.     for y=1, 16 do
  84.         turtle.select(y)
  85.         turtle.drop()
  86.     end
  87.     turtle.turnLeft()
  88.     turtle.turnLeft()
  89.     m = m + 1
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement