Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local length = tonumber(tArgs[1]) or 0
- local width = tonumber(tArgs[2]) or 0
- local height = tonumber(tArgs[3]) or 0
- local slot = 0
- local qu_x = 1
- local qu_y = 0
- local qu_z = 1
- local facing = 2
- --[[
- 13 - pavement
- 14 - walls
- 15 - roof
- ]]--
- function move (dir)
- if dir == "up" then
- if turtle.up() then
- qu_y = qu_y + 1
- return true
- else
- return false
- end
- elseif dir == "down" then
- if turtle.down() then
- qu_y = qu_y - 1
- return true
- else
- return false
- end
- elseif dir == "north" or dir == "south" or dir == "west" or dir == "east" then
- turnTo(dir)
- local moved = turtle.forward()
- if moved then
- if dir == "north" then qu_z = qu_z + 1 elseif dir == "south" then qu_z = qu_z - 1 elseif dir == "west" then qu_x = qu_x - 1 elseif dir == "east" then qu_x = qu_x + 1 end
- return true
- else
- return false
- end
- end
- return false
- end
- function turn(direction)
- if direction == "left" or direction == "right" then
- local d = 0
- if direction == "left" then d = 1; turtle.turnLeft() else d = -1; turtle.turnRight() end
- facing = facing + d
- if (facing == -1) then facing = 3 elseif (facing == 4) then facing = 0 end
- return true
- end
- return false
- end
- -- Function turns to the specified facing location.
- function turnToN (face)
- if face == facing then return true end
- local lOrR = (facing - face + 4) % 4
- if lOrR > 2 then
- turn("left")
- elseif lOrR < 2 then
- turn("right")
- else
- turn("left")
- turn("left")
- end
- return true
- end
- function turnTo (nesw)
- if nesw == "north" then
- turnToN(0)
- elseif nesw == "south" then
- turnToN(2)
- elseif nesw == "west" then
- turnToN(1)
- elseif nesw == "east" then
- turnToN(3)
- end
- end
- function start()
- turtle.select(1)
- buildRoof()
- print("x"..qu_x)
- print("z"..qu_z)
- end
- function spinAndPlace(dir,s)
- turtle.turnRight()
- turtle.turnRight()
- place(dir,s)
- end
- function buildRoof()
- turnTo("north")
- for x = 1, width, 1 do
- for z = 1, length - 1, 1 do
- if ( x % 2 == 1 ) then
- move("south")
- else
- move("north")
- end
- spinAndPlace("front",15)
- end
- move("west")
- spinAndPlace("front",15)
- end
- end
- function place(dir, s)
- turtle.select(s)
- if turtle.getItemCount(s) > 1 or s == 16 then
- if dir == "up" then
- turtle.placeUp()
- elseif dir == "down" then
- turtle.placeDown()
- else
- turtle.place()
- end
- else
- local didTransfer = false
- for i=1,12,1 do
- if i ~= s and turtle.compareTo(i)then
- turtle.select(i)
- didTransfer = didTransfer or turtle.transferTo(s)
- turtle.select(s)
- end
- end
- if didTransfer then
- turtle.select(s)
- place(dir,s)
- else
- restock()
- place(dir,s)
- end
- end
- end
- function suck(dir)
- if dir == "up" then
- turtle.suckUp()
- elseif dir == "down" then
- turtle.suckDown()
- else
- turtle.suck()
- end
- end
- function dig(dir)
- if dir == "up" then
- turtle.digUp()
- elseif dir == "down" then
- turtle.digDown()
- else
- turtle.dig()
- end
- end
- function restock()
- turtle.select(16)
- local dir = ""
- if not turtle.detectUp() then
- dir = "up"
- elseif not turtle.detect() then
- dir = "front"
- else
- dir = "down"
- turtle.digDown()
- turtle.placeDown()
- end
- dig(dir)
- place(dir,16)
- turtle.select(1)
- for i=1,3 do
- suck(dir)
- end
- turtle.select(16)
- turtle.drop()
- dig(dir)
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement