Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. height = 16
  2. width = 14
  3. pos = {}
  4. pos.x = 1
  5. pos.y = 0
  6.  
  7. endp = {}
  8. endp.x = width
  9. move = "+"
  10.  
  11. if (width % 2 == 0) then
  12.     endp.y = 1
  13.     direction = "toward"
  14. else
  15.     endp.y = height
  16.     direction = "away"
  17. end
  18.  
  19. function restock (turtle)
  20.     turtle.turnRight()
  21.     local i = 2
  22.  
  23.     while (i <= 16) do
  24.         turtle.select(i)
  25.         turtle.drop()
  26.     end
  27.  
  28.     turtle.turnRight()
  29.     -- ADD Refuel from bottom if needed
  30. end
  31.  
  32. function forwardCheck (turtle, pos)
  33.     turtle.forward()
  34.  
  35.     if (move == "+") then
  36.         pos.y = pos.y + 1
  37.     else
  38.         pos.y = pos.y - 1
  39.     end
  40.  
  41.     local suc, crop = turtle.inspectDown()
  42.     if (crop.name == 'minecraft:wheat' and crop.metadata == 7) then
  43.         turtle.digDown()
  44.         turtle.select(1)
  45.         turtle.placeDown()
  46.     end
  47. end
  48.  
  49. function leftTurnCheck (turtle, pos)
  50.     turtle.turnLeft()
  51.     turtle.forward()
  52.     pos.x = pos.x + 1
  53.     turtle.turnLeft()
  54.     move = "-"
  55.  
  56.     local suc, crop = turtle.inspectDown()
  57.     if (crop.name == 'minecraft:wheat' and crop.metadata == 7) then
  58.         turtle.digDown()
  59.         turtle.select(1)
  60.         turtle.placeDown()
  61.     end
  62. end
  63.  
  64. function rightTurnCheck (turtle, pos)
  65.     turtle.turnRight()
  66.     turtle.forward()
  67.     pos.x = pos.x + 1
  68.     turtle.turnRight()
  69.     move = "+"
  70.  
  71.     local suc, crop = turtle.inspectDown()
  72.     if (crop.name == 'minecraft:wheat' and crop.metadata == 7) then
  73.         turtle.digDown()
  74.         turtle.select(1)
  75.         turtle.placeDown()
  76.     end
  77. end
  78.  
  79. while true do
  80.     print('end-x: ', endp.x, ' end-y: ', endp.y)
  81.     print('x: ', pos.x, ' y: ', pos.y)
  82.     if (pos.x == endp.x and pos.y == endp.y) then
  83.         if (direction == "away") then
  84.             turtle.turnLeft()
  85.             turtle.turnLeft()
  86.         end
  87.  
  88.         while (pos.y > 1) do
  89.             turtle.forward()
  90.             pos.y = pos.y - 1
  91.         end
  92.  
  93.         turtle.turnLeft()
  94.  
  95.         while (pos.x > 1) do
  96.             turtle.forward()
  97.             pos.x = pos.x - 1
  98.         end
  99.  
  100.         turtle.turnRight()
  101.         turtle.forward()
  102.         pos.y = pos.y - 1
  103.         turtle.turnLeft()
  104.         turtle.turnLeft()
  105.  
  106.         restock(turtle)
  107.         print('x: ', pos.x, ' y: ', pos.y)
  108.        
  109.         sleep(5)
  110.     else
  111.         if (pos.x == 1 and pos.y == 0) then
  112.             forwardCheck(turtle, pos)
  113.             forwardCheck(turtle, pos)
  114.             forwardCheck(turtle, pos)
  115.         elseif (pos.y == 1) then
  116.             rightTurnCheck(turtle, pos)
  117.             forwardCheck(turtle, pos)
  118.         elseif (pos.y == height) then
  119.             leftTurnCheck(turtle, pos)
  120.             forwardCheck(turtle, pos)
  121.         else
  122.             forwardCheck(turtle, pos)
  123.         end
  124.     end
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement