Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local depth, width, height = ...
- if not (width and depth and height) then
- error("Not enough arguments; should be depth, width, height")
- end
- width = tonumber(width)
- depth = tonumber(depth)
- height = tonumber(height)
- abs = math.abs
- floor = math.floor
- local heading = 0
- local x, y, z = 0, 0, 0
- local normalPasses = floor(height/3)
- local remainingLayers = height % 3
- local layers = 3
- function isOdd(num)
- if num % 2 == 0 then
- return false
- else
- return true
- end
- end
- function changeHeading(amount)
- heading = (heading + amount) % 4
- end
- function turnRight()
- turtle.turnRight()
- changeHeading(1)
- end
- function turnLeft()
- turtle.turnLeft()
- changeHeading(-1)
- end
- function xIncrement(heading)
- if heading == 1 or heading == 3 then
- return 0
- elseif heading == 0 then
- return 1
- else return -1
- end
- end
- function zIncrement(heading)
- if heading == 0 or heading == 2 then
- return 0
- elseif heading == 1 then
- return 1
- else return -1
- end
- end
- function turnTo(newHeading)
- local rightTurns = (newHeading-heading)%4
- if rightTurns <= 2 then
- for i = 1, rightTurns do
- turnRight()
- end
- elseif rightTurns == 3 then
- turnLeft()
- end
- end
- function up()
- turtle.up()
- y = y+1
- end
- function down()
- turtle.down()
- y = y-1
- end
- function moveVert(signedDist)
- if signedDist < 0 then
- for i = signedDist, -1 do
- down()
- end
- else
- for i = 1, signedDist do
- up()
- end
- end
- end
- function moveHor(distance, direction)
- turnTo(direction)
- for i = 1, distance do
- forw()
- end
- end
- oddWidth = isOdd(width)
- oddDepth = isOdd(depth)
- oddHeight = isOdd(height)
- function checkRefuel()
- if turtle.getFuelLevel() < 10 then
- turtle.refuel()
- end
- end
- function moveTo(destX, destZ, destY)
- if destY then
- moveVert(destY-y)
- end
- if destZ then
- local diffZ = destZ-z
- local distZ = abs(diffZ)
- moveHor(distZ, diffZ>0 and 1 or 3)
- end
- if destX then
- local diffX = destX-x
- local distX = abs(diffX)
- moveHor(distX, diffX>0 and 0 or 2)
- end
- end
- function forw()
- turtle.forward()
- x = x + xIncrement(heading)
- z = z + zIncrement(heading)
- --print("x"..x)
- --print("z"..z)
- end
- function fullDig()
- turtle.dig()
- if layers > 2 then turtle.digDown() end
- if layers > 1 then turtle.digUp() end
- end
- function moveX()
- fullDig()
- forw()
- end
- function moveZ()
- checkRefuel()
- if isOdd(z) then
- while x > 0 do
- moveX()
- end
- else
- while x < depth-1 do
- moveX()
- end
- end
- print("ferdigz "..z)
- end
- function moveY()
- while z < width-1 do
- moveZ()
- if not isOdd(z) then
- turnRight()
- fullDig()
- forw()
- turnRight()
- else
- turnLeft()
- fullDig()
- forw()
- turnLeft()
- end
- end
- moveZ()
- if layers > 1 then turtle.digUp() end
- if layers > 2 then turtle.digDown() end
- end
- function clearCube()
- turtle.dig()
- turtle.forward()
- while y < height-1 do
- moveY()
- moveTo(0,0,nil)
- turtle.digUp()
- up()
- turnTo(0)
- end
- moveY()
- moveTo(-1,0,0)
- end
- --clearCube()
- function clearCubeEfficient()
- turtle.dig()
- turtle.forward()
- for pass = 1, normalPasses do
- if pass > 1 then
- turtle.digUp()
- up()
- turtle.digUp()
- up()
- end
- turtle.digUp()
- up()
- moveY()
- moveTo(0, 0, nil)
- turnTo(0)
- end
- layers = remainingLayers
- if remainingLayers > 0 then
- turtle.digUp()
- up()
- turtle.digUp()
- up()
- moveY()
- end
- moveTo(-1, 0, 0)
- end
- clearCubeEfficient()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement