Advertisement
CaptainSpaceCat

Recursive Tree Miner

Dec 30th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local acceptedItems = {
  2.     "Natura:Dark Tree",
  3.     "Natura:Dark Leaves",
  4.     "minecraft:log",
  5.     "minecraft:leaves"
  6. }
  7.  
  8. local plantItem = "minecraft:sapling"
  9. local fuelItem = "minecraft:log"
  10.  
  11. function checkData(d)
  12.     for _, v in ipairs(acceptedItems) do
  13.         if d.name == v then
  14.             return true
  15.         end
  16.     end
  17.     return false
  18. end
  19.  
  20. function checkRefuel()
  21.     if turtle.getFuelLevel() < 100 then
  22.         reorganize()
  23.         turtle.select(16)
  24.         turtle.refuel(turtle.getItemCount(16))
  25.     end
  26. end
  27.  
  28. function breakTree()
  29.     checkRefuel()
  30.     local block, data = turtle.inspect()
  31.     if block and checkData(data) then
  32.         turtle.dig()
  33.         turtle.suck()
  34.         turtle.forward()
  35.         breakTree()
  36.         turtle.back()
  37.     end
  38.     local block, data = turtle.inspectUp()
  39.     if block and checkData(data) then
  40.         turtle.digUp()
  41.         turtle.suckUp()
  42.         turtle.up()
  43.         breakTree()
  44.         turtle.down()
  45.     end
  46.     local block, data = turtle.inspectDown()
  47.     if block and checkData(data) then
  48.         turtle.digDown()
  49.         turtle.suckDown()
  50.         turtle.down()
  51.         breakTree()
  52.         turtle.up()
  53.     end
  54.     turtle.turnLeft()
  55.     local block, data = turtle.inspect()
  56.     if block and checkData(data) then
  57.         turtle.dig()
  58.         turtle.suck()
  59.         turtle.forward()
  60.         breakTree()
  61.         turtle.back()
  62.     end
  63.     turtle.turnRight()
  64.     turtle.turnRight()
  65.     local block, data = turtle.inspect()
  66.     if block and checkData(data) then
  67.         turtle.dig()
  68.         turtle.suck()
  69.         turtle.forward()
  70.         breakTree()
  71.         turtle.back()
  72.     end
  73.     turtle.turnLeft()
  74. end
  75.  
  76. function plantSapling()
  77.     turtle.select(1)
  78.     turtle.place()
  79. end
  80.  
  81. function reorganize()
  82.     for i = 1, 16 do
  83.         turtle.select(i)
  84.         local data = turtle.getItemDetail()
  85.         if data and data.name == plantItem then
  86.             turtle.transferTo(1)
  87.         elseif data and data.name == fuelItem then
  88.             turtle.transferTo(16)
  89.         end
  90.     end
  91. end
  92.  
  93. while true do
  94.     local block, data = turtle.inspect()
  95.     if block and checkData(data) then
  96.         breakTree()
  97.         reorganize()
  98.         plantSapling()
  99.     end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement