Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Usage: tower <width / length> {direction [r|l]} {height}
- -- height is automatically adjustable or if you decide to set it, start counting from the floor
- -- v1.1: turtle's movement cant be disturbed by falling blocks or creeps
- local dig = function ()
- if turtle.detect() then
- return turtle.dig()
- end
- return false
- end
- local digUp = function ()
- if turtle.detectUp() then
- return turtle.digUp()
- end
- return false
- end
- local digDown = function ()
- if turtle.detectDown() then
- return turtle.digDown()
- end
- return false
- end
- local forward = function()
- if turtle.forward() == false then
- while turtle.forward() == false do
- turtle.dig()
- end
- end
- end
- local function digRow(length)
- for i = 1, length do
- dig()
- digDown()
- digUp()
- forward()
- end
- digUp()
- digDown()
- end
- local function digLevel(a, b)
- if not a then a = 1 end
- if not b then b = args[1] end
- for i = a, b do
- digRow( args[1] - 1)
- if i~=b then -- don't turn in the last row
- turn()
- else
- turtle.turnLeft(); turtle.turnLeft()
- reverseDirection()
- end
- end
- end
- function turn()
- turtle[ nextTurn ]()
- dig()
- forward()
- turtle[ nextTurn ]()
- reverseDirection()
- end
- function reverseDirection()
- if nextTurn ~= "" then
- if nextTurn == "turnRight" then
- nextTurn = "turnLeft"
- return true
- else
- nextTurn = "turnRight"
- return true
- end
- else
- print("nextTurn variable not set! :(")
- error()
- return false
- end
- end
- function detectLayer() -- is there one more layer above? || moving 2 blocks up
- result = false
- for i = 1, 3 do
- if (turtle.detectUp() and turtle.digUp() and turtle.up()) or (turtle.up() and turtle.detectUp() or turtle.down() and false) then -- more lulz
- result = true
- else
- break
- end
- end
- print(tostring(result))
- return result
- end
- function isEven(n)
- if n%2 == 0 then
- return true
- end
- return false
- end
- args = {...}
- args[1] = tonumber(args[1])
- nextTurn = ""
- if args[1] == nil then
- print("First argument must be a number!")
- error()
- end
- if args[2] == "r" or args[2] == "l" then
- else
- print("Second argument is invalid! It can be either l or r")
- end
- args[3] = tonumber(args[3])
- if args[3] ~= nil then
- height = 2
- function detectLayer ( height )
- if height + 2 < args[3] then
- for i = 1, 3 do
- digUp(); turtle.up()
- end
- return true
- else
- return false
- end
- end
- else
- height = 2
- end
- print(args[2])
- print("Size: "..args[1] .. "x" ..args[1] .. ", direction: ".. (tostring(args[2])~="nil" and args[2] or "not set")) -- for the lulz, without any if
- sleep(2)
- print("\nBeginning...")
- turtle.up()
- digRow( args[1] ) -- 1
- if args[2] == "r" then
- nextTurn = "turnRight"
- else
- nextTurn = "turnLeft"
- end
- if nextTurn == "" then
- print("nexturn="..nextTurn)
- turtle.turnRight() -- where to continue?
- if turtle.detect() then
- nextTurn = "turnRight"
- turtle.turnLeft()
- else
- turtle.turnLeft(); turtle.turnLeft()
- if turtle.detect() then
- nextTurn = "turnLeft"
- turtle.turnRight()
- else
- print("Can't find the path around the corner!\n\nAborting!")
- error()
- end
- end
- end
- turn()
- digLevel(2, args[1])
- while detectLayer(height) do
- reverseDirection()
- digLevel(1, args[1])
- height = height + 2
- end
- print("Height: " .. height)
- while height > 0 do
- turtle.down()
- height = height - 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement