Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Lazy Nub Stairs v0.04
- lava resistant blocks in slot 1 (optional)
- fuel in slot 15 (coal, charcoal, lava bucket so on..)
- torches in slot 16 (optional)
- Will build downward straight or spiral single width stair.
- It will place torches if you wish and at any
- distance apart you specify.
- Suggestion: Torches 7 apart.
- Also will ensure there is always a step placed
- but optionally will build 100% enclosed stair well
- in order to traverse lava and water areas safely.
- if you select secure building, place lava resistant
- blocks in slot 1.
- fuel required is 2 times stair depth for normal stairs
- or 4 times stair depth for secure stairs.
- Turtle will run a fuel level check before digging.
- fuel slot is 15
- ]]--
- --[[ Robust Turtle
- Modified version of
- Robust Turtle API by SpeedR
- integrated
- ]]--
- --Digging with gravel/sand detection
- function dig()
- local tries = 0
- while turtle.detect() do
- turtle.dig()
- sleep(0.5)
- tries = tries + 1
- if tries>500 then
- print("Error: dug for too long.")
- return false
- end
- end
- return true
- end
- function digUp()
- local tries = 0
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.5)
- tries = tries + 1
- if tries>500 then
- print("Error: dug up for too long.")
- return false
- end
- end
- return true
- end
- function digDown()
- local tries = 0
- while turtle.detectDown() do
- turtle.digDown()
- sleep(0.5)
- tries = tries + 1
- if tries>500 then
- print("Error: dug down for too long.")
- return false
- end
- end
- return true
- end
- --Traveling: Goes in the direction no matter what (almost)
- --Will not be stopped by blocks or mobs
- function forward(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.forward() ~= true do
- turtle.dig()
- turtle.attack()
- sleep(0.2)
- tries = tries + 1
- if tries>500 then
- print("Error: can't move forward.")
- return false
- end
- end
- end
- return true
- end
- function up(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.up() ~= true do
- turtle.digUp()
- turtle.attackUp()
- sleep(0.2)
- tries = tries + 1
- if tries>500 then
- print("Error: can't move up.")
- return false
- end
- end
- end
- return true
- end
- function down(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.down() ~= true do
- turtle.digDown()
- turtle.attackDown()
- sleep(0.2)
- tries = tries + 1
- if tries>500 then
- print("Error: can't move down.")
- return false
- end
- end
- end
- return true
- end
- function back(l)
- l=l or 1
- for i=1,l do
- if turtle.back() ~= true then
- turnAround()
- forward()
- turnAround()
- end
- end
- end
- --Place blocks
- --Does not place when there's already the right block.
- function place(block)
- turtle.select(block)
- if turtle.compare()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- dig()
- turtle.place()
- end
- end
- function placeUp(block)
- turtle.select(block)
- if turtle.compareUp()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- digUp()
- turtle.placeUp()
- end
- end
- function placeDown(block)
- turtle.select(block)
- if turtle.compareDown()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- digDown()
- turtle.placeDown()
- end
- end
- local function outOfResource()
- print("Ran out of a resource. Block: ",block , ".")
- print("Refill, then say something to proceed.")
- read()
- end
- function placeRight(block)
- turtle.turnRight()
- place(block)
- turtle.turnLeft()
- end
- function placeLeft(block)
- turtle.turnLeft()
- place(block)
- turtle.turnRight()
- end
- function placeBack(block)
- turnAround()
- place(block)
- turnAround()
- end
- --place row e.g. placeRow(up, marble, forward, 15)
- function placeRow(placeDir, block, travelDir, l)
- l=l or 1
- for i=1,l do
- if placeDir == "forward" then
- place(block)
- elseif placeDir == "up" then
- placeUp(block)
- elseif placeDir == "down" then
- placeDown(block)
- elseif placeDir == "right" then
- placeRight(block)
- elseif placeDir == "left" then
- placeLeft(block)
- elseif placeDir == "back" then
- placeBack(block)
- else
- print('"', placeDir, '" is not a valid direction!')
- return false
- end
- if travelDir == "forward" then
- forward()
- elseif travelDir == "up" then
- up()
- elseif travelDir == "down" then
- down()
- elseif travelDir == "right" then
- strafeRight()
- elseif travelDir == "left" then
- strafeLeft()
- elseif travelDir == "back" then
- back()
- else
- print('"', travelDir, '" is not a valid direction!')
- return false
- end
- end
- return true
- end
- --Turning
- function turnAround()
- turtle.turnRight()
- turtle.turnRight()
- end
- function right()
- turtle.turnRight()
- end
- function left()
- turtle.turnLeft()
- end
- function goRight(l)
- l=l or 1
- turtle.turnRight()
- forward(l)
- end
- function goLeft(l)
- l=l or 1
- turtle.turnLeft()
- forward(l)
- end
- function strafeRight(l)
- l=l or 1
- goRight(l)
- turtle.turnLeft()
- end
- function strafeLeft(l)
- l=l or 1
- goLeft(l)
- turtle.turnRight()
- end
- --[[ End of Robust Turtle
- ]]--
- function getBlock()
- i = 1
- while turtle.getItemCount(i) < 1 and i < 16 do
- i= i+1
- end
- return i
- end
- --[[
- Main
- ]]--
- local stairLength = 1
- local torchDistance = 5
- local placeTorch = false
- local torchSlot = 16
- local running = true
- local secureStairs = false
- local spiralStairs = false
- term.clear()
- term.setCursorPos (1, 1)
- print("Lazy Nub Stairs v0.04")
- print("=====================")
- print("What length of stair: ")
- stairLength = read()
- print("Spiral Stairs (y/n): ")
- ut = read()
- if ut == "y" or ut == "Y" then
- spiralStairs = true
- end
- print("Use Torches (y/n): ")
- ut = read()
- if ut == "y" or ut == "Y" then
- placeTorch = true
- print("How Far Apart: ")
- torchDistance = read()
- if (stairLength/torchDistance) > (turtle.getItemCount(torchSlot)) then
- print("Place atleast ".. math.ceil(stairLength/torchDistance).." in slot "..torchSlot.." <ENTER>")
- ut = read()
- end
- end
- print("Build Securely (y/n): ")
- ut = read()
- if ut == "y" or ut == "Y" then
- secureStairs = true
- if not turtle.getItemCount(1) then
- print("Place lava resistant blocks in slot 1")
- while not turtle.getItemCount(1) do
- end
- end
- end
- if (not secureStairs and (turtle.getFuelLevel() < (stairLength*2)))
- or (secureStairs and (turtle.getFuelLevel() < (stairLength*4))) then
- if secureStairs then
- print("Need "..(stairLength*4).." fuel")
- else
- print("Need "..(stairLength*2).." fuel")
- end
- print("Fuel Level at: "..turtle.getFuelLevel())
- while (not secureStairs and (turtle.getFuelLevel() < (stairLength*2)))
- or (secureStairs and (turtle.getFuelLevel() < (stairLength*4))) do
- turtle.select(15)
- print ("Place fuel item into slot 15 and press <Enter>")
- ut = read()
- turtle.refuel(1)
- print("Fuel Level at: "..turtle.getFuelLevel())
- end
- turtle.select(1)
- end
- while running do
- for i = 1,stairLength do
- if spiralStairs and ( i%3 == 0) then -- may need to add wall check for secure builds
- right()
- end
- forward()
- if placeTorch == true then
- if i%torchDistance ==0 then
- turtle.select(torchSlot)
- turnAround()
- place(torchSlot)
- turnAround()
- end
- end
- if secureStairs then
- right()
- if not turtle.detect() then
- place(getBlock())
- end
- turnAround()
- if not turtle.detect() then
- place(getBlock())
- end
- right()
- end
- digUp()
- if secureStairs then
- up()
- if not turtle.detectUp() then
- placeUp(getBlock())
- end
- if not turtle.detect() then
- place(getBlock())
- end
- right()
- if not turtle.detect() then
- place(getBlock())
- end
- turnAround()
- if not turtle.detect() then
- place(getBlock())
- end
- right()
- down()
- end
- down()
- if secureStairs then
- right()
- if not turtle.detect() then
- place(getBlock())
- end
- turnAround()
- if not turtle.detect() then
- place(getBlock())
- end
- right()
- end
- if not turtle.detectDown() then
- placeDown(getBlock())
- end
- end
- running = false
- end
- print("finished")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement