Advertisement
Punio

lumber

May 31st, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | None | 0 0
  1.  
  2. -- made by Punio (ironblocks.de)
  3.  
  4. local mainSteps   = 2
  5. local mainTimer   = 30
  6. local woolSlot    = 16
  7. local chestSlot   = 15
  8. local woodSlot    = 14
  9. local saplingSlot = 13
  10.  
  11. local checkSide = false
  12. local turned = false
  13.  
  14.  
  15. -- functions
  16. function message(msg)
  17.    term.clear()
  18.    term.setCursorPos(1,1)
  19.    print(msg)
  20. end
  21.  
  22. function harvest()
  23.    while not turtle.forward() do
  24.       while not turtle.dig() and turtle.detect() do
  25.          turtle.attack()
  26.          sleep(.1)
  27.       end
  28.    end
  29.    
  30.    moved = 0
  31.    
  32.    while turtle.detectUp() do
  33.       while not turtle.up() do
  34.          while not turtle.digUp() and turtle.detectUp() do
  35.             turtle.attackUp()
  36.             sleep(.1)
  37.          end
  38.       end
  39.      
  40.       moved = moved + 1
  41.    end
  42.    
  43.    while moved > 0 do
  44.       if checkSide then
  45.          for i = 1,4 do
  46.             while turtle.detect() do
  47.                turtle.dig()
  48.             end
  49.             turtle.turnLeft()
  50.          end
  51.       end
  52.      
  53.       while not turtle.down() do
  54.          turtle.attackDown()
  55.          if turtle.detectDown() then
  56.             turtle.digDown()
  57.          end
  58.       end  
  59.  
  60.       moved = moved - 1
  61.    end
  62.    
  63.    while not turtle.back() do
  64.       message("cant move back!")
  65.       sleep(.1)
  66.    end
  67. end
  68.  
  69. function plant()
  70.    while not (turtle.getItemCount(saplingSlot) > 1) do
  71.       message("pls refill sapling!")
  72.       sleep(.1)
  73.    end
  74.  
  75.    turtle.select(saplingSlot)
  76.    if not turtle.compare() and not turtle.detect() then
  77.       while not turtle.place() do
  78.          message("cant place sapling!")
  79.          sleep(.1)
  80.       end
  81.    end
  82. end
  83.  
  84. function check()
  85.    turtle.select(chestSlot)
  86.    if not turtle.compare() then
  87.       turtle.turnLeft()
  88.  
  89.       if turtle.detect() then
  90.          turtle.select(woodSlot)
  91.          if turtle.compare() then
  92.             harvest()
  93.          end
  94.       end
  95.      
  96.       plant()
  97.       turtle.turnRight()
  98.    end
  99. end
  100.  
  101. function turn()
  102.    turtle.turnLeft()
  103.    turtle.turnLeft()
  104.    
  105.    turned = not turned
  106. end
  107.  
  108. function move(steps)
  109.    for i = 1, steps do
  110.       turtle.select(woolSlot)
  111.       if not turtle.compareDown() or turned then
  112.          while not turtle.forward() do
  113.             turtle.attack()
  114.             sleep(.1)
  115.          end
  116.       else
  117.          break
  118.       end
  119.    end
  120.    
  121.    turtle.select(woolSlot)
  122.    return not turtle.compareDown()
  123. end
  124.  
  125. function drop()
  126.    for i = 1, 16 do
  127.       if turtle.getItemCount(i) > 0 then
  128.          turtle.select(i)
  129.          if i ~= woolSlot and i ~= woodSlot and i ~= chestSlot then
  130.             if i ~= saplingSlot then
  131.                while not turtle.drop() do
  132.                   message("no more space in chest!")
  133.                   sleep(.1)
  134.                end
  135.             end
  136.          else
  137.             if turtle.getItemCount(i) > 1 then
  138.                while not turtle.drop(turtle.getItemCount(i) - 1) do
  139.                   message("no more space in chest!")
  140.                   sleep(.1)
  141.                end
  142.             end
  143.          end
  144.       end
  145.    end
  146. end
  147.  
  148. function wait(timer)
  149.    while timer > 0 do
  150.       message("wait " .. timer .."sec")
  151.       sleep(1)
  152.       timer = timer - 1
  153.    end
  154. end
  155.  
  156. -- main loop
  157. while true do
  158.    if turtle.getItemCount(woolSlot) > 0 and turtle.getItemCount(woodSlot) > 0 and turtle.getItemCount(chestSlot) > 0 then
  159.       turtle.select(chestSlot)
  160.       if turtle.compare() then
  161.          drop()
  162.          turn()
  163.          wait(mainTimer)
  164.       else
  165.          if move(mainSteps) then
  166.             check()
  167.          else
  168.             turn()
  169.          end
  170.       end
  171.    else
  172.       message("pls fill needed items in slots")
  173.    end
  174.    sleep(.1)
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement