Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Open Rednet
- if not rednet.isOpen() then
- rednet.open("right")
- end
- --Get current turtle coordinates
- local function getCoord(coord)
- local f = fs.open("coords/"..coord..".loc", "r")
- local c = f.readAll()
- f.close()
- return tonumber(c)
- end
- --Update the coordinates of the turtle
- local function updateCoord(coord, change)
- local f = fs.open("coords/"..coord..".loc", "w")
- f.write(change)
- f.close()
- end
- --Move the turtle one block forward
- local function walk()
- if turtle.getFuelLevel() > 0 then
- local x,z,r = getCoord("x"),getCoord("z"),getCoord("r")
- turtle.forward()
- if r == 1 then
- updateCoord("x", x + 1)
- elseif r == 2 then
- updateCoord("z", z + 1)
- elseif r == 3 then
- updateCoord("x", x - 1)
- elseif r == 4 then
- updateCoord("z", z - 1)
- end
- else
- print("Insufficient fuel!")
- end
- end
- --Rotate the turtle once
- local function rotate()
- local r = getCoord("r")
- turtle.turnRight()
- if r < 4 then
- updateCoord("r", r + 1)
- else
- updateCoord("r", 1)
- end
- end
- --Mine 3 blocks
- local function path()
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- end
- --Goes to selected coordinates, X first then Z
- local function goTo(dX, dZ)
- if turtle.getFuelLevel() < (dX + dZ) then
- term.setTextColor(colors.red)
- write("[X] ")
- term.setTextColor(colors.white)
- write("Turtle ID#"..os.getComputerID().." does not have enough fuel to go to specified location.")
- return
- elseif turtle.getFuelLevel() < (dX + dZ) * 2 then
- term.setTextColor(colors.orange)
- write("[!] ")
- term.setTextColor(colors.white)
- write("Turtle ID#"..os.getComputerID().." does not have enough fuel to travel and return. Continue (Y/n)?")
- print("")
- while true do
- local input = read()
- if string.lower(input) == "n" then
- print("Cancelled!")
- return
- elseif string.lower(input) == "y" then
- break
- else
- print("Not understood. Please try again.")
- end
- end
- end
- local x, z, r = getCoord("x"), getCoord("z"), getCoord("r")
- if x ~= dX then
- if x < dX then
- if r ~= 1 then
- repeat rotate() r = getCoord("r") until r == 1
- end
- elseif x > dX then
- if r ~= 3 then
- repeat rotate() r = getCoord("r") until r == 3
- end
- end
- repeat walk() xC = getCoord("x") until xC == dX
- end
- if z ~= dZ then
- if x < dZ then
- if r ~= 2 then
- repeat rotate() r = getCoord("r") until r == 2
- end
- elseif z > dZ then
- if r ~= 4 then
- repeat rotate() r = getCoord("r") until r == 4
- end
- end
- repeat walk() zC = getCoord("z") until zC == dZ
- end
- end
- local function mineLine(length)
- for i = 1,length - 1 do
- path()
- walk()
- end
- local r = getCoord("r")
- if r == 1 then
- rotate()
- else
- rotate()
- rotate()
- rotate()
- end
- path()
- walk()
- if r ==1 then
- rotate()
- else
- rotate()
- rotate()
- rotate()
- end
- end
- local function mineBox(bW, bH)
- for i = 1,bW do
- mineLine(bH)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement