TheKojent

autoHarvest

Mar 30th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. --Program that harvests Redwood trees with a specific chest setup.
  2.  
  3. local tArgs = { ... }
  4. if # tArgs ~= 1 then
  5.     print("Usage: autoHarvest <iterations>")
  6.     return
  7. end
  8. local count = tonumber(tArgs[1])
  9.  
  10. local function harvest()
  11.     turtle.select(3)
  12.     turtle.dig()
  13.     turtle.forward()
  14.     while turtle.detectUp() do
  15.         turtle.dig()
  16.         turtle.digUp()
  17.         turtle.up()
  18.     end
  19.     turtle.dig()
  20.     turtle.turnRight()
  21.     turtle.dig()
  22.     turtle.forward()
  23.     turtle.turnLeft()
  24.     while turtle.detectDown() do
  25.         turtle.dig()
  26.         turtle.digDown()
  27.         turtle.down()
  28.     end
  29.     turtle.up()
  30.     turtle.select(16)
  31.     turtle.placeDown()
  32. end
  33.  
  34. local function invDump()
  35.     for i = 1,13 do
  36.         turtle.select(i+2)
  37.         turtle.drop()
  38.     end
  39. end
  40.  
  41. local function restock()
  42.     if turtle.getItemCount(1) < 4 then --Saplings in slot 1
  43.         turtle.select(1)
  44.         turtle.dropUp()
  45.         turtle.suckUp()
  46.     end
  47.     if turtle.getItemCount(2) < 10 then --Bone meal in slot 2
  48.         turtle.select(2)
  49.         turtle.dropDown()
  50.         turtle.suckDown()
  51.     end
  52.     turtle.turnRight()
  53.     if turtle.getFuelLevel() < 500 then
  54.         turtle.select(15)
  55.         turtle.suck()
  56.         turtle.refuel()
  57.     end
  58.     turtle.turnRight()
  59. end
  60.  
  61. local function forward(dist)
  62.     for i = 1,dist do
  63.         turtle.forward()
  64.     end
  65. end
  66.  
  67. local function replant()
  68.     turtle.select(1)
  69.     turtle.placeDown()
  70.     forward(1)
  71.     turtle.placeDown()
  72.     turtle.turnRight()
  73.     forward(1)
  74.     turtle.placeDown()
  75.     turtle.turnRight()
  76.     forward(1)
  77.     turtle.placeDown()
  78.     forward(1)
  79.     turtle.turnRight()
  80.     forward(1)
  81.     turtle.down()
  82.     turtle.turnRight()
  83.     turtle.select(2)
  84.     while turtle.place() do
  85.         sleep(0.5)
  86.     end
  87. end
  88.  
  89. --Main Loop
  90.  
  91. while true do
  92.     print("Make sure to keep at least 2 dirt in slot 16. Press E to continue.")
  93.     local event, param1 = os.pullEvent("char")
  94.     if param1 == "e" then
  95.         term.clear()
  96.         print("Harvesting " .. count .. "trees.")
  97.         break
  98.     else
  99.         sleep(0.5)
  100.     end
  101. end
  102. for i = 1,count do
  103.     restock()
  104.     forward(5)
  105.     replant()
  106.     harvest()
  107.     turtle.turnLeft()
  108.     forward(1)
  109.     turtle.turnLeft()
  110.     turtle.up()
  111.     forward(5)
  112.     invDump()
  113.     sleep(300)
  114. end
  115. print("Finished harvesting " .. count .. " trees!")
Advertisement
Add Comment
Please, Sign In to add comment