Want more features on Pastebin? Sign Up, it's FREE!
Guest

Logfella

By: npexception on Mar 3rd, 2013  |  syntax: Lua  |  size: 3.63 KB  |  views: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- Set this to the maximumHeight the turtle is allowed to dig up.
  2. -- Lowering this limit is only needed if the turtle
  3. -- does not hit Air while digging up
  4. local maximumHeight = 256
  5.  
  6. -- fuell is taken from a chest to the left and placed in this slot
  7. local fuelSlot = 1
  8. -- bonmeal is taken from a chest to the right and placed in this slot
  9. local bonemealSlot = 2
  10. -- saplings are taken from a chest behind and placed in this slot
  11. local saplingSlot = 3
  12. -- the slot which is compared to the tree place at least one log
  13. -- of the tree you want to cut down in this slot
  14. local compareLogSlot = 4
  15. -- start of the inventory
  16. local inventorySlot = 5
  17.  
  18. local useBoneMeal = true
  19.  
  20. -- called to reduce serverload. If that is no problem for you,
  21. -- just comment out the sleep command
  22. local function rest()
  23.   sleep(0.3)
  24. end
  25.  
  26. -- refuelling will be done, in case the internal fuel reserve is smaller than 500
  27. local function refuel()
  28.   if turtle.getFuelLevel() < 500 then
  29.     turtle.select(fuelSlot)
  30.     turtle.turnLeft()
  31.     turtle.refuel(64)
  32.     turtle.suck()
  33.     if turtle.getFuelLevel() < 2000 then
  34.       print("WAITING FOR FUEL")
  35.       repeat
  36.         turtle.refuel(64)
  37.         turtle.suck()
  38.         sleep(5)
  39.       until turtle.getFuelLevel() >= 2000
  40.     end
  41.     if turtle.getItemCount(fuelSlot) == 0 then
  42.       print("WAITING FOR FUEL")
  43.       repeat
  44.         turtle.suck()
  45.         sleep(5)
  46.       until turtle.getItemCount(fuelSlot) > 0
  47.     end
  48.     turtle.turnRight()
  49.     turtle.select(inventorySlot)
  50.   end
  51. end
  52.  
  53.  
  54. --fells a single collumn of logs
  55. local function fellSingle()
  56.  
  57.   local function goUp()
  58.     rest()
  59.     return turtle.up()
  60.   end
  61.  
  62.   local function goDown()
  63.     rest()
  64.     return turtle.down()
  65.   end
  66.  
  67.   turtle.select(inventorySlot)
  68.   local height = 0
  69.  
  70.   while turtle.digUp() and (height < (maximumHeight-1)) do
  71.     goUp()
  72.     height = height +1
  73.   end
  74.  
  75.   while height > 0 do
  76.     goDown()
  77.     height = height -1
  78.   end
  79. end
  80.  
  81.      
  82.  
  83. local function bonemeal()
  84.   if (not useBoneMeal) then
  85.     return
  86.   end
  87.   print("BONEMEALING")
  88.   turtle.select(bonemealSlot)
  89.   turtle.place()
  90.   if turtle.getItemCount(bonemealSlot)==0 then
  91.     turtle.turnRight()
  92.     turtle.suck()
  93.     if turtle.getItemCount(bonemealSlot) == 0 then
  94.       print("WAITING FOR BONEMEAL")
  95.       repeat
  96.         turtle.suck()
  97.         sleep(5)
  98.       until turtle.getItemCount(bonemealSlot) > 0
  99.     end
  100.     turtle.turnLeft()
  101.   end
  102. end
  103.  
  104. local function main()
  105.   while true do
  106.     if turtle.detect() then
  107.      
  108.       -- check sapling suply
  109.       if turtle.getItemCount(saplingSlot) < 2 then
  110.         turtle.select(saplingSlot)
  111.         turtle.turnLeft()
  112.         turtle.turnLeft()
  113.         turtle.suck()
  114.         if turtle.getItemCount(saplingSlot) < 2 then
  115.           print("WAITING FOR SAPLINGS")
  116.           repeat
  117.             sleep(3)
  118.             turtle.suck()
  119.           until turtle.getItemCount(saplingSlot) >= 2
  120.         end
  121.         turtle.turnLeft()
  122.         turtle.turnLeft()
  123.       end
  124.      
  125.       turtle.select(compareLogSlot)
  126.       while not turtle.compare() do
  127.         bonemeal()
  128.         turtle.select(compareLogSlot)
  129.         rest()
  130.       end
  131.      
  132.       refuel()
  133.  
  134.       turtle.select(inventorySlot)
  135.      
  136.       turtle.dig()
  137.       turtle.forward()
  138.       fellSingle()
  139.      
  140.       turtle.back()
  141.       turtle.select(saplingSlot)
  142.       turtle.place()
  143.      
  144.       for i=inventorySlot,(inventorySlot+11) do
  145.         turtle.select(i)
  146.         turtle.dropDown(turtle.getItemCount(i))
  147.       end
  148.     else
  149.       print("NOTHING THERE.")
  150.       print("PLEASE PLACE A SAPLING IN FRONT.")
  151.     end
  152.     sleep(3)
  153.   end
  154. end
  155.  
  156. main()
clone this paste RAW Paste Data