Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- uses Robust Turtle API: pastebin get 0TnEBf2P t
- os.loadAPI("t")
- local args = {...}
- local versionNumber = "2.4"
- local programName = "StarDustMiner"
- local programNameShort = "SDMiner"
- local startInventory = 2
- local torchEnabled = true
- local torchName = "minecraft:torch"
- -- CHANGEABLE BY USER
- local indivTunnelSpacing = 3
- -- do the same for indivDug
- local indivDug = 3
- -- Start nonIndivDug at 3 so that the first corridor places a torch.
- local nonIndivDug = 3
- local blocksSinceLastTorch = 0
- if #args < 2 or #args > 3 then
- print ("Usage: "..programNameShort.." (Main Tunnel Length) (Individual Tunnel Length) [Tunnel Spacing]")
- return
- else
- mainTL = tonumber(args[1])
- indivTL = tonumber(args[2])
- if #args == 3 then
- indivTunnelSpacing = tonumber(args[3])
- end
- if mainTL < 1 then
- print("Main Tunnel Length must be positive.")
- return
- end
- if indivTL < 1 then
- print("Individual Tunnel Length must be positive.")
- return
- end
- if indivTunnelSpacing < 1 then
- print("Tunnel Spacing must be positive.")
- return
- end
- -- INITIAL SETUP FASE
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome to"..programName.."Version "..versionNumber.." !")
- print("(Coded by MrHG using RobustTurtleAPI)")
- print("")
- sleep(1)
- -- FUEL CALCULATION
- -- for every 2 blocks after block 1 in MainTL, add 4 times IndivTL.
- -- then add 1 for every time you add 4xIndivTL. Then add another MainTL
- -- then add 80 just in case.
- local blocksToTravel = (2*mainTL) + (((math.floor(mainTL/2)+1)*4) * indivTL + 1) + 80
- if blocksToTravel>3000 then
- print("This will result in a mine bigger than 3000 blocks. Are you sure? (y/n)")
- if read()~="y" then
- print("Aborting operation")
- return
- end
- end
- print("Operation will need " .. blocksToTravel .. " fuel.")
- print("~" .. math.floor(blocksToTravel/80) .. " Pieces of coal.")
- print("Please ensure these are located in the top left slot.")
- print("To enable Torchmode, put torches next to the fuel.")
- print("Starting in 3 Seconds...")
- sleep(3)
- term.clear()
- print("Commencing Dig.")
- end
- function DisableTorchMode()
- print("No torches found, Disabling Torch Mode.")
- startInventory = 2
- torchEnabled = false
- return false
- end
- function checkForTorches()
- if torchEnabled == true then
- if turtle.getItemDetail(2) then
- if turtle.getItemDetail(2).name == torchName then
- startInventory = 3
- torchEnabled = true
- return true
- else
- DisableTorchMode()
- end
- else
- DisableTorchMode()
- end
- else
- startInventory = 2
- end
- end
- function Refuel(amountOfRequiredFuel)
- turtle.select(1)
- if (turtle.getFuelLevel() == "unlimited") then
- -- that's pretty neat dude.
- return
- end
- if (turtle.getFuelLevel() < amountOfRequiredFuel) then
- while (true) do
- if turtle.refuel(1) then
- if (turtle.getFuelLevel() > amountOfRequiredFuel) then
- break
- end
- else
- print("Turtle could not refuel. Please check why.")
- error()
- end
- end
- end
- end
- function PlaceTorch()
- if checkForTorches() then
- t.digUp()
- t.up()
- if turtle.detect() then
- t.turnAround()
- t.forward()
- t.turnAround()
- t.place(2)
- t.down()
- t.forward()
- return
- end
- t.down()
- end
- end
- function DigIndivTunnel()
- blocksSinceLastTorch = 0
- for i=1,indivTL do
- Refuel(160)
- t.dig()
- t.forward()
- blocksSinceLastTorch = blocksSinceLastTorch + 1
- t.digUp()
- -- Torches every 7 blocks
- if indivTL % 7 ~= 0 and i % 7 == 0 and torchEnabled then
- if checkForTorches() then
- t.up()
- t.right()
- t.forward()
- t.dig()
- local blockDetected = turtle.detectDown()
- t.back()
- -- do divisable by 3 check here so the hole is still made
- -- allowing light from other torches to pass through.
- if blockDetected and indivDug%3 == 0 then
- t.place(2)
- blocksSinceLastTorch = 0
- end
- t.left()
- t.down()
- end
- end
- end
- if torchEnabled and blocksSinceLastTorch > 4 then
- PlaceTorch()
- end
- t.turnAround()
- Refuel(indivTL)
- t.forward(indivTL)
- end
- function EmptyInventory()
- local itemsDepositedCount = 0
- for i=startInventory,16 do
- turtle.select(i)
- itemsDepositedCount = itemsDepositedCount + turtle.getItemCount()
- if turtle.getItemCount() == 0 then
- --twiddle your thumbs
- elseif not turtle.drop() then
- print("Container full. Please empty it.")
- error()
- end
- end
- print("Deposited "..itemsDepositedCount.." Items.")
- if not torchEnabled then
- print("Torch mode currently Disabled.")
- print("Insert torches in slot 2 to enable.")
- sleep(3)
- torchEnabled = true
- if checkForTorches() then
- print("Torch mode Enabled.")
- end
- end
- turtle.select(1)
- end
- -- Main Block
- checkForTorches()
- t.turnAround()
- EmptyInventory()
- print("Inventory emptied. Heading out.")
- t.turnAround()
- local blocksAwayFromContainer = 0
- for i=1,mainTL do
- Refuel(160)
- t.dig()
- t.forward()
- blocksAwayFromContainer = blocksAwayFromContainer + 1
- t.digUp()
- if (i%indivTunnelSpacing == 0) then
- t.left()
- DigIndivTunnel()
- -- Inventory check
- turtle.select(14)
- if turtle.getItemCount() > 0 then
- t.right()
- t.forward(blocksAwayFromContainer)
- EmptyInventory()
- t.turnAround()
- t.forward(blocksAwayFromContainer)
- t.right()
- end
- DigIndivTunnel()
- -- Increment Amount of Individual Tunnels dug by 1
- -- We do this after every second tunnel so it stays even on every side.
- indivDug = indivDug + 1
- turtle.select(14)
- if turtle.getItemCount() > 0 then
- t.left()
- t.forward(blocksAwayFromContainer)
- EmptyInventory()
- t.turnAround()
- t.forward(blocksAwayFromContainer)
- else
- t.right()
- end
- else
- Refuel(160)
- t.right()
- t.dig()
- t.up()
- t.dig()
- if torchEnabled and (nonIndivDug % 3 == 0)then
- if checkForTorches() then
- t.place(2)
- end
- end
- t.turnAround()
- t.dig()
- t.down()
- t.dig()
- t.right()
- nonIndivDug = nonIndivDug + 1
- end
- end
- t.turnAround()
- t.forward(mainTL)
- EmptyInventory()
- t.turnAround()
- print("")
- print("Dig Complete!")
- print("Thank you for using "..programName.."!")
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement