Advertisement
LJack2k

Turtle Chopper

Jan 28th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --pastebin get 02QNcL4m tree
  2. --pastebin run 02QNcL4m
  3.  
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. print("Hurde's Tree Program")
  7. print("modded by LJack2k")
  8. print("")
  9. print("Press ENTER to stop")
  10. print("")
  11. print("First slot: The sapling")
  12. print("Second slot: bonemeal")
  13. print("Fourth slot: The wood type you want")
  14. print("Fifth till sixteen: fuel")
  15.  
  16. function plant()
  17.     turtle.select(1)
  18.     if not turtle.compare() then
  19.         turtle.place()
  20.     end
  21. end
  22.  
  23. function grow()
  24.     turtle.select(4)
  25.     if not turtle.compare() then
  26.         turtle.select(2)
  27.         turtle.place()
  28.     end
  29. end
  30.  
  31. function hak()
  32.     while turtle.detectUp() do
  33.         turtle.digUp()
  34.         turtle.up()
  35.     end
  36.     while not turtle.detectDown() do
  37.         turtle.down()
  38.     end
  39.     turtle.back()
  40. end
  41.  
  42. function fuel()
  43.   if turtle.getFuelLevel() < 100 then
  44.    for i = 5, 16 do -- loop through the slots
  45.     turtle.select(i) -- change to the slot
  46.      if turtle.refuel(0) then -- if it's valid fuel
  47.        local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
  48.        turtle.refuel(halfStack) -- consume half the stack as fuel
  49.      end
  50.    end  
  51.   end
  52. end
  53.  
  54. function program()
  55.   while true do
  56.     fuel()
  57.     plant()
  58.     turtle.select(4)
  59.     if turtle.compare() then
  60.      turtle.dig()
  61.      turtle.forward()
  62.      hak()
  63.     else
  64.      grow()
  65.     end
  66.     sleep(0.5)
  67.   end
  68. end
  69.  
  70. function exitProgram()
  71.   repeat
  72.     local ev, key = os.pullEvent('key')
  73.   until key == keys.enter
  74. end
  75.  
  76. parallel.waitForAny(program, exitProgram)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement