Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- stairup
- -- builds covered stairs up until it runs out of material or hits an obstacle
- -- stair (bottom) material in slots 1-2 (eg. cobblestone steps/stairs)
- -- WARNING! Don't use the stairs block in computercraft prior 1.5.1, placing stairs does not work there properly!
- -- walls and ceiling in slots 3-16 (eg. cobblestone)
- local posX = 0
- local height = 0
- local stepCount = 0
- local orient = 1 -- 1 forward, -1 back
- function selectFromTo(fromSlot,toSlot)
- local slotIndex = fromSlot
- local result = false
- turtle.select(slotIndex)
- while (turtle.getItemCount(slotIndex)==0) and (slotIndex < toSlot) do
- slotIndex = slotIndex + 1
- turtle.select(slotIndex)
- end
- if turtle.getItemCount(slotIndex)>0 then
- result = true
- end
- if not result then print("select from "..fromSlot.." failed") end
- return result
- end
- function selectStair()
- return selectFromTo(1,2)
- end
- function selectWall()
- return selectFromTo(3,16)
- end
- function forward()
- local result = false
- if turtle.forward() then
- result = true
- posX = posX + orient
- end
- if not result then print("forward failed") end
- return result
- end
- function back()
- local result = false
- if turtle.back() then
- result = true
- posX = posX - orient
- end
- if not result then print("back failed") end
- return result
- end
- function up()
- local result = false
- if turtle.up() then
- result = true
- height = height + 1
- end
- if not result then print("up failed") end
- return result
- end
- function down()
- local result = false
- if turtle.down() then
- result = true
- height = height - 1
- end
- if not result then print("down failed") end
- return result
- end
- function stepUp()
- local result = true
- result = selectStair()
- if result then
- result = turtle.place()
- selectWall()
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- if result then
- result = up()
- if turtle.detectUp() then result = false end
- if result then
- turtle.place()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- if result then result = forward() end
- else
- turtle.turnLeft()
- end
- else
- turtle.turnLeft()
- end
- end
- return result
- end
- function isAlignedDown()
- local result = false
- if height == (posX + 2) then
- result = true
- end
- return result
- end
- function compensateOffset()
- while (not isAlignedDown()) and (posX>0) and (height>1) do
- if not isAlignedDown() then forward() end
- if not isAlignedDown() then forward() end
- if not isAlignedDown() then down() end
- if not isAlignedDown() then forward() end
- if not isAlignedDown() then forward() end
- while (not isAlignedDown()) and (posX+2 < height) and (posX>0) and (height>1) and back() do end
- end
- if not isAlignedDown() then return false end
- return true
- end
- function stepDown()
- selectWall()
- turtle.placeUp()
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- down()
- forward()
- end
- local buildUp = true
- while buildUp do
- buildUp = stepUp()
- os.sleep(0.3)
- stepCount = stepCount + 1
- if turtle.detectUp() or turtle.detect() then
- buildUp = false
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- orient = -1
- if not compensateOffset() then
- print("can't compensate offset, something's wrong, exiting")
- return false
- end
- -- build ceiling on the way back
- for i = 2,height do
- stepDown()
- end
- print("built "..stepCount.." steps")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement