Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Replacement
- -- ----------------------------------------------------------
- -- Configures a newly placed turtle to take up a suitable job.
- -- ----------------------------------------------------------
- if not turtle then
- shell.run("\\startup")
- error()
- elseif turtle.craft then
- os.setComputerLabel("BBCrafter1")
- file = fs.open("\\update","w")
- file.writeLine("shell.run(\"rm\",\"startup\")")
- file.writeLine("shell.run(\"pastebin\",\"get\",\"kCTERg1Z\",\"startup\")")
- file.close()
- shell.run("pastebin","get","kCTERg1Z","\\startup")
- while not turtle.back() do
- for i=1,16 do if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.refuel()
- end end
- turtle.turnLeft()
- end
- os.reboot()
- end
- -- ----------------------------------------------------------
- -- Initialise important values:
- node = {{{253,435,61},
- {253,435,67},
- {252,435,67}},
- {{245,438,71},
- {249,443,65}},
- {{238,445,77},
- {228,457,65}},
- {{229,440,75},
- {221,440,71},
- {215,437,65}}}
- local facing = {"north","east","south","west"}
- local direction, x, y, z
- -- ----------------------------------------------------------
- -- Functions and stuff:
- -- ----------------------------------------------------------
- -- Accepts strings representing compass-facings to turn the turtle.
- local function faceDirection(targetdirection)
- local tardir
- for i=1,4 do if targetdirection == facing[i] then
- tardir = i
- break
- end end
- if tardir < direction then
- if tardir == 1 and direction == 4 then while not turtle.turnRight() do end
- else for i=1,direction-tardir do while not turtle.turnLeft() do end end end
- elseif tardir > direction then
- if tardir == 4 and direction == 1 then while not turtle.turnLeft() do end
- else for i=1,tardir-direction do while not turtle.turnRight() do end end end
- end
- direction = tardir
- end
- -- Travel to a co-ordinate.
- local function goToPos(targetx,targety,targetz)
- while x ~= targetx or y ~= targety or z ~= targetz do
- if z > targetz then if turtle.down() then z = z - 1 end
- elseif z < targetz then if turtle.up() then z = z + 1 end end
- if x > targetx then
- if direction ~= 4 then faceDirection("west") end
- if turtle.forward() then x = x - 1 end
- elseif x < targetx then
- if direction ~= 2 then faceDirection("east") end
- if turtle.forward() then x = x + 1 end
- end
- if y > targety then
- if direction ~= 1 then faceDirection("north") end
- if turtle.forward() then y = y - 1 end
- elseif y < targety then
- if direction ~= 3 then faceDirection("south") end
- if turtle.forward() then y = y + 1 end
- end
- end
- end
- -- ----------------------------------------------------------
- -- Init complete, let's go!
- -- ----------------------------------------------------------
- turtle.select(1)
- turtle.refuel()
- local file = fs.open("\\disk\\id","r")
- local myID = tonumber(file.readLine())
- file.close()
- shell.run("cp","\\disk\\update","\\update")
- shell.run("cp","\\disk\\node"..myID,"\\node")
- file = fs.open("\\startup","w")
- file.writeLine("shell.run(\"chopper\")")
- file.close()
- shell.run("pastebin","get","waF1RFPz","\\chopper")
- os.setComputerLabel("BBChopper"..myID)
- do
- local tempx, tempy, tempz
- while tempx == nil or tempy == nil or tempz == nil do
- tempx, tempy, tempz = gps.locate(5)
- sleep(5)
- end
- while not turtle.forward() do while not turtle.turnLeft() do end end
- x,y,z = gps.locate(5)
- if x < tempx then direction = 4
- elseif x > tempx then direction = 2
- elseif y < tempy then direction = 1
- else direction = 3 end
- end
- for i=1,#node[1] do goToPos(node[1][i][1],node[1][i][2],node[1][i][3]) end
- for i=1,#node[1+myID] do goToPos(node[1+myID][i][1],node[1+myID][i][2],node[1+myID][i][3]) end
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement