Ni_Jay_Ni

FARM

Jun 20th, 2021
746
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[ FARM program v0.5 ]]--
  2. print("farm [# spaces forward] [# columns]")
  3.  
  4. args = { ... }
  5.  
  6. if args ~= nil and #args < 1 then
  7.     print("Please input how far forward the turtle should go...")
  8.     y = io.read()
  9. else
  10.     y = args[1]
  11. end
  12. if args ~= nil and #args < 2 then
  13.     print("Please input the number of columns there are...")
  14.     x = io.read()
  15. else
  16.     x = args[2]
  17. end
  18.  
  19. if x == nil or y == nil then
  20.     return
  21. end
  22.  
  23.  
  24. print("You should place the turtle at the X.")
  25. for rowsSample=0,y-1,1 do
  26.     print(string.rep('.',x))
  27. end
  28. print("X"..string.rep('.',x-1))
  29. print("Input Y to continue.")
  30. confirmation = io.read()
  31.  
  32. if confirmation ~= "Y" then
  33.     print("Cancelled farming...")
  34.     return
  35. end
  36.  
  37. alternating = false
  38. function alternateTurn()
  39.     if alternating then
  40.         turtle.turnLeft()
  41.         turtle.forward()
  42.         turtle.turnLeft()
  43.     else
  44.         turtle.turnRight()
  45.         turtle.forward()
  46.         turtle.turnRight()
  47.     end
  48. end
  49.  
  50. function checkCrop()
  51.     local exists, data = turtle.inspectDown()
  52.     if exists and data.name == "minecraft:wheat" and data.metadata == 7 then
  53.         turtle.digDown()
  54.         turtle.placeDown()
  55.     end
  56. end
  57.  
  58. for ax=1,x,1 do
  59.     for ay=1,y,1 do
  60.         checkCrop()
  61.         turtle.forward()
  62.     end
  63.     checkCrop()    
  64.     alternateTurn()
  65.     alternating = not alternating
  66. end
  67.  
  68. for invSlot=1,16,1 do
  69.     turtle.select(invSlot)
  70.     turtle.dropDown()
  71. end
  72.  
  73. turtle.turnLeft()
  74. for homeForward=1,x,1 do
  75.     turtle.forward()
  76. end
  77. turtle.turnRight()
  78.  
RAW Paste Data