Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- north = 1
- south = 2
- west = 3
- east = 4
- ignoreStart = 14
- northDir = {0, 1}
- southDir = {0, -1}
- eastDir = {1, 0}
- westDir = {-1, 0}
- startz = 0
- startx = 0
- starty = 0
- x = 0
- y = 0
- z = startz
- fuelStack = 1
- yieldStart = 1
- -- start at facing north
- currentDir = north
- local mov = {}
- local rot = {}
- local dig = {}
- mov.forward = function(times)
- local boolean v = false
- for i=1,times do
- if turtle.detect() == false then
- while not turtle.forward() do
- sleep(1)
- end
- v = true
- else
- v = false
- return v
- end
- end
- return v
- end
- mov.back = function(times)
- local boolean v = false
- for i=1,times do
- while not turtle.back() do
- sleep(1)
- end
- v = true
- end
- return v
- end
- mov.up = function(times)
- local boolean v = false
- for i=1,times do
- if turtle.detectUp() == false then
- while not turtle.up() do
- sleep(1)
- end
- v = true
- else
- v = false
- return v
- end
- end
- return v
- end
- mov.down = function(times)
- local boolean v = false
- print("mov.down");
- for i=1,times do
- if turtle.detectDown() == false then
- print("!detectDown");
- while not turtle.down() do
- sleep(1)
- end
- v = true
- else
- print("detectDown");
- v = false
- return v
- end
- end
- return v
- end
- mov.place = function()
- while not turtle.place() do
- sleep(1)
- end
- return true
- end
- rot.right = function()
- while not turtle.turnRight() do
- sleep(1)
- end
- if RotatePosition == "FORWARD" then
- RotatePosition = "RIGHT"
- elseif RotatePosition == "LEFT" then
- RotatePosition = "FORWARD"
- end
- filewriteline("BranchMineData", 5, RotatePosition)
- return true
- end
- rot.left = function()
- while not turtle.turnLeft() do
- sleep(1)
- end
- if RotatePosition == "FORWARD" then
- RotatePosition = "LEFT"
- elseif RotatePosition == "RIGHT" then
- RotatePosition = "FORWARD"
- end
- filewriteline("BranchMineData", 5, RotatePosition)
- return true
- end
- dig.forward = function()
- if turtle.detect() then
- local doit = true
- while not turtle.dig() do
- sleep(1)
- end
- return true
- else
- print("No Block to mine forward")
- return false
- end
- end
- dig.up = function()
- if turtle.detectUp() then
- while not turtle.digUp() do
- sleep(1)
- end
- return true
- else
- print("No Block to mine up")
- return false
- end
- end
- dig.down = function()
- if turtle.detectDown() then
- while not turtle.digDown() do
- sleep(1)
- end
- return true
- else
- print("No Block to mine down")
- return false
- end
- end
- function DigMoveForward()
- if mov.forward(1) == false then
- dig.forward()
- sleep(0.5)
- DigMoveForward()
- end
- end
- function DigMoveUp()
- if mov.up(1) == false then
- dig.up()
- sleep(0.5)
- DigMoveUp()
- else
- z = z + 1
- end
- end
- function DigMoveDown()
- print("moving down")
- if mov.down(1) == false then
- print("failed moving down - digging")
- dig.down()
- sleep(0.5)
- print("trying again")
- DigMoveDown()
- else
- print("aucceeeded")
- z = z - 1
- end
- end
- function forward()
- DigMoveForward()
- end
- function goWest()
- faceWest()
- forward()
- end
- function goEast()
- faceEast()
- forward()
- end
- function goNorth()
- faceNorth()
- forward()
- end
- function goSouth()
- faceSouth()
- forward()
- end
- function goUp()
- DigMoveUp()
- end
- function goDown()
- DigMoveDown()
- end
- local function readLines(sPath)
- local file = fs.open(sPath, "r") -- open the file
- if file then -- check if it's open
- local tLines = {} -- table to store the lines
- local sLine = file.readLine() -- read a line from the file
- while sLine do -- while there's a line in the file
- table.insert(tLines, sLine) -- add it to the table
- sLine = file.readLine() -- get the next line
- end
- file.close() -- close the file
- return tLines -- return the table with the lines
- end
- return nil -- there was an error opening the file, return nil to let the user know
- end
- local function writeLines(sPath, tLines)
- local file = fs.open(sPath, "w") -- open the file
- if file then -- check if the file is open
- for _, sLine in ipairs(tLines) do -- for each line in the table
- file.writeLine(sLine) -- write the line
- end
- file.close() -- close the file
- end
- end
- function filereadline(filename, line)
- local tLines = readLines(filename) -- read the lines from the file (using the previous functions)
- if not tLines then -- if there was an error
- return nil -- return nil/error
- end
- return tLines[line] -- return the line
- end
- function filewriteline(filename, line, text)
- local tLines = readLines(filename) -- read the lines from the file (using the previous functions)
- if tLines then -- if there was no error
- tLines[line] = text -- set the line
- writeLines(filename, tLines) -- write the lines back to the file (using the previous functions)
- end
- end
- print("Input Width")
- width = tonumber(read())
- print("Input Breadth")
- breadth = tonumber(read())
- print("Input Height")
- height = tonumber(read())
- print ("Start at top? y/n")
- fromTop = (string.find(tostring(read()), "y") ~= nil)
- print ("Start at right? y/n")
- fromRight = (string.find(tostring(read()), "y") ~= nil)
- print(tostring(fromTop))
- altz = false
- alty = false
- altx = false
- turtle.refuel()
- isZOdd = math.floor(height/2.0) ~= height
- for cx = 0, width-1 do
- for cz = 0, height-1 do
- for cy = 0, breadth-2 do
- DigMoveForward()
- end
- if cz < height-1 then
- turtle.turnLeft()
- turtle.turnLeft()
- if fromTop then
- if altz then
- goUp()
- else
- goDown()
- end
- else
- if not altz then
- goUp()
- else
- goDown()
- end
- end
- end
- alty = not alty
- end
- print ("fromRight = "..tostring(fromRight))
- local test = fromRight
- if isZOdd then test = not test end
- print ("isZOdd = "..tostring(isZOdd))
- if altz then test = not test end
- print ("altz = "..tostring(altz))
- test = not test
- if cx < width - 1 then
- if test then
- print ("left")
- turtle.turnLeft()
- else
- print ("right")
- turtle.turnRight()
- end
- DigMoveForward()
- if test then
- print ("left")
- turtle.turnLeft()
- else
- print ("right")
- turtle.turnRight()
- end
- altz = not altz
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement