Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- COPYRIGHTED CONTENT
- -- Do not distribute
- -- (c) 2012 February 28 - Rickydaan and Turboneater, ask Rickydaan on Minecraftforums to copy this into your own program
- if turtle then
- function installCheckTurtleAPI()
- if fs.exists("config") then
- else
- shell.run("mkdir", "cur")
- file = io.open("config", "w")
- file : write([[
- function coords()
- term.clear()
- term.setCursorPos(1,1)
- print("Cur X")
- x = read()
- print("Cur Z")
- z = read()
- print("Cur Y")
- y = read()
- file = io.open("cur/x", "w")
- file : write(x)
- file : close()
- file = io.open("cur/y", "w")
- file : write(y)
- file : close()
- file = io.open("cur/z", "w")
- file : write(z)
- file : close()
- file = io.open("cur/config", "w")
- file : write('dir')
- file : close()
- dir()
- end
- function dir()
- term.clear()
- term.setCursorPos(1,1)
- print("What direction (n (1), e (2), s (3), w (4))")
- print("East is when the x is going down (Press F3)")
- print("West, is when the X is going up (Press F3)")
- print("North, is when the Z is going down (Press F3)")
- print("South, is when the Z is going up (Press F3)")
- dir = read()
- if dir == "1" or dir == "2" or dir == "3" or dir == "4" then
- file = io.open("cur/dir", "w")
- file : write(dir)
- file : close()
- file = io.open("cur/config", "w")
- file : write('start')
- file : close()
- else
- shell.run("config")
- end
- end
- file = io.open("cur/config", "r")
- status = file : read()
- file : close()
- if status == "start" then
- coords()
- elseif status == "dir" then
- dir()
- else
- coords()
- end
- ]])
- file : close()
- end
- end
- function updateDir(value)
- file = io.open("cur/dir", "w")
- file : write(value)
- file : close()
- end
- function turnLeft()
- file = io.open("cur/dir", "r")
- curdirection = file : read()
- file : close()
- if curdirection == "1" then -- north
- updateDir("4")
- elseif curdirection == "2" then -- east
- updateDir("1")
- elseif curdirection == "3" then -- south
- updateDir("2")
- elseif curdirection == "4" then -- west
- updateDir("3")
- else
- print("Unsupported direction")
- end
- end
- function turnRight()
- file = io.open("cur/dir", "r")
- curdirection = file : read()
- file : close()
- if curdirection == "1" then -- north
- updateDir("2")
- elseif curdirection == "2" then -- east
- updateDir("3")
- elseif curdirection == "3" then -- then south
- updateDir("4")
- elseif curdirection == "4" then -- west
- updateDir("1")
- else
- print("Unsupported direction")
- end
- end
- function printDir()
- file = io.open("cur/dir", "r")
- direction = file : read()
- file : close()
- if direction == "1" then
- print("north")
- elseif direction == "2" then
- print("east")
- elseif direction == "3" then
- print("south")
- elseif direction == "4" then
- print("west")
- else
- print("Error: Unknown direction")
- end
- end
- function updateDirForward()
- file = io.open("cur/dir", "r")
- direction = file : read()
- file : close()
- if direction == "1" then -- north
- file = io.open("cur/z", "r")
- ona = file : read()
- file : close()
- na = tonumber(ona)
- cna = na - 1
- file = io.open("cur/z", "w")
- file : write(cna)
- file : close()
- elseif direction == "2" then -- east
- file = io.open("cur/x", "r")
- ocx = file : read()
- file : close()
- cx = tonumber(ocx)
- cnx = cx - 1
- file = io.open("cur/x", "w")
- file : write(cnx)
- file : close()
- elseif direction == "3" then -- south
- file = io.open("cur/z", "r")
- ocs = file : read()
- file : close()
- cs = tonumber(ocs)
- cns = cs + 1
- file = io.open("cur/z", "w")
- file : write(cns)
- file : close()
- elseif direction == "4" then -- west
- file = io.open("cur/x", "r")
- ocw = file : read()
- file : close()
- cw = tonumber(ocw)
- cnw = cw + 1
- file = io.open("cur/x", "w")
- file : write(cnw)
- file : close()
- else
- print("Error at config -> Please type config in the main terminal to fix this")
- end
- end
- function updateDirBack()
- file = io.open("cur/dir", "r")
- direction = file : read()
- file : close()
- if direction == "1" then -- north
- file = io.open("cur/z", "r")
- ona = file : read()
- file : close()
- na = tonumber(ona)
- cna = na + 1
- file = io.open("cur/z", "w")
- file : write(cna)
- file : close()
- elseif direction == "2" then -- east
- file = io.open("cur/x", "r")
- ocx = file : read()
- file : close()
- cx = tonumber(ocx)
- cnx = cx + 1
- file = io.open("cur/x", "w")
- file : write(cnx)
- file : close()
- elseif direction == "3" then -- south
- file = io.open("cur/z", "r")
- ocs = file : read()
- file : close()
- cs = tonumber(ocs)
- cns = cs - 1
- file = io.open("cur/z", "w")
- file : write(cns)
- file : close()
- elseif direction == "4" then -- west
- file = io.open("cur/x", "r")
- ocw = file : read()
- file : close()
- cw = tonumber(ocw)
- cnw = cw - 1
- file = io.open("cur/x", "w")
- file : write(cnw)
- file : close()
- else
- print("Error at config -> Please type config in the main terminal to fix this")
- end
- end
- function coordsShow()
- file = io.open("cur/x", "r")
- x = file : read()
- file : close()
- file = io.open("cur/z", "r")
- z = file : read()
- file : close()
- file = io.open("cur/y", "r")
- y = file : read()
- file : close()
- printDir()
- print("X: " .. x)
- print("Y: " .. y)
- print("Z: " .. z)
- end
- function coordsForward()
- if turtle.detect() then
- print("Unable to go forward")
- else
- turtle.forward()
- updateDirBack()
- end
- end
- function coordsBack()
- turtle.back()
- updateDirForward()
- end
- function coordsUp()
- if turtle.detectUp() == true then
- print("Unable to go up")
- else
- turtle.up()
- file = io.open("cur/y", "r")
- chh = file : read()
- file : close()
- ch = tonumber(chh)
- nch = ch + 1
- file = io.open("cur/y", "w")
- file : write(nch)
- file : close()
- end
- end
- function coordsDown()
- if turtle.detectDown() == true then
- print("Unable to go down")
- else
- turtle.down()
- file = io.open("cur/y", "r")
- hc = file : read()
- file : close()
- hcc = tonumber(hc)
- nhc = hcc - 1
- file = io.open("cur/y", "w")
- file : write(nhc)
- file : close()
- end
- end
- function coordsTurnRight()
- turtle.turnRight()
- turnRight()
- end
- function coordsTurnLeft()
- turtle.turnLeft()
- turnLeft()
- end
- installCheckTurtleAPI()
- else
- print("This API requires to be runned on a Turtle")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement