raniel

Lumberjack Turtle 2.4.2-dev

Apr 2nd, 2015 (edited)
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --"Lumberjack Turtle" v2.4-dev
  2. -- Author: Daniele "Raniel" Sabre
  3.  
  4. -- configuration
  5. woodToUseForFuel = 1 -- higher number = less wood produced but more sustain (set 0 to deactivate)
  6. minFuelRequired = 20
  7. wait = 5
  8. slotWood = 1
  9. slotsBoneMeal = {5, 6, 7, 8}
  10. slotsSaplings = {9, 10, 11, 12}
  11. slotCompare = 16
  12.  
  13. print("Lumberjack started")
  14. print("[hold ctrl+t to terminate]")
  15.  
  16. turtle.select(slotCompare)
  17.  
  18. counterLoop = 0
  19. continue = true
  20.  
  21. while turtle.getFuelLevel() > minFuelRequired and continue do -- if the fuel gets below  the loop stops
  22.     -- increment counter
  23.     counterLoop = counterLoop + 1
  24.    
  25.     -- compare the sapling with the block in front of the turtle
  26.     while turtle.compare() do
  27.         -- bone meal action
  28.         for k, v in pairs(slotsBoneMeal) do
  29.             data = turtle.getItemDetail(v)
  30.            
  31.             if data then
  32.                 if data.name == "minecraft:dye" then
  33.                     turtle.select(v)
  34.                     turtle.place()
  35.                     turtle.select(slotCompare)
  36.                    
  37.                     break
  38.                 end
  39.             end
  40.         end
  41.        
  42.         sleep(wait)
  43.     end
  44.  
  45.     -- init procedure to get wood from tree
  46.     turtle.select(slotWood)
  47.     turtle.dig()
  48.     turtle.forward()
  49.  
  50.     -- the turtle will keep going up until there are no more blocks above him
  51.     while turtle.detectUp() == true  do
  52.         turtle.digUp()
  53.         turtle.up()
  54.     end
  55.  
  56.     -- go down
  57.     while turtle.down() == true do
  58.     end
  59.  
  60.     -- until it hits the ground
  61.     turtle.back()
  62.    
  63.     -- place a new sapling
  64.     found = false
  65.     for k, v in pairs(slotsSaplings) do
  66.         data = turtle.getItemDetail(v)
  67.        
  68.         if data.name == "minecraft:sapling" then
  69.             turtle.select(v)
  70.             turtle.place()
  71.             found = true -- sapling found
  72.            
  73.             break
  74.         end
  75.     end
  76.    
  77.     -- if no sapling are found this is the last cycle
  78.     if not found then
  79.         continue = false
  80.     end
  81.    
  82.     -- select the slot of the wood
  83.     turtle.select(1)
  84.    
  85.     -- use  of wood to refuel turtle
  86.     if woodToUseForFuel > 0 then
  87.         turtle.refuel(woodToUseForFuel)
  88.     end
  89.    
  90.     turtle.dropDown() -- dropDown the remain woods
  91.    
  92.     -- reselect slot compare
  93.     turtle.select(slotCompare)
  94.    
  95.     print("Cycle "..counterLoop.." completed")
  96. end
  97.  
  98. -- if the turtle runs out of fuel, it will print a message and terminate the program
  99. print("Empty fuel or saplings not found")
Add Comment
Please, Sign In to add comment