2024-01-16 22:47:14 +00:00
|
|
|
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
|
|
|
|
|
2024-01-17 01:28:48 +00:00
|
|
|
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)
|
2024-01-16 22:47:14 +00:00
|
|
|
while true do
|
|
|
|
local targetId, msg = rednet.receive(PROTOCOL)
|
2024-01-17 01:28:48 +00:00
|
|
|
if types[msg.type] and msg.name == self.target and msg.dimension == self.dimension then
|
2024-01-16 22:47:14 +00:00
|
|
|
return targetId, msg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-17 01:28:48 +00:00
|
|
|
function MineRemote:run()
|
2024-01-16 22:47:14 +00:00
|
|
|
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))
|
2024-01-17 01:28:48 +00:00
|
|
|
print(self.target .. " will recall to " .. to:tostring())
|
2024-01-16 22:47:14 +00:00
|
|
|
|
2024-01-17 01:28:48 +00:00
|
|
|
print("Waiting for " .. self.target .. "...")
|
|
|
|
local targetId, msg = self:awaitMessage(Set{"iterationStart", "veinStart"}, self.target)
|
2024-01-16 22:47:14 +00:00
|
|
|
assert(targetId)
|
|
|
|
|
|
|
|
print("Sending recall request")
|
|
|
|
rednet.send(targetId, {
|
|
|
|
type = "recall",
|
|
|
|
to = to,
|
|
|
|
}, PROTOCOL_CTRL)
|
|
|
|
|
2024-01-17 01:28:48 +00:00
|
|
|
local _, msg = self:awaitMessage(Set{"ackRecall"}, self.target)
|
2024-01-16 22:47:14 +00:00
|
|
|
assert(msg)
|
2024-01-17 01:28:48 +00:00
|
|
|
print("Received confirmation of recall from " .. self.target )
|
2024-01-16 22:47:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if arg[1] then
|
2024-01-17 01:28:48 +00:00
|
|
|
local r = MineRemote.new(arg[1])
|
|
|
|
r:run()
|
2024-01-16 22:47:14 +00:00
|
|
|
else
|
|
|
|
print("usage: " .. arg[0] .. " <target>")
|
|
|
|
end
|