robocyclone

why

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