ThirdRateMeatwater

mining.lua

Jun 24th, 2021 (edited)
932
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local height = 0
  2. local width = 0
  3. local depth = 0
  4.  
  5. if #args == 3 then
  6.     height = tonumber(arg[1])
  7.     width = tonumber(arg[2])
  8.     depth = tonumber(arg[3])
  9.  
  10.     if width % 2 ==0 or height % 2 == 0 then
  11.         print("Height and width arguments must be odd numbers")
  12.         return
  13.     end
  14.  
  15. else
  16.     print("You need to input the correct number arguments. These are height, width and depth.")
  17.     return
  18. end
  19.  
  20. local INVENTORY_SIZE = 16
  21. local heightMovement = math.floor(height / 2)
  22. local widthMovement = math.floor(width / 2)
  23.  
  24. -- accepted fuels
  25. local ACCEPTED_FUELS = {
  26.     "minecraft:coal_block",
  27.     "minecraft:coal",
  28.     "minecraft: lava_bucket"
  29. }
  30.  
  31. -- blacklisted items
  32. local BLACKLISTED_ITEMS = {
  33.     "minecraft:cobblestone",
  34.     "minecraft:sand",
  35.     "minecraft:gravel",
  36.     "minecraft:dirt",
  37.     "minecraft:obsidian",
  38. }
  39.  
  40. --perform check
  41. function inventoryCheck()
  42.     for i = 1, INVENTORY_SIZE do
  43.         local currentItem = turtle.getItemDetail(i)
  44.         if currentItem ~= nil then
  45.             local isBlacklistedItem = false
  46.             for x = 1, #ACCEPTED_ITEMS do
  47.                 if currentItem.name == BLACKLISTED_ITEMS[x] then
  48.                     turtle.select(i)
  49.                     turtle.dropUp()
  50.                 end
  51.             end
  52.         end
  53.     end
  54. end
  55.  
  56. --group items
  57.     for j = 1, INVENTORY_SIZE do
  58.         local currentItem = turtle.getItemDetail(j)
  59.        
  60.         if currentItem ~= nil then
  61.             turtle.select(j)
  62.             for k = j, INVENTORY_SIZE do
  63.                 if turtle.compareTo(k) then
  64.                     turtle.select(k)
  65.                     turtle.transferTo(j)
  66.                     turtle.select(j)
  67.                 end
  68.             end
  69.         end
  70.     end
  71. end
  72.  
  73.  
  74. -- Refuel
  75. function refuel(slot_number)
  76.     print("[TURTLE] refueling. . .  ")
  77.     turtle.select(slot_number)
  78.     turtle.refuel()
  79.     print("[TURTLE] Nom. Nom. Nom.")
  80. end
  81.  
  82. --checks fuel level
  83. function checkFuelLevel()
  84.     local requiredFuelLevel = math.ceil((height*width*height) + (heightMovement + widthMovement))
  85.     local currentFuelLevel = turtle.getFuelLevel()
  86.  
  87.     print("[TURTLE] current fuel level is: "..fuelLevel.." - required: "..requiredFuelLevel)
  88.  
  89.     if currentFuelLevel < requiredFuelLevel then
  90.  
  91.         print("[TURTLE] attempting to locate fuel.")
  92.  
  93.         for i = 1, INVENTORY_SIZE do
  94.             local currentItem = turtle.getItemDetail(i)
  95.             if currentItem ~= nil then
  96.                 for x = 1, #ACCEPTED_FUELS do
  97.                     if currentItem.name == ACCEPTED_FUELS[x] then
  98.                         print("[TURTLE] fuel found:"..ACCEPTED_FUELS[x])
  99.  
  100.                         if currentFuelLevel < requiredFuelLevel then
  101.                             refuel(i)
  102.                         else
  103.                             return true
  104.                         end
  105.                     end
  106.                 end
  107.             end
  108.         end
  109.         print("[TURTLE] No acceptable fuel found, program exiting...")
  110.         return false
  111.     else
  112.         return true
  113.     end
  114.  
  115. --combat gravel/sand
  116. function moveUpAndDig()
  117.     while turtle.up() == false do
  118.         turtle.digUp()
  119.     end
  120. end
  121.  
  122. function moveForwardAndDig()
  123.     while turtle.forward() == false do
  124.         turtle.dig()
  125.     end
  126. end
  127.  
  128. function moveDownAndDig()
  129.     while turtle.down() == false do
  130.         turtle.digDown()
  131.     end
  132. end
  133.  
  134. -- move to start position
  135. function moveToStartPosition()
  136.  
  137.     --move to horizontal start
  138.     turtle.turnLeft()
  139.     for i = 1, widthMovement do
  140.         moveForwardAndDig()
  141.     end
  142.     turtle.turnRight()
  143.  
  144.     --move to verticle start position
  145.     for i = 1, heightMovement do
  146.         moveUpAndDig()
  147.     end
  148. end
  149.  
  150.  
  151. -- mining sequence
  152. function mineSequence()
  153.  
  154.     for x  = 1, depth do
  155.  
  156.         turtle.dig()
  157.         turtle.forward()
  158.  
  159.         for i = 1, height do
  160.  
  161.             if x % 2 == 0 then
  162.                 turtle.turnLeft()
  163.             else
  164.                 turtle.turnRight()
  165.             end
  166.  
  167.             for y = 1, width - 1 do
  168.                 moveForwardAndDig()
  169.             end
  170.  
  171.             if i ~= height then
  172.                 if x % 2 == 0 then
  173.                     turtle.turnLeft()
  174.                     moveUpAndDig()
  175.                 else
  176.                     turtle.turnRight()
  177.                     moveDownAndDig()
  178.                 end
  179.             end
  180.         end
  181.  
  182.         if x % 2 == 0 then
  183.             turtle.turnRight()
  184.         else
  185.             turtle.turnLeft()
  186.         end
  187.         inventoryCheck()
  188.  
  189.     end
  190.  
  191. end
  192.  
  193. if checkFuelLevel() then
  194.     mineSequence()
  195. end
RAW Paste Data