Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Feeder
- -- ----------------------------------------------------------
- -- Goes around and dumps various forms of animal food into
- -- automated feeder units.
- -- ----------------------------------------------------------
- -- Initialise important values:
- -- ----------------------------------------------------------
- -- Locations of interest:
- local node = {{255,447,66,"south"}, -- 1, feed chest (turtle will face south when it gets here, make sure that's where the ME system is)
- {255,441,65,"west",true}, -- 2, chickens. (turtle will face west here, but all feed will be placed downwards)
- {255,443,65,"west"}, -- 3, a way point where no feeding will be performed.
- {255,442,65,"west"}, -- 4, another waypoint.
- {255,442,65,"west",true}} -- 5, another feeding point.
- local facing = {"north","east","south","west"}
- local direction,x,y,z,counter
- local modem = peripheral.wrap("right")
- -- ----------------------------------------------------------
- -- Functions and stuff:
- -- ----------------------------------------------------------
- -- Returns true if the turtle is carrying anything.
- local function carrying()
- for i=1,16 do if turtle.getItemCount(i) ~= 0 then return true end end
- return false
- end
- -- Accepts strings representing compass-facings to turn the turtle.
- local function faceDirection(targetdirection)
- local tardir = 1
- for i=1,4 do if targetdirection == facing[i] then tardir = i end end
- if tardir < direction then
- if tardir == 1 and direction == 4 then
- turtle.turnRight()
- else
- for i=1,direction-tardir do turtle.turnLeft() end
- end
- elseif tardir > direction then
- if tardir == 4 and direction == 1 then
- turtle.turnLeft()
- else
- for i=1,tardir-direction do turtle.turnRight() end
- end
- end
- direction = tardir
- end
- -- Travel to a co-ordinate.
- local function goToPos(target,digger)
- while (x ~= node[target][1]) or (y ~= node[target][2]) or (z ~= node[target][3]) do
- if z > node[target][3] then
- if turtle.down() then z = z - 1 elseif digger then turtle.digDown() end
- elseif z < node[target][3] then
- if turtle.up() then z = z + 1 elseif digger then turtle.digUp() end
- end
- if x > node[target][1] then
- if direction ~= 4 then faceDirection("west") end
- if turtle.forward() then x = x - 1 elseif digger then turtle.dig() end
- elseif x < node[target][1] then
- if direction ~= 2 then faceDirection("east") end
- if turtle.forward() then x = x + 1 elseif digger then turtle.dig() end
- end
- if y > node[target][2] then
- if direction ~= 1 then faceDirection("north") end
- if turtle.forward() then y = y - 1 elseif digger then turtle.dig() end
- elseif y < node[target][2] then
- if direction ~= 3 then faceDirection("south") end
- if turtle.forward() then y = y + 1 elseif digger then turtle.dig() end
- end
- end
- faceDirection(node[target][4])
- end
- -- ----------------------------------------------------------
- -- I've just booted up. Where am I? Who am I? etc...
- -- ----------------------------------------------------------
- x, y, z = gps.locate(5)
- -- Ping the GPS servers until I get a valid reading.
- while x == nil or y == nil or z == nil do
- print("GPS servers aren't answering; trying again...")
- x, y, z = gps.locate(5)
- sleep(5)
- end
- -- Just a way of isolating some throw-away local variables.
- do
- while not turtle.forward() do
- turtle.down()
- turtle.turnLeft()
- end
- local tempx, tempy, tempz = 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
- x, y, z = gps.locate(5)
- print("I'm at "..x..","..y..","..z..", I have "..turtle.getFuelLevel().." fuel and I'm facing "..facing[direction]..".")
- print("")
- while true do
- print("Heading to stock...")
- print("")
- goToPos(1)
- stock = peripheral.wrap("front")
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.drop(i)
- end
- end
- if turtle.getFuelLevel() < 1000 then
- turtle.select(1)
- stock.pushItem("south",6,64) -- Assuming the turtle is south of the ME system, and you have charcoal or whatever in slot 6 of the ME system.
- if turtle.getItemCount(1) == 0 then print("Warning: ME system out of turtle fuel! Will continue until out of power...")
- turtle.refuel()
- end
- counter = 1
- for i=2,#node do
- if node[i][5] then
- turtle.select(counter)
- stock.pushItem("south",counter,64)
- if turtle.getItemCount(counter) == 0 then error("Error: ME system out of food!!! Exiting...") end
- counter = counter + 1
- end
- end
- counter = 1
- print("Feeding critters...")
- print("")
- for i=2,#node do
- goToPos(i)
- if node[i][5] then
- turtle.select(counter)
- turtle.dropDown()
- counter = counter + 1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement