Advertisement
Paradox4624

harvestTree.lua

Jan 20th, 2022
877
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ScanAndDig()
  2.     if turtle.compareUp() == true then
  3.         DigAndMove("up")
  4.     else
  5.         return false
  6.     end
  7.     return true
  8. end
  9.  
  10. function DigAndScan( psDirection )
  11.     local iSleep=0.5
  12.     if psDirection=="up" then
  13.         while turtle.detectUp() do
  14.             if not turtle.digUp() then return false end
  15.             sleep(iSleep)
  16.         end
  17.     elseif psDirection=="down" then
  18.         while turtle.detectDown() do
  19.             if not turtle.digDown() then return false end
  20.             sleep(iSleep)
  21.         end
  22.     else
  23.         while turtle.detect() do
  24.             if not turtle.dig() then return false end
  25.             sleep(iSleep)
  26.         end
  27.     end
  28.     return true
  29. end
  30.  
  31. function DigAndMove(psDirection)
  32.     local bExit=false
  33.     local iSleep=0.5
  34.     while bExit==false do
  35.         if not DigAndScan(psDirection) then
  36.             return false
  37.         end
  38.         if psDirection=="up" then
  39.             if not turtle.up() then
  40.                 turtle.attackUp()
  41.                 sleep(iSleep)
  42.             else
  43.                 bExit=true
  44.             end
  45.         elseif psDirection=="down" then
  46.             if not turtle.down() then
  47.                 turtle.attackDown()
  48.                 sleep(iSleep)
  49.             else
  50.                 bExit=true
  51.             end        
  52.         else
  53.             if not turtle.forward() then
  54.                 turtle.attack()
  55.                 sleep(iSleep)
  56.             else
  57.                 bExit=true
  58.             end        
  59.         end    
  60.     end
  61.     return true
  62. end
  63.  
  64. if turtle.detect() == false and turtle.detectUp() == false then    
  65.     print("No tree detected")
  66.     print("Place turtle under or against tree")
  67.     return false
  68. end
  69.  
  70. if turtle.getItemCount(1) > 0 then
  71.     turtle.select(1)
  72.     turtle.dropUp()
  73.     for q=2,16 do
  74.         turtle.select(q)
  75.         if turtle.getItemCount(q) == 0 then
  76.             turtle.suckUp()
  77.             break
  78.         end
  79.     end
  80. end
  81.  
  82. turtle.select(1)
  83. local iLevel = 0
  84. if turtle.detect() == true then
  85.     DigAndMove("forward")
  86. elseif turtle.detectUp() == true then
  87.     DigAndMove("up")
  88.     iLevel = iLevel + 1
  89. end
  90.  
  91. while ScanAndDig() == true do
  92.     iLevel = iLevel + 1
  93. end
  94.  
  95. for q=(iLevel-1),0,-1 do
  96.     DigAndMove("down")
  97. end
  98.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement