ericek111

Dig

Sep 15th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. -- This Version
  2. -- 0.38 4/10/2014 2:00 AM
  3. -- Changelogs
  4. -- 0.30 Rewrite of Everything
  5. -- 0.31 Extreme Bugs Fixing
  6. -- 0.32 Change Speed of Wide so wont look like program stop but if gravel in way it still works and change speed of Chest Code
  7. -- 0.33 Weird Chest Bug With Gravel Fix. So i change speed of chest to 1 sec i hope that fix it.
  8. -- 0.34 I think i found out want was making items on ground when turtle go back it cant bump it item so it on floor i now fix it.
  9. -- 0.35 Opps Fuel Code was worng
  10. -- 0.36 Fully Fixed Bug Where Items fall on ground it was Length Code
  11. -- 0.37 Change: Until High == Hc To Until High <= Hc so if number is not divible by 3 will stop when it past high limit
  12. -- 0.38 Change: Remove -5 on high so you can have you own hight
  13.  
  14. -- Local Variables
  15. local Wide = 0 -- How Wide
  16. local Wc = 0 -- Wide Counter
  17. local Long = 0 -- How Long
  18. local Lc = 0 -- Long Counter
  19. local High = 0 -- How High
  20. local Hc = 0 -- Hign Counter
  21. local FuelCount = turtle.getItemCount(1) -- Fuel Counter
  22. local FuelCount1 = turtle.getItemCount(2) -- Fuel 2 Counter
  23. local Chest = turtle.getItemCount(3) -- Chest Counter
  24. local TotalBlocks = 0 -- TotalBlocks
  25. local LSorWS = 0 -- Go Left or Go Right This is for Wide Code
  26. local Error = 0 -- Error Code
  27. local Recheck = 0 -- Recheck Code
  28. local NoFuelNeed = 0 -- If computercraft Config Has Fuel Off then this is 1 but not then it is 0
  29. local TotalBlockDone = 0 -- How many Block Mined
  30. local BlockUp = 0 -- Fixing to Chest Probleem and moving probleem
  31.  
  32. -- Local Functions
  33. local function Length1() -- Length Mine
  34. if turtle.detect() then
  35. turtle.dig()
  36. end
  37. if turtle.forward() then
  38. Lc = Lc + 1
  39. TotalBlockDone = TotalBlockDone + 3
  40. print(TotalBlocks - TotalBlockDone)
  41. else
  42. repeat
  43. turtle.dig()
  44. sleep(0.6)
  45. if turtle.forward() then
  46. BlockUp = 0
  47. else
  48. BlockUp = 1
  49. end
  50. until BlockUp == 0
  51. Lc = Lc + 1
  52. TotalBlockDone = TotalBlockDone + 3
  53. print(TotalBlocks - TotalBlockDone)
  54. end
  55. if turtle.detectUp() then
  56. turtle.digUp()
  57. end
  58. if turtle.detectDown() then
  59. turtle.digDown()
  60. end
  61. end
  62.  
  63. local function Wide1() -- Wide Around Right
  64. turtle.turnRight()
  65. if turtle.detect() then
  66. turtle.dig()
  67. sleep(0.6) -- Minor bug fix if there is gravel
  68. end
  69. if turtle.forward() then
  70. else
  71. repeat
  72. turtle.dig()
  73. sleep(0.6)
  74. if turtle.forward() then
  75. BlockUp = 0
  76. else
  77. BlockUp = 1
  78. end
  79. until BlockUp == 0
  80. end
  81. if turtle.detectUp() then
  82. turtle.digUp()
  83. end
  84. if turtle.detectDown() then
  85. turtle.digDown()
  86. end
  87. turtle.turnRight()
  88. LSorWS = 1
  89. Lc = 0
  90. Wc = Wc + 1
  91. end
  92.  
  93. local function Wide2() -- Wide Around Left
  94. turtle.turnLeft()
  95. if turtle.detect() then
  96. turtle.dig()
  97. sleep(0.6) -- Minor bug fix if there is gravel
  98. end
  99. if turtle.forward() then
  100. else
  101. repeat
  102. turtle.dig()
  103. sleep(0.6)
  104. if turtle.forward() then
  105. BlockUp = 0
  106. else
  107. BlockUp = 1
  108. end
  109. until BlockUp == 0
  110. end
  111. if turtle.detectUp() then
  112. turtle.digUp()
  113. end
  114. if turtle.detectDown() then
  115. turtle.digDown()
  116. end
  117. turtle.turnLeft()
  118. LSorWS = 0
  119. Lc = 0
  120. Wc = Wc + 1
  121. end
  122.  
  123. -- High Code
  124. local function High1()
  125. turtle.digDown()
  126. turtle.down()
  127. turtle.digDown()
  128. turtle.down()
  129. turtle.digDown()
  130. turtle.down()
  131. turtle.digDown()
  132. Wc = 0
  133. Lc = 0
  134. Hc = Hc + 3
  135. end
  136.  
  137. -- Checking
  138. local function Check()
  139. if FuelCount == 0 then
  140. print("Turtle has no fuel")
  141. print("put fuel in 1 first and second slot")
  142. Error = 1
  143. else
  144. print("turtle has Fuel")
  145. end
  146. if FuelCount1 == 0 then
  147. print("turtle has no extra fuel but if is short job it okey")
  148. end
  149. if Chest == 0 then
  150. print("No chest in Turtle")
  151. print("Put chest in 3 slot")
  152. Error = 1
  153. else
  154. print("turtle has chest")
  155. end
  156. if Error == 1 then
  157. print("Items are missing please try again")
  158. print("turtle will recheck in 10 sec")
  159. end
  160. end
  161.  
  162. -- Recheck if user forget something turtle will check after 15 sec
  163. local function Recheck()
  164. FuelCount = turtle.getItemCount(1)
  165. FuelCount1 = turtle.getItemCount(2)
  166. Chest = turtle.getItemCount(3)
  167. Error = 0
  168. end
  169.  
  170. -- Refuel
  171. local function Refuel()
  172. if NoFuelNeed == 0 then
  173. if turtle.getFuelLevel() < 300 then
  174. if FuelCount > 10 then
  175. turtle.select(1)
  176. turtle.refuel(10)
  177. FuelCount = FuelCount - 10
  178. elseif FuelCount1 > 10 then
  179. turtle.select(2)
  180. turtle.refuel(10)
  181. FuelCount1 = FuelCount1 - 10
  182. else
  183. print("out of fuel")
  184. os.shutdown()
  185. end
  186. end
  187. end
  188. end
  189.  
  190. local function Chest1()
  191. if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  192. repeat -- The Fix to Gravel Chest Bug. It check if gravel above then it dig three times
  193. turtle.digUp()
  194. sleep(1)
  195. if turtle.detectUp() then
  196. turtle.digUp()
  197. BlockUp = 0
  198. else
  199. BlockUp = 1
  200. end
  201. until BlockUp == 1
  202. turtle.select(3)
  203. turtle.placeUp()
  204. Chest = Chest - 1
  205. for slot = 4, 16 do
  206. turtle.select(slot)
  207. sleep(1.45) -- Small fix for slow pc because i had people problem with this
  208. turtle.dropUp()
  209. end
  210. turtle.select(4)
  211. if Chest == 0 then
  212. print("Out Of Chest")
  213. os.shutdown()
  214. end
  215. end
  216. end
  217.  
  218. local function Start()
  219. turtle.digDown()
  220. turtle.down()
  221. turtle.digDown()
  222. turtle.down()
  223. turtle.digDown()
  224. Wc = 0
  225. Lc = 0
  226. Hc = Hc + 3
  227. end
  228.  
  229. function MainPart()
  230. repeat
  231. repeat
  232. Length1()
  233. Refuel()
  234. Chest1()
  235. if Long == Lc then
  236. if LSorWS == 0 then
  237. Wide1()
  238. else
  239. Wide2()
  240. end
  241. end
  242. until Wide == Wc
  243. repeat
  244. Length1()
  245. Refuel()
  246. Chest1()
  247. until Long == Lc
  248. turtle.turnRight()
  249. LSorWS = 0
  250. High1()
  251. until High <= Hc
  252. print("Turtle Is Done")
  253. end
  254.  
  255. -- Starting
  256. print("Welcome To Excavation Turtle Program")
  257. print("Note: This Program Stop Before Bedrock.")
  258. print("Slot 1: Fuel, Slot 2:Fuel, Slot 3:Chest")
  259. print("Note: if now put item in then it say error just wait for recheck")
  260. print("How long you want")
  261. input = io.read()
  262. Wide = tonumber(input)
  263. Wide = Wide - 1
  264. print("How wide you want")
  265. input2 = io.read()
  266. Long = tonumber(input2)
  267. Long = Long - 1
  268. print("How Deep You Want")
  269. input3 = io.read()
  270. High = tonumber(input3)
  271. print("caluclating")
  272. TotalBlocks = Wide * Long * High
  273. print("Total amount for block to mine is")
  274. print(TotalBlocks)
  275. print("turtle now starting")
  276. if turtle.getFuelLevel() == "unlimited" then
  277. print("your turtle config does need fuel")
  278. NoFuelNeed = 1
  279. elseif turtle.getFuelLevel() < 200 then
  280. turtle.select(1)
  281. turtle.refuel(2)
  282. end
  283. Check()
  284. if Error == 1 then
  285. repeat
  286. sleep(10)
  287. Recheck()
  288. Check()
  289. until Error == 0
  290. end
  291. Start()
  292. MainPart()
Advertisement
Add Comment
Please, Sign In to add comment