eniallator

Crop Farmer

Dec 30th, 2020 (edited)
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. local sideLength = 9
  2. local inspectAttempts = 5
  3. local desiredFuelPercent = 0.5
  4.  
  5. local move = {
  6.     forward = function()
  7.         while not turtle.forward() do
  8.             turtle.dig()
  9.         end
  10.     end,
  11.     up = function()
  12.         while not turtle.up() do
  13.             turtle.digUp()
  14.         end
  15.     end,
  16.     down = function()
  17.         while not turtle.down() do
  18.             turtle.digDown()
  19.         end
  20.     end
  21. }
  22.  
  23. local checkBlock = {
  24.     forward = function(name)
  25.         local i
  26.         for i = 1, inspectAttempts do
  27.             local success, blockData = turtle.inspect()
  28.             if success then
  29.                 return blockData.name:find(name) ~= nil
  30.             end
  31.         end
  32.     end,
  33.     up = function(name)
  34.         local i
  35.         for i = 1, inspectAttempts do
  36.             local success, blockData = turtle.inspectUp()
  37.             if success then
  38.                 return blockData.name:find(name) ~= nil
  39.             end
  40.         end
  41.     end,
  42.     down = function(name)
  43.         local i
  44.         for i = 1, inspectAttempts do
  45.             local success, blockData = turtle.inspectDown()
  46.             if success then
  47.                 return blockData.name:find(name) ~= nil
  48.             end
  49.         end
  50.     end
  51. }
  52.  
  53. local function doAction()
  54.     turtle.placeDown()
  55. end
  56.  
  57. while true do
  58.     turtle.select(1)
  59.     move.forward()
  60.     doAction()
  61.  
  62.     local i, j
  63.     for i = 1, sideLength do
  64.         for j = 1, sideLength - 1 do
  65.             move.forward()
  66.             doAction()
  67.         end
  68.         if i < sideLength then
  69.             if i % 2 == 1 then
  70.                 turtle.turnRight()
  71.                 move.forward()
  72.                 doAction()
  73.                 turtle.turnRight()
  74.             else
  75.                 turtle.turnLeft()
  76.                 move.forward()
  77.                 doAction()
  78.                 turtle.turnLeft()
  79.             end
  80.         end
  81.     end
  82.  
  83.     move.forward()
  84.     turtle.turnRight()
  85.     turtle.turnRight()
  86.     if
  87.         turtle.getFuelLevel() ~= 'unlimited' and checkBlock.down('condenser') and
  88.             turtle.getFuelLevel() < turtle.getFuelLimit() * desiredFuelPercent
  89.      then
  90.         turtle.select(16)
  91.         turtle.suckDown()
  92.         turtle.refuel()
  93.     end
  94.     sleep(60)
  95. end
Advertisement
Add Comment
Please, Sign In to add comment