Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle API: built by ZomibeZach
- -- F 0= north 1= east 2= south 3= west
- -- south z+ east x+
- x = 0
- y = 0
- z = 0
- facing = 0
- function tFuel()
- if turtle.getFuelLevel() <= 10 then
- turtle.select(16)
- turtle.refuel(1)
- turtle.select(1)
- rednet.open("right")
- rednet.send(10, "Refueled to level: "..turtle.getFuelLevel())
- rednet.close("right")
- end
- end
- function startLoc()
- rednet.open("right")
- x, y, z = gps.locate(3)
- facing = 0
- rednet.close("right")
- return facing
- end
- function getLoc()
- return x, y, z, facing
- end
- function tl(ct)
- ct = ct or 1
- for i = 1, ct do
- turtle.turnLeft()
- facing = (facing + 3)%4
- end
- return i
- end
- function tr(ct)
- ct = ct or 1
- for i = 1, ct do
- turtle.turnRight()
- facing = (facing + 1)%4
- end
- end
- function up()
- tFuel()
- if turtle.detectUp() == false then
- turtle.up()
- y = y + 1
- end
- end
- function dn()
- tFuel()
- if turtle.detectDown() == false then
- turtle.down()
- y = y - 1
- end
- end
- function fd()
- tFuel()
- if turtle.detect() == false then
- turtle.forward()
- if facing == 0 then
- z = z + 1
- elseif facing == 2 then
- z = z - 1
- elseif facing == 1 then
- x = x + 1
- elseif facing == 3 then
- x = x - 1
- end
- end
- end
- function bk()
- rt(2)
- if turtle.detect() == false then
- fd()
- if facing == 0 then
- z = z + 1
- elseif facing == 2 then
- z = z - 1
- elseif facing == 1 then
- x = x + 1
- elseif facing == 3 then
- x = x - 1
- end
- end
- end
- function gotoX(toX)
- if toX > x then
- face(3)
- elseif toX< x then
- face(1)
- end
- while x ~= toX do
- fd()
- if turtle.detect() == true then
- tl()
- if turtle.detect() == false then
- fd()
- tr()
- elseif turtle.detect() == true then
- tl()
- if turtle.detect() == false then
- fd()
- tr(2)
- end
- else
- tl(2)
- if turtle.detect() == false then
- fd()
- tr(3)
- end
- end
- end
- end
- end
- function gotoZ(toZ)
- if toZ > z then
- face(2)
- elseif toZ < z then
- face(0)
- end
- while z ~= toZ do
- fd()
- if turtle.detect() == true then
- tl()
- if turtle.detect() == false then
- fd()
- tr()
- elseif turtle.detect() == true then
- tl()
- if turtle.detect() == false then
- fd()
- tr(2)
- end
- else
- tl(2)
- if turtle.detect() == false then
- fd()
- tr(3)
- end
- end
- end
- end
- end
- function gotoY(toY)
- if toY > y then
- while toY ~= y do
- dn()
- end
- elseif toY < y then
- while toY ~= y do
- up()
- end
- end
- end
- function gotoA(toX, toY, toZ)
- gotoX(toX)
- gotoY(toY)
- gotoZ(toZ)
- end
- function face(dir)
- if dir == 0 and facing == 3 then
- tr()
- elseif dir == 3 and facing == 0 then
- tl()
- elseif dir > facing then
- tr(dir - facing)
- elseif dir < facing then
- tl(facing - dir)
- end
- end
- function getX()
- return x
- end
- function getZ()
- return z
- end
- function getY()
- return y
- end
- print("Turtles Made Simple: T-APIS")
Advertisement
Add Comment
Please, Sign In to add comment