Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 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. radar()
  163. turtle.dig()
  164. end
  165. if not turtle.forward() then
  166. repeat
  167. if turtle.detect() then -- First check if there is block front if there is dig if not next step.
  168. turtle.dig()
  169. sleep(0.6)
  170. end
  171. if turtle.forward() then -- try to move if turtle can move blocked == 0 if cant move then blocked 1
  172. blocked = 0
  173. else
  174. blocked = 1
  175. end
  176. until blocked == 0
  177. end
  178. if turtle.detectUp() then
  179. turtle.digUp()
  180. end
  181. if turtle.detectDown() then
  182. turtle.digDown()
  183. end
  184. longCount = longCount + 1
  185. totalBlocksDone = totalBlocksDone + 3
  186. end
  187.  
  188. -- Mining Width
  189. local function mineWide()
  190. if LorR == 0 then
  191. turtle.turnRight()
  192. else
  193. turtle.turnLeft()
  194. end
  195. if turtle.detect() then
  196. turtle.dig()
  197. end
  198. if not turtle.forward() then
  199. repeat
  200. if turtle.detect() then
  201. turtle.dig()
  202. sleep(0.6)
  203. end
  204. if turtle.forward() then
  205. blocked = 0
  206. else
  207. blocked = 1
  208. end
  209. until blocked == 0
  210. end
  211. if turtle.detectUp() then
  212. turtle.digUp()
  213. end
  214. if turtle.detectDown() then
  215. turtle.digDown()
  216. end
  217. if LorR == 0 then
  218. turtle.turnRight()
  219. LorR = 1
  220. else
  221. turtle.turnLeft()
  222. LorR = 0
  223. end
  224. longCount = 0
  225. wideCount = wideCount + 1
  226. totalBlocksDone = totalBlocksDone + 3
  227. end
  228.  
  229. -- Mine Deep
  230. local function mineDeep()
  231. turtle.digDown()
  232. turtle.down()
  233. turtle.digDown()
  234. turtle.down()
  235. turtle.digDown()
  236. turtle.down()
  237. turtle.digDown()
  238. turtle.turnRight()
  239. turtle.turnRight()
  240. wideCount = 0
  241. longCount = 0
  242. deepCount = deepCount + 3
  243. totalBlocksDone = totalBlocksDone + 3
  244. end
  245.  
  246. local function firstDig()
  247. turtle.digDown()
  248. turtle.down()
  249. turtle.digDown()
  250. turtle.down()
  251. turtle.digDown()
  252. wideCount = 0
  253. longCount = 0
  254. deepCount = deepCount + 3
  255. totalBlocksDone = totalBlocksDone + 3
  256. end
  257.  
  258.  
  259.  
  260.  
  261. local function radar()
  262.  
  263. local success, data = turtle.inspect()
  264.  
  265. if success then
  266. print("Block name: ", data.name)
  267. print("Block metadata: ", data.metadata)
  268. if data.name == "minecraft:dirt" then
  269. print("yes it is dirt, destroying it now")
  270. turtle.attack()
  271. end
  272. end
  273. end
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. local function main()
  281. repeat
  282. radar()
  283. mineLong()
  284. refuel()
  285. chestDump()
  286. if longCount == long then
  287. process = totalBlocksDone / totalBlocks * 100
  288. processRaw = totalBlocks - totalBlocksDone
  289. print("How Much Is Done: " .. math.floor(process+0.5) .. " %")
  290. print("TotalBlocks Still Need To Dig Is " .. processRaw)
  291. if wideCount == wide then
  292. if deepCount < deep then
  293. mineDeep()
  294. end
  295. else
  296. mineWide()
  297. end
  298. end
  299. if longCount == long and wideCount == wide and deepCount >= deep then
  300. doneDig = 1
  301. end
  302. until doneDig == 1
  303. print("turtle is Done")
  304. end
  305.  
  306. local function start()
  307. print("Welcome To Excavation Turtle Program")
  308. print("Slot 1: Fuel, Slot 2: Fuel, Slot 3: Chest")
  309. repeat
  310. print("Whats is Lenght you want")
  311. long = tonumber(read()-1)
  312. print("Whats is Width you want")
  313. wide = tonumber(read()-1)
  314. print("Whats is Depth You Want")
  315. deep = tonumber(read())
  316. print("Is This Corrent Lenght " .. "Lenght = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep))
  317. print("Type y Or Y if it is correct and if not then n or N")
  318. corrent = read()
  319. until correct == N or correct == n
  320. totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code
  321. print("Total amount for block to mine is " .. totalBlocks)
  322. coalNeeded = totalBlocks / 3 / 80
  323. if turtle.getFuelLevel() == "unlimited" then
  324. print("Your turtle config does need fuel")
  325. noFuelNeed = 1
  326. else
  327. print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5))
  328. sleep(1)
  329. end
  330. print("Are you using Modded EnderChest Instead")
  331. print("Y or N")
  332. userInput = read()
  333. if userInput == "Y" or userInput == "y" then
  334. enderChest = 1
  335. end
  336. repeat
  337. itemCount()
  338. check()
  339. if(errorItems ~= 0) then
  340. sleep(5)
  341. end
  342. until errorItems == 0
  343. if noFuelNeed == 0 then
  344. if turtle.getFuelLevel() < 120 then
  345. turtle.select(1)
  346. turtle.refuel(2)
  347. end
  348. end
  349. print("Do You Want Redstone as Starting Input")
  350. print("Note: Redstone Input can only be detect from back turtle")
  351. print("Y or N")
  352. starting = read()
  353. if starting == "Y" or starting == "y" then
  354. local On = 0
  355. repeat
  356. os.pullEvent("redstone") -- Wait For Redstone Input without it break with words Too long without yielding.
  357. if redstone.getInput("back") then
  358. On = 1
  359. end
  360. until On == 1
  361. end
  362. print("Turtle will now start!")
  363. firstDig()
  364. main()
  365. end
  366.  
  367. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement