Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- torchDist = 5 -- 5 by default
- totalDig = 0
- chestPlaced = 0
- tunnelH = nil
- tunnelW = nil
- turtle.select(1)
- local function clear(color, lineStart, lineEnd)
- if color == nil and lineStart == nil then
- term.clear()
- term.setCursorPos(1, 1)
- elseif color == true then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- end
- if lineStart ~= nil then
- if lineEnd == nil then
- term.setCursorPos(1, lineStart)
- term.clearLine()
- else
- for i = lineStart, lineEnd do
- term.setCursorPos(1, i)
- term.clearLine()
- end
- end
- end
- end
- local function screenWrite(text, pos, line, textColor, backgroundColor, fullLineBackgroundColor, newLine, slowPrint)
- -- for colors, use Computercrafts Color API here "http://computercraft.info/wiki/Colors_(API)"
- local screenX, screenY = term.getSize()
- if pos == "center" then
- startPos = screenX/2 - string.len(text)/2
- elseif pos == "left" then
- startPos = 1
- elseif pos == "right" then
- startPos = screenX - string.len(text)
- elseif type(pos) == "number" then
- if pos < screenX or pos > 1 then
- startPos = pos
- else
- error("Cannot start a line out of the screen")
- end
- end
- if string.len(text) > screenX then
- error("Sorry, this program does not support a screenWrite() that long at this time.")
- else
- if term.isColor() == true then
- term.setTextColor(textColor)
- term.setBackgroundColor(backgroundColor)
- if fullLineBackgroundColor == true then
- term.setCursorPos(1, line)
- clear(false, line)
- --term.clearLine()
- end
- end
- term.setCursorPos(startPos, line)
- if slowPrint == false or slowPrint == nil then
- term.write(text)
- else
- if slowPrint == 0 then
- error("Writing something at a pace of 0 letters per minute won't accomplish anything")
- end
- textutils.slowWrite(text, slowPrint)
- end
- end
- if newLine == true then
- term.setCursorPos(1, line+1)
- end
- end
- function renderBar(current, max, label, line) -- Special thanks to Lyqyd and Bomb Bloke from the Computercraft forums for this function.
- local cursorX, cursorY = term.getCursorPos()
- local screenX, screenY = term.getSize()
- local center = math.floor(screenX / 2)
- local transition = current * screenX / max
- local textStart = center - math.floor(#label / 2)
- local textStop = textStart + #label
- local before, after = textStart - 1, screenX - textStop
- local beforeStart, afterStart = math.floor(before / 2) - math.floor(string.len(tostring(current)) / 2), math.floor(after / 2) - math.floor(string.len(tostring(after)) / 2) + textStop
- local barString = string.rep(" ", beforeStart)..tostring(current)
- barString = barString..string.rep(" ", textStart - #barString)..label
- barString = barString..string.rep(" ", afterStart - #barString)..tostring(max)
- barString = barString..string.rep(" ", screenX - #barString)
- local first, second = string.sub(barString, math.min(1, transition - 1), transition - 1), string.sub(barString, transition)
- term.setCursorPos(1, line)--cursorY)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.green)
- term.write(first)
- term.setBackgroundColor(colors.red)
- term.write(second)
- end
- local function isBetween(small, large, numb)
- if numb > small then
- if numb < large then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- local function invGrid() -- WIP
- for i = 1, 4 do
- for m = 1, 4 do
- if i+m % 2 == 0 then
- paintutils.drawPixel(m+29, i+5, colors.gray)
- else
- paintutils.drawPixel(m+29, i+5, colors.lightGray)
- end
- end
- end
- --[[
- local linePosX = 30
- local linePosY = 6
- for i = 1, 16 do
- if i % 4 == 0 then
- linePosY = linePosY + 1
- linePosX = 30
- end
- if i % 2 == 0 then
- paintutils.drawPixel(linePosX, linePosY, colors.lightGray)
- linePosX = linePosX + 1
- else
- paintutils.drawPixel(linePosX, linePosY, colors.gray)
- linePosX = linePosX + 1
- end
- end]]
- end
- local function tunnelDisplay(current, lackFuel) -- add fuel bar
- renderBar(current, tArgs[1], "Progress", 1)
- screenWrite("Blocks dug: "..totalDig, "center", 3, colors.black, colors.lightGray, true, false, false)
- -- Fuel text color
- screenWrite("Fuel Remaining: "..turtle.getFuelLevel(), "center", 4, colors.black, colors.lightGray, true, false, false)
- -- if lackFuel then
- -- renderBar(
- -- end
- end
- local function tunnelDisplayExtra(info, msg)
- local screenX, screenY = term.getSize()
- --screenWrite(text, pos, line, textColor, backgroundColor, fullLineBackgroundColor, newLine, slowPrint)
- term.setBackgroundColor(colors.lightGray)
- clear(false, 5, 11)
- if info == 1 then
- screenWrite("This program will place", "left", 6, colors.black, colors.lightGray, false, false, false)
- screenWrite("torches every 5 blocks.", "left", 7, colors.black, colors.lightGray, false, false, false)
- --screenWrite("Slot 16 is the bottom right slot.", "left", 8, colors.black, colors.lightGray, false, false, false)
- screenWrite("Slot 16 is shown on", "left", 9, colors.black, colors.lightGray, false, false, false)
- screenWrite("the graph to the right", "left", 10, colors.black, colors.lightGray, false, false, false)
- screenWrite("WIP", 34, 8, colors.black, colors.lightGray, false, false, false)
- -- invGrid()
- elseif info == 2 then
- screenWrite("This program will place a bridge down.", "left", 6, colors.black, colors.lightGray, false, false, false)
- screenWrite("It needs solid blocks to place.", "left", 7, colors.black, colors.lightGray, false, false, false)
- elseif info == 3 then
- screenWrite("You will need "..tostring(tArgs[1]*5 - turtle.getFuelLevel()).." more", "left", 6, colors.black, colors.lightGray, false, false, false)
- screenWrite("fuel to complete this tunnel.", "left", 7, colors.black, colors.lightGray, false, false, false)
- screenWrite("Left click drag to refuel enough.", "left", 9, colors.black, colors.lightGray, false, false, false)
- screenWrite("Right click drag to refuel completely.", "left", 10, colors.black, colors.lightGray, false, false, false)
- elseif info == "exit" then
- screenWrite("Are you sure you want to exit?", "center", 6, colors.red, colors.lightGray, false, false, false)
- screenWrite(" Yes ", 12, 9, colors.white, colors.gray, false, false, false)
- screenWrite(" No ", screenX - 15, 9, colors.white, colors.gray, false, false, false)
- while true do
- local evt, arg1, arg2, arg3 = os.pullEvent()
- if evt == "mouse_click" then
- if arg3 == 9 then
- if isBetween(12, 12+5, arg2) == true then
- clear(true)
- print("Thank you for using JJSax's tunnel program.")
- error()
- elseif isBetween(screenX - 15, screenX - 15 + 4, arg2) == true then
- clear(true)
- break
- end
- end
- end
- end
- elseif info == "shortCenter" then
- screenWrite(msg, "center", 7, colors.black, colors.lightGray, false, false, false)
- end
- end
- local function smartRefuel(fuelRequired) -- WIP
- for i = 1, 14 do -- check for chest first
- if tArgs[1]*5 > turtle.getFuelLevel() then
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if turtle.refuel(0) == true then
- turtle.refuel(1)
- matchSlots = {}
- for i = 2, 14 do -- check for chest first
- if turtle.compareTo(i) then
- matchSlots[#matchSlots+1] = i
- end
- end
- local newFuelLevel = turtle.getFuelLevel()
- local fuelPerItem = newFuelLevel - startFuel
- local numberToFill = tArgs[1] * 5 / fuelPerItem
- turtle.refuel(numberToFill-1)
- if tArgs[1]*5 < turtle.getFuelLevel() then
- break
- end
- end
- end
- if turtle.getFuelLevel() > startFuel then
- tunnelDisplayExtra("shortCenter", turtle.getFuelLevel() - startFuel.." fuel consumed.")
- elseif i < 16 then
- tunnelDisplayExtra("shortCenter", "No fuel yet. Still looking")
- else
- tunnelDisplayExtra("shortCenter", "No fuel in inventory.")
- end
- end
- end
- end
- local function turn(dir)
- if dir == "left" or dir == "right" or dir == "around" then
- if dir == "around" then
- dir = "left 2"
- end
- shell.run("turn "..dir)
- else
- clear()
- screenWrite("Not a turning dir", "center", 6, colors.black, colors.red, false, true, false)
- end
- end
- function checkDig(dir, cur)-- _ to dig forward
- if dir ~= "up" then
- if dir == "left" or dir == "right" then
- turn(dir)
- end
- while turtle.detect() do
- turtle.dig()
- totalDig = totalDig + 1
- tunnelDisplay(cur)
- end
- while turtle.suck() do end
- if dir == "left" then
- turn("right")
- elseif dir == "right" then
- turn("left")
- end
- else
- if dir == "up" then
- while turtle.detectUp() do
- turtle.digUp()
- totalDig = totalDig + 1
- tunnelDisplay(cur)
- sleep(.4)
- end
- while turtle.suckUp() do end
- elseif dir == "down" then
- while turtle.detectDown() do
- turtle.digDown()
- totalDig = totalDig + 1
- tunnelDisplay(cur)
- end
- while turtle.suckDown() do end
- else
- error("Can't dig "..dir)
- end
- end
- end
- --[[ ADD CUSTIMIZATION SCREEN HERE
- ]]
- blocksNeeded = 10
- torchesNeeded = tArgs[1] / 5
- local i = 0
- local timer = os.startTimer(1)
- clear(true)
- if (turtle.getFuelLevel() < tArgs[1] * 5) or (math.ceil(torchesNeeded - turtle.getItemCount(16)-1) >= 0) then
- if math.ceil(torchesNeeded - turtle.getItemCount(16)) > 0 then
- screenWrite("Need "..math.ceil(torchesNeeded-turtle.getItemCount(16)).." more torches in slot 16.", "center", 1, colors.orange, colors.black, false, false, false)
- else
- screenWrite("Torch supply fulfilled", "center", 1, colors.lime, colors.black, true, false, false)
- end
- if blocksNeeded-turtle.getItemCount(1) > 0 then
- screenWrite("I recommend "..blocksNeeded-turtle.getItemCount(1).." more blocks.", "center", 2, colors.cyan, colors.black, true, false, false)
- else
- screenWrite("Block request fulfilled", "center", 2, colors.lime, colors.black, true, false, false)
- end
- if tArgs[1]*5 > turtle.getFuelLevel() then
- screenWrite(" You need "..tArgs[1]*5 - turtle.getFuelLevel().." more fuel! ", "center", 3, colors.black, colors.red, false, false, false)
- end
- -- up to stack 64 of items.
- screenWrite(" Exit ", "right", 13, colors.white, colors.red, false, false, false)
- screenWrite("Press any letter to skip", "left", 13, colors.lime, colors.black, false, false, 50)
- end
- while (turtle.getFuelLevel() < tArgs[1] * 5) or (math.ceil(torchesNeeded - turtle.getItemCount(16)-1) >= 0) do
- if math.ceil(torchesNeeded - turtle.getItemCount(16)) > 0 then
- clear(true, 1)
- screenWrite("Need "..math.ceil(torchesNeeded-turtle.getItemCount(16)).." more torches in slot 16.", "center", 1, colors.orange, colors.black, true, false, false)
- else
- screenWrite("Torch supply fulfilled", "center", 1, colors.lime, colors.black, true, false, false)
- end
- if blocksNeeded-turtle.getItemCount(1) > 0 then
- screenWrite("I recommend "..blocksNeeded-turtle.getItemCount(1).." more blocks.", "center", 2, colors.cyan, colors.black, true, false, false)
- else
- screenWrite("Block request fulfilled", "center", 2, colors.lime, colors.black, true, false, false)
- end
- if tArgs[1]*5 > turtle.getFuelLevel() then
- screenWrite(" You need "..tArgs[1]*5 - turtle.getFuelLevel().." more fuel! ", "center", 3, colors.black, colors.red, false, false, false)
- else
- screenWrite("Fuel request fulfilled", "center", 3, colors.lime, colors.black, true, false, false)
- end
- screenWrite("Press any letter to skip", "left", 13, colors.lime, colors.black, false, false, false)
- screenWrite(" Exit ", "right", 13, colors.white, colors.red, false, false, false)
- local evt, arg1, arg2, arg3 = os.pullEvent()
- if evt == "timer" then
- if arg1 == timer then
- timer = os.startTimer(1)
- end
- elseif evt == "mouse_drag" then -- Turn into function
- startFuel = turtle.getFuelLevel()
- turtle.select(1)
- if arg1 == 1 then
- if arg3 == 3 then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- -- TEMP. Real thing is in smartRefuel()
- while turtle.getFuelLevel() < tArgs[1] * 5 do
- for i = 2, 14 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if turtle.refuel(0) then
- while turtle.getItemCount(i) > 0 do
- turtle.refuel(1)
- end
- end
- end
- end
- end
- --smartRefuel()
- end
- --shell.run("noFuel") -- REMOVE
- elseif arg1 == 2 then
- if arg3 == 3 then
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if turtle.refuel(0) == true then
- turtle.refuel(turtle.getItemCount(i))
- end
- end
- end
- end
- --shell.run("noFuel") -- REMOVE
- end
- elseif evt == "mouse_click" then
- if arg3 <= 3 then
- clear(true, 4, 12)
- if arg1 == 1 then
- tunnelDisplayExtra(arg3)
- elseif arg1 == 2 then
- end
- elseif arg3 == 13 then
- if arg2 >= 33 then
- tunnelDisplayExtra("exit")
- end
- end
- elseif evt == "char" then
- break
- end
- end
- clear(true)
- tunnelDisplay(1)
- checkDig("up", 1)
- shell.run("noFuel") -- REMOVE
- for i = 1, tArgs[1] do
- tunnelDisplay(i)
- sleep(.5)
- end
- --[[ -- Temp Cut
- for i = 1, tArgs[1] do
- tunnelDisplay(i)
- checkDig(_, i)
- checkDig("left", i)
- checkDig("right", i)
- checkDig("up", i)
- turtle.up()
- checkDig("left", i)
- checkDig("right", i)
- turtle.down()
- turtle.down()
- checkDig("left", i)
- checkDig("right", i)
- if turtle.detectDown() == false then
- for i = 1, 15 do -- change when adding chest
- turtle.select(i)
- if turtle.placeDown() then
- temp = true
- break
- end
- if temp ~= true then
- error("DEBUG: Add something to do if out of placeable blocks")
- end
- end
- end
- turtle.up()
- end
- ]]
- clear(true)
- print("Thank you for using JJSax's tunnel program.")
Advertisement
Add Comment
Please, Sign In to add comment