Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. -- Functions
  2. function distance () return long + haut + pitPos - 2 end
  3.  
  4. function uTurn ()
  5.  
  6. checkMode = false
  7.  
  8. breakRoutine()
  9. if haut%2 == 1 then turtle.turnRight() else turtle.turnLeft() end
  10.  
  11. haut = haut + 1
  12. move(true)
  13.  
  14. if haut%2 == 0 then turtle.turnRight() else turtle.turnLeft() end
  15.  
  16. checkMode = true
  17.  
  18. end
  19.  
  20. function mouvementLine ( _length, _state )
  21.  
  22. for i = 1, _length, 1 do
  23. if _state then breakRoutine() end
  24. move(_state)
  25. if _state then if haut%2 == 1 then long = long + 1 else long = long - 1 end end
  26. end
  27.  
  28. end
  29.  
  30. function breakRoutine ()
  31.  
  32. repeat
  33. turtle.digUp()
  34. checkItem()
  35. until not turtle.detectUp()
  36.  
  37. turtle.digDown()
  38. checkItem()
  39.  
  40.  
  41. end
  42.  
  43. function move ( _state )
  44.  
  45. if _state then
  46. repeat
  47. turtle.dig()
  48. checkItem()
  49. until not turtle.detect()
  50.  
  51. print("l: " .. long .. " h: " .. haut .. " p: " .. pitPos .. " d: " .. distance() .. " f: " .. turtle.getFuelLevel())
  52. if turtle.getFuelLevel() < 3 * distance() + 5 then refuel() end
  53. if turtle.getFuelLevel() < 3 * distance() + 5 and checkMode then backHome(0) end
  54. end
  55.  
  56. turtle.forward()
  57.  
  58. end
  59.  
  60. function checkItem ()
  61.  
  62. Items.dropIfItems(unwantedBlocks, 1)
  63. local result = Items.moveItem(1)
  64.  
  65. if not result then refuel() end
  66.  
  67. result = Items.moveItem(1)
  68. if checkMode then if not result then backHome(1) end end
  69.  
  70. end
  71.  
  72. function backHome ( _state )
  73.  
  74. print("Come from: " .. long .. " " .. haut .. " " .. pitPos)
  75.  
  76. goUp()
  77.  
  78. if haut%2 == 1 then turtle.turnLeft()
  79. elseif haut%2 == 0 then turtle.turnRight()
  80. end
  81.  
  82. mouvementLine(haut - 1, false)
  83. turtle.turnLeft()
  84. mouvementLine(long - 1, false)
  85. turtle.turnLeft()
  86. if _state == 0 then print("No fuel left!")
  87. elseif _state == 1 then print("Turtle is full!")
  88. elseif _state == 2 then print("Job done!")
  89. elseif _state == 3 then print("Floor done!") long, haut = 1, 1
  90. end
  91.  
  92. emptyInv(_state)
  93.  
  94. end
  95.  
  96. function refuel ()
  97.  
  98. local slot = Items.checkForItem("minecraft:coal", 0, false)
  99. if slot ~= 0 then turtle.select(slot) turtle.refuel() end
  100. turtle.select(1)
  101.  
  102. end
  103.  
  104. function emptyInv ( _state )
  105.  
  106. turtle.turnLeft() turtle.turnLeft()
  107. for i = 1, 16, 1 do
  108. turtle.select(i)
  109. turtle.drop()
  110. end
  111. turtle.select(1)
  112. turtle.turnLeft() turtle.turnLeft()
  113.  
  114. if _state == 0 then
  115. print("Need fuel ...")
  116. repeat refuel()
  117. until turtle.getFuelLevel() > 3 * distance() + 5
  118. goBack()
  119. elseif _state == 1 or _state == 3 then goBack()
  120. elseif _state == 2 then error()
  121. end
  122.  
  123. end
  124.  
  125. function goBack ()
  126.  
  127. turtle.turnLeft()
  128. mouvementLine(long - 1, false)
  129. turtle.turnRight()
  130. mouvementLine(haut - 1, false)
  131.  
  132. if haut%2 == 0 then turtle.turnRight()
  133. elseif haut%2 == 1 then turtle.turnLeft()
  134. end
  135.  
  136. goBackDown()
  137.  
  138. end
  139.  
  140. function goDown ()
  141.  
  142. checkMode = false
  143.  
  144. for i = 1, 3, 1 do
  145. turtle.digDown()
  146. checkItem()
  147. if turtle.detectDown() then bedrockFound = true print("Bedrock found") return end
  148. turtle.down()
  149. pitPos = pitPos + 1
  150. end
  151.  
  152. checkTrue = false
  153.  
  154. end
  155.  
  156. function goUp ()
  157.  
  158. for i = 1, pitPos, 1 do turtle.up() end
  159.  
  160. end
  161.  
  162. function goBackDown ()
  163.  
  164. for i = 1, pitPos, 1 do turtle.down() end
  165.  
  166. end
  167.  
  168. function usage ()
  169.  
  170. print("Usage:. \nMining <side> <depth> <pit mode (boolean)> [old coordonates]")
  171.  
  172. end
  173. -- Variables
  174. side = 5
  175. depth = 5
  176. long = 1
  177. haut = 1
  178. pitMode = false
  179. pitPos = 0
  180. checkMode = true
  181. bedrockFound = false
  182. unwantedBlocks = {"minecraft:cobblestone", "minecraft:dirt", "minecraft:gravel", "chisel:marble", "chisel:andesite", "chisel:granite", "chisel:diorite", "chisel:limestone"}
  183.  
  184. -- Main
  185. os.loadAPI("Items")
  186.  
  187. local tArgs = { ... }
  188. if #tArgs ~= 3 or #tArgs ~= 6 then usage() return end
  189.  
  190. side = tonumber(tArgs[1]) - 1
  191. depth = tonumber(tArgs[2])
  192. pitMode = (tArgs[3] == "true")
  193.  
  194. if side == nil or depth == nil then usage() return end
  195.  
  196. if #tArgs == 6 then
  197. long = tonumber(tArgs[4])
  198. haut = tonumber(tArgs[5])
  199. pitPos = tonumber(tArgs[6])
  200. if long == nil or haut == nil or pitPos == nil then usage() return end
  201. if long > side - 1 or haut > depth then usage() return end
  202. goBack()
  203. local rest
  204. if haut%2 == 0 then rest = long else rest = side - long + 1 end
  205. mouvementLine(,true)
  206. uTurn()
  207. end
  208.  
  209.  
  210. turtle.select(1)
  211. turtle.turnLeft()
  212.  
  213. if depth == 0 then
  214. while true do
  215. mouvementLine(side, true)
  216. uTurn()
  217. end
  218. else
  219. if not pitMode then
  220. while haut < depth do
  221. mouvementLine(side, true)
  222. uTurn()
  223. end
  224. mouvementLine(side, true)
  225. breakRoutine()
  226. backHome(2)
  227.  
  228. else
  229.  
  230. bedrockFound = false
  231. repeat
  232. while haut < depth do
  233. mouvementLine(side, true)
  234. uTurn()
  235. end
  236. mouvementLine(side, true)
  237. breakRoutine()
  238. backHome(3)
  239.  
  240. goDown()
  241.  
  242. until bedrockFound
  243. backHome(2)
  244. end
  245. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement