local PROTOCOL = "automine" local PROTOCOL_CTRL = "automineCtrl" function Set(list) local set = {} for _, l in ipairs(list) do set[l] = true end return set end MineRemote = {} function MineRemote.new(target) local self = setmetatable({}, { __index = MineRemote }) self.target = target self:loadDimension() rednet.open("back") return self end function MineRemote:loadDimension() local m = peripheral.wrap("back") local replyChannel = 666 + os.computerID() m.open(replyChannel) m.transmit(666, replyChannel) local event, side, channel, _, reply, distance = os.pullEvent("modem_message") assert(distance) assert(channel == replyChannel) m.close(replyChannel) self.dimension = reply end function MineRemote:awaitMessage(types) while true do local targetId, msg = rednet.receive(PROTOCOL) if types[msg.type] and msg.name == self.target and msg.dimension == self.dimension then return targetId, msg end end end function MineRemote:run() local x, y, z = gps.locate() assert(x, "Couldn't run GPS") local to = vector.new(math.floor(x), math.floor(y), math.floor(z)) print(self.target .. " will recall to " .. to:tostring()) print("Waiting for " .. self.target .. "...") local targetId, msg = self:awaitMessage(Set{"iterationStart", "veinStart"}, self.target) assert(targetId) print("Sending recall request") rednet.send(targetId, { type = "recall", to = to, }, PROTOCOL_CTRL) local _, msg = self:awaitMessage(Set{"ackRecall"}, self.target) assert(msg) print("Received confirmation of recall from " .. self.target ) end if arg[1] then local r = MineRemote.new(arg[1]) r:run() else print("usage: " .. arg[0] .. " ") end