Advertisement
AyrA

rect

Dec 8th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. function printFuel()
  2.     fuel=turtle.getFuelLevel()
  3.     fuelbar=math.floor(fuel/100)
  4.     if fuelbar>20 then
  5.         fuelbar=20
  6.     end
  7.    
  8.     term.clear()
  9.     term.setCursorPos(1,1)
  10.    
  11.     print("------------------------")
  12.     term.write("--")
  13.     for i=1,fuelbar do
  14.         term.write("#")
  15.     end
  16.     for j=fuelbar,19 do
  17.         term.write("=")
  18.     end
  19.     print("--")
  20.     print("------------------------")
  21.     print(fuel.." Steps left")
  22. end
  23.  
  24. function checkFuel()
  25.     if turtle.getFuelLevel() < 100 then
  26.         turtle.select(16)
  27.         turtle.refuel()
  28.         turtle.select(1)
  29.     end
  30.     printFuel()
  31. end
  32.  
  33. function df()
  34.     if turtle.detect() then
  35.         turtle.dig()
  36.     end
  37. end
  38.  
  39. function f()
  40.     while turtle.detect() do
  41.         df()
  42.         sleep(0.5)
  43.     end
  44.     turtle.forward()
  45.     checkFuel()
  46. end
  47.  
  48. function du()
  49.     if  turtle.detectUp() then
  50.         turtle.digUp()
  51.     end
  52. end
  53.  
  54. function u()
  55.     while turtle.detectUp() do
  56.         du()
  57.         sleep(0.5)
  58.     end
  59.     turtle.up()
  60.     checkFuel()
  61. end
  62.  
  63. function r()
  64.     turtle.turnRight()
  65. end
  66.  
  67. function l()
  68.     turtle.turnLeft()
  69. end
  70.  
  71. function dd()
  72.     if  turtle.detectDown() then
  73.         turtle.digDown()
  74.     end
  75. end
  76.  
  77. function d()
  78.     dd()
  79.     turtle.down()
  80.     checkFuel()
  81. end
  82.  
  83. function main()
  84.     checkFuel()
  85.    
  86.     term.write("Enter WxH: ")
  87.     WxH=read()
  88.  
  89.     if string.find(WxH,"x") then
  90.         W=string.sub(WxH,1,string.find(WxH,"x")-1)
  91.         H=string.sub(WxH,string.find(WxH,"x")+1)
  92.  
  93.         if tonumber(W) and tonumber(H) then
  94.             for i=1,W do
  95.                 for j=1,H do
  96.                     f()
  97.                 end
  98.                 if i%2==1 then
  99.                     r()
  100.                     f()
  101.                     r()
  102.                 else
  103.                     l()
  104.                     f()
  105.                     l()
  106.                 end
  107.             end
  108.         else
  109.             print("ERR: Not a Number in W or H")
  110.         end
  111.     else
  112.         print("ERR: Wrong Format")
  113.     end
  114. end
  115.  
  116. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement