LayZee

ComputerCraft lzChop

Jun 24th, 2014
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. local saplingSlot = 15
  2. local boneMealSlot = 16
  3.  
  4. local bone, chop, empty, plant, wait, waitForKey, watch
  5.  
  6. bone = function()
  7.     turtle.select(saplingSlot)
  8.  
  9.     while turtle.getItemCount(boneMealSlot) > 1 and turtle.compare() do
  10.         turtle.select(boneMealSlot)
  11.         turtle.place()
  12.         turtle.select(saplingSlot)
  13.     end
  14. end
  15.  
  16. chop = function()
  17.     local height = 1
  18.     local downSteps = 1
  19.  
  20.     turtle.select(1)
  21.     turtle.dig()
  22.     turtle.forward()
  23.  
  24.     while turtle.compareUp() do
  25.         turtle.digUp()
  26.         turtle.up()
  27.  
  28.         height = height + 1
  29.     end
  30.  
  31.     for i = 1, height - 1 do
  32.         turtle.down()
  33.     end
  34.  
  35.     turtle.back()
  36. end
  37.  
  38. empty = function()
  39.     for slot = 1, 14 do
  40.         if turtle.getItemCount(slot) > 0 then
  41.             turtle.select(slot)
  42.             turtle.dropUp()
  43.         end
  44.     end
  45. end
  46.  
  47. plant = function()
  48.     turtle.select(saplingSlot)
  49.  
  50.     while true do
  51.         turtle.dropDown()
  52.         turtle.suckDown()
  53.  
  54.         if turtle.getItemCount(saplingSlot) > 1 then
  55.             break
  56.         end
  57.  
  58.         wait(60)
  59.     end
  60.  
  61.     if not turtle.place() then
  62.         print 'Obstacle in front of Turtle or no ground to plant on'
  63.         waitForKey(keys.enter)
  64.     end
  65. end
  66.  
  67. wait = function(seconds)
  68.     seconds = seconds or 1
  69.  
  70.     local timerId = os.startTimer(seconds)
  71.  
  72.     local _, id
  73.  
  74.     repeat
  75.         _, id = os.pullEvent 'timer'
  76.     until id == timerId
  77. end
  78.  
  79. waitForKey = function(key)
  80.     local _, keyPressed
  81.  
  82.     repeat
  83.         _, keyPressed = os.pullEvent 'key'
  84.  
  85.     until keyPressed == key
  86. end
  87.  
  88. watch = function()
  89.     turtle.select(saplingSlot)
  90.  
  91.     while turtle.compare() do
  92.         wait(1)
  93.     end
  94. end
  95.  
  96. -- Main loop
  97. (function()
  98.     print('Saplings in slot ', saplingSlot)
  99.     print('Bone Meal in slot ', boneMealSlot)
  100.  
  101.     print 'Logs are output to top face'
  102.     print 'Saplings are input from bottom face'
  103.     print 'Press Enter when ready'
  104.  
  105.     waitForKey(keys.enter)
  106.  
  107.     while true do
  108.         plant()
  109.         bone()
  110.         watch()
  111.         chop()
  112.         empty()
  113.     end
  114. end)()
Advertisement
Add Comment
Please, Sign In to add comment