Advertisement
Guest User

chop

a guest
Mar 2nd, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. local function up(x)
  2.   repeat
  3.     x=x-1
  4.     while not turtle.up() do
  5.       print("Failed to move UP")
  6.       sleep(0.2)
  7.     end
  8.   until x==0
  9. end
  10.  
  11. local function down(x)
  12.   repeat
  13.     x=x-1
  14.     while not turtle.down() do
  15.       print("Failed to move DOWN")
  16.       sleep(0.2)
  17.     end
  18.   until x==0
  19. end
  20.  
  21. local function forward(x)
  22.   repeat
  23.     x=x-1
  24.     while not turtle.forward() do
  25.       print("Failed to move FORWARD")
  26.       sleep(0.2)
  27.     end
  28.   until x==0
  29. end
  30.  
  31. local function back(x)
  32.   repeat
  33.     x=x-1
  34.     while not turtle.back() do
  35.       print("Failed to move BACK")
  36.       sleep(0.2)
  37.     end
  38.   until x==0
  39. end
  40.  
  41. local function left(x)
  42.   repeat
  43.     x=x-1
  44.     turtle.turnLeft()
  45.   until x==0
  46. end
  47.  
  48. local function right(x)
  49.   repeat
  50.     x=x-1
  51.     turtle.turnRight()
  52.   until x==0
  53. end
  54.  
  55. local function fuel()
  56.   if turtle.getFuelLevel() < 1000 then do
  57.     turtle.select(1)
  58.     turtle.refuel(10)
  59.     end
  60.   end
  61. end
  62.  
  63. local function fell()
  64.   forward(10)
  65.   right(1)
  66.   turtle.select(2)
  67.   while not turtle.compare() do
  68.     print("Tree not grown yet")
  69.     sleep(5.0)
  70.   end
  71.   turtle.dig()
  72.   forward(1)
  73.   while turtle.compare() do
  74.     turtle.dig()
  75.     turtle.digUp()
  76.     up(1)
  77.   end
  78.   fuel()
  79.   left(1)
  80.   turtle.dig()
  81.   forward(1)
  82.   right(1)
  83.   while turtle.compareDown() do
  84.     turtle.digDown()
  85.     down(1)
  86.     turtle.dig()
  87.   end
  88.   fuel()
  89. end
  90.  
  91. local function plant()
  92.   up(1)
  93.   turtle.select(3)
  94.   x=2
  95.   repeat
  96.     x=x-1
  97.     turtle.placeDown()
  98.     forward(1)
  99.     right(1)
  100.   until x==0
  101.   turtle.placeDown()
  102.   forward(1)
  103.   turtle.placeDown()
  104.   forward(1)
  105.   down(1)
  106.   left(1)
  107.   forward(10)
  108.   left(1)
  109.   turtle.suck(4)
  110.   left(1)
  111.   fuel()
  112. end
  113.    
  114. local function drop()
  115.   for i=4,16 do
  116.     turtle.select(i)
  117.     p = turtle.getItemCount(i)
  118.     turtle.dropDown(p-1)
  119.   end
  120. end
  121.  
  122. local function suck()
  123.   turtle.select(1)
  124.   turtle.suckDown()
  125. end
  126.  
  127. local function supply()
  128.   left(1)
  129.   up(4)
  130.   forward(24)
  131.   left(1)
  132.   forward(12)
  133.   down(1)
  134.   left(1)
  135.   drop()
  136.   forward(6)
  137.   right(1)
  138.   forward(1)
  139.   left(1)
  140.   suck()
  141.   forward(15)
  142.   left(1)
  143.   forward(13)
  144.   right(1)
  145.   forward(3)
  146.   down(3)
  147.   left(1)
  148.   fuel()
  149. end      
  150.  
  151. local function program()
  152.   y=1
  153.   repeat
  154.     fell()
  155.     plant()
  156.     supply()
  157.   until y==2
  158. end
  159.  
  160.  
  161. function stopLoop()
  162.     repeat
  163.       local ev, key = os.pullEvent('key')
  164.     until key == keys.backspace
  165.     y=2
  166. end
  167.  
  168. parallel.waitForAll(stopLoop, program)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement