Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local s = turtle.select
- local f = turtle.forward
- local b = turtle.back
- local l = turtle.turnLeft
- local r = turtle.turnRight
- local u = turtle.up
- local d = turtle.down
- local function select(num)
- if num == nil then
- return turtle.slot
- else
- rawset(turtle, "slot", num)
- return s(num)
- end
- end
- local function forward()
- if f() then
- rawset(turtle, "x", turtle.x + turtle.dirX)
- rawset(turtle, "z", turtle.z + turtle.dirZ)
- return true
- end
- return false
- end
- local function back()
- if b() then
- rawset(turtle, "x", turtle.x - turtle.dirX)
- rawset(turtle, "z", turtle.z - turtle.dirZ)
- return true
- end
- return false
- end
- local function left()
- local dirX, dirZ = turtle.dirZ, -turtle.dirX
- rawset(turtle, "dirX", dirX)
- rawset(turtle, "dirZ", dirZ)
- return l()
- end
- local function right()
- local dirX, dirZ = -turtle.dirZ, turtle.dirX
- rawset(turtle, "dirX", dirX)
- rawset(turtle, "dirZ", dirZ)
- return r()
- end
- local function up()
- if u() then
- rawset(turtle, "y", turtle.y + 1)
- return true
- end
- return false
- end
- local function down()
- if d() then
- rawset(turtle, "y", turtle.y - 1)
- return true
- end
- return false
- end
- local function loc()
- return turtle.x, turtle.y, turtle.z
- end
- local function dir()
- return turtle.dirX, turtle.dirZ
- end
- local function rotate(x, z)
- if math.abs(x - z) == 1 and
- math.abs(x + z) == 1 then
- while turtle.dirX ~= x or
- turtle.dirZ ~= z do
- right()
- end
- end
- end
- local function init(x, y, z, dirX, dirZ)
- rawset(turtle, "x", x)
- rawset(turtle, "y", y)
- rawset(turtle, "z", z)
- rawset(turtle, "dirX", dirX)
- rawset(turtle, "dirZ", dirZ)
- end
- local function front()
- x, y, z = turtle.loc()
- dirX, dirZ = turtle.dir()
- return x + dirX, y, z + dirZ
- end
- rawset(turtle, "select", select)
- rawset(turtle, "forward", forward)
- rawset(turtle, "back", back)
- rawset(turtle, "turnLeft", left)
- rawset(turtle, "turnRight", right)
- rawset(turtle, "up", up)
- rawset(turtle, "down", down)
- rawset(turtle, "loc", loc)
- rawset(turtle, "dir", dir)
- rawset(turtle, "rotate", rotate)
- rawset(turtle, "init", init)
- rawset(turtle, "front", front)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement