Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Move API Beta
- x = 0
- y = 0
- z = 0
- dir = 1
- xdir = {0,1,0,-1}
- zdir = {-1,0,1,0}
- if fs.exists("move/pos.lua") then
- h = fs.open("move/pos.lua","r")
- dir = tonumber(h.readLine())
- x = tonumber(h.readLine())
- y = tonumber(h.readLine())
- z = tonumber(h.readLine())
- h.close()
- end
- function getx()
- return x
- end
- function gety()
- return y
- end
- function getz()
- return z
- end
- function getd()
- return dir
- end
- function getnext()
- tx = x + xdir[dir]
- tz = z + zdir[dir]
- return tx, y, tz
- end
- function forward()
- turtle.suckDown()
- turtle.dig()
- if turtle.forward() then
- x = x + xdir[dir]
- z = z + zdir[dir]
- record()
- return true
- else
- return false
- end
- end
- function back()
- if turtle.back() then
- x = x - xdir[dir]
- z = z - zdir[dir]
- record()
- return true
- else
- return false
- end
- end
- function left()
- if turtle.turnLeft() then
- dir = dir - 1
- if dir < 1 then
- dir = 4
- end
- record()
- return true
- end
- return false
- end
- function right()
- if turtle.turnRight() then
- dir = dir + 1
- if dir > 4 then
- dir = 1
- end
- record()
- return true
- end
- return false
- end
- function up()
- turtle.digUp()
- if turtle.up() then
- y = y + 1
- record()
- return true
- end
- return false
- end
- function down()
- turtle.digDown()
- if turtle.down() then
- y = y - 1
- record()
- return true
- end
- return false
- end
- function face(d)
- while d < dir do
- left()
- end
- while d > dir do
- right()
- end
- end
- function move(tx, ty, tz)
- while tx > x do
- face(2)
- forward()
- end
- while tx < x do
- face(4)
- forward()
- end
- while tz > z do
- face(3)
- forward()
- end
- while tz < z do
- face(1)
- forward()
- end
- count = 0
- while ty > y do
- count = count + 1
- up()
- if count > 300 then
- print("Couldn't move up!")
- return "top"
- end
- end
- while ty < y do
- count = count + 1
- down()
- if count > 300 then
- print("Couldn't move down!")
- return "bed"
- end
- end
- return "success"
- end
- function record()
- h = fs.open("move/pos.lua","w")
- h.writeLine(dir)
- h.writeLine(x)
- h.writeLine(y)
- h.writeLine(z)
- h.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement