robocyclone

Turtle Farming Process

Feb 18th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. local x,y = 0,0
  2. local direction = "north"
  3.  
  4. local success, idtable = turtle.inspectDown()
  5.  
  6. if success and idtable.name == "minecraft:chest" then
  7.     print("Success")
  8. else
  9.     error("Need chest below turtle to start farming!")
  10. end
  11.  
  12. function testForAvailableFuel()
  13.     for i = 1, 16 do
  14.         turtle.select(i)
  15.         if turtle.refuel(0) then
  16.             return true
  17.         end
  18.     end
  19. end
  20.  
  21. function fuel()
  22.     if not turtle.getFuelLevel() <= math.floor(turtle.getFuelLimit()/2) or not testForAvailableFuel() then return end
  23.     for i = 1, 16 do
  24.         turtle.select(i)
  25.         if turtle.refuel(0) then
  26.             local halfStack = math.floor(turtle.getItemCount(i)/2)
  27.             turtle.refuel(halfStack)
  28.         end
  29.     end
  30. end
  31.  
  32. function forward(dirToGo)
  33.     if dirToGo == "north" then
  34.         y = y + 1
  35.         if direction == "north" then
  36.             turtle.forward()
  37.         elseif direction == "south" then
  38.             turtle.turnLeft()
  39.             turtle.turnLeft()
  40.             turtle.forward()
  41.         elseif direction == "west" then
  42.             turtle.turnRight()
  43.             turtle.forward()
  44.         elseif direction == "east" then
  45.             turtle.turnLeft()
  46.             turtle.forward()
  47.         end
  48.         direction = "north"
  49.     elseif dirToGo == "east" then
  50.         x = x + 1
  51.         if direction == "north" then
  52.             turtle.turnRight()
  53.             turtle.forward()
  54.         elseif direction == "west" then
  55.             turtle.turnLeft()
  56.             turtle.turnLeft()
  57.             turtle.forward()
  58.         elseif direction == "east" then
  59.             turtle.forward()
  60.         elseif direction == "south" then
  61.             turtle.turnLeft()
  62.             turtle.forward()
  63.         end
  64.         direction = "east"
  65.     elseif dirToGo == "south" then
  66.         y = y - 1
  67.         if direction == "south" then
  68.             turtle.forward()
  69.         elseif direction == "north" then
  70.             turtle.turnLeft()
  71.             turtle.turnLeft()
  72.             turtle.forward()
  73.         elseif direction == "east" then
  74.             turtle.turnRight()
  75.             turtle.forward()
  76.         elseif direction == "west" then
  77.             turtle.turnLeft()
  78.             turtle.forward()
  79.         end
  80.         direction = "south"
  81.     elseif dirToGo == "west" then
  82.         x = x - 1
  83.         if direction == "west" then
  84.             turtle.forward()
  85.         elseif direction == "east" then
  86.             turtle.turnLeft()
  87.             turtle.turnLeft()
  88.             turtle.forward()
  89.         elseif direction == "south" then
  90.             turtle.turnRight()
  91.             turtle.forward()
  92.         elseif direction == "north" then
  93.             turtle.turnLeft()
  94.             turtle.forward()
  95.         end
  96.         direction = "west"
  97.     end
  98.     fuel()
  99. end
  100.  
  101. function moveTo(x2, y2)
  102.     if x2 > x then
  103.         local x3 = x2 - x
  104.         for f = 1, x3 do
  105.             forward("east")
  106.         end
  107.     elseif x2 < x then
  108.         local x3 = (math.abs(x2)) - x
  109.         for f = 1, x3 do
  110.             forward("west")
  111.         end
  112.     end
  113.     if y2 > y then
  114.         local y3 = y2 - y2
  115.         for g = 1, y3 do
  116.             forward("north")
  117.         end
  118.     elseif y2 < y then
  119.         local y3 = (math.abs(y2)) - y2
  120.         for g = 1, y3 do
  121.             forward("south")
  122.         end
  123.     end
  124. end
  125.  
  126. function dropOff()
  127.     moveTo(0,0)
  128.     for i = 1, 16 do
  129.         turtle.select(i)
  130.         turtle.dropDown()
  131.     end
  132.     turtle.suckDown()
  133. end
  134.  
  135. function findSeeds()
  136.     for i = 1, 16 do
  137.         turtle.select(i)
  138.         local idtable = turtle.getItemDetail()
  139.         if idtable.name == "minecraft:wheat_seeds" then
  140.             return i
  141.         end
  142.     end
  143. end
  144.  
  145. function harvestGrownAndPlant()
  146.     local success, idtable = turtle.inspectDown()
  147.     if success then
  148.         if idtable.state.age == 7 then
  149.             local seeds = findSeeds()
  150.             turtle.digDown()
  151.             turtle.select(seeds)
  152.             turtle.placeDown()
  153.         end
  154.     end
  155. end
  156.  
  157. function harvestAll()
  158.     for k = 1, 27 do
  159.         for p = 1, 27 do
  160.             moveTo(k, p)
  161.             harvestGrownAndPlant()
  162.         end
  163.     end
  164.     moveTo(0,0)
  165. end
  166.  
  167. while true do
  168.     dropOff()
  169.     harvestAll()
  170.     sleep(600)
  171. end
Advertisement
Add Comment
Please, Sign In to add comment