Advertisement
gravitowl

SimpleMiningScript

Mar 19th, 2021 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. --[[
  2.  
  3. Script Created by CEEBS
  4. YouTube: https://www.youtube.com/c/OriginalCEEBS
  5. Twitter: https://twitter.com/OnlyCeebs
  6.  
  7. Really appreciate all the support you have given me, so thank you!
  8.  
  9. -----------------------------------------------------------------
  10.  
  11. I'll be interested to see any modifications made, so please feel free to let me know what you've come up with. Happy coding, happy gaming. Peace!
  12.  
  13. One little issue with the checkFuelLevel and refuel function. The script may refuse to run after refueling, just run the script again and it'll be fine. Please feel free to troubleshoot, not a difficult fix, will just require some conditional logic.
  14.  
  15. ]]--
  16.  
  17. -- Receive arguments and perform some basic validation
  18. local height = 0
  19. local width = 0
  20. local depth = 0
  21.  
  22. if #arg == 3 then
  23. height = tonumber(arg[1])
  24. width = tonumber(arg[2])
  25. depth = tonumber(arg[3])
  26.  
  27. if width % 2 == 0 or height % 2 == 0 then
  28. print("Both the height and width arguments must be an odd number")
  29. return
  30. elseif width == 1 or height == 1 then
  31. print("Both the height and width arguments must be greater and 1")
  32. return
  33. end
  34. else
  35. print("Please enter the correct arguments when executing this script. The height width and depth are required (e.g. mining 5 5 10)")
  36. return
  37. end
  38.  
  39. local INVENTORY_SIZE = 16
  40. local heightMovement = math.floor(height / 2)
  41. local widthMovement = math.floor(width / 2)
  42.  
  43. -- List of accepted fuels
  44. local ACCEPTED_FUELS = {
  45. "minecraft:coal_block",
  46. "minecraft:coal"
  47. }
  48.  
  49. -- List of whitelisted items
  50. local ACCEPTED_ITEMS = {
  51. "minecraft:gold_ore",
  52. "minecraft:iron_ore",
  53. "minecraft:coal",
  54. "minecraft:redstone",
  55. "minecraft:diamond",
  56. "minecraft:emerald",
  57. "minecraft:lapis_lazuli",
  58. "minecraft:quartz",
  59. "astralsorcery:rock_crystal",
  60. "immersiveengineering:ore_uranium",
  61. "immersiveengineering:ore_nickel",
  62. "immersiveengineering:ore_silver",
  63. "immersiveengineering:ore_lead",
  64. "immersiveengineering:ore_aluminium",
  65. "immersiveengineering:ore_copper",
  66. "mysticalworld:tin_ore",
  67. "mysticalworld:silver_ore",
  68. "mysticalworld:quicksilver_ore",
  69. "mysticalworld:lead_ore",
  70. "mysticalworld:copper_ore",
  71. "mysticalworld:amethyst",
  72. "mekanism:lead_ore",
  73. "mekanism:fluorite_gem",
  74. "mekanism:uranium_ore",
  75. "mekanism:osmium_ore",
  76. "mekanism:tin_ore",
  77. "mekanism:copper_ore",
  78. "powah:uraninite_raw_dense",
  79. "powah:uraninite_raw",
  80. "powah:uraninite_raw_poor",
  81. "create:zinc_ore",
  82. "create:copper_ore",
  83. "druidcraft:rockroot",
  84. "druidcraft:fiery_glass",
  85. "druidcraft:moonstone",
  86. "druidcraft:amber",
  87. "eidolon:lead_ore",
  88. "astralsorcery:starmetal_ore"
  89. }
  90.  
  91. -- Perform inventory check
  92. function inventoryCheck()
  93. -- Check for rubbish items
  94. for i = 1, INVENTORY_SIZE do
  95. local currentItem = turtle.getItemDetail(i)
  96. if currentItem ~= nil then
  97. local isAcceptedItem = false
  98. for x = 1, #ACCEPTED_ITEMS do
  99. if currentItem.name == ACCEPTED_ITEMS[x] then
  100. isAcceptedItem = true
  101. end
  102. end
  103. if not isAcceptedItem then
  104. turtle.select(i)
  105. turtle.dropUp()
  106. end
  107. end
  108. end
  109.  
  110. -- Group items together
  111. for j = 1, INVENTORY_SIZE do
  112. local currentItem = turtle.getItemDetail(j)
  113.  
  114. if currentItem ~= nil then
  115. turtle.select(j)
  116. for k = j, INVENTORY_SIZE do
  117. if turtle.compareTo(k) then
  118. turtle.select(k)
  119. turtle.transferTo(j)
  120. turtle.select(j)
  121. end
  122. end
  123. end
  124. end
  125. end
  126.  
  127. -- Refuel using the found fuel
  128. function refuel(slot_number)
  129. print("[TURTLE] Refueling... ")
  130. turtle.select(slot_number)
  131. turtle.refuel()
  132. print("[TURTLE] Nom. Nom. Nom.")
  133. end
  134.  
  135. -- Check the current fuel level
  136. function checkFuelLevel()
  137. local requiredFuelLevel = math.ceil((height * width * depth) + (heightMovement + widthMovement))
  138. local currentFuelLevel = turtle.getFuelLevel()
  139.  
  140. print("[TURTLE] Current fuel level is: "..currentFuelLevel.." - Required: "..requiredFuelLevel)
  141.  
  142. if currentFuelLevel < requiredFuelLevel then
  143.  
  144. print("[TURTLE] Attempting to locate fuel.")
  145.  
  146. for i = 1, INVENTORY_SIZE do
  147. local currentItem = turtle.getItemDetail(i)
  148. if currentItem ~= nil then
  149. for x = 1, #ACCEPTED_FUELS do
  150. if currentItem.name == ACCEPTED_FUELS[x] then
  151. print("[TURTLE] Acceptable fuel found: " ..ACCEPTED_FUELS[x])
  152.  
  153. if currentFuelLevel < requiredFuelLevel then
  154. refuel(i)
  155. else
  156. return true
  157. end
  158. end
  159. end
  160. end
  161. end
  162. print("[TURTLE] No acceptable fuel or not enough found, terminating program...")
  163. return false
  164. else
  165. return true
  166. end
  167. end
  168.  
  169. -- Combat gravel/sand
  170. function moveUpAndDig()
  171. while turtle.up() == false do
  172. turtle.digUp()
  173. end
  174. end
  175.  
  176. function moveForwardAndDig()
  177. while turtle.forward() == false do
  178. turtle.dig()
  179. end
  180. end
  181.  
  182. function moveDownAndDig()
  183. while turtle.down() == false do
  184. turtle.digDown()
  185. end
  186. end
  187.  
  188. -- Move to start position
  189. function moveToStartPosition()
  190.  
  191. -- Move to horizontal start position
  192. turtle.turnLeft()
  193. for i = 1, widthMovement do
  194. moveForwardAndDig()
  195. end
  196. turtle.turnRight()
  197.  
  198. -- Move to vertical start postion
  199. for i = 1, heightMovement do
  200. moveUpAndDig()
  201. end
  202.  
  203. end
  204.  
  205. -- Mining Sequence
  206. function mineSequence()
  207.  
  208. moveToStartPosition()
  209.  
  210. for x = 1, depth do
  211.  
  212. moveForwardAndDig()
  213.  
  214. for i = 1, height do
  215.  
  216. if x % 2 == 0 then
  217. turtle.turnLeft()
  218. else
  219. turtle.turnRight()
  220. end
  221.  
  222. for y = 1, width - 1 do
  223. moveForwardAndDig()
  224. end
  225.  
  226. if i ~= height then
  227. if x % 2 == 0 then
  228. turtle.turnLeft()
  229. moveUpAndDig()
  230. else
  231. turtle.turnRight()
  232. moveDownAndDig()
  233. end
  234. end
  235.  
  236. end
  237.  
  238. if x % 2 == 0 then
  239. turtle.turnRight()
  240. else
  241. turtle.turnLeft()
  242. end
  243.  
  244. inventoryCheck()
  245.  
  246. end
  247.  
  248. end
  249.  
  250. if checkFuelLevel() then
  251. mineSequence()
  252. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement