thor12022

Automated Turtle Harvesting

Apr 24th, 2014
3,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. --@author thor12022
  2. local fieldSize = 8
  3. local isOdd = math.ceil(fieldSize/2) ~= (fieldSize/2)
  4. -- It goes forever
  5. while true do
  6.     -- if we need more fuel for this pass
  7.     --TODO update for odd
  8.     if (isOdd and turtle.getFuelLevel() < ((fieldSize * fieldSize) + 2*fieldSize)) or (turtle.getFuelLevel() < ((fieldSize * fieldSize) + fieldSize)) then
  9.         turtle.suckUp()
  10.         turtle.refuel()
  11.     end
  12.     -- face outward
  13.     turtle.turnLeft()
  14.     turtle.turnLeft()
  15.     -- loop over the rows
  16.     local turnRight = true
  17.     for x = 1,fieldSize,1 do
  18.         -- loop over the columns (except the last one)
  19.         for y = 1,fieldSize - 1,1 do
  20.             turtle.digDown()
  21.             turtle.placeDown()
  22.             turtle.forward()
  23.         end
  24.         -- harvest the last one
  25.         turtle.digDown()
  26.         turtle.placeDown()
  27.         -- all but the last row
  28.         if x ~= fieldSize then
  29.             -- turn right or left and change column
  30.             if turnRight == true then
  31.                 turtle.turnRight()
  32.                 turtle.forward()
  33.                 turtle.turnRight()
  34.                 turnRight = false
  35.             else
  36.                 turtle.turnLeft()
  37.                 turtle.forward()
  38.                 turtle.turnLeft()
  39.                 turnRight = true
  40.             end
  41.         end
  42.     end
  43.    
  44.     -- face the starting point
  45.     turtle.turnRight()
  46.     -- go back over the row if there was an odd size
  47.     if isOdd then
  48.         turtle.turnRight()
  49.         for back = 1,(fieldSize-1),1 do
  50.             turtle.forward()
  51.         end
  52.         turtle.turnRight()
  53.     end
  54.     -- go back down the column
  55.     for back = 1,(fieldSize-1),1 do
  56.         turtle.forward()
  57.     end
  58.     -- face the chest
  59.     turtle.turnLeft()
  60.     --empty everything into the chest
  61.     for slot = 1,16,1 do
  62.         turtle.select(slot)
  63.         -- we keep trying to dump inventory
  64.         while turtle.getItemCount(slot) ~= 0 do
  65.             if not turtle.drop() then
  66.                 -- if the target inventory was full, we'll try it again later
  67.                 os.sleep(10)
  68.             end
  69.         end
  70.     end
  71.     -- reset to the starting conditions
  72.     turtle.select(1)
  73.     -- go again in 45 minutes
  74.     os.sleep(2400)
  75. end
Advertisement
Add Comment
Please, Sign In to add comment