Advertisement
xmarks

Harvest

May 18th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.58 KB | None | 0 0
  1. -- Made by Xmarks
  2. -- https://www.youtube.com/channel/UCA6oAnFqdDcc0sa6H8G5DSA
  3. -- Program originally designed to Chop-down a 2x2 Tree, like RedWood
  4. -- Redundancy digging going down for trees sprouting additional
  5. -- wood-blocks around the main 2x2 area, like Jungle Trees
  6. -- Program Digs everything in a 10x10 area going down
  7. -- Returns to Origin, and drops items in slots 2-to-14
  8. -- *****************************************
  9. -- Fuel goes to 1
  10. -- Wood Block for comparison goes to slot 15
  11. -- Tree-sapplings go to slot 16
  12. -- *****************************************
  13.  
  14.  
  15. local function checkFuel()
  16.     if turtle.getFuelLevel() < 20 then
  17.         turtle.select(1)
  18.         turtle.refuel(1)
  19.     end
  20. end
  21.  
  22. local function move()
  23.     checkFuel()
  24.     local moved = 0
  25.     while moved < 1 do
  26.         if turtle.forward() then
  27.             moved = moved + 1
  28.         elseif turtle.detect() then
  29.             turtle.dig()
  30.             if turtle.forward() then
  31.                 moved = moved + 1
  32.             end
  33.         elseif turtle.attack() then
  34.             if turtle.forward() then
  35.                 moved = moved + 1
  36.             end
  37.         end
  38.     end
  39. end
  40.  
  41. local function moveUp()
  42.     checkFuel()
  43.     local moved = 0
  44.     while moved < 1 do
  45.         if turtle.up() then
  46.             moved = moved + 1
  47.         elseif turtle.detectUp() then
  48.             turtle.digUp()
  49.             if turtle.up() then
  50.                 moved = moved + 1
  51.             end
  52.         elseif turtle.attackUp() then
  53.             if turtle.up() then
  54.                 moved = moved + 1
  55.             end
  56.         end
  57.     end
  58. end
  59.  
  60. local function moveDown()
  61.     checkFuel()
  62.     local moved = 0
  63.     while moved < 1 do
  64.         if turtle.down() then
  65.             moved = moved + 1
  66.         elseif turtle.detectDown() then
  67.             turtle.digDown()
  68.             if turtle.down() then
  69.                 moved = moved + 1
  70.             end
  71.         elseif turtle.attackDown() then
  72.             if turtle.down() then
  73.                 moved = moved + 1
  74.             end
  75.         end
  76.     end
  77. end
  78.  
  79. local height = 0
  80.  
  81. local function fellUp()
  82.     move()
  83.     print('digging upwards until no more blocks detected')
  84.     while turtle.detectUp() do
  85.         turtle.dig()
  86.         moveUp()
  87.         height = height + 1
  88.     end
  89.     print('Dug up to a Height of ' .. height)
  90. end
  91.  
  92. local heightDown = 0
  93.  
  94. local function obliterate()
  95.     print('Going top-left corner of a 10 by 10 area')
  96.     for i = 0,4 do
  97.         move()
  98.     end
  99.     turtle.turnLeft()
  100.     for i = 0,3 do
  101.         move()
  102.     end
  103.     print('Digging everything in a 10 by 10 area, until reached initial location - 1')
  104.     while heightDown < height do
  105.         print('Digging Down. Current heightDown is ' .. heightDown)
  106.         if heightDown % 2 == 0 then
  107.             print('Digging area from top-left corner to bottom-left corner')
  108.             turtle.turnLeft()
  109.             turtle.turnLeft()
  110.             for y = 0,9 do
  111.                 if y % 2 == 0 then
  112.                     for xright = 0,8 do
  113.                         move()
  114.                     end
  115.                     turtle.turnRight()
  116.                     move()
  117.                     turtle.turnRight()
  118.                 elseif y % 2 == 1 then
  119.                     for xleft = 0,8 do
  120.                         move()
  121.                     end
  122.                     turtle.turnLeft()
  123.                     move()
  124.                     turtle.turnLeft()
  125.                 end
  126.             end
  127.             turtle.turnLeft()
  128.             move()
  129.             turtle.turnLeft()
  130.         elseif heightDown % 2 == 1 then
  131.             print('Digging Area from bottom-left corner to top-left corner')
  132.             turtle.turnRight()
  133.             turtle.turnRight()
  134.             for y = 0,9 do
  135.                 if y % 2 == 0 then
  136.                     for xright = 0,8 do
  137.                         move()
  138.                     end
  139.                     turtle.turnLeft()
  140.                     move()
  141.                     turtle.turnLeft()
  142.                 elseif y % 2 == 1 then
  143.                     for xleft = 0,8 do
  144.                         move()
  145.                     end
  146.                     turtle.turnRight()
  147.                     move()
  148.                     turtle.turnRight()
  149.                 end
  150.             end
  151.             turtle.turnRight()
  152.             move()
  153.             turtle.turnRight()
  154.         end
  155.         heightDown = heightDown + 1
  156.         moveDown()
  157.     end
  158.    
  159.     print(heightDown)
  160.    
  161.     if heightDown % 2 == 0 then
  162.         print('Rearched the end of digging. Starting to the top-left corner, going back to Origin')
  163.         turtle.turnLeft()
  164.         for originy = 0,4 do
  165.             move()
  166.         end
  167.         turtle.turnLeft()
  168.         for originx = 0,4 do
  169.             move()
  170.         end
  171.         turtle.turnLeft()
  172.         turtle.dig()
  173.     elseif heightDown % 2 == 1 then
  174.         print('Reached the end of digging. Starting from the bottom-left corner, going back to Origin')
  175.         turtle.turnRight()
  176.         for originy = 0,3 do
  177.             move()
  178.         end
  179.         turtle.turnRight()
  180.         for originx = 0,4 do
  181.             move()
  182.         end
  183.         turtle.turnLeft()
  184.         turtle.dig()
  185.     end
  186. end
  187.  
  188. local function replant()
  189.     print('Replanting seeds')
  190.     turtle.select(16)
  191.     turtle.place()
  192.     turtle.turnLeft()
  193.     move()
  194.     turtle.turnRight()
  195.     turtle.place()
  196.     turtle.turnRight()
  197.     turtle.place()
  198.     turtle.turnRight()
  199.     move()
  200.     print('Dropping all blocks in slots 2-to-14 into the chest')
  201.     for slot = 2,14 do
  202.         turtle.select(slot)
  203.         turtle.drop()
  204.     end
  205.     turtle.turnLeft()
  206.     turtle.turnLeft()
  207.     turtle.select(16)
  208.     turtle.place()
  209. end
  210.  
  211. while true do
  212.     turtle.select(15)
  213.     if turtle.compare() then
  214.         fellUp()
  215.         obliterate()
  216.         replant()
  217.         -- Reset Heights
  218.         height = 0
  219.         heightDown = 0
  220.     else
  221.         turtle.suck()
  222.     end
  223. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement