Guest User

tfarm.lua

a guest
Feb 12th, 2021
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. local rowLength = 20
  2. local numRows = 16
  3. local turnRightFirst = true
  4.  
  5. local turnRightNext = turnRightFirst
  6. local currentSlot = 1
  7.  
  8. function setActiveSlot(slotNumber)
  9.     slotNumber = tonumber(slotNumber)
  10.     if slotNumber ~= nil then
  11.         currentSlot = slotNumber
  12.         turtle.select(slotNumber)
  13.     end
  14. end
  15.  
  16. function harvest()
  17.     print("Harvesting...")
  18.     setActiveSlot(1)
  19.     turtle.digDown()
  20.     turtle.placeDown()
  21. end
  22.  
  23. function refuelFromLastSlot()
  24.     setActiveSlot(16)
  25.     turtle.refuel()
  26. end
  27.  
  28. function turn(numberOfTimes, goRight)
  29.     if goRight == true then
  30.         for i=0, numberOfTimes do
  31.             turtle.turnRight()
  32.         end
  33.     else
  34.         for i=0, numberOfTimes do
  35.             turtle.turnLeft()
  36.         end
  37.     end
  38. end
  39.  
  40. function returnHome()
  41.     turtle.forward()
  42.     turtle.turnRight()
  43.     for i=0, 30 do
  44.         turtle.forward()
  45.     end
  46. end
  47.  
  48. refuelFromLastSlot()
  49. for i=0, numRows do
  50.     for j=0, rowLength do
  51.         turtle.forward()
  52.         harvest()
  53.     end
  54.  
  55.     turn(1, turnRightNext)    
  56.     turtle.forward()
  57.     turtle.forward()
  58.     turn(1, turnRightNext)
  59.     turnRightNext = not turnRightNext
  60. end
  61.  
  62. returnHome()
Advertisement
Add Comment
Please, Sign In to add comment