Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. local farmWidth = 4
  2. local farmLength = 4
  3. local farmStartLeft = true
  4.  
  5. --
  6. -- dont edit below here
  7. --
  8. local function farmSquare(width, length, startLeft)
  9. local slot = 1
  10. turtle.select(slot) -- select first slot
  11.  
  12. -- check for initial items to place
  13. if turtle.getItemCount(slot) == 0 then
  14. print('error: nothing to place in slot 1!')
  15. return
  16. end
  17.  
  18. print('start farming: ' .. length .. 'x' .. width)
  19.  
  20. for y = 1, width do
  21. for x = 1, length do
  22. -- dig and place
  23. turtle.digDown()
  24. turtle.digDown()
  25. turtle.placeDown()
  26.  
  27. -- select next slot if current is empty
  28. if turtle.getItemCount(slot) == 0 then
  29. slot = slot + 1
  30. turtle.select(slot)
  31. end
  32.  
  33. -- go forward if not on edge
  34. if x ~= length then
  35. turtle.forward()
  36. end
  37. end
  38.  
  39. if y ~= width then
  40. -- move to next row
  41. if (y % 2) == 0 then
  42. if startLeft then
  43. turtle.turnLeft()
  44. turtle.forward()
  45. turtle.turnLeft()
  46. else
  47. turtle.turnRight()
  48. turtle.forward()
  49. turtle.turnRight()
  50. end
  51. else
  52. if startLeft then
  53. turtle.turnRight()
  54. turtle.forward()
  55. turtle.turnRight()
  56. else
  57. turtle.turnLeft()
  58. turtle.forward()
  59. turtle.turnLeft()
  60. end
  61. end
  62. else
  63. -- move back if ended on uneven row
  64. if (y % 2) ~= 0 then
  65. -- move back
  66. for i = 1, (length - 1) do
  67. turtle.back()
  68. end
  69.  
  70. -- turn
  71. if startLeft then
  72. turtle.turnLeft()
  73. else
  74. turtle.turnRight()
  75. end
  76. else
  77. -- turn
  78. if startLeft then
  79. turtle.turnRight()
  80. else
  81. turtle.turnLeft()
  82. end
  83. end
  84.  
  85. -- move cells down
  86. for i = 1, (width - 1) do
  87. turtle.forward()
  88. end
  89.  
  90. -- turn into start pos
  91. if startLeft then
  92. turtle.turnRight()
  93. else
  94. turtle.turnLeft()
  95. end
  96. end
  97. end
  98.  
  99. print('finished farming')
  100. end
  101.  
  102. farmSquare(farmWidth, farmLength, farmStartLeft)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement