Advertisement
DumperJumper

Chop Script

Feb 9th, 2016
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. --- Chop v.2.0 by DumperJumper(dumperjumper.com) from 09.02.16
  2.  
  3. -- Turtle expects a Chest behind it to put wood in and
  4. -- a chest on the right for Saplings
  5. --
  6. -- Layout:
  7. --  SS        S=Sapling
  8. --  SS        T=Turtle
  9. --   TC       C=Chest
  10. --   C
  11.  
  12. local checkInterval = 20    -- Seconds the Turtle waits before next check if a Tree has grown
  13. local height = 0            -- Needed in Runtime
  14. local tree = true           -- Needed in Runtime
  15. local wait = 0              -- Needed in Runtime
  16.  
  17. local function refuel()
  18.     if turtle.getFuelLevel() < 100 then
  19.         turtle.select(1)
  20.         turtle.refuel(1)
  21.     end
  22. end
  23.  
  24. --MOVEMENT-FUNCTIONS
  25.  
  26. local function forward()
  27.     refuel()
  28.     turtle.forward()
  29. end
  30.  
  31. local function back()
  32.     refuel()
  33.     turtle.back()
  34. end
  35.  
  36. local function down()
  37.     refuel()
  38.     if turtle.detectDown() then
  39.         turtle.digDown()
  40.     end
  41.     turtle.down()
  42.     height = height - 1
  43. end
  44.  
  45. local function up()
  46.     refuel()
  47.     if turtle.detectUp() then
  48.         turtle.digUp()
  49.     end
  50.     turtle.up()
  51.     height = height + 1
  52. end
  53.  
  54. --MOVEMENT-END
  55.  
  56. local function plantSapling()
  57.     if turtle.getItemCount(2) < 1 then
  58.         print("Could not replant Tree, Sapling in Slot 2 are missing")
  59.     else
  60.         turtle.select(2)
  61.         turtle.place()
  62.     end
  63. end
  64.  
  65. local function replant()
  66.     plantSapling()
  67.     turtle.turnLeft()
  68.     back()
  69.     plantSapling()
  70.     turtle.turnRight()
  71.     plantSapling()
  72.     back()
  73.     plantSapling()
  74. end
  75.  
  76. local function manageItems()
  77.     turtle.turnLeft()
  78.     turtle.turnLeft()
  79.    
  80.     for i=3, 16 do
  81.         turtle.select(i)
  82.         if not turtle.compareTo(2) then
  83.             turtle.drop()
  84.         end
  85.     end
  86.    
  87.     turtle.turnLeft()
  88.    
  89.     for i=3, 16 do
  90.         turtle.select(i)
  91.         turtle.drop()
  92.     end
  93.    
  94.     while turtle.getItemCount(2) < 8 do
  95.         turtle.select(2)
  96.         if not turtle.suck() then
  97.             print("NOOOO!!! NO MOAR SAPLINGS! *killed himself*")
  98.             turtle.turnLeft()
  99.             os.shutdown()
  100.         end
  101.     end
  102.    
  103.     turtle.turnLeft()
  104. end
  105.  
  106. while true do
  107.    
  108.     while tree do
  109.         turtle.dig()
  110.         if height == 0 then forward() end
  111.         turtle.dig()
  112.        
  113.         tree = turtle.detectUp()
  114.        
  115.         up()
  116.     end
  117.    
  118.     turtle.turnLeft()
  119.     forward()
  120.     turtle.turnRight()
  121.    
  122.     while height > 0 do
  123.         down()
  124.         turtle.dig()
  125.     end
  126.    
  127.     print("Done felling Tree")
  128.     print("Replanting...")
  129.    
  130.     replant()
  131.    
  132.     manageItems()
  133.    
  134.     print("Waiting for new Tree to grow...")
  135.    
  136.     while not tree do
  137.         os.sleep(checkInterval)
  138.         up()
  139.         tree = turtle.detect()
  140.         down()
  141.         wait = wait + 1
  142.     end
  143.    
  144.     print("WOAH new Tree! That took " .. wait*checkInterval .. " seconds!")
  145.    
  146.     height = 0
  147.     wait = 0
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement