Advertisement
DOGGYWOOF

Untitled

Jan 24th, 2025 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. -- Additional functions for farming
  2. local function hoeSoil()
  3. if turtle.detectDown() then
  4. turtle.digDown()
  5. end
  6. turtle.select(1) -- Assuming hoe is in slot 1
  7. turtle.placeDown()
  8. end
  9.  
  10. local function plantSeed()
  11. local seedSlot = nil
  12. -- Search for seeds in the inventory
  13. for slot = 2, 16 do
  14. turtle.select(slot)
  15. local item = turtle.getItemDetail()
  16. if item and item.name:match("minecraft:wheat_seeds") then
  17. seedSlot = slot
  18. break
  19. end
  20. end
  21.  
  22. if seedSlot then
  23. turtle.select(seedSlot)
  24. if turtle.placeDown() then
  25. log("Seed planted.")
  26. else
  27. log("Failed to plant seed.")
  28. end
  29. else
  30. log("No seeds found in inventory.")
  31. end
  32. end
  33.  
  34. local function harvestCrop()
  35. turtle.select(1) -- Assuming a hoe is in slot 1
  36. if turtle.detectDown() then
  37. local item = turtle.getItemDetail()
  38. if item and item.name == "minecraft:wheat" then
  39. turtle.digDown() -- Harvest the crop
  40. log("Crop harvested.")
  41. end
  42. end
  43. end
  44.  
  45. local function smartFarm()
  46. -- Iterate over a farm grid to hoe, plant, or harvest
  47. for x = 1, 10 do -- A 10x10 grid for simplicity
  48. for z = 1, 10 do
  49. -- Hoe the soil if it's not hoed
  50. hoeSoil()
  51. -- Plant seeds if the soil is prepared
  52. plantSeed()
  53. -- Harvest crops if they are fully grown
  54. harvestCrop()
  55. tryMoveForward() -- Move the turtle to the next position
  56. end
  57. -- Move to the next row and turn around
  58. tryTurn("right")
  59. tryMoveForward()
  60. tryTurn("right")
  61. tryMoveForward()
  62. tryTurn("right")
  63. end
  64. end
  65.  
  66. -- Main program modification to include farming option
  67. local function main()
  68. while true do
  69. if not passwordProtection() then
  70. return
  71. end
  72.  
  73. updateDashboard("Idle", nil, turtle.getFuelLevel(), 0)
  74. print("Commands: mine, explore, refuel, settings, farm, stop")
  75. local command = read()
  76.  
  77. if command == "mine" then
  78. navigateAndMine()
  79. elseif command == "explore" then
  80. exploreAndMap()
  81. elseif command == "refuel" then
  82. refuel()
  83. elseif command == "settings" then
  84. settingsPage()
  85. elseif command == "farm" then
  86. smartFarm() -- Add the farming command here
  87. elseif command == "stop" then
  88. log("Stopping the Turtle.")
  89. os.shutdown()
  90. else
  91. log("Invalid command.")
  92. end
  93. end
  94. end
  95.  
  96. -- Start the main program
  97. main()
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement