morganamilo

farm

Jun 3rd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. local args = {...}
  2. local xSize = tonumber(args[2])
  3. local ySize = tonumber(args[1])
  4. local timeout = tonumber(args[3])
  5.  
  6. local function checkWheat()
  7.     local isBlock, data = turtle.inspectDown()
  8.     if isBlock and data.name == "minecraft:wheat" and data.metadata == 7 then
  9.         turtle.digDown()
  10.         turtle.select(1)
  11.         turtle.placeDown()
  12.     end
  13. end
  14.  
  15. local function refuelIfEmpty() -- refuels if fuel level is 0
  16.   if turtle.getFuelLevel() == 0 then
  17.     print('Out of fuel\nWaiting for fuel in slot ' .. turtle.getSelectedSlot() .. '...')
  18.     while not turtle.refuel do os.pullEvent('turtle_inventory') end
  19.     print('Fuel level is: ' .. turtle.getFuelLevel())
  20.   end
  21. end
  22.  
  23. local function forward()
  24.     checkWheat()
  25.  
  26.   while not turtle.forward() do
  27.     refuelIfEmpty()
  28.     if turtle.detect() then turtle.dig() end
  29.   end
  30. end
  31.  
  32. local function doPass()
  33.     for n = 1, ySize do
  34.         for m = 1, xSize -1 do
  35.             forward()
  36.         end
  37.        
  38.         if n < ySize then
  39.             if n % 2 == 0 then
  40.                 turtle.turnRight()
  41.                 forward()
  42.                 turtle.turnRight()
  43.             else
  44.                 turtle.turnLeft()
  45.                 forward()
  46.                 turtle.turnLeft()
  47.             end
  48.         end
  49.     end
  50.  
  51.     if ySize % 2 ~= 0 then
  52.         turtle.turnRight()
  53.         turtle.turnRight()
  54.  
  55.         for n = 1, xSize -1 do
  56.             turtle.forward()
  57.         end
  58.     end
  59.  
  60.     turtle.turnLeft()
  61.  
  62. for n = 1, ySize -1 do
  63.             turtle.forward()
  64.         end
  65. end
  66.  
  67. local function useChest()
  68.     for n = 2, 16 do
  69.         turtle.select(n)
  70.         turtle.drop()
  71.     end
  72. end
  73. while true do
  74.     doPass()
  75.     turtle.turnRight()
  76.     useChest()
  77.     turtle.turnRight()
  78.     turtle.turnRight()
  79.     sleep(timeout or 25*60)
  80. end
Add Comment
Please, Sign In to add comment