Maschini

Untitled

Feb 23rd, 2023 (edited)
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. local function isGrown()
  2.     local inspected, data = turtle.inspectDown()
  3.     return (inspected and data["state"]["age"] == 7)
  4. end
  5.  
  6. local function farmTile()
  7.     turtle.digDown()
  8.     turtle.select(1)
  9.     turtle.placeDown()
  10. end
  11.  
  12. local function empty()
  13.     for i = 2, 15, 1 do
  14.         turtle.select(i)
  15.         turtle.drop(turtle.getItemCount(i))
  16.     end
  17.     turtle.select(1)
  18. end
  19.  
  20. local function orientTurtle()
  21.     local count = 0
  22.     while count < 2 do
  23.         if turtle.detect() then
  24.             if peripheral.hasType("front", "inventory") then
  25.                 empty()
  26.             end
  27.             count = count + 1
  28.         end
  29.         if count >= 2 then
  30.             break
  31.         end
  32.         turtle.turnRight()
  33.     end
  34.  
  35.     turtle.turnLeft()
  36.     turtle.turnLeft()
  37. end
  38.  
  39.  
  40. local function farmField()
  41.     local direction = true
  42.     local function turn(update)
  43.         update = update or false
  44.         if direction then
  45.             turtle.turnLeft()
  46.             if update then
  47.                 direction = false
  48.             end
  49.         else
  50.             turtle.turnRight()
  51.             if update then
  52.                 direction = true
  53.             end
  54.         end
  55.     end
  56.  
  57.     local function farmWhenGrown()
  58.         if isGrown() then
  59.             print("found grown tile")
  60.             farmTile()
  61.         end
  62.     end
  63.  
  64.     while true do
  65.         farmWhenGrown()
  66.         while not turtle.detect() do
  67.             turtle.forward()
  68.             farmWhenGrown()
  69.         end
  70.         turn()
  71.         if not turtle.forward() then
  72.             break
  73.         end
  74.         turn(true)
  75.     end
  76. end
  77.  
  78. local function refuel()
  79.     turtle.select(16)
  80.     local count = turtle.getItemCount(16)
  81.     turtle.refuel(count)
  82.     turtle.select(1)
  83. end
  84.  
  85. while true do
  86.     print("farming field")
  87.     refuel()
  88.     orientTurtle()
  89.     farmField()
  90.     print("waiting for 120 seconds")
  91.     sleep(120)
  92. end
Advertisement
Add Comment
Please, Sign In to add comment