Clor

wood_CC_refuel

Dec 25th, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.24 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.   if((turtle.getFuelLimit() - turtle.getFuelLevel())/80 >= 64) then
  217.   turtle.select(15)
  218.   turtle.suckDown(64)
  219.   turtle.refuel(54)
  220.   end
  221.   Left()
  222.   if not count_sapl() then return "sapling" end
  223.   return true
  224. end
  225.  
  226. function count_sapl()
  227. if turtle.getItemCount(2) < 5 then return false else return true end
  228. end
  229.  
  230. function full()
  231. if turtle.getItemCount(13) == 0  then return true else return false end
  232. end
  233.  
  234. function energy()
  235. sleep(0)
  236. end
  237.  
  238. -- MultiFunction
  239. function woodAll()
  240.   while true do
  241.        if count_sapl() and full() then
  242.            detect = detect_wood()
  243.            if detect == "clear" then sapling() break
  244.            elseif detect == "wood" then wood() sapling() break  
  245.            elseif detect == "sapling" then break end
  246.    else
  247.     bksp("chest")
  248.  _exit = chest()
  249.       if "sapling" ==_exit then Around() print("not sapling, stop!") os.exit()
  250.    end
  251.  bksp("wood")
  252.   end
  253.  end
  254. end
  255.  
  256. --Programs:
  257.  
  258. Right()
  259. while true do
  260.   for i=1,4 do
  261.    woodAll()
  262.    run_a()
  263.    end
  264. woodAll()
  265. run_b()
  266. for i=1,4 do
  267.    woodAll()
  268.    run_c()
  269.   end
  270. woodAll()
  271. run_d()
  272. end
Advertisement
Add Comment
Please, Sign In to add comment