Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local HOME = vector.new(7,69,124)
- local STARTROW1 = vector.new(6, 71, 122)
- local ENDROW1 = vector.new(-14, 71, 122)
- local STARTROW2 = vector.new(-14, 71, 121)
- local ENDROW2 = vector.new(6, 71, 121)
- local pos, dir
- function init()
- main()
- end
- function getOrientation()
- print("getting Orientation")
- loc1 = vector.new(gps.locate(2, false))
- if not turtle.forward() then
- for j=1,6 do
- if not turtle.forward() then
- turtle.turnRight()
- else break end
- end
- end
- loc2 = vector.new(gps.locate(2, false))
- heading = loc2 - loc1
- return ((heading.x + math.abs(heading.x) * 2) + (heading.z + math.abs(heading.z) * 3))
- end
- function forward()
- while not turtle.forward() do end
- local heading = vector.new(0,0,0)
- if dir == 1 then
- heading = vector.new(-1,0,0)
- elseif dir == 2 then
- heading = vector.new(0,0,-1)
- elseif dir == 3 then
- heading = vector.new(1,0,0)
- elseif dir == 4 then
- heading = vector.new(0,0,1)
- end
- pos = pos + heading
- end
- function back()
- while not turtle.back() do end
- if dir == 1 then
- heading = vector.new(-1,0,0)
- elseif dir == 2 then
- heading = vector.new(0,0,-1)
- elseif dir == 3 then
- heading = vector.new(1,0,0)
- elseif dir == 4 then
- heading = vector.new(0,0,1)
- end
- pos = pos - heading
- end
- function up()
- while not turtle.up() do end
- pos = pos + vector.new(0,1,0)
- end
- function down()
- while not turtle.down() do end
- pos = pos - vector.new(0,1,0)
- end
- function left()
- turtle.turnLeft()
- dir = dir - 1
- if dir < 1 then dir = dir + 4 end
- end
- function right()
- turtle.turnRight()
- dir = dir + 1
- if dir > 4 then dir = dir - 4 end
- end
- function setDir(destDir)
- while dir ~= destDir do
- right()
- end
- end
- function goto(vec, finalDir)
- if pos.x < vec.x then
- setDir(3)
- elseif pos.x > vec.x then
- setDir(1)
- end
- while pos.x ~= vec.x do
- forward()
- end
- if pos.z > vec.z then
- setDir(2)
- elseif pos.z < vec.z then
- setDir(4)
- end
- while pos.z ~= vec.z do
- forward()
- end
- while pos.y > vec.y do
- down()
- end
- while pos.y < vec.y do
- up()
- end
- setDir(finalDir)
- end
- function goHome()
- goto(HOME, 4)
- end
- function makeARound()
- goto(STARTROW1, 1)
- while pos ~= ENDROW1 do
- while turtle.attackDown() do end
- forward()
- end
- goto(STARTROW2, 3)
- while pos ~= ENDROW2 do
- while turtle.attackDown() do end
- forward()
- end
- goHome()
- end
- function main()
- while true do
- makeARound()
- sleep(120)
- end
- end
- dir = getOrientation()
- pos = vector.new(gps.locate())
- print(dir)
- print(pos)
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement