Advertisement
TheTrueCubic

OC Wheat Bot

Aug 3rd, 2022 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local robot = require("robot")
  4. local sides = require("sides")
  5. local geolyzer = component.geolyzer
  6. local inventory_controller = component.inventory_controller
  7.  
  8. term.write("Enter length (number): ")
  9. local length = term.read()
  10.  
  11. term.write("Enter width (number): ")
  12. local width = term.read()
  13.  
  14. local right = true
  15.  
  16. function turn()
  17. if (right) then robot.turnRight() else robot.turnLeft() end
  18. end
  19.  
  20. function tryForward()
  21. if (not robot.forward()) then tryForward() end
  22. end
  23.  
  24. function isSelectingSeed()
  25. local selectedItem = inventory_controller.getStackInInternalSlot()
  26. return (selectedItem and selectedItem.name == "minecraft:wheat_seeds")
  27. end
  28.  
  29. function plant()
  30. local lastSlot = robot.inventorySize()
  31. robot.select(lastSlot)
  32. robot.dropDown(robot.count())
  33. inventory_controller.equip()
  34. if (not isSelectingSeed()) then
  35. local i = 1
  36. while true do
  37. robot.select(i)
  38. if (isSelectingSeed()) then
  39. break
  40. end
  41. if (i == lastSlot) then
  42. i = 1
  43. else
  44. i = i + 1
  45. end
  46. end
  47. end
  48. inventory_controller.equip()
  49. robot.useDown()
  50. end
  51.  
  52. function farm()
  53. robot.select(1)
  54. local block = geolyzer.analyze(sides.bottom)
  55. if (block.growth == 1 and block.name == "minecraft:wheat") then
  56. robot.swingDown()
  57. plant()
  58. end
  59. end
  60.  
  61. function moveX(j)
  62. for i = length, 1, -1 do
  63. farm()
  64. if (i > 1) then
  65. tryForward()
  66. elseif (j > 1) then
  67. turn()
  68. farm()
  69. tryForward()
  70. turn()
  71. end
  72. end
  73. end
  74.  
  75. function moveY()
  76. for i = width, 0, -1 do
  77. if (i > 0) then
  78. moveX(i)
  79. right = not right
  80. end
  81. end
  82. robot.turnAround()
  83. right = not right
  84. end
  85.  
  86. while true do
  87. moveY()
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement