jig487

Farm Program

Jun 12th, 2021 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. local tArgs = {...}
  2. print("X: "..tArgs[1].." Z: "..tArgs[2])
  3. --[1] is X, [2] is Z
  4.  
  5. tArgs[1] = tonumber(tArgs[1]) --Changes tArgs[1] & [2] from a string to a number
  6. tArgs[2] = tonumber(tArgs[2])
  7.  
  8. local success, data = turtle.inspect()
  9. local x = 0 --Counter for determining when to turn left / right depending on if this is odd or even
  10.  
  11. function checkFuel()
  12.     while turtle.getFuelLevel() < 1000 do
  13.         for i = 1, 16 do -- loop through the slots
  14.             turtle.select(i) -- change to the slot
  15.             if turtle.refuel(0) then -- if it's valid fuel
  16.               local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
  17.               turtle.refuel(halfStack) -- consume half the stack as fuel
  18.             end
  19.         end
  20.     end
  21. end
  22.  
  23. function inspect()
  24.     if turtle.inspectDown() then
  25.         local success, data = turtle.inspectDown()
  26.         if data and data.state.age == 7 then
  27.             print("Crop ready.")
  28.             print("Block name: ", data.name)
  29.             print("Block metadata: ", data.state.age)
  30.             turtle.digDown()
  31.             turtle.suckDown()
  32.             turtle.placeDown()
  33.         end
  34.     end
  35.     turtle.forward()
  36. end
  37.  
  38. function resetPos()
  39.     --print("Resetting pos...")
  40.     if tArgs[1] % 2 == 0 then
  41.         --print("X is even. Straight path.")
  42.         turtle.turnRight()
  43.             for i = 1, tArgs[1] - 1 do
  44.                 turtle.forward()
  45.             end
  46.     else
  47.         --print("X is odd. Following a corner path.")
  48.         turtle.turnRight()
  49.         turtle.turnRight()
  50.         for i = 1, tArgs[2] - 1 do
  51.             turtle.forward()
  52.         end
  53.         turtle.turnRight()
  54.         for i = 1, tArgs[1] do
  55.             turtle.forward()
  56.         end
  57.     end
  58.     --print("Final right turn.")
  59.     turtle.turnRight()
  60. end
  61.  
  62. function turn()
  63.     if x % 2 == 0 then
  64.         turtle.turnLeft()
  65.         turtle.forward()
  66.         turtle.turnLeft()
  67.         --print("Switching Left")
  68.     else
  69.         turtle.turnRight()
  70.         turtle.forward()
  71.         turtle.turnRight()
  72.         --print("Switching Right")
  73.     end
  74. end
  75.  
  76. --Main Code
  77.  
  78. for u = 1, tArgs[1] do
  79.     for y = 1, tArgs[2] do
  80.         inspect()
  81.         --print("Y: "..y)
  82.     end
  83.     --checkFuel()
  84.     x = x + 1
  85.     if x<tArgs[1] then
  86.         turn()
  87.     else
  88.         --print("Not changing lanes.")
  89.     end
  90.     --print("U: "..u)
  91.     --print("X: "..x)
  92.     --print("X%: "..x % 2)
  93. end
  94. resetPos()
Add Comment
Please, Sign In to add comment