Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Programmed: 17 May 2014
- -- by Skyler James
- --
- -- Digs stairs <width> wide
- -- and <length> long, placing
- -- blocks underneath it as
- -- needed (ensures you can
- -- always get to your turtle)
- --
- -- The most important functions
- -- are digstair and digxsides
- local tArgs = { ... }
- if #tArgs ~= 2 then
- print( "Usage: stairmine <width> <length>" )
- return
- end
- -- Set width of stairs with user input
- local width = tonumber( tArgs[1] )
- if width < 1 or width > 3 then
- print( "Stair width must be between 1 and 3, inclusive" )
- return
- end
- -- Set length of stairs with user input
- local length = tonumber( tArgs[2] )
- if length < 1 then
- print( "Stair length must be positive" )
- return
- end
- -- Dig, then wait in case
- -- gravel / sand falls
- function digfront()
- while turtle.detect() do
- turtle.dig()
- sleep(0.65)
- end
- end
- -- If width is 3 dig
- -- both sides of turtle
- function dig2sides()
- turtle.turnRight()
- digfront()
- turtle.turnLeft()
- turtle.turnLeft()
- digfront()
- turtle.turnRight()
- end
- -- If width is 2 dig
- -- right side of turtle
- function dig1side()
- turtle.turnRight()
- digfront()
- turtle.turnLeft()
- end
- -- Dig, then wait in case
- -- sand / gravel falls
- function digup()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.65)
- end
- end
- -- Decide which digside
- -- function to call based
- -- on user input
- function digxsides()
- if width == 3 then
- dig2sides()
- elseif width == 2 then
- dig1side()
- end
- end
- -- If there is nothing under the turtle,
- -- it will place a block. Very prone
- -- to bugs, but not needed often
- -- Will only build bridge / stairs
- -- 1 block wide, but it works
- function putblockifneeded()
- -- first, of course, check
- -- if a block is needed
- if not (turtle.detectDown()) then
- local highestcount = 0
- local slotwithmost = 0
- local tempnum = 0
- -- iterate through 9 slots
- -- and find which one has
- -- the most blocks. That
- -- slot is most likely
- -- dirt or cobblestone.
- for i = 1,9,1 do
- tempnum = turtle.getItemCount(i)
- if tempnum > highestcount then
- slotwithmost = i
- highestcount = tempnum
- end
- end
- -- double check that there
- -- are any blocks to use.
- -- If yes, place one.
- turtle.select(slotwithmost)
- if highestcount > 0 then
- turtle.placeDown()
- else
- return
- end
- end
- end
- -- Move the turtle in a stair
- -- mining pattern, digging a
- -- ceiling 4 blocks high and
- -- calling digxsides as needed
- function digstair()
- digxsides()
- digup()
- turtle.digDown()
- turtle.up()
- digxsides()
- digup()
- turtle.up()
- digxsides()
- turtle.down()
- turtle.down()
- turtle.down()
- putblockifneeded()
- digxsides()
- end
- -- user input is not faulty,
- -- so begin mining stairs
- -- <length> blocks deep
- print("Mining stairs . . .")
- for i = 1,length,1 do
- digfront()
- turtle.forward()
- digstair()
- print("Mined "..i.." stairs")
- end
- -- That's all, folks!
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement