robocyclone

turtle?

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