Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- uses Robust Turtle API: pastebin get RXTW1YbW t
- os.loadAPI("t")
- local args = {...}
- local versionNumber = "3.1"
- local programName = "StarDustMiner "
- local programNameShort = "SDMiner"
- local startInventory = 2
- local torchEnabled = true
- local containerEnabled = true
- -- 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
- local tunnelsSinceLastTorch = 6
- local tunnelTimer = 2
- if #args < 2 or #args > 3 then
- print ("Usage: "..programNameShort.." (Main Tunnel Length) (Corridor Length) [Corridor 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("Corridor Length must be positive.")
- return
- end
- if indivTunnelSpacing < 1 then
- print("Corridor Spacing must be positive.")
- return
- end
- -- INITIAL SETUP FASE
- term.clear()
- term.setCursorPos(1,1)
- print(programName..versionNumber.." Coded by MrHG")
- 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
- print("Required fuel: " .. blocksToTravel)
- print("Slot 1: Fuel")
- print("Slot 2-4: Torches")
- print("Commencing Dig.")
- end
- function DisableTorchMode()
- print("Out of Torches.")
- startInventory = 2
- torchEnabled = false
- return false
- end
- function checkForTorches()
- if torchEnabled == true then
- if turtle.getItemCount(2) > 1 then
- startInventory = 3
- torchEnabled = true
- return true
- else
- if t.restock(2,3,true) then
- return true
- else
- DisableTorchMode()
- end
- end
- else
- startInventory = 2
- end
- end
- function PlaceTorch()
- if checkForTorches() then
- if turtle.detect() then
- t.back()
- blocksToMove = blocksToMove-1
- t.place(2)
- turtle.select(startInventory)
- return
- end
- end
- end
- function PlaceTorchDown()
- if checkForTorches() then
- t.down()
- if turtle.detectDown() then
- t.up()
- t.placeDown(2)
- turtle.select(startInventory)
- else
- t.up()
- end
- end
- end
- function DigIndivTunnel()
- blocksSinceLastTorch = 0
- for i=1,indivTL do
- t.refuel(160,startInventory)
- t.dig()
- t.forward()
- blocksSinceLastTorch = blocksSinceLastTorch + 1
- t.digUp()
- t.digDown()
- -- Torches every 7 blocks
- if indivTL % 7 ~= 0 and i % 7 == 0 and torchEnabled and indivTunnelSpacing > 1 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
- if tunnelsSinceLastTorch > 5 and torchEnabled and indivTunnelSpacing == 1 then
- if i % 5 == 0 and checkForTorches() then
- PlaceTorchDown()
- end
- end
- end
- blocksToMove = indivTL
- if torchEnabled and blocksSinceLastTorch > 2 then
- if indivTunnelSpacing ~= 1 then
- PlaceTorch()
- else
- tunnelsSinceLastTorch = tunnelsSinceLastTorch + 1
- if tunnelsSinceLastTorch > 5 then
- PlaceTorch()
- tunnelTimer = tunnelTimer-1
- if tunnelTimer == 0 then
- tunnelsSinceLastTorch = 0
- tunnelTimer = 2
- end
- end
- end
- end
- t.turnAround()
- t.refuel(blocksToMove,startInventory)
- t.forward(blocksToMove)
- 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
- sleep(3)
- torchEnabled = true
- if checkForTorches() then
- print("Torch mode enabled.")
- end
- end
- turtle.select(startInventory)
- end
- function InventoryCheck(LeftSide)
- turtle.select(fullInv)
- if turtle.getItemCount() > 0 then
- if LeftSide then
- t.right()
- else
- t.left()
- end
- t.forward(blocksAwayFromContainer)
- t.down()
- if not containerEnabled then
- print("Inventory Full.")
- brokeEarly = true
- return true
- end
- EmptyInventory()
- t.turnAround()
- t.up()
- t.forward(blocksAwayFromContainer)
- if LeftSide then
- t.right()
- else
- t.left()
- end
- end
- return false
- end
- -- Main Block
- t.refuel(160,startInventory)
- checkForTorches()
- t.turnAround()
- containerEnabled = turtle.detect()
- fullInv = 14
- if containerEnabled then
- EmptyInventory()
- print("Inventory emptied. Heading out.")
- fullInv = 14
- else
- print("No container: Mining until full.")
- fullInv = 16
- end
- t.turnAround()
- t.up()
- blocksAwayFromContainer = 0
- brokeEarly = false
- for i=1,mainTL do
- t.refuel(160,startInventory)
- t.dig()
- t.forward()
- blocksAwayFromContainer = blocksAwayFromContainer + 1
- t.digUp()
- t.digDown()
- if (i%indivTunnelSpacing == 0) then
- t.left()
- DigIndivTunnel()
- -- Inventory check for Left tunnel
- if InventoryCheck(true) then
- break
- 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
- -- Inventory check for Right tunnel
- if InventoryCheck(false) then
- break
- end
- t.right()
- else
- t.refuel(160,startInventory)
- t.right()
- t.dig()
- t.forward()
- t.digUp()
- t.digDown()
- t.back()
- if torchEnabled and (nonIndivDug % 3 == 0)then
- if checkForTorches() then
- t.place(2)
- end
- end
- t.turnAround()
- t.dig()
- t.forward()
- t.digUp()
- t.digDown()
- t.back()
- t.right()
- nonIndivDug = nonIndivDug + 1
- end
- end
- if not brokeEarly then
- t.turnAround()
- t.forward(mainTL)
- t.down()
- if containerEnabled then
- EmptyInventory()
- end
- t.turnAround()
- end
- print("")
- print("Dig Complete!")
- print("Thank you for using "..programName.."!")
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement