Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Config ]]--
- local mTorch = true
- --> Places torches
- local torchDistance = 5
- --> The distance the torches will be placed
- local rFill = true
- --> Fills ring to prevent liquid leaks
- ---> Not Implemented
- local enderchest = false
- --> Uses an enderchest to empty inventory
- local textFlash = true
- --> Flashes various text!
- ---> For important reasons of course!
- ---> You can disable this if you can't see the message clearly... :(
- local rTStart = true
- --> The turtle will return to start when finished
- local sRFuel = false
- --> The turtle will refuel 10% of all fuel
- local lastSlot = 13
- --> The last slot the turtle will check for items
- --> Just in case you wanted to shrink.. your.. turtle's inventory..?
- --[[ Slot Settings ]]--
- local slots = {
- {14, "Enderchest"},
- {15, "Fuel"},
- {16, "Torch"}
- }
- --> The first number is the slot number, the second is the display name
- --[[ DO NOT EDIT WHAT'S BELOW UNLESS YOU KNOW WHAT YOU'RE DOING ]]--
- --[[ Variables ]]--
- --> pVersion uses a specific naming convention.
- ---> The numbers on the left side of the dash (-) is the last version the program was edited in
- ---> The number(s) on the right side of the dash (-) is the release version
- local pVersion = "1.7.10-2"
- local pHeader = "Branch Miner v"..pVersion.." BETA"
- local pFooter = "Bug reports ARE helpful!"
- local tDistance = 0
- --[[ Functions ]]--
- local function cs()
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function centerT(text, textType)
- local mx, my = term.getSize()
- local cx, cy = term.getCursorPos()
- term.setCursorPos(math.floor((mx-string.len(text))/2), cy)
- if string.lower(textType) == "print" then
- print(text)
- elseif string.lower(textType) == "write" then
- write(text)
- elseif string.lower(textType) == "error" then
- printError(text)
- elseif string.lower(textType) == "swrite" then
- textutils.slowWrite(text)
- elseif string.lower(textType) == "sprint" then
- textutils.slowPrint(text)
- end
- end
- local function dScreen()
- cs()
- centerT(pHeader, "print")
- centerT("-------------", "print")
- local mx, my = term.getSize()
- term.setCursorPos(1, my-1)
- centerT("-------------", "print")
- centerT(pFooter, "write")
- term.setCursorPos(1, 5)
- end
- local function cFuel()
- if sRFuel then
- local fuelLevel = turtle.getFuelLevel()
- local sFuel = 0
- for a=1, lastSlot do
- if turtle.getItemCount(a) > 0 then
- turtle.select(a)
- for b=1, #slots do
- if string.lower(slots[b][2]) == "fuel" then
- if turtle.compareTo(slots[b][1]) then
- sFuel = sFuel + turtle.getItemCount(a)
- end
- end
- end
- end
- end
- local sFuel = math.floor(sFuel/10)
- if fuelLevel <= 20 then
- for a=1, lastSlot do
- turtle.select(a)
- for b=1, #slots do
- if string.lower(slots[b][2]) == "fuel" then
- if turtle.compareTo(slots[b][1]) then
- local iFuel = turtle.getItemCount(a)
- local uFuel = iFuel - sFuel
- if sFuel <= iFuel then
- turtle.refuel(sFuel)
- break
- else
- turtle.refuel()
- sFuel = sFuel - iFuel
- end
- end
- end
- end
- end
- elseif fuelLevel == "unlimited" then
- centerT("You have unlimited fuel!", "print")
- centerT("Why did you enable smart refuel..?", "print")
- end
- else
- for a=1, lastSlot do
- turtle.select(a)
- for b=1, #slots do
- if string.lower(slots[b][2]) == "fuel" then
- if turtle.compareTo(15) then
- turtle.refuel()
- break
- end
- end
- end
- end
- end
- end
- local function sInventory()
- if turtle.getItemCount(lastSlot) > 0 then
- for a=1, lastSlot do
- if turtle.getItemCount(a) < 64 and turtle.getItemCount(a) > 0 then
- for b=a+1, lastSlot do
- if turtle.getItemCount(b) > 0 then
- turtle.select(b)
- if string.lower(slots[1][2]) == "enderchest" then
- if enderchest and b ~= slots[1][1] then
- if turtle.compareTo(a) and turtle.getItemCount(a) < 64 then
- turtle.select(b)
- turtle.transferTo(a)
- end
- else
- if turtle.compareTo(a) and turtle.getItemCount(a) < 64 then
- turtle.select(b)
- turtle.transferTo(a)
- end
- end
- end
- end
- end
- end
- end
- for a=1, lastSlot do
- for b=a+1, lastSlot do
- if string.lower(slots[1][2]) == "enderchest" then
- if enderchest and b ~= slots[1][1] then
- if turtle.getItemCount(a) == 0 and turtle.getItemCount(b) > 0 then
- turtle.select(b)
- turtle.transferTo(a)
- end
- else
- if turtle.getItemCount(a) == 0 and turtle.getItemCount(b) > 0 then
- turtle.select(b)
- turtle.transferTo(a)
- end
- end
- end
- end
- end
- end
- end
- local function eInventory()
- sInventory()
- if turtle.getItemCount(lastSlot) > 0 then
- if enderchest then
- if turtle.getItemCount(lastSlot) > 0 then
- turtle.select(16)
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.place()
- for a=1, lastSlot do
- turtle.select(a)
- turtle.drop()
- end
- turtle.select(16)
- turtle.dig()
- turtle.select(1)
- turtle.turnRight()
- turtle.turnRight()
- end
- else
- turtle.turnLeft()
- turtle.turnLeft()
- for a=1, tDistance do
- turtle.forward()
- end
- for a=1, lastSlot do
- turtle.select(a)
- turtle.drop()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for a=1, tDistance do
- turtle.forward()
- end
- end
- end
- end
- local function stats()
- cs()
- local fuelLevel = turtle.getFuelLevel()
- local availFuel = 0
- local uInventory = 0
- local fInventory = 64 * lastSlot
- for a=1, lastSlot do
- if turtle.getItemCount(a) > 0 then
- uInventory = uInventory + turtle.getItemCount(a)
- turtle.select(a)
- end
- for b=1, #slots do
- if string.lower(slots[b][2]) == "fuel" then
- if turtle.compareTo(slots[b][1]) then
- availFuel = availFuel + turtle.getItemCount(a)
- end
- end
- end
- end
- if smart_refuel then
- local sFuel = math.floor(availFuel/10)
- end
- dScreen()
- centerT("Fuel: "..fuelLevel, "print")
- if smart_refuel then
- centerT("Fuel Supplies: "..sFuel.."/"..availFuel, "print")
- else
- centerT("Fuel Supplies: "..availFuel, "print")
- end
- local pInventory = math.floor((uInventory/fInventory)*100)
- centerT("Last Storage Slot: "..lastSlot, "print")
- centerT("Storage: "..pInventory.."% full ("..uInventory.." items)", "print")
- centerT("Distance: "..tDistance.." out of "..length.." ("..length-tDistance.." left) ", "print")
- end
- local function bMine()
- for a=1, length do
- sInventory()
- stats()
- cFuel()
- turtle.select(1)
- for b=1, 3 do
- if a ~= length then
- if turtle.detect() then
- repeat
- turtle.dig()
- sleep(0.5)
- until not turtle.detect()
- end
- end
- turtle.turnLeft()
- if turtle.detect() then
- repeat
- turtle.dig()
- sleep(0.5)
- until not turtle.detect()
- end
- if b == 2 and (tDistance % torchDistance) == 0 and mTorch then
- turtle.forward()
- if turtle.detect() then
- turtle.dig()
- end
- for d=1, #slots do
- if string.lower(slots[d][2]) == "torch" then
- turtle.select(slots[d][1])
- turtle.place()
- end
- end
- turtle.back()
- end
- turtle.turnRight()
- turtle.turnRight()
- if turtle.detect() then
- repeat
- turtle.dig()
- sleep(0.5)
- until not turtle.detect()
- end
- turtle.turnLeft()
- if b < 3 then
- if turtle.detectUp() then
- repeat
- turtle.digUp()
- sleep(0.5)
- until not turtle.detectUp()
- end
- end
- if b < 3 then
- turtle.up()
- end
- end
- for b=1, 2 do
- turtle.down()
- end
- if not turtle.forward() then
- repeat
- turtle.dig()
- sleep(0.5)
- until not turtle.detect()
- turtle.forward()
- end
- tDistance = tDistance + 1
- eInventory()
- end
- if rTStart then
- turtle.turnRight()
- turtle.turnRight()
- for a=1, length do
- turtle.forward()
- end
- end
- end
- --[[ Main ]]--
- --[[ Get Inputs ]]--
- repeat
- dScreen()
- centerT("How far should I tunnel?", "print")
- centerT("TIP: This shouldn't be less than 10", "print")
- local cx, cy = term.getCursorPos()
- write("> ")
- local ulength = read()
- term.setCursorPos(1, cy-1)
- term.clearLine(cy-1)
- term.setCursorPos(1, cy)
- term.clearLine(cy)
- local mx, my = term.getSize()
- term.setCursorPos(1, my-3)
- centerT("Distance: "..ulength, "print")
- if type(tonumber(ulength)) == "nil" then
- length = string.len(ulength)
- else
- length = tonumber(ulength)
- end
- sleep(1)
- until length > 0
- --[[ Slot Usage ]]--
- dScreen()
- centerT("Loading...", "swrite")
- sleep(0.5)
- term.clearLine(1)
- term.setCursorPos(1, 4)
- for a=slots[1][1], slots[#slots][1] do
- if a == 14 then
- if enderchest then
- centerT('Please put an "'..slots[a-13][2]..'" in slot '..slots[a-13][1], "print")
- end
- elseif a == 15 then
- centerT('Please put "'..slots[a-13][2]..'" in slot '..slots[a-13][1], "print")
- else
- centerT('Please put a "'..slots[a-13][2]..'" in slot '..slots[a-13][1], "print")
- end
- end
- local mx, my = term.getSize()
- term.setCursorPos(1, my-3)
- centerT("Press any key to continue", "print")
- local event = os.pullEvent("key")
- if event then
- for a=slots[1][1], slots[#slots][1] do
- cs()
- dScreen()
- if a == 14 then
- if string.lower(slots[a-13][2]) == "enderchest" and enderchest then
- repeat
- cs()
- dScreen()
- if textFlash then
- sleep(1)
- end
- if turtle.getItemCount(a) > 0 then
- print('Assuming an "'..slots[a-13][2]..'" is in slot '..a)
- else
- centerT('Missing an "'..slots[a-13][2]..'" in slot '..a, "error")
- centerT("I will check again in 1 second...", "print")
- end
- if textFlash then
- sleep(1)
- end
- until turtle.getItemCount(a) > 0
- else
- centerT("Enderchest use is disabled!", "error")
- if lastSlot == 13 then
- print("Assuming last slot is the default value")
- lastSlot = 14
- sleep(0.5)
- end
- end
- elseif a == 15 then
- repeat
- cs()
- dScreen()
- if textFlash then
- sleep(1)
- end
- if turtle.getItemCount(a) > 0 then
- centerT('Assuming "'..slots[a-13][2]..'" is in slot '..a, "print")
- else
- centerT('Missing "'..slots[a-13][2]..'" in slot '..a, "error")
- centerT("I will check again in 1 second...", "print")
- end
- if textFlash then
- sleep(1)
- end
- until turtle.getItemCount(a) > 0
- else
- repeat
- cs()
- dScreen()
- if textFlash then
- sleep(1)
- end
- if turtle.getItemCount(a) > 0 then
- centerT('Assuming a "'..slots[a-13][2]..'" is in slot '..a, "print")
- else
- centerT('Missing a "'..slots[a-13][2]..'" in slot '..a, "error")
- centerT("I will check again in 1 second...", "print")
- end
- if textFlash then
- sleep(1)
- end
- until turtle.getItemCount(a) > 0
- end
- sleep(0.5)
- end
- end
- --[[ Branch Mine ]]--
- bMine()
- stats()
- local mx, my = term.getSize()
- centerT("Finished!", "print")
- sleep(2)
- cs()
Advertisement
Add Comment
Please, Sign In to add comment