Advertisement
ladyDia

Farming Code

Dec 22nd, 2020 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. local a = {}
  2. local args = {...}
  3.  
  4. local xSize = args[1]
  5. local zSize = args[2]
  6.  
  7. local xPos = 0
  8. local zPos = 0
  9.  
  10. local xDiff = 0
  11. local yDiff = 0
  12.  
  13. local xTemp = 0
  14. local zTemp = 0
  15.  
  16. local slot = 1
  17. local foundSeed = false
  18.  
  19. function a.goToPlace(x,z)
  20. xDiff = xPos-x
  21. zDiff = zPos-z
  22.  
  23. if xDiff ~=0 then
  24. turtle.turnRight()
  25. while xDiff ~= 0 do
  26. if xDiff<0 then
  27. turtle.back()
  28. xDiff = xDiff+1
  29. xPos = xPos+1
  30. end
  31. if xDiff > 0 then
  32. turtle.forward()
  33. xDiff = xDiff-1
  34. xPos = xPos-1
  35. end
  36. end
  37. turtle.turnLeft()
  38. end
  39.  
  40.  
  41. while zDiff ~= 0 do
  42. if zDiff<0 then
  43. turtle.forward()
  44. zDiff = zDiff+1
  45. zPos = zPos+1
  46. end
  47. if zDiff>0 then
  48. turtle.back()
  49. zDiff = zDiff-1
  50. zPos = zPos-1
  51. end
  52. end
  53. end
  54.  
  55. function a.plantSeed()
  56. if turtle.getItemDetail(slot) == nil then
  57. foundSeed = false
  58. while(foundSeed ~= true) and(slot~=17) do
  59. print(slot)
  60. if(turtle.getItemDetail(slot) ~= nil) then
  61. if(turtle.getItemDetail(slot).name=="minecraft:wheat_seeds") then
  62. foundSeed = true
  63. end
  64. else
  65. slot = slot+1
  66. end
  67. end
  68. end
  69. if(slot==17)then
  70. slot = 1
  71. xTemp = xPos
  72. zTemp = zPos
  73. a.goToPlace(0,0)
  74. print("Please give me seeds")
  75. while(foundSeed ~= true)do
  76. if(turtle.getItemDetail(slot) ~= nil) then
  77. if(turtle.getItemDetail(slot).name=="minecraft:wheat_seeds") then
  78. foundSeed = true
  79. sleep(1)
  80. end
  81. end
  82. end
  83. print("Thank you!")
  84. a.goToPlace(xTemp,zTemp)
  85. else
  86. turtle.placeDown()
  87. end
  88. end
  89.  
  90. while(turtle.getFuelLevel()>(xSize*zSize*2))do
  91. for x = 0, xSize do
  92. for z = 0, zSize do
  93. if x % 2 == 1 then
  94. a.goToPlace(x,(zSize-z))
  95. end
  96. if x % 2 == 0 then
  97. a.goToPlace(x,z)
  98. end
  99. turtle.digDown()
  100. a.plantSeed()
  101. end
  102. end
  103. a.goToPlace(0,0)
  104. sleep(1200)
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement