Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Simple 1-block-wide stairs maker by Miki_Tellurium
- Version: 1.0
- Make a 1-block-wide staircase of specified height (min = 3).
- Usage:
- <fileName> -- default to 5
- or
- <fileName> height
- ]]
- if not turtle then
- error("Computer is not a turtle.")
- end
- local arg = ...
- local maxHeight = 5
- if arg then
- local n = tonumber(arg)
- if n then
- maxHeight = n
- end
- end
- -- Max height less than 3 breaks digNext()
- -- also a player wouldn't fit in the stairs
- if maxHeight < 3 then
- error("Height can't be less than 3.")
- end
- local fuel = turtle.getFuelLevel()
- if fuel == 0 then
- error("No fuel.")
- elseif fuel < maxHeight * 50 then
- local ogColor = term.getTextColor()
- term.setTextColor(colors.orange)
- print("Low fuel level, consider refueling.")
- term.setTextColor(ogColor)
- end
- -- Handle falling blocks
- -- try to advance for 10 seconds and return false if no success
- local function advance()
- local function timeout()
- sleep(10)
- print("Timeout reached, giving up.")
- end
- local function tryAdvance()
- while not turtle.forward() do
- turtle.dig()
- end
- end
- local result = parallel.waitForAny(tryAdvance, timeout)
- if result == 1 then
- return true
- else
- return false
- end
- end
- -- Return false if an unbreakable block is found
- local function digNext(height)
- local toMove = height - 2 -- Exclude top and bottom block
- if not advance() then return false end
- turtle.digDown()
- for _ = 1,toMove do
- turtle.down()
- if turtle.detectDown() and not turtle.digDown() then
- return false
- end
- end
- if toMove == maxHeight-2 then toMove = toMove - 1 end -- Move up one block less if we are doing full stairs height
- for _ = 1,toMove do
- turtle.up()
- end
- return true
- end
- local keepGoing = true
- local currentHeight = 3
- local steps = 0
- print("Selected block height: "..maxHeight)
- turtle.digUp()
- turtle.up()
- while keepGoing do
- if turtle.getFuelLevel() == 0 then
- error("Run out of fuel.")
- end
- keepGoing = digNext(currentHeight)
- if keepGoing then
- if currentHeight < maxHeight then
- currentHeight = currentHeight + 1
- end
- steps = steps + 1
- else
- print("Unbreakable block found.")
- end
- end
- print("Finished stairs with "..steps.." steps.")
Advertisement
Add Comment
Please, Sign In to add comment