Advertisement
MikiCZEch

Wood cutter (CC Turtle)

Feb 21st, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. temptree = 0 -- Pocet pokacenych stromu
  2. y = 1 -- pozice Y
  3. sfuel = 50 -- start fuel
  4.  
  5. function unload() --unload
  6.     for n = 3,16 do
  7.         local nCount = turtle.getItemCount(n)
  8.         if nCount > 0 then
  9.             turtle.select(n)
  10.             turtle.dropDown()
  11.         end
  12.     end
  13.     turtle.select(1)
  14. end
  15.    
  16. function compare() -- compare block / turn left
  17.     turtle.select(1)
  18.     while not turtle.compare() do
  19.         turtle.turnLeft()
  20.         sapling() -- check/place sapling
  21.         os.sleep(5)
  22.     end
  23. end
  24.  
  25. function refueltest() -- check fuel in slot 1
  26.     if turtle.getItemCount(1) == 0 then
  27.         print("Get fuel to slot 1 and press enter")
  28.         event, enter = os.pullEvent("key")
  29.         return
  30.     else
  31.         refueling()
  32.     end
  33. end
  34.  
  35. function refueling() -- refueling to start fuel level
  36.     while turtle.getFuelLevel() < sfuel do
  37.         turtle.select(1)
  38.         os.sleep(0.2)
  39.         turtle.refuel(1)
  40.         os.sleep(0.2)
  41.     end
  42. end
  43.  
  44. function moveup() -- move up
  45.     while not turtle.up() do
  46.     turtle.digUp()
  47.     os.sleep(0.5)
  48.     end
  49. end
  50.  
  51. function compareup() -- compare/move up
  52.     refueltest()
  53.     turtle.select(1)
  54.     while turtle.compareUp() do
  55.         moveup()
  56.         y = y + 1
  57.         os.sleep(0.5)
  58.     end
  59. end
  60.  
  61. function movedown() -- move down
  62.     while not turtle.down() do
  63.     turtle.digDown()
  64.     os.sleep(0.5)
  65.     end
  66. end
  67.  
  68. function moveback() -- move back
  69.     while y > 1 do
  70.     movedown()
  71.     y = y - 1
  72.     os.sleep(0.2)
  73.     end
  74. end
  75.  
  76. function sapling() -- place sapling
  77.     turtle.select(16)
  78.     if turtle.compare() == true then
  79.         turtle.select(2)
  80.         turtle.place()
  81.         turtle.select(1)
  82.         os.sleep(0.2)
  83.     else
  84.         turtle.select(1)
  85.         os.sleep(0.2)
  86.     end
  87. end
  88.  
  89. function cutter() -- PROGRAM CORE
  90.     if turtle.getItemCount(2) == 0 then -- check sapling slot before start
  91.         print("Cutted trees: "..temptree)
  92.         print("Get sapling to slot 2 and press key or press key to exit")
  93.         print("or press key to exit")
  94.         event, enter = os.pullEvent("key")
  95.         if turtle.getItemCount(2) == 0 then
  96.             os.reboot()
  97.             else
  98.             print("Continue cutting")
  99.         end
  100.         return
  101.     end
  102.  
  103.     compare() -- Wait for tree
  104.  
  105.     if turtle.getFuelLevel() == 0 then
  106.     refueltest()
  107.     end
  108.  
  109.     while not turtle.forward() do -- Try forward
  110.     turtle.dig()
  111.     os.sleep(0.5)
  112.     end
  113.  
  114.     compareup() -- cutting tree
  115.     moveback() -- move down
  116.    
  117.     while not turtle.back() do -- move start position
  118.         turtle.turnLeft()
  119.         turtle.turnLeft()
  120.         os.sleep(0.2)
  121.         turtle.dig()
  122.         turtle.turnLeft()
  123.         turtle.turnLeft()
  124.         os.sleep(0.2)
  125.     end
  126.    
  127.     sapling() -- check/place sapling
  128.     unload() -- unload
  129.     temptree = temptree + 1 -- counting cutted tree
  130. end
  131.  
  132. ---------------------------------------------------------------
  133. ---------------------------------------------------------------
  134. print("Place chest under turtle, get to slot 1 a few fuel & slot 2 a few sapling's")
  135.  
  136. while true do
  137.     cutter()
  138. end
  139.  
  140. print("Pocet pokacenych stromu: "..temptree)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement