Advertisement
ArbitraryHubris

Fixed Advanced Felling Turtle

Jun 9th, 2013
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | None | 0 0
  1. -- Advanced 2x2 Tree Felling Program
  2. -- Written by ianJustice
  3. -- Inspired by SethBling
  4. -- Tree detection fixed by ArbitraryHubris
  5.  
  6. -- Place in front of left side of 2x2 tree
  7.  
  8. fuel = 1
  9. saplings = 2
  10. bonemeal = 3
  11. logs = 4
  12.  
  13. -- Place fuel in indicated slot
  14.  
  15. local function checkFuel()
  16.   if turtle.getFuelLevel() < 1 then
  17.     turtle.select(fuel)
  18.     turtle.refuel(1)
  19.   end
  20. end
  21.  
  22. local function digAndMove()
  23.   turtle.dig()
  24.   turtle.attack()
  25.   checkFuel()
  26.   turtle.forward()
  27. end
  28.  
  29. local function digAndMoveUp()
  30.   turtle.digUp()
  31.   checkFuel()
  32.   turtle.up()
  33. end
  34.  
  35. local function turnAround()
  36.   turtle.turnRight()
  37.   turtle.turnRight()
  38. end
  39.  
  40. local function chopUp()
  41.   digAndMove()
  42.   while turtle.digUp() do
  43.     turtle.dig()
  44.     checkFuel()
  45.     turtle.up()
  46.   end
  47.  
  48.   turtle.dig()
  49.   checkFuel()
  50.  
  51.   while turtle.down() do
  52.     checkFuel()
  53.   end
  54. end
  55.  
  56. local function fell()
  57.   chopUp()
  58.   turnAround()
  59.   digAndMove()
  60.   turtle.turnLeft()
  61.   digAndMove()
  62.   turtle.turnLeft()
  63.   chopUp()
  64.   turtle.turnLeft()
  65.   digAndMove()
  66.   turtle.turnLeft()
  67.   digAndMove()
  68.   turnAround()
  69. end
  70.  
  71. local function plant()
  72.   digAndMove()
  73.   digAndMove()
  74.   turtle.turnRight()
  75.   turtle.select(saplings)
  76.   turtle.place()
  77.   turtle.turnRight()
  78.   digAndMove()
  79.   turtle.turnLeft()
  80.   turtle.place()
  81.   turtle.turnLeft()
  82.   turtle.place()
  83.   turnAround()
  84.   digAndMove()
  85.   turnAround()
  86.   turtle.place()
  87.   turtle.select(bonemeal)
  88.   turtle.place()
  89.   turtle.select(saplings)
  90.   seconds = 0
  91.   while turtle.compare() do
  92.     if seconds == 300 then
  93.       turtle.select(bonemeal)
  94.       turtle.place()
  95.       turtle.select(saplings)
  96.       seconds = 0
  97.     end
  98.     seconds = seconds + 1
  99.     os.sleep(1.0)
  100.   end
  101. end
  102.  
  103. local function dropLogs()
  104.   print("Depositing Lumber")
  105.   for i = 5, 16 do
  106.     turtle.select(i)
  107.     if turtle.compareTo(logs) == true then
  108.       turtle.drop()
  109.     end
  110.   end
  111. end
  112.  
  113. local function getCoal()
  114.   if turtle.getItemCount(fuel) < 4 then
  115.     print("Resupplying Coal")
  116.     turtle.select(fuel)
  117.     turtle.suck(16)
  118.   end
  119. end
  120.  
  121. local function getSaplings()
  122.   if turtle.getItemCount(saplings) < 4 then
  123.     print("Resupplying Saplings")
  124.     turtle.select(saplings)
  125.     turtle.suckDown(16)
  126.   end
  127. end
  128.  
  129. local function getBonemeal()
  130.   if turtle.getItemCount(bonemeal) < 4 then
  131.     print("Resupplying Bonemeal")
  132.     turtle.select(bonemeal)
  133.     turtle.suckUp(16)
  134.   end
  135. end
  136.  
  137. while true do
  138.   plant()
  139.   print("Tree successfully planted")
  140.   fell()
  141.   print("Tree successfully felled")
  142.   turtle.turnLeft()
  143.   getCoal()
  144.   turtle.turnLeft()
  145.   dropLogs()
  146.   turnAround()
  147.   getSaplings()
  148.   getBonemeal()
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement