Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function update(dir)
- if dir == "forward" then
- if face == "north" then
- lengthPos = lengthPos - 1
- elseif face == "south" then
- lengthPos = lengthPos + 1
- elseif face == "west" then
- widthPos = widthPos - 1
- elseif face == "east" then
- widthPos = widthPos + 1
- end
- elseif dir == "backward" then
- if face == "north" then
- lengthPos = lengthPos + 1
- elseif face == "south" then
- lengthPos = lengthPos - 1
- elseif face == "west" then
- widthPos = widthPos + 1
- elseif face == "east" then
- widthPos = widthPos - 1
- end
- elseif dir == "up" then
- heightPos = heightPos + 1
- elseif dir == "down" then
- heightPos = heightPos - 1
- elseif dir == "right" then
- if face == "north" then
- face = "east"
- elseif face == "east" then
- face = "south"
- elseif face == "south" then
- face = "west"
- elseif face == "west" then
- face = "north"
- end
- elseif dir == "left" then
- if face == "north" then
- face = "west"
- elseif face == "west" then
- face = "south"
- elseif face == "south" then
- face = "east"
- elseif face == "east" then
- face = "north"
- end
- end
- recordPos(heightPos,widthPos,lengthPos,face)
- end
- function goto(heightGoal,widthGoal,lengthGoal)
- shell.run("position")
- if turtle.getFuelLevel() < 200 then
- refill()
- end
- if heightGoal > heightPos then
- while heightGoal > heightPos do
- up()
- end
- elseif heightGoal < heightPos then
- while heightGoal < heightPos do
- down()
- end
- end
- if widthGoal > widthPos then
- turn("east")
- while widthGoal > widthPos do
- forward()
- end
- elseif widthGoal < widthPos then
- turn("west")
- while widthGoal < widthPos do
- forward()
- end
- end
- if lengthGoal > lengthPos then
- turn("south")
- while lengthGoal > lengthPos do
- forward()
- end
- elseif lengthGoal < lengthPos then
- turn("north")
- while lengthGoal < lengthPos do
- forward()
- end
- end
- end
- function recordPos(heightPos,widthPos,lengthPos,face)
- local h = fs.open("position","w")
- h.writeLine("heightPos = "..tostring(heightPos))
- h.writeLine("widthPos = "..tostring(widthPos))
- h.writeLine("lengthPos = "..tostring(lengthPos))
- h.writeLine("face = ".."\""..tostring(face).."\"")
- h.close()
- end
- function gpsi.forward()
- update("forward")
- while not turtle.forward() do
- turtle.dig()
- end
- end
- function gpsi.up()
- update("up")
- while not turtle.up() do
- turtle.digUp()
- end
- end
- function gpsi.down()
- update("down")
- while not turtle.down() do
- turtle.digDown()
- end
- end
- function gpsi.right()
- update("right")
- turtle.turnRight()
- end
- function gpsi.left()
- update("left")
- turtle.turnLeft()
- end
- function turn(dir)
- if face == "north" then
- if dir == "east" then
- while face ~= dir do
- right()
- end
- else
- while face ~= dir do
- left()
- end
- end
- elseif face == "east" then
- if dir == "south" then
- while face ~= dir do
- right()
- end
- else
- while face ~= dir do
- left()
- end
- end
- elseif face == "south" then
- if dir == "west" then
- while face ~= dir do
- right()
- end
- else
- while face ~= dir do
- left()
- end
- end
- elseif face == "west" then
- if dir == "north" then
- while face ~= dir do
- right()
- end
- else
- while face ~= dir do
- left()
- end
- end
- end
- end
- function gpsi.init()
- if fs.exists("position") then
- shell.run("position")
- else
- recordPos(0,0,0,"south")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement