Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- flatten
- -- Will clear all the blocks in the square area and all the blocks above it, up to the first row of 5 air block it encounters
- -- Arguments <Forward> <Right> [blocks to check]
- --Config settings
- local maxAirRun = 5
- local tArgs = { ... }
- if #tArgs < 2 then
- print("Usage: <Forward> <Right> [blocks to check]")
- return
- end
- --program temp variables
- local maxX = tonumber(tArgs[1])
- local maxZ = tonumber(tArgs[2])
- if(#tArgs > 2) then
- maxAirRun = tonumber(tArgs[3])
- end
- --A helper function to try and move forward, it will attempt to dig if it is blocked.
- local function moveForward()
- if turtle.forward() == false then
- --Failed to move, see if we can dig our way forward
- while turtle.dig() do
- turtle.drop()
- --Keep digging till we can't dig any more, in case gravel is falling.
- end
- if turtle.forward() == false then
- print("I am either blocked or out of fuel.")
- return false
- end
- end
- return true
- end
- --A helper function to try and move down, it will attempt to dig if it is blocked.
- local function moveDown()
- if turtle.down() == false then
- --Failed to move, see if we can dig our way down
- turtle.digDown()
- if turtle.down() == false then
- print("I am either blocked or out of fuel.")
- return false
- end
- end
- return true
- end
- --A helper function to try and move down, it will attempt to dig if it is blocked.
- local function moveUp()
- if turtle.up() == false then
- --Failed to move, see if we can dig our way down
- while turtle.digUp() do
- --Keep digging till we can't dig any more, in case gravel is falling.
- end
- if turtle.up() == false then
- print("I am either blocked or out of fuel.")
- return false
- end
- end
- return true
- end
- --Dig the column of dirt up
- local function digColumnUp()
- airCount = 0
- moveCount = 0
- --Keep going up till we hit the top
- while airCount < maxAirRun do
- local dug = false
- while(turtle.digUp()) do
- turtle.dropDown()
- dug = true
- airCount = 0
- end
- if(dug == false) then
- airCount = airCount + 1
- end
- --move up to the next level
- if(moveUp() == false) then
- error("Could not move up, WTF?")
- end
- moveCount = moveCount + 1
- end
- for i = 1, moveCount do
- if(moveDown() == false) then
- error("Could not move down, WTF?")
- end
- end
- end
- moveForward()
- for z = 1, maxZ do
- for x = 1, maxX - 1 do
- --Only run at the start of the 2nd loop
- if(x == 1 and z > 1) then
- if(z % 2 == 0) then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- digColumnUp()
- moveForward()
- if(z % 2 == 0) then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- digColumnUp()
- moveForward()
- end
- end
- --dig up the last column
- digColumnUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement