Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- map = {}
- x = 1
- y = 1
- direction = "+y"
- reversing = false
- filepath = arg[1]
- if filepath == nil then filepath = "map" end
- function FindStuff()
- if CheckSlot() then
- return true
- end
- for i = 1, 16, 1 do
- turtle.select(i)
- if CheckSlot() then
- return true
- end
- end
- return false
- end
- function CheckSlot()
- if turtle.getItemCount() > 0 then
- item = turtle.getItemDetail()
- if item.name == "minecraft:stone" or string.find(item.name, "log") ~= nil then
- return true
- end
- end
- return false
- end
- function ReadMap()
- local file = fs.open(filepath, "r")
- if file == nil then
- shell.run("MakeMap")
- reversing = true
- file = fs.open(filepath, "r")
- end
- local line = file.readLine()
- local bounds = line:gmatch("%S+")
- local maxX = tonumber(bounds())
- local maxY = tonumber(bounds())
- local i = 1
- local j = maxY
- while j >= 1 do
- line = file.readLine()
- if line == nil then
- break
- end
- i = 1
- for word in line:gmatch("%S+") do
- map[i .. " " .. j] = word
- i = i + 1
- end
- j = j - 1
- end
- file.close()
- end
- function ReadLog()
- local log = fs.open("log", "r")
- if log == nil then
- UpdateLog()
- else
- x = tonumber(log.readLine())
- y = tonumber(log.readLine())
- direction = log.readLine()
- reversing = log.readLine() == "true"
- log.close()
- end
- end
- function UpdateLog()
- local log = fs.open("log", "w")
- log.writeLine(x)
- log.writeLine(y)
- log.writeLine(direction)
- log.writeLine(reversing)
- log.close()
- end
- function Checkblock()
- local success, block = turtle.inspectDown()
- if success then
- if block.name == "botania:livingrock" or block.name == "botania:livingwood" then
- return "living"
- elseif block.name == "minecraft:stone" or string.find(block.name, "log") ~= nil then
- return "block"
- elseif block.name == "botania:pure_daisy" then
- return "daisy"
- end
- end
- return "air"
- end
- function Move(d)
- if d == "-E" or d == "+E" then
- reversing = true
- UpdateLog()
- ReturnHome()
- return
- elseif d == "+S" then
- d = "+y"
- reversing = false
- end
- FaceDirection(d)
- if direction == "+x" then
- x = x + 1
- elseif direction == "-x" then
- x = x - 1
- elseif direction == "+y" then
- y = y + 1
- elseif direction == "-y" then
- y = y - 1
- end
- UpdateLog()
- turtle.forward()
- end
- function FaceDirection(d)
- if direction == d then return end
- if direction == "+y" then
- if d == "+x" then
- turtle.turnRight()
- elseif d == "-x" then
- turtle.turnLeft()
- elseif d == "-y" then
- turtle.turnRight()
- turtle.turnRight()
- end
- elseif direction == "+x" then
- if d == "+y" then
- turtle.turnLeft()
- elseif d == "-x" then
- turtle.turnRight()
- turtle.turnRight()
- elseif d == "-y" then
- turtle.turnRight()
- end
- elseif direction == "-x" then
- if d == "+y" then
- turtle.turnRight()
- elseif d == "+x" then
- turtle.turnRight()
- turtle.turnRight()
- elseif d == "-y" then
- turtle.turnLeft()
- end
- elseif direction == "-y" then
- if d == "+y" then
- turtle.turnRight()
- turtle.turnRight()
- elseif d == "+x" then
- turtle.turnLeft()
- elseif d == "-x" then
- turtle.turnRight()
- end
- end
- direction = d
- UpdateLog()
- end
- function ReturnHome()
- while x ~= 1 or y ~= 1 do
- if x > 1 then
- Move("-x")
- elseif y > 1 then
- Move("-y")
- end
- end
- reversing = false
- UpdateLog()
- end
- ReadLog()
- ReadMap()
- if reversing then ReturnHome() end
- while FindStuff() do
- local block = Checkblock()
- if block == "living" then
- turtle.digDown()
- turtle.placeDown()
- elseif block == "block" then
- repeat
- sleep(1)
- until Checkblock() == "living"
- turtle.digDown()
- turtle.placeDown()
- elseif block == "air" then
- turtle.placeDown()
- end
- Move(map[x .. " " .. y])
- end
- print("Done")
Add Comment
Please, Sign In to add comment