hunterbr549

Untitled

May 26th, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.23 KB | None | 0 0
  1. --[[
  2. Version
  3. 0.06 5/10/2017
  4. Changelog
  5. 0.01 1/20/2017 -- Copy my old code
  6. 0.02 1/20/2017 -- Added Item Worng Place Checking Code
  7. 0.03 1/20/2017 -- Added EnderChest Support Not Tested
  8. 0.04 1/26/2017 -- Bug Fixing
  9. 0.05 5/10/2017 -- fix Small Mistakes
  10. 0.06 5/11/2017 -- Small Speed Tweaks and compacting of code
  11. ToDo
  12. Remove Gravel code from chestDrop since turtle are now non-full blocks so gravel break when it falls on turtle.
  13. it also break when it falls on chest.
  14. ]]
  15.  
  16. -- Local Variables in My New Program style it now a-z not random
  17. -- Area
  18. local deep = 0
  19. local deepCount = 0
  20. local long = 0
  21. local longCount = 0
  22. local wide = 0
  23. local wideCount = 0
  24. -- Misc
  25. local corrent
  26. local coalNeeded
  27. local itemData
  28. local process
  29. local processRaw
  30. local starting
  31. local totalBlocks = 0
  32. local totalBlocksDone = 0
  33. local userInput
  34. -- Inventory
  35. local chest = 0
  36. local enderChest = 0
  37. local errorItems = 0
  38. local fuelCount = 0
  39. local fuelCount1 = 0
  40. local noFuelNeed = 0 -- This is 0 if fuel is needed and 1 is not needed
  41. -- Dig Misc
  42. local blocked = 0 -- Fixing to Chest Probleem and moving probleem
  43. local LorR = 0 -- Left or Right This is for Wide Code
  44. local doneDig = 0
  45.  
  46. -- ItemCheck
  47. local function itemCount()
  48. fuelCount = turtle.getItemCount(1)
  49. fuelCount1 = turtle.getItemCount(2)
  50. chest = turtle.getItemCount(3)
  51. errorItems = 0
  52. end
  53.  
  54. -- Checking
  55. local function check()
  56. if noFuelNeed == 0 then
  57. if fuelCount == 0 then
  58. print("Turtle has no fuel")
  59. print("Put fuel in First and Second slot")
  60. errorItems = 1
  61. else
  62. itemData = turtle.getItemDetail(1)
  63. if itemData.name == "minecraft:chest" then
  64. print("Chest are in wrong slot please move them to slot 3")
  65. errorItems = 1
  66. else
  67. print("Turtle has Fuel Slot 1")
  68. end
  69. end
  70. if fuelCount1 == 0 then
  71. print("Turtle has no extra fuel but if is short job it okey")
  72. else
  73. itemData = turtle.getItemDetail(2)
  74. if itemData.name == "minecraft:chest" then
  75. print("Chest are in wrong slot please move them to slot 3")
  76. errorItems = 1
  77. else
  78. print("Turtle has Fuel Slot 2")
  79. end
  80. end
  81. end
  82. if chest == 0 then
  83. print("No chest in Turtle")
  84. print("Put chest in Thrid slot")
  85. errorItems = 1
  86. else
  87. print("Turtle has chest or Ender Chest")
  88. end
  89. if errorItems == 1 then
  90. print("Items are missing please try again")
  91. print("Turtle will recheck in 5 sec")
  92. end
  93. end
  94.  
  95. -- ItemDump
  96. local function chestDump()
  97. if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  98. repeat -- Better Fix To Gravel Problem. Compacted and Faster and less like to break.
  99. sleep(0.6) -- I let turtle wait for 0.6 second for gravel to fall
  100. if turtle.detectUp() then -- if there is gravel remove it before placing chest
  101. turtle.digUp()
  102. sleep(0.6)
  103. blocked = 1
  104. else
  105. blocked = 0
  106. end
  107. until blocked == 0
  108. if enderChest == 0 then
  109. turtle.select(3)
  110. turtle.placeUp()
  111. chest = chest - 1
  112. for slot = 4, 16 do
  113. turtle.select(slot)
  114. sleep(0.6) -- Small fix for slow pc because i had people problem with this
  115. turtle.dropUp()
  116. end
  117. turtle.select(4)
  118. if chest == 0 then
  119. print("Out Of Chest")
  120. os.shutdown()
  121. end
  122. else -- Added Support Modded EnderChest
  123. turtle.select(3)
  124. turtle.placeUp()
  125. for slot = 4, 16 do
  126. turtle.select(slot)
  127. sleep(0.6) -- Small fix for slow pc because i had people problem with this
  128. turtle.dropUp()
  129. end
  130. turtle.select(3)
  131. turtle.digUp()
  132. turtle.select(4)
  133. end
  134. end
  135. end
  136.  
  137. -- Refuel
  138. local function refuel()
  139. if noFuelNeed == 0 then
  140. repeat
  141. if turtle.getFuelLevel() < 120 then
  142. if fuelCount > 0 then
  143. turtle.select(1)
  144. turtle.refuel(1)
  145. fuelCount = fuelCount - 1
  146. elseif fuelCount1 > 0 then
  147. turtle.select(2)
  148. turtle.refuel(1)
  149. fuelCount1 = fuelCount1 - 1
  150. else
  151. print("Out Of Fuel")
  152. os.shutdown()
  153. end
  154. end
  155. until turtle.getFuelLevel() >= 120
  156. end
  157. end
  158.  
  159. -- Mining Lenght
  160. local function mineLong()
  161. if turtle.detect() then
  162. turtle.dig()
  163. end
  164. if not turtle.forward() then
  165. repeat
  166. if turtle.detect() then -- First check if there is block front if there is dig if not next step.
  167. turtle.dig()
  168. sleep(0.6)
  169. end
  170. if turtle.forward() then -- try to move if turtle can move blocked == 0 if cant move then blocked 1
  171. blocked = 0
  172. else
  173. blocked = 1
  174. end
  175. until blocked == 0
  176. end
  177. if turtle.detectUp() then
  178. turtle.digUp()
  179. end
  180. if turtle.detectDown() then
  181. turtle.digDown()
  182. end
  183. longCount = longCount + 1
  184. totalBlocksDone = totalBlocksDone + 3
  185. end
  186.  
  187. -- Mining Width
  188. local function mineWide()
  189. if LorR == 0 then
  190. turtle.turnRight()
  191. else
  192. turtle.turnLeft()
  193. end
  194. if turtle.detect() then
  195. turtle.dig()
  196. end
  197. if not turtle.forward() then
  198. repeat
  199. if turtle.detect() then
  200. turtle.dig()
  201. sleep(0.6)
  202. end
  203. if turtle.forward() then
  204. blocked = 0
  205. else
  206. blocked = 1
  207. end
  208. until blocked == 0
  209. end
  210. if turtle.detectUp() then
  211. turtle.digUp()
  212. end
  213. if turtle.detectDown() then
  214. turtle.digDown()
  215. end
  216. if LorR == 0 then
  217. turtle.turnRight()
  218. LorR = 1
  219. else
  220. turtle.turnLeft()
  221. LorR = 0
  222. end
  223. longCount = 0
  224. wideCount = wideCount + 1
  225. totalBlocksDone = totalBlocksDone + 3
  226. end
  227.  
  228. -- Mine Deep
  229. local function mineDeep()
  230. turtle.digDown()
  231. turtle.down()
  232. turtle.digDown()
  233. turtle.down()
  234. turtle.digDown()
  235. turtle.down()
  236. turtle.digDown()
  237. turtle.turnRight()
  238. turtle.turnRight()
  239. wideCount = 0
  240. longCount = 0
  241. deepCount = deepCount + 3
  242. totalBlocksDone = totalBlocksDone + 3
  243. end
  244.  
  245. local function firstDig()
  246. turtle.digDown()
  247. turtle.down()
  248. turtle.digDown()
  249. turtle.down()
  250. turtle.digDown()
  251. wideCount = 0
  252. longCount = 0
  253. deepCount = deepCount + 3
  254. totalBlocksDone = totalBlocksDone + 3
  255. end
  256.  
  257. local function main()
  258. repeat
  259. mineLong()
  260. refuel()
  261. chestDump()
  262. if longCount == long then
  263. process = totalBlocksDone / totalBlocks * 100
  264. processRaw = totalBlocks - totalBlocksDone
  265. print("How Much Is Done: " .. math.floor(process+0.5) .. " %")
  266. print("TotalBlocks Still Need To Dig Is " .. processRaw)
  267. if wideCount == wide then
  268. if deepCount < deep then
  269. mineDeep()
  270. end
  271. else
  272. mineWide()
  273. end
  274. end
  275. if longCount == long and wideCount == wide and deepCount >= deep then
  276. doneDig = 1
  277. end
  278. until doneDig == 1
  279. print("turtle is Done")
  280. end
  281.  
  282. local function start()
  283. print("Welcome To Excavation Turtle Program")
  284. print("Slot 1: Fuel, Slot 2: Fuel, Slot 3: Chest")
  285. repeat
  286. print("Whats is Lenght you want")
  287. long = tonumber(read()-1)
  288. print("Whats is Width you want")
  289. wide = tonumber(read()-1)
  290. print("Whats is Depth You Want")
  291. deep = tonumber(read())
  292. print("Is This Corrent Lenght " .. "Lenght = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep))
  293. print("Type y Or Y if it is correct and if not then n or N")
  294. corrent = read()
  295. until correct == N or correct == n
  296. totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code
  297. print("Total amount for block to mine is " .. totalBlocks)
  298. coalNeeded = totalBlocks / 3 / 80
  299. if turtle.getFuelLevel() == "unlimited" then
  300. print("Your turtle config does need fuel")
  301. noFuelNeed = 1
  302. else
  303. print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5))
  304. sleep(1)
  305. end
  306. print("Are you using Modded EnderChest Instead")
  307. print("Y or N")
  308. userInput = read()
  309. if userInput == "Y" or userInput == "y" then
  310. enderChest = 1
  311. end
  312. repeat
  313. itemCount()
  314. check()
  315. if(errorItems ~= 0) then
  316. sleep(5)
  317. end
  318. until errorItems == 0
  319. if noFuelNeed == 0 then
  320. if turtle.getFuelLevel() < 120 then
  321. turtle.select(1)
  322. turtle.refuel(2)
  323. end
  324. end
  325. print("Do You Want Redstone as Starting Input")
  326. print("Note: Redstone Input can only be detect from back turtle")
  327. print("Y or N")
  328. starting = read()
  329. if starting == "Y" or starting == "y" then
  330. local On = 0
  331. repeat
  332. os.pullEvent("redstone") -- Wait For Redstone Input without it break with words Too long without yielding.
  333. if redstone.getInput("back") then
  334. On = 1
  335. end
  336. until On == 1
  337. end
  338. print("Turtle will now start!")
  339. firstDig()
  340. main()
  341. end
  342.  
  343. start()
Add Comment
Please, Sign In to add comment