Fettish

farmer

Sep 24th, 2025 (edited)
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local gridSize = 7
  2. local potatoSlot = 1
  3. local fuelSlot = 16
  4.  
  5. function refuelTurtle()
  6.     print("Refueling...")
  7.     turtle.select(fuelSlot)
  8.     turtle.refuel()
  9.     turtle.select(potatoSlot)
  10. end
  11.  
  12. function isMaturePotato()
  13.     local success, data = turtle.inspectDown()
  14.     if success then
  15.         print("Inspecting block:", data.name)
  16.         if data.state and data.state.age then
  17.             print("Crop age:", data.state.age)
  18.             return data.name == "minecraft:potatoes" and data.state.age == 7
  19.         else
  20.             print("No age data found for this block.")
  21.         end
  22.     else
  23.         print("No block detected below.")
  24.     end
  25.     return false
  26. end
  27.  
  28.  
  29. function harvestAndReplant()
  30.     print("Scanning...")
  31.     if isMaturePotato() then
  32.         turtle.digDown()
  33.         turtle.select(potatoSlot)
  34.         turtle.placeDown()
  35.     end
  36. end
  37.  
  38. function scanFarm()
  39.   for row = 1, gridSize do
  40.     for col = 1, gridSize do
  41.       harvestAndReplant()
  42.       if col < gridSize then turtle.forward() end
  43.     end
  44.     -- Move to next row
  45.     if row < gridSize then
  46.       if row % 2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  47.       turtle.forward()
  48.       if row % 2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  49.     end
  50.   end
  51. end
  52.  
  53. function returnToStart()
  54.   -- Reverse the scan pattern to return to top-left
  55.   turtle.turnLeft()
  56.   turtle.turnLeft()
  57.   for i = 1, gridSize - 1 do turtle.forward() end
  58.   turtle.turnRight()
  59.   for i = 1, gridSize - 1 do turtle.forward() end
  60.   turtle.turnRight()
  61. end
  62.  
  63. function dumpPotatoes()
  64.   turtle.back()
  65.   turtle.down()
  66.   for slot = 1, 15 do
  67.     turtle.select(slot)
  68.     turtle.dropDown()
  69.   end
  70.   turtle.up()
  71.   turtle.forward()
  72. end
  73.  
  74. -- Main loop
  75. while true do
  76.     refuelTurtle()
  77.     scanFarm()
  78.     returnToStart()
  79.     dumpPotatoes()
  80.     sleep(240)
  81. end
Advertisement
Add Comment
Please, Sign In to add comment