blunderhund

Untitled

Mar 9th, 2021
1,092
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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:coal",
  52.     "minecraft:iron_ore",
  53.     "minecraft:gold_ore",
  54.     "minecraft:redstone",
  55.     "minecraft:diamond",
  56.     "minecraft:emerald",
  57.     "minecraft:dye",
  58.     "thermalfoundation:ore",
  59.     "appliedenergistics2:material",
  60.     "tconstruct:ore",
  61. }
  62.  
  63. -- Perform inventory check
  64. function inventoryCheck()
  65.     -- Check for rubbish items
  66.     for i = 1, INVENTORY_SIZE do
  67.         local currentItem = turtle.getItemDetail(i)
  68.         if currentItem ~= nil then
  69.             local isAcceptedItem = false
  70.             for x = 1, #ACCEPTED_ITEMS do
  71.                 if currentItem.name == ACCEPTED_ITEMS[x] then
  72.                     isAcceptedItem = true
  73.                 end
  74.             end
  75.             if not isAcceptedItem then
  76.                 turtle.select(i)
  77.                 turtle.dropUp()
  78.             end
  79.         end
  80.     end
  81.  
  82.     -- Group items together
  83.     for j = 1, INVENTORY_SIZE do
  84.         local currentItem = turtle.getItemDetail(j)
  85.  
  86.         if currentItem ~= nil then
  87.             turtle.select(j)
  88.             for k = j, INVENTORY_SIZE do
  89.                 if turtle.compareTo(k) then
  90.                     turtle.select(k)
  91.                     turtle.transferTo(j)
  92.                     turtle.select(j)
  93.                 end
  94.             end
  95.         end
  96.     end
  97. end
  98.  
  99. -- Refuel using the found fuel
  100. function refuel(slot_number)
  101.     print("[TURTLE] Refueling... ")
  102.     turtle.select(slot_number)
  103.     turtle.refuel()
  104.     print("[TURTLE] Nom. Nom. Nom.")
  105. end
  106.  
  107. -- Check the current fuel level
  108. function checkFuelLevel()
  109.     local requiredFuelLevel = math.ceil((height * width * depth) + (heightMovement + widthMovement))
  110.     local currentFuelLevel = turtle.getFuelLevel()
  111.  
  112.     print("[TURTLE] Current fuel level is: "..currentFuelLevel.." - Required: "..requiredFuelLevel)
  113.  
  114.     if currentFuelLevel < requiredFuelLevel then
  115.  
  116.         print("[TURTLE] Attempting to locate fuel.")
  117.  
  118.         for i = 1, INVENTORY_SIZE do
  119.             local currentItem = turtle.getItemDetail(i)
  120.             if currentItem ~= nil then
  121.                 for x = 1, #ACCEPTED_FUELS do
  122.                     if currentItem.name == ACCEPTED_FUELS[x] then
  123.                         print("[TURTLE] Acceptable fuel found: " ..ACCEPTED_FUELS[x])
  124.  
  125.                         if currentFuelLevel < requiredFuelLevel then
  126.                             refuel(i)
  127.                         else
  128.                             return true
  129.                         end
  130.                     end
  131.                 end
  132.             end
  133.         end
  134.         print("[TURTLE] No acceptable fuel or not enough found, terminating program...")
  135.         return false
  136.     else
  137.         return true
  138.     end
  139. end
  140.  
  141. -- Combat gravel/sand
  142. function moveUpAndDig()
  143.     while turtle.up() == false do
  144.         turtle.digUp()
  145.     end
  146. end
  147.  
  148. function moveForwardAndDig()
  149.     while turtle.forward() == false do
  150.         turtle.dig()
  151.     end
  152. end
  153.  
  154. function moveDownAndDig()
  155.     while turtle.down() == false do
  156.         turtle.digDown()
  157.     end
  158. end
  159.  
  160. -- Move to start position
  161. function moveToStartPosition()
  162.    
  163.     -- Move to horizontal start position
  164.     turtle.turnLeft()
  165.     for i = 1, widthMovement do
  166.         moveForwardAndDig()
  167.     end
  168.     turtle.turnRight()
  169.  
  170.     -- Move to vertical start postion
  171.     for i = 1, heightMovement do
  172.         moveUpAndDig()
  173.     end
  174.  
  175. end
  176.  
  177. -- Mining Sequence
  178. function mineSequence()
  179.  
  180.     moveToStartPosition()
  181.  
  182.     for x = 1, depth do
  183.    
  184.         moveForwardAndDig()
  185.  
  186.         for i = 1, height do
  187.  
  188.             if x % 2 == 0 then
  189.                 turtle.turnLeft()
  190.             else
  191.                 turtle.turnRight()
  192.             end
  193.  
  194.             for y = 1, width - 1 do
  195.                 moveForwardAndDig()
  196.             end
  197.  
  198.             if i ~= height then
  199.                 if x % 2 == 0 then
  200.                     turtle.turnLeft()
  201.                     moveUpAndDig()
  202.                 else
  203.                     turtle.turnRight()
  204.                     moveDownAndDig()
  205.                 end
  206.             end
  207.  
  208.         end
  209.  
  210.         if x % 2 == 0 then
  211.             turtle.turnRight()
  212.         else
  213.             turtle.turnLeft()
  214.         end
  215.  
  216.         inventoryCheck()
  217.  
  218.     end
  219.  
  220. end
  221.  
  222. if checkFuelLevel() then
  223.     mineSequence()
  224. end
Advertisement
Add Comment
Please, Sign In to add comment