Guest User

Minecraft Turtle mining script

a guest
Aug 3rd, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.42 KB | None | 0 0
  1. --[[
  2. Version
  3. 0.07 1/2/2015 1:41 PM
  4. Changelog
  5. 0.01 - Starting Of Rewriting
  6. 0.02 - More Writing
  7. 0.03 - Adding Fuel Code
  8. 0.04 - Small but many program error fixed
  9. 0.05 - Fully Test
  10. 0.06 - Fixing Minor Bug when add 3 to deep because firstdig had no 3 add to deepcount
  11. 0.07 - Fixing High Error
  12. --]]
  13.  
  14. -- Local Variables
  15. -- Starting
  16. local wide = 0
  17. local wideCount = 0
  18. local long = 0
  19. local longCount = 0
  20. local deep = 0
  21. local deepCount = 0
  22. local totalBlocks = 0
  23. local coalNeeded = 0
  24. local corrent = n
  25. -- Inventory This Will Check At Start Code
  26. local chest = 0
  27. local fuelCount = 0
  28. local fuelCount1 = 0
  29. local noFuelNeed = 0 -- if Config has fuel no need on
  30. local error = 0 -- Error Code
  31. local reCheck = 0 -- Recheck Code
  32. -- Others
  33. local totalBlocks = 0
  34. local totalBlockDone = 0 -- How many Block Mined
  35. local LSorWS = 0 -- Go Left or Go Right This is for Wide Code
  36. local ALorAR = 0 -- align left Or align Right
  37. local processRaw = 0
  38. local process = 0
  39. local enderChest = 0 -- TODO
  40. local blockUp = 0 -- Fixing to Chest Probleem and moving probleem
  41. local processRaw = 0
  42. local process = 0
  43.  
  44. -- Checking
  45. local function check()
  46. if noFuelNeed == 0 then
  47. if fuelCount == 0 then
  48. print("Turtle has no fuel")
  49. print("Put fuel in Second and Thrid slot")
  50. error = 1
  51. else
  52. print("Turtle has Fuel")
  53. end
  54. if fuelCount1 == 0 then
  55. print("Turtle has no extra fuel but if is short job it okey")
  56. end
  57. end
  58. if chest == 0 then
  59. print("No chest in Turtle")
  60. print("Put chest in 1 slot")
  61. error = 1
  62. else
  63. print("Turtle has chest")
  64. end
  65. if error == 1 then
  66. print("Items are missing please try again")
  67. print("Turtle will recheck in 8 sec")
  68. end
  69. end
  70.  
  71. -- Recheck if user forget something turtle will check after 6 sec
  72. local function reCheck()
  73. chest = turtle.getItemCount(1)
  74. fuelCount = turtle.getItemCount(2)
  75. fuelCount1 = turtle.getItemCount(3)
  76. error = 0
  77. end
  78.  
  79. local function chestDump()
  80. if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  81. repeat -- The Fix to Gravel Chest Bug. It check if gravel above then it dig till it gone
  82. turtle.digUp()
  83. sleep(0.6)
  84. if turtle.detectUp() then
  85. turtle.digUp()
  86. blockUp = 1
  87. else
  88. blockUp = 0
  89. end
  90. until blockUp == 0
  91. turtle.select(1)
  92. turtle.placeUp()
  93. chest = chest - 1
  94. for slot = 4, 16 do
  95. turtle.select(slot)
  96. sleep(0.6) -- Small fix for slow pc because i had people problem with this
  97. turtle.dropUp()
  98. end
  99. turtle.select(4)
  100. if Chest == 0 then
  101. print("Out Of Chest")
  102. os.shutdown()
  103. end
  104. end
  105. end
  106.  
  107. -- Refuel
  108. local function refuel()
  109. if noFuelNeed == 0 then
  110. repeat
  111. if turtle.getFuelLevel() < 160 then
  112. if fuelCount > 0 then
  113. turtle.select(2)
  114. turtle.refuel(1)
  115. fuelCount = fuelCount - 1
  116. elseif fuelCount1 > 0 then
  117. turtle.select(3)
  118. turtle.refuel(1)
  119. fuelCount1 = fuelCount1 - 1
  120. else
  121. print("out of fuel")
  122. os.shutdown()
  123. end
  124. end
  125. until turtle.getFuelLevel() >= 160
  126. end
  127. end
  128.  
  129. local function mineLong()
  130. if turtle.detect() then
  131. turtle.dig()
  132. end
  133. if turtle.forward() then
  134. longCount = longCount + 1
  135. else
  136. repeat
  137. turtle.dig()
  138. sleep(0.6)
  139. if turtle.forward() then
  140. blockUp = 0
  141. else
  142. blockUp = 1
  143. end
  144. until blockUp == 0
  145. longCount = longCount + 1
  146. print(totalBlocks - totalBlockDone)
  147. end
  148. if turtle.detectUp() then
  149. turtle.digUp()
  150. end
  151. if turtle.detectDown() then
  152. turtle.digDown()
  153. end
  154. totalBlockDone = totalBlockDone + 3
  155. end
  156.  
  157. local function wideMineLeft() -- TODO
  158. turtle.turnLeft()
  159. if turtle.detect() then
  160. turtle.dig()
  161. sleep(0.6) -- Minor bug fix if there is gravel
  162. end
  163. if turtle.forward() then
  164. --notting
  165. else
  166. repeat
  167. turtle.dig()
  168. sleep(0.6)
  169. if turtle.forward() then
  170. blockUp = 0
  171. else
  172. blockUp = 1
  173. end
  174. until blockUp == 0
  175. end
  176. if turtle.detectUp() then
  177. turtle.digUp()
  178. end
  179. if turtle.detectDown() then
  180. turtle.digDown()
  181. end
  182. turtle.turnLeft()
  183. LSorWS = 0
  184. longCount = 0
  185. wideCount = wideCount + 1
  186. totalBlockDone = totalBlockDone + 3
  187. end
  188.  
  189. local function wideMineRight() -- TODO
  190. turtle.turnRight()
  191. if turtle.detect() then
  192. turtle.dig()
  193. sleep(0.6)
  194. end
  195. if turtle.forward() then
  196. --Notting
  197. else
  198. repeat
  199. turtle.dig()
  200. sleep(0.6)
  201. if turtle.forward() then
  202. blockUp = 0
  203. else
  204. blockUp = 1
  205. end
  206. until blockUp == 0
  207. end
  208. if turtle.detectUp() then
  209. turtle.digUp()
  210. end
  211. if turtle.detectDown() then
  212. turtle.digDown()
  213. end
  214. turtle.turnRight()
  215. LSorWS = 1
  216. longCount = 0
  217. wideCount = wideCount + 1
  218. totalBlockDone = totalBlockDone + 3
  219. end
  220.  
  221. local function deepMine()
  222. turtle.digDown()
  223. turtle.down()
  224. turtle.digDown()
  225. turtle.down()
  226. turtle.digDown()
  227. turtle.down()
  228. turtle.digDown()
  229. turtle.turnRight()
  230. turtle.turnRight()
  231. wideCount = 0
  232. longCount = 0
  233. deepCount = deepCount + 3
  234. totalBlockDone = totalBlockDone + 3
  235. end
  236.  
  237. local function main()
  238. repeat --Repeat for each level
  239. mineLong()
  240. refuel()
  241. chestDump()
  242. if longCount == long then
  243. if wideCount ~= wide then
  244. process = totalBlockDone / totalBlocks * 100
  245. processRaw = totalBlocks - totalBlockDone
  246. print("How Much Is Done: " .. math.floor(process+0.5) .. " %")
  247. print("TotalBlocks Still Need To Dig Is " .. processRaw)
  248. if LSorWS == 0 then
  249. wideMineRight()
  250. else
  251. wideMineLeft()
  252. end
  253. elseif wideCount >= wide then
  254. deepMine()
  255. end
  256. end
  257. until deepCount >= deep
  258. print("turtle is Done")
  259. end
  260.  
  261. local function firstDig()
  262. turtle.digDown()
  263. turtle.down()
  264. turtle.digDown()
  265. turtle.down()
  266. turtle.digDown()
  267. wideCount = 0
  268. longCount = 0
  269. totalBlockDone = totalBlockDone + 3
  270. end
  271.  
  272. local function start()
  273. print("Welcome To Excavation Turtle Program")
  274. print("Slot 1: Chest, Slot 2: Fuel, Slot 3: Fuel")
  275. print("Note: If now put item in then it say error just wait it fix it self")
  276. print("How long(Lenght) you want")
  277. input = io.read()
  278. long = tonumber(input)
  279. long = long - 1
  280. print("How wide(Width) you want")
  281. input2 = io.read()
  282. wide = tonumber(input2)
  283. wide = wide - 1
  284. print("How Deep(Depth) You Want")
  285. input3 = io.read()
  286. deep = tonumber(input3)
  287. print("Is This Corrent Lenght " .. "Lenght = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep))
  288. print("Type y Or Y if it is correct and if not then n or N")
  289. corrent = io.read()
  290. if corrent == n or N then
  291. os.reboot()
  292. end
  293. print("Okey Program Will Do Calculations")
  294. totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code
  295. print("Total amount for block to mine is " .. totalBlocks)
  296. coalNeeded = totalBlocks / 3 / 80
  297. print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5))
  298. if turtle.getFuelLevel() == "unlimited" then
  299. print("Your turtle config does need fuel")
  300. noFuelNeed = 1
  301. elseif turtle.getFuelLevel() < 160 then
  302. turtle.select(2)
  303. turtle.refuel(2)
  304. end
  305. reCheck()
  306. check()
  307. if error == 1 then
  308. repeat
  309. sleep(6)
  310. reCheck()
  311. check()
  312. until error == 0
  313. end
  314. print("Turtle will now start!")
  315. firstDig()
  316. main()
  317. end
  318.  
  319. start()
Add Comment
Please, Sign In to add comment