Blackhome

CC Tweak Ore Miner

Jan 4th, 2025 (edited)
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.01 KB | Gaming | 0 0
  1. --number of tunnels (2 blocks in between)
  2. numTunnels = 20
  3. --length of single tunnel
  4. lenTunnel = 30
  5.  
  6. --side for the tunnels
  7. tunnelSide = "left"
  8. --uses or destroys bordering lava
  9. bLava = true
  10.  
  11. --uses or destroys all connected lava
  12. bAllLava = true
  13.  
  14. --testRun, only Tunnels
  15. bTest = false
  16.  
  17. --Counter for found lava springs
  18. lavaCnt = 0
  19.  
  20. blocksToMine = {
  21.                 "minecraft:copper_ore", "minecraft:deepslate_copper_ore",
  22.                 "minecraft:coal_ore", "deepslate_coal_ore",
  23.  
  24.                 "minecraft:iron_ore", "minecraft:deepslate_iron_ore",
  25.                 "minecraft:gold_ore", "minecraft:deepslate_gold_ore",
  26.                 "minecraft:deepslate_diamond_ore", "minecraft:diamond_ore",
  27.                 "minecraft:emerald_ore", "minecraft:deepslate_emerald_ore",
  28.  
  29.                 "minecraft:redstone_ore", "minecraft:deepslate_redstone_ore",
  30.                 "minecraft:lapis_ore", "minecraft:deepslate_lapis_ore",
  31.  
  32.                 "minecraft:nether_gold_ore", "minecraft:nether_quartz_ore",
  33.                 "minecraft:ancient_debris"
  34.             }
  35. notDroppedBlocks = {
  36.                     "minecraft:chest", "minecraft:torch",
  37.                     "minecraft:bucket", "minecraft:lava_bucket"
  38.                     }
  39. lavaArray = {"minecraft:lava"}
  40. bucketList = {"minecraft:bucket", "minecraft:lava_bucket"}
  41.  
  42.  
  43. -- tries to refuel till possible
  44. function refuelProcess()
  45.     local cnt = 0
  46.     local bFueld = false
  47.     while not bFueld do
  48.         for i = 1, 16, 1 do
  49.             turtle.select(i)
  50.             local item = turtle.getItemDetail()
  51.             if item then
  52.                 if not (item.name == "minecraft:chest") then
  53.                     local ok, err = turtle.refuel()
  54.                 end
  55.             end
  56.         end
  57.         if turtle.getFuelLevel() > 0 then
  58.             print("New fuel level:   " .. tostring(turtle.getFuelLevel()))
  59.             return true
  60.         end
  61.         if cnt == 0 then
  62.             print("Pls enter fuel to continue")
  63.         end
  64.         cnt = 1
  65.     end
  66.     return true
  67. end
  68.  
  69. -- Checks if fuel is available or starts refuel process
  70. function fuelCheck()
  71.     if turtle.getFuelLevel() > 0 then
  72.         return
  73.     else
  74.         refuelProcess()
  75.     end
  76. end
  77.  
  78. -- Digs in given direction till turtle can move
  79. function moveForward()
  80.     fuelCheck()
  81.  
  82.     local b = false
  83.     while not b do
  84.         b = turtle.forward()
  85.         if not b then
  86.             turtle.dig()
  87.         end
  88.     end
  89. end
  90. function moveUp()
  91.     fuelCheck()
  92.  
  93.     local b = false
  94.     while not b do
  95.         b = turtle.up()
  96.         if not b then
  97.             turtle.digUp()
  98.         end
  99.     end
  100. end
  101. function moveDown()
  102.     fuelCheck()
  103.  
  104.     local b = false
  105.     while not b do
  106.         b = turtle.down()
  107.         if not b then
  108.             turtle.digDown()
  109.         end
  110.     end
  111. end
  112.  
  113. -- Turn turtle 180°
  114. function turnBack()
  115.     turtle.turnLeft()
  116.     turtle.turnLeft()
  117. end
  118.  
  119. -- turns into tunnel or back out in starting direction
  120. function takeTurn()
  121.     if tunnelSide == "left" then
  122.         turtle.turnLeft()
  123.     else
  124.         turtle.turnRight()
  125.     end
  126. end
  127.  
  128. -- returns true if the block in this directions is in the given array
  129. function inspectForward(arr)
  130.     local bBlockForward, data = turtle.inspect()
  131.     local blockname = data.name
  132.     if bBlockForward then
  133.         for i = 1, #arr, 1 do
  134.             if blockname == arr[i] then
  135.                 if blockname == "minecraft:lava" then
  136.                     local level = data.state.level
  137.                     if not (level == 0) then
  138.                         return false
  139.                     end
  140.                 end
  141.                 return true
  142.             end
  143.         end
  144.     end
  145.     return false
  146. end
  147.  
  148. function inspectUp(arr)
  149.     local bBlockUp, data = turtle.inspectUp()
  150.     local blockname = data.name
  151.     if bBlockUp then
  152.         for i = 1, #arr, 1 do
  153.             if blockname == arr[i] then
  154.                 if blockname == "minecraft:lava" then
  155.                     local level = data.state.level
  156.                     if not (level == 0) then
  157.                         return false
  158.                     end
  159.                 end
  160.                 return true
  161.             end
  162.         end
  163.     end
  164.     return false
  165. end
  166.  
  167. function inspectDown(arr)
  168.     local bBlockDown, data = turtle.inspectDown()
  169.     local blockname = data.name
  170.     if bBlockDown then
  171.         for i = 1, #arr, 1 do
  172.             if blockname == arr[i] then
  173.                 if blockname == "minecraft:lava" then
  174.                     local level = data.state.level
  175.                     if not (level == 0) then
  176.                         return false
  177.                     end
  178.                 end
  179.                 return true
  180.             end
  181.         end
  182.     end
  183.     return false
  184. end
  185.  
  186. -- selects slot with bucket
  187. function selectBucket()
  188.     local item = turtle.getItemDetail()
  189.     if item then
  190.         if (item.name == bucketList[1]) then
  191.             return true
  192.         end
  193.         if (item.name == bucketList[2]) then
  194.             return true
  195.         end
  196.     end
  197.  
  198.     for i=1, 16, 1 do
  199.         turtle.select(i)
  200.         item = turtle.getItemDetail()
  201.         if item then
  202.             if (item.name == bucketList[1]) then
  203.                 return true
  204.             end
  205.             if (item.name == bucketList[2]) then
  206.                 return true
  207.             end
  208.         end
  209.     end
  210.     return false
  211. end
  212.  
  213. --Returns bool bFullTank and bBucketIsEmpty (if fuel is maximum and if bucket contains nothing)
  214. function getBucketAndFuelData()
  215.     local fuelLevel = turtle.getFuelLevel()
  216.     local maxFuelLevel = turtle.getFuelLimit()
  217.     local bFullTank = (fuelLevel == maxFuelLevel)
  218.  
  219.     local bBucketIsEmpty = true
  220.     local item = turtle.getItemDetail()
  221.  
  222.     if item then
  223.         if (item.name == bucketList[1]) then
  224.             bBucketIsEmpty = true
  225.         end
  226.         if (item.name == bucketList[2]) then
  227.             bBucketIsEmpty = false
  228.         end
  229.     end
  230.     return bFullTank, bBucketIsEmpty
  231. end
  232.  
  233. --collects lava in this direction (tries to use it)
  234. function collectFrontLava()
  235.     local bFullTank, bEmptyBucket = getBucketAndFuelData()
  236.     local bRefueld = false
  237.  
  238.     if bEmptyBucket then
  239.         turtle.place()
  240.     end
  241.     if not bFullTank then
  242.         turtle.refuel()
  243.         bRefueld = true
  244.     end
  245.     if not bEmptyBucket then
  246.         turtle.place()
  247.         if not bRefueld then
  248.             turtle.place()
  249.         end
  250.     end
  251.     lavaCnt = lavaCnt + 1
  252. end
  253.  
  254. function collectTopLava()
  255.     local bFullTank, bEmptyBucket = getBucketAndFuelData()
  256.     local bRefueld = false
  257.  
  258.     if bEmptyBucket then
  259.         turtle.placeUp()
  260.     end
  261.     if not bFullTank then
  262.         turtle.refuel()
  263.         bRefueld = true
  264.     end
  265.     if not bEmptyBucket then
  266.         turtle.placeUp()
  267.         if not bRefueld then
  268.             turtle.placeUp()
  269.         end
  270.     end
  271.     lavaCnt = lavaCnt + 1
  272. end
  273.  
  274. function collectBottomLava()
  275.     local bFullTank, bEmptyBucket = getBucketAndFuelData()
  276.     local bRefueld = false
  277.  
  278.     if bEmptyBucket then
  279.         turtle.placeDown()
  280.     end
  281.     if not bFullTank then
  282.         turtle.refuel()
  283.         bRefueld = true
  284.     end
  285.     if not bEmptyBucket then
  286.         turtle.placeDown()
  287.         if not bRefueld then
  288.             turtle.placeDown()
  289.         end
  290.     end
  291.     lavaCnt = lavaCnt + 1
  292. end
  293.  
  294. -- collects all valuable blcoks that are connected to start block (+Lava collection/destruction possible)
  295. function collectAllValuables()
  296.     local bLocLava = bLava
  297.     if not selectBucket() then
  298.         bLocLava = false
  299.     end
  300.  
  301.     if inspectDown(blocksToMine) then
  302.         moveDown()
  303.         collectAllValuables()
  304.         moveUp()
  305.     elseif inspectDown(lavaArray) and bLocLava then
  306.         collectBottomLava()
  307.         if bAllLava then
  308.             moveDown()
  309.             collectAllValuables()
  310.             moveUp()
  311.         end
  312.     end
  313.  
  314.     if inspectForward(blocksToMine) then
  315.         moveForward()
  316.         collectAllValuables()
  317.         turnBack()
  318.         moveForward()
  319.         turnBack()
  320.     elseif inspectForward(lavaArray) and bLocLava then
  321.         collectFrontLava()
  322.         if bAllLava then
  323.             moveForward()
  324.             collectAllValuables()
  325.             turnBack()
  326.             moveForward()
  327.             turnBack()
  328.         end
  329.     end
  330.     turtle.turnRight()      -- right
  331.  
  332.     if inspectForward(blocksToMine) then
  333.         moveForward()
  334.         collectAllValuables()
  335.         turnBack()
  336.         moveForward()
  337.         turnBack()
  338.     elseif inspectForward(lavaArray) and bLocLava then
  339.         collectFrontLava()
  340.         if bAllLava then
  341.             moveForward()
  342.             collectAllValuables()
  343.             turnBack()
  344.             moveForward()
  345.             turnBack()
  346.         end
  347.     end
  348.     turtle.turnRight()      -- back
  349.  
  350.     if inspectForward(blocksToMine) then
  351.         moveForward()
  352.         collectAllValuables()
  353.         turnBack()
  354.         moveForward()
  355.         turnBack()
  356.     elseif inspectForward(lavaArray) and bLocLava then
  357.         collectFrontLava()
  358.         if bAllLava then
  359.             moveForward()
  360.             collectAllValuables()
  361.             turnBack()
  362.             moveForward()
  363.             turnBack()
  364.         end
  365.     end
  366.     turtle.turnRight()      -- left
  367.  
  368.     if inspectForward(blocksToMine) then
  369.         moveForward()
  370.         collectAllValuables()
  371.         turnBack()
  372.         moveForward()
  373.         turnBack()
  374.     elseif inspectForward(lavaArray) and bLocLava then
  375.         collectFrontLava()
  376.         if bAllLava then
  377.             moveForward()
  378.             collectAllValuables()
  379.             turnBack()
  380.             moveForward()
  381.             turnBack()
  382.         end
  383.     end
  384.     turtle.turnRight()      -- forward
  385.  
  386.     if inspectUp(blocksToMine) then
  387.         moveUp()
  388.         collectAllValuables()
  389.         moveDown()
  390.     elseif inspectUp(lavaArray) and bLocLava then
  391.         collectTopLava()
  392.         if bAllLava then
  393.             moveUp()
  394.             collectAllValuables()
  395.             moveDown()
  396.         end
  397.     end
  398.  
  399.     return true
  400. end
  401.  
  402. -- Drops all slots except items from list in above storage
  403. function dropALLUp()
  404.     local bDrop = true
  405.     for i = 1, 16, 1 do
  406.         turtle.select(i)
  407.         for j = 1, #notDroppedBlocks, 1 do
  408.             itemDetail = turtle.getItemDetail()
  409.             if itemDetail then
  410.                 if itemDetail.name == notDroppedBlocks[j] then
  411.                     bDrop = False
  412.                 end
  413.             end
  414.         end
  415.         if bDrop then
  416.             turtle.dropUp()
  417.         end
  418.         bDrop = true
  419.     end
  420. end
  421.  
  422. -- places chest on top of turtle
  423. function placeChest()
  424.     for i = 1, 16, 1 do
  425.         turtle.select(i)
  426.         itemDetail = turtle.getItemDetail()
  427.         if itemDetail then
  428.             if itemDetail.name == "minecraft:chest" then
  429.                 moveUp()
  430.                 moveDown()
  431.                 turtle.placeUp()
  432.                 return true
  433.             end
  434.         end
  435.     end
  436.     if bLava then
  437.         if not (lavaCnt == 0) then
  438.             print(tostring(lavaCnt).." Lavablocks were collected/destroyed")
  439.             lavaCnt = 0
  440.         end
  441.     end
  442.     return false
  443. end
  444.  
  445. -- places torch NOT WRITTEN YET
  446. function placeTorch()
  447.     return true
  448. end
  449.  
  450.  
  451.  
  452.  
  453. -- mines one tunnel and comes back out
  454. function mineTunnel (remainingLength)
  455.     if not (remainingLength == 0) then
  456.         moveForward()
  457.         if not bTest then
  458.             collectAllValuables()
  459.         end
  460.         moveUp()
  461.         if not bTest then
  462.             collectAllValuables()
  463.         end
  464.         moveDown()
  465.         mineTunnel(remainingLength - 1)
  466.         moveForward()
  467.     else
  468.         turnBack()
  469.     end
  470. end
  471.  
  472. -- Digs and mines all tunnels
  473. function runTunnelMiner()
  474.     for i=1, numTunnels, 1 do
  475.         takeTurn()
  476.         mineTunnel(lenTunnel)
  477.         if placeChest() then
  478.                 dropALLUp()
  479.         end
  480.         takeTurn()
  481.         if not (i == numTunnels) then
  482.             moveForward()
  483.             moveForward()
  484.             moveForward()
  485.         end
  486.     end
  487. end
  488.  
  489. runTunnelMiner()
Add Comment
Please, Sign In to add comment