black_stormy

DirtyDigger - Minecraft Strip Mine Program

Oct 26th, 2023 (edited)
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.51 KB | Gaming | 0 0
  1. -- Dirty Digger v0.72
  2. -- + dropping torches between tunnels
  3.  
  4. -- Dirty Digger v0.71
  5. -- + added digging in main tunnel if there are blocks in the way of starting new tunnels
  6.  
  7. -- Dirty Digger v0.7
  8. -- + debugged support for parallel tunnels
  9.  
  10. -- Dirty Digger v0.6
  11. -- + added support for parallel tunnels
  12.  
  13. -- Dirty Digger v0.5
  14. -- + added support for regular chests
  15.  
  16. -- Dirty Digger v0.4
  17. -- + dig, digUp, digDown functions that detect additional blocks to mine before moving on
  18.  
  19. -- Dirty Digger v0.3
  20. -- + Added wall check and replace to fill in holes in the tunnel as its being mined.
  21. -- + Adjusted checks at end of mining sequence so space check is before torch check to avoid conflicts with the two
  22.  
  23. -- Dirty Digger v0.2
  24. -- + Auto return to starting position
  25.  
  26. -- Dirty Digger v0.1
  27. -- + 3x3 tunnels
  28. -- + enderchest storage
  29. -- + auto torch (every 4 blocks)
  30. -- + auto refuel (when below 10 fuel level)
  31.  
  32. -- Roadmap:
  33. -- + Detect missing walls and replace
  34. -- + Make sure enderchest and torches can't be placed in same block
  35. -- + Parallel tunnels (left or right)
  36. -- + Variable tunnel width
  37. -- + Varible torch spacing
  38. -- + Slots to define trash blocks
  39.  
  40. local function distanceCheck()
  41.     print("===========")
  42.     print("Tunnel Length to mine? (1-100)")
  43.     local tunnelLength = tonumber(read())
  44.  
  45.     if tunnelLength and tunnelLength > 0 and tunnelLength < 101 then
  46.         print("===========")
  47.         print("Tunnel Length: "..tunnelLength)
  48.         return tunnelLength
  49.     else
  50.         print("===========")
  51.         print("Please enter a number between 1 and 100.")
  52.         return distanceCheck()
  53.     end
  54. end
  55.  
  56. local function fuelCheck()
  57.     local fuelLevel = turtle.getFuelLevel()
  58.     if fuelLevel < 10 then
  59.         turtle.select(2)
  60.         turtle.refuel(10)
  61.         fuelLevel = turtle.getFuelLevel() -- Update fuel level after refueling
  62.         print("===========")
  63.         print("Fuel Level: "..fuelLevel)
  64.         print("Low Fuel - Refueling!")
  65.     else
  66.         print("===========")
  67.         print("Fuel Level: "..fuelLevel)
  68.         print("Mining Turtle has sufficient fuel!")
  69.     end
  70.     return fuelLevel
  71. end
  72.  
  73. local function torchCheck(distanceMoved)
  74.     if distanceMoved % 4 == 0 then
  75.         turtle.select(1)
  76.         turtle.placeDown()
  77.     end
  78. end
  79.  
  80. local function enderDrop()
  81.     turtle.select(16)
  82.     turtle.placeDown()
  83.  
  84.     for i = 4, 15 do
  85.         turtle.select(i)
  86.         turtle.dropDown()
  87.     end
  88.  
  89.     turtle.select(16)
  90.     turtle.digDown()
  91.     turtle.digDown()
  92. end
  93.  
  94. local function chestDrop()
  95.     turtle.select(16)
  96.     turtle.placeDown()
  97.  
  98.     for i = 4, 15 do
  99.         turtle.select(i)
  100.         turtle.dropDown()
  101.     end
  102. end
  103.  
  104. local function spaceCheck(chestType)
  105.     local occupiedSlots = 0
  106.     for i = 3, 15 do
  107.         if turtle.getItemCount(i) > 0 then
  108.             occupiedSlots = occupiedSlots + 1
  109.         end
  110.     end
  111.  
  112.     if occupiedSlots >= 13 then
  113.         print("===========")
  114.         print("Inventory full, time to unload!")
  115.         if chestType == 1 then
  116.             enderDrop()
  117.         else
  118.             chestDrop()
  119.         end
  120.     else
  121.         print("===========")
  122.         print("Still have space to continue mining.")
  123.     end
  124. end
  125.  
  126. local function wallCheck()
  127.     local function replaceDown()
  128.         if not turtle.detectDown() then
  129.             turtle.placeDown()
  130.         end
  131.     end
  132.  
  133.     local function replaceForward()
  134.         if not turtle.detect() then
  135.             turtle.place()
  136.         end
  137.     end
  138.  
  139.     local function replaceUp()
  140.         if not turtle.detectUp() then
  141.             turtle.placeUp()
  142.         end
  143.     end
  144.  
  145.     turtle.select(3)
  146.  
  147.     turtle.down()
  148.     replaceDown()
  149.  
  150.     turtle.turnLeft()
  151.     turtle.forward()
  152.     replaceDown()
  153.     replaceForward()
  154.  
  155.     turtle.up()
  156.     replaceForward()
  157.  
  158.     turtle.up()
  159.     replaceForward()
  160.     replaceUp()
  161.  
  162.     turtle.turnLeft()
  163.     turtle.turnLeft()
  164.     turtle.forward()
  165.     replaceUp()
  166.  
  167.     turtle.forward()
  168.     replaceUp()
  169.     replaceForward()
  170.  
  171.     turtle.down()
  172.     replaceForward()
  173.  
  174.     turtle.down()
  175.     replaceForward()
  176.     replaceDown()
  177.  
  178.     turtle.back()
  179.  
  180.     turtle.up()
  181.     turtle.turnLeft()
  182. end
  183.  
  184. local function mine(distanceMoved, tunnelLength, chestType)
  185.     local function dig()
  186.         while turtle.detect() do
  187.             turtle.dig()
  188.         end
  189.     end
  190.  
  191.     local function digDown()
  192.         while turtle.detectDown() do
  193.             turtle.digDown()
  194.         end
  195.     end
  196.  
  197.     local function digUp()
  198.         while turtle.detectUp() do
  199.             turtle.digUp()
  200.         end
  201.     end
  202.  
  203.     turtle.up()
  204.  
  205.     while tunnelLength >= 1 do
  206.         dig()
  207.         turtle.forward()
  208.         distanceMoved = distanceMoved + 1
  209.         tunnelLength = tunnelLength - 1
  210.         digUp()
  211.         digDown()
  212.  
  213.         turtle.turnLeft()
  214.         dig()
  215.         turtle.forward()
  216.         digUp()
  217.         digDown()
  218.  
  219.         turtle.turnRight()
  220.         turtle.turnRight()
  221.         turtle.forward()
  222.         dig()
  223.         turtle.forward()
  224.         digUp()
  225.         digDown()
  226.  
  227.         turtle.turnLeft()
  228.         turtle.turnLeft()
  229.         turtle.forward()
  230.         turtle.turnRight()
  231.  
  232.         fuelCheck()
  233.         wallCheck()
  234.         spaceCheck(chestType)
  235.         torchCheck(distanceMoved)
  236.     end
  237.     turtle.down()
  238.     return distanceMoved
  239. end
  240.  
  241. local function readyCheck()
  242.     print("===========")
  243.     print("When materials are in slots, press Y to start mining.")
  244.     local input = read():upper()
  245.     if input == "Y" then
  246.         print("===========")
  247.         print("Starting to mine!")
  248.         return true
  249.     else
  250.         print("===========")
  251.         print("Please type 'Y' when ready.")
  252.         return readyCheck()
  253.     end
  254. end
  255.  
  256. local function chestCheck()
  257.     print("===========")
  258.     print("Are you using an EnderChest? (Y/N)")
  259.     local input = read():upper()
  260.     if input == "Y" or input == "y" then
  261.         return 1
  262.     else
  263.         return 2
  264.     end
  265. end
  266.  
  267. local function tunnelCheck()
  268.     print("===========")
  269.     print("How many parallel tunnels would you like to mine? (1-100)")
  270.  
  271.     local tunnelCount = tonumber(read())
  272.  
  273.     if tunnelCount and tunnelCount > 0 and tunnelCount < 101 then
  274.         print("===========")
  275.         print("Tunnel Count: "..tunnelCount)
  276.         return tunnelCount
  277.     else
  278.         print("===========")
  279.         print("Please enter a number between 1 and 100.")
  280.         return tunnelCheck()
  281.     end
  282. end
  283.  
  284. local function main()
  285.     term.clear()
  286.     print("===========")
  287.     print("Dirty Digger v0.71")
  288.     print("Created by Stormy Waters")
  289.  
  290.     -- instruction where to put materials
  291.     print("===========")
  292.     print("Place these materials in the following slots:")
  293.     print("Slot 1: Torches")
  294.     print("Slot 2: Fuel")
  295.     print("Slot 3: Cobblestone")
  296.     print("Slot 16: Storage Chest")
  297.  
  298.     local tunnelLength = distanceCheck()
  299.     local chestType = chestCheck()
  300.     local tunnelCount = tunnelCheck()
  301.     -- added local functions for dig and dig up that include detection
  302.     local function dig()
  303.         while turtle.detect() do
  304.             turtle.dig()
  305.         end
  306.     end
  307.  
  308.     local function digDown()
  309.         while turtle.detectDown() do
  310.             turtle.digDown()
  311.         end
  312.     end
  313.  
  314.     local function digUp()
  315.         while turtle.detectUp() do
  316.             turtle.digUp()
  317.         end
  318.     end
  319.  
  320.     fuelCheck()
  321.  
  322.     if readyCheck() then
  323.         for i = 1, tunnelCount do
  324.             local distanceMoved = mine(0, tunnelLength, chestType)
  325.             turtle.turnLeft()
  326.             turtle.turnLeft()
  327.  
  328.             for j = 1, distanceMoved do
  329.                 turtle.forward()
  330.             end
  331.  
  332.             turtle.turnLeft()
  333.             turtle.turnLeft()
  334.             -- added dig():330 and digUp():332
  335.             if i < tunnelCount then
  336.                 turtle.turnRight()
  337.                 for k = 1, 2 do
  338.                     dig()
  339.                     turtle.forward()
  340.                     digUp()
  341.                     turtle.up()
  342.                     digUp()
  343.                     dig()
  344.                     turtle.forward()
  345.                     digUp()
  346.                     digDown()
  347.                     turtle.down()
  348.                 end
  349.             -- insert torch on ground below
  350.             turtle.select(1)
  351.             turtle.placeUp()
  352.             turtle.turnLeft()
  353.             end
  354.         end
  355.  
  356.         print("||======================||")
  357.         print("|| Mining 100% Complete ||")
  358.         print("||======================||")
  359.     else
  360.         print("Exiting program.")
  361.     end
  362. end
  363.  
  364. main()
  365.  
Add Comment
Please, Sign In to add comment