Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables ----------------------------------------------------------
- local tArgs = { ... }
- local tFuel = tonumber (turtle.getFuelLevel())
- local tSlot = 1
- if #tArgs < 1 then
- term.clear()
- term.setCursorPos(1,1)
- print("Usage: shafter <length> <height> <width> <Direction>");
- print("Type shafter and a '?' or 'help' for more info.")
- return
- elseif (tArgs[1] == '?' or tArgs[1] == 'help') then
- term.clear()
- term.setCursorPos(1,1)
- print("shafter <length> <height> <width> <Direction>");
- print("Examples:")
- print("shafter 20 2 5 1")
- print("Creates a 20 long, 5 wide, 2 high room from right to left.")
- print("If details are omitted,")
- print("default height is 2,")
- print("default width is 1,")
- print("default direction is 2 (left to right).")
- print("Shaft length is mandatory.")
- return
- end
- local sLength = tonumber ( tArgs[1] )
- local sWidth = tonumber (tArgs [3] )
- local sHeight = tonumber (tArgs [2] )
- local sDirection = tonumber (tArgs [4] )
- if sWidth == nil then
- sWidth = 1
- end
- if sHeight == nil then
- sHeight = 2
- end
- if sDirection == nil then
- sDirection = 2
- end
- -- local turns = sWidth - 1
- local aSize = (sLength * sWidth) * sHeight
- local sRows = sWidth
- hasTurned = false
- -- Functions ------------------------------------------------------------
- local function digShaft(length, height)
- if hasTurned == true then
- length = length - 1
- end
- for i = 1, length do
- turtle.dig()
- for j = 1, height - 1 do
- turtle.up()
- turtle.dig()
- end
- if (turtle.detectUp() == false) then
- turtle.select(2)
- turtle.placeUp()
- end
- for j = 1, height - 1 do
- turtle.down()
- end
- turtle.forward()
- if (turtle.detectDown() == false) then
- turtle.select(2)
- turtle.placeDown()
- end
- end
- sRows = sRows - 1
- end
- local function swapTurn(direction)
- if direction == 1 then
- sDirection = 2
- elseif direction == 2 then
- sDirection = 1
- end
- end
- local function turnTurtle(direction)
- if direction == 1 then
- turtle.turnLeft()
- elseif direction == 2 then
- turtle.turnRight()
- end
- end
- local function makeTurn(height)
- turnTurtle(sDirection)
- turtle.dig()
- for u = 1, height - 1 do
- turtle.up()
- turtle.dig()
- end
- if (turtle.detectUp() == false) then
- turtle.select(2)
- turtle.placeUp()
- end
- for d = 1, height - 1 do
- turtle.down()
- end
- turtle.forward()
- if (turtle.detectDown() == false) then
- turtle.select(2)
- turtle.placeDown()
- end
- turnTurtle(sDirection)
- swapTurn(sDirection)
- hasTurned = true
- end
- -- Check fuel ----------------------------
- -------------------------------------------
- local function checkFuel(size)
- fuel = turtle.getFuelLevel()
- trips = (size / 2) * 3 -- wrong!
- fuelNeeded = trips - fuel
- if fuelNeeded < 0 then
- fuelNeeded = 0
- end
- print("Remaining fuel: "..fuel)
- print("Area to dig: "..size)
- print("Fuel needed: "..fuelNeeded)
- --- fuel = size + length if turtle finishes job away from starting point
- if fuelNeeded > 0 then
- print("Attempting to get enough fuel for the job...")
- while fuel < trips and tSlot < 17 do
- turtle.select(tSlot)
- if turtle.refuel(1) == false then
- tSlot = tSlot + 1
- end
- if tSlot == 17 then
- print ("Not enough accessible tFuel. Aborting!")
- return false
- end
- if tSlot < 17 and fuelNeeded == 0 then
- print ("Done refueling. Commencing job!")
- turtle.select(2)
- end
- fuel = turtle.getFuelLevel()
- end
- print ("fuel: "..fuel)
- end
- return true
- end
- -- Temporary function to prevent getting stuck if there's a block above at start
- local function checkSpace()
- while turtle.detectUp() do
- turtle.back()
- end
- end
- local function doJob()
- while sRows ~= 0 do
- digShaft(sLength, sHeight)
- if sRows ~= 0 then
- makeTurn(sHeight)
- end
- end
- end
- -- Do the job ------------------------------------------------------
- --------------------------------------------------------------------
- -- Debug stuff
- print ("sLength: "..sLength.." \\ sHeight: "..sHeight.." \\ sWidth: "..sWidth)
- print ("tFuel: "..tFuel.. " \\ aSize: "..aSize)
- print ("sDirection: "..sDirection.." \\ sRows: "..sRows)
- -- actual actions
- if checkFuel(aSize) then
- checkSpace()
- doJob()
- end
Advertisement
Add Comment
Please, Sign In to add comment