Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- if #tArgs ~= 3 then
- print("Usage: makeRoom <x> <y> <z>")
- return
- end
- if (tonumber(tArgs[3]) < 3) then tArgs[3] = "3" end
- -- Local Variables
- local movesNeeded = tonumber(tArgs[1])*tonumber(tArgs[2])*(tonumber(tArgs[3]/3))
- local xPos, yPos, xyDir
- print("Fuel Needed for this room: "..movesNeeded)
- if (turtle.getFuelLevel() < movesNeeded) then
- print("Need more fuel.")
- print("Current Fuel Levels: "..turtle.getFuelLevel())
- return
- end
- local function updatePos()
- -- xyDir 0 is forward, relative to start (x++)
- -- xyDir 1 is right, relative to start (y++)
- -- xyDir 2 is back, relative to start (x--)
- -- xyDir 3 is left, relative to start (y--)
- if xyDir == 0 then
- xPos = xPos + 1
- elseif xyDir == 1 then
- yPos = yPos +1
- elseif xyDir == 2 then
- xPos = xPos - 1
- else yPos = yPos - 1
- end
- end
- local function changeDir( lorr )
- if lorr == "L" then
- xyDir = xyDir - 1
- if xyDir == -1 then xyDir = 3 end
- else
- xyDir = xyDir + 1
- if xyDir == 4 then xyDir = 0 end
- end
- end
- local function turnRight()
- turtle.turnRight()
- changeDir("R")
- end
- local function turnLeft()
- turtle.turnLeft()
- changeDir("L")
- end
- local function dforward()
- while turtle.detect() == true do
- turtle.dig()
- sleep(0.1)
- end
- turtle.forward()
- updatePos()
- end
- local function goToStart()
- if xyDir == 0 then
- turnLeft()
- end
- if xyDir == 1 then
- turnRight()
- end
- while (xPos > 1) or (yPos > 0) do
- print(xyDir)
- if (xyDir == 2) and (xPos >1) then
- dforward()
- elseif (xPos == 1) and (xyDir == 2) then
- turnRight()
- elseif (xyDir == 3) and (yPos >0) then
- dforward()
- elseif (xyDir == 3) and (yPos == 0) then
- turnLeft()
- end
- end
- end
- local function digUD()
- while turtle.detectUp() == true do
- turtle.digUp()
- sleep(0.1)
- end
- turtle.digDown()
- end
- local function digLine( _fnDist )
- local move = 0
- for move = 1, _fnDist do
- digUD()
- dforward()
- end
- end
- local function digRoomLL ( _x, _y )
- local x1 = _x;
- local y1 = _y;
- while (x1>0) and (y1>0) do
- digLine(x1)
- turnRight()
- digLine(y1-1)
- turnRight()
- digLine(x1-1)
- turnRight()
- digLine(y1-2)
- turnRight()
- x1 = x1 - 2
- y1 = y1 - 2
- end
- digUD()
- end
- function checkGoUp()
- while turtle.detectUp() == true do
- turtle.digUp()
- sleep(0.1)
- end
- turtle.up()
- end
- -- program starts here.
- -- init variables
- local z1 = tonumber(tArgs[3]);
- -- Start at (0,0) facting 0
- xPos = 0
- yPos = 0
- xyDir = 0
- -- move into starting position
- checkGoUp()
- dforward()
- --vertical logic. Repeat while counter > 0
- while ( z1 > 2 ) do
- xPos = 1
- digRoomLL( tonumber(tArgs[1]), tonumber(tArgs[2]) )
- goToStart()
- turnRight()
- turnRight()
- z1 = z1 - 3;
- if (z1>=3) then
- checkGoUp()
- checkGoUp()
- checkGoUp()
- end
- end
- if (z1 == 2) then
- checkGoUp()
- checkGoUp()
- digRoomLL( tonumber(tArgs[1]), tonumber(tArgs[2]) )
- end
- if (z1 == 1) then
- checkGoUp()
- digRoomLL( tonumber(tArgs[1]), tonumber(tArgs[2]) )
- end
- goToStart()
- for gd = 1,tonumber(tArgs[3]) do
- turtle.down()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement