Advertisement
Clor

CC_wood

Jan 8th, 2015
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.10 KB | None | 0 0
  1. --Var
  2. Xn = 0
  3. Yn = 0
  4. Zn = 0
  5. nSide = 0
  6. Xc,Xt,Yc,Yt,Zc,Zt = 0,0,0,0,0,0
  7.  
  8. --Function
  9.  
  10. function Left()
  11. turtle.turnLeft()
  12. nSide = nSide+1
  13. end
  14.  
  15. function Right()
  16. turtle.turnRight()
  17. nSide = nSide-1
  18. end
  19.  
  20. function Around()
  21. turtle.turnRight()
  22. turtle.turnRight()
  23. nSide = nSide-2
  24. end
  25.  
  26. function forward()
  27. local n = 0
  28. while true do
  29. if turtle.forward() then
  30. nSide = nSide%4
  31. if nSide == 0 then Xt = Xt+1
  32. elseif nSide == 1 then Zt = Zt+1
  33. elseif nSide == 2 then Xt = Xt-1
  34. elseif nSide == 3 then Zt = Zt-1
  35. end
  36. return true
  37. else
  38.     if turtle.detect() then turtle.dig() else turtle.attack() end
  39. n = n+1
  40. end
  41. if n == 20 then print("no run forward, program stop!") os.exit() end
  42. end
  43. end
  44.  
  45. function up()
  46. local n = 0
  47. while true do
  48. if turtle.up() then Yt = Yt+1 return true else
  49.     if turtle.detectUp() then turtle.digUp() else turtle.attackUp() end
  50. n = n+1
  51. end
  52. if n == 20 then print("no run up, program stop!") os.exit() end
  53. end
  54. end
  55.  
  56. function down()
  57. local n = 0
  58. while true do
  59. if turtle.down() then Yt = Yt-1 return true else
  60.     if turtle.detectDown() then turtle.digDown() else turtle.attackDown() end
  61. n = n+1
  62. end
  63. if n == 20 then print("no run down, program stop!") os.exit() end
  64. end
  65. end
  66.  
  67.  
  68. function sapling()
  69. turtle.select(2)
  70. up()
  71. forward()
  72. turtle.placeDown()
  73. forward()
  74. turtle.placeDown()
  75. Left()
  76. forward()
  77. turtle.placeDown()
  78. Left()
  79. forward()
  80. turtle.placeDown()
  81. forward()
  82. Left()
  83. forward()
  84. Left()
  85. down()
  86. end
  87.  
  88. function wood()
  89. local n=0
  90. turtle.dig()
  91. forward()
  92. while true do
  93.   if turtle.detectUp() then
  94.   n=n+1
  95.   turtle.dig()
  96.   turtle.digUp()
  97.   up()
  98.   else break end
  99. end
  100. turtle.dig()
  101. Left()
  102. turtle.dig()
  103. forward()
  104. Right()
  105. for i=1,n do
  106. turtle.dig()
  107. turtle.digDown()
  108. down()
  109. end
  110. turtle.dig()
  111. Right()
  112. forward()
  113. Right()
  114. forward()
  115. Around()
  116. end
  117.  
  118.  
  119. function detect_wood()
  120.  if turtle.detect() then
  121.   up()
  122.    if turtle.detect() then
  123.     down()
  124.     return "wood"
  125.    else
  126.     down()
  127.     return "sapling"
  128.    end
  129.  else
  130.   return "clear"
  131.  end
  132. end
  133.  
  134. function run_a()
  135. Left()
  136. for i=1,10 do
  137. forward()
  138. end
  139. Right()
  140. end
  141.  
  142. function run_b()
  143. Right()
  144. forward()
  145. Right()
  146. for i=1,10 do
  147. forward()
  148. end
  149. Right()
  150. forward()
  151. Right()
  152. end
  153.  
  154. function run_c()
  155. Right()
  156. for i=1,10 do
  157. forward()
  158. end
  159. Left()
  160. end
  161.  
  162. function run_d()
  163. Left()
  164. forward()
  165. forward()
  166. Right()
  167. for i=1,10 do
  168. forward()
  169. end
  170. Right()
  171. forward()
  172. forward()
  173. Left()
  174. end
  175.  
  176. function bksp(area)
  177. if area == "chest" then
  178.   Left()
  179.   forward()
  180.   forward()
  181.   Right()
  182.  Xc=Xt Yc=Yt Zc=Zt
  183.       while Zn~=Zt do
  184.       forward()
  185.       end
  186.     Right()  
  187.       while Xn~=Xt do
  188.       forward()
  189.       end      
  190. elseif area == "wood" then
  191.     Around()
  192.       while Xc~=Xt do
  193.       forward()
  194.       end
  195.    Left()
  196.       while Zc~=Zt do
  197.       forward()
  198.       end
  199.    Left()
  200.    forward()
  201.    forward()
  202.    Left()
  203. end
  204. end
  205.  
  206. function chest()
  207.     for i=3,16 do
  208.   turtle.select(i)
  209.   if (turtle.getItemCount(i) ~= 0) and (not turtle.drop(64)) then Around() print("chest full, stop!") os.exit() end
  210.   end
  211.   Right()
  212.   turtle.select(2)
  213.    for i=1,5 do
  214.    if turtle.getItemCount(2) ~= 64 then turtle.suck(turtle.getItemSpace(2)) else break end
  215.   end
  216.   Left()
  217.   if not count_sapl() then return "sapling" end
  218.   return true
  219. end
  220.  
  221. function count_sapl()
  222. if turtle.getItemCount(2) < 5 then return false else return true end
  223. end
  224.  
  225. function full()
  226. if turtle.getItemCount(13) == 0  then return true else return false end
  227. end
  228.  
  229. function energy()
  230. sleep(0)
  231. end
  232.  
  233. -- MultiFunction
  234. function woodAll()
  235.   while true do
  236.        if count_sapl() and full() then
  237.            detect = detect_wood()
  238.            if detect == "clear" then sapling() break
  239.            elseif detect == "wood" then wood() sapling() break  
  240.            elseif detect == "sapling" then break end
  241.    else
  242.     bksp("chest")
  243.  _exit = chest()
  244.       if "sapling" ==_exit then Around() print("not sapling, stop!") os.exit()
  245.    end
  246.  bksp("wood")
  247.   end
  248.  end
  249. end
  250.  
  251. --Programs:
  252.  
  253. Right()
  254. while true do
  255.   for i=1,4 do
  256.    woodAll()
  257.    run_a()
  258.    end
  259. woodAll()
  260. run_b()
  261. for i=1,4 do
  262.    woodAll()
  263.    run_c()
  264.   end
  265. woodAll()
  266. run_d()
  267. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement