Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to parse command line arguments
- local function parseArgs(args)
- local count = tonumber(args[1])
- local acceptAny = false
- if args[2] == "--accept-any" then
- acceptAny = true
- end
- return count, acceptAny
- end
- -- Function to find and select more stairs
- local function selectStairs(initialItemDetail, acceptAny)
- for slot = 1, 16 do
- local itemDetail = turtle.getItemDetail(slot)
- if itemDetail then
- if acceptAny or (itemDetail.name == initialItemDetail.name) then
- turtle.select(slot)
- return true
- end
- end
- end
- return false
- end
- -- Function to place a stair block below the turtle
- local function placeStair(initialItemDetail, acceptAny)
- while not turtle.placeDown() do
- turtle.digDown()
- if turtle.getItemCount() == 0 then
- if not selectStairs(initialItemDetail, acceptAny) then
- print("Out of stairs!")
- return false
- end
- end
- end
- return true
- end
- -- Function to move the turtle up safely
- local function moveUp()
- while not turtle.up() do
- turtle.digUp()
- end
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- -- Function to move the turtle forward safely
- local function moveForward()
- while not turtle.forward() do
- turtle.dig()
- end
- end
- -- Main function to build stairs
- local function buildStairs(count, acceptAny)
- local initialItemDetail = turtle.getItemDetail(1)
- if not initialItemDetail then
- print("No stairs in slot 1!")
- return
- end
- for i = 1, count do
- if not placeStair(initialItemDetail, acceptAny) then
- break
- end
- moveUp()
- moveForward()
- end
- end
- -- Get command line arguments
- local tArgs = {...}
- local stairsCount, acceptAny = parseArgs(tArgs)
- -- Check if the number of stairs is provided
- if not stairsCount then
- print("Usage: buildStairs <number_of_stairs> [--accept-any]")
- return
- end
- -- Start building stairs
- buildStairs(stairsCount, acceptAny)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement