2024-01-16 22:47:14 +00:00
|
|
|
local PROTOCOL = "automine"
|
2024-01-15 13:14:17 +00:00
|
|
|
local TARGET = "devplayer0"
|
2024-01-17 01:28:48 +00:00
|
|
|
|
|
|
|
local DIM_MAP = {
|
|
|
|
overworld = "Overworld",
|
|
|
|
the_nether = "Nether",
|
|
|
|
the_end = "End",
|
|
|
|
}
|
|
|
|
|
2024-01-15 13:14:17 +00:00
|
|
|
local ICON_BASE = "https://p.nul.ie/cc/icon/"
|
|
|
|
local ORE_ICONS = {
|
|
|
|
["minecraft:coal_ore"] = "coal",
|
|
|
|
["minecraft:deepslate_coal_ore"] = "ds-coal",
|
|
|
|
["minecraft:iron_ore"] = "iron",
|
|
|
|
["minecraft:deepslate_iron_ore"] = "ds-iron",
|
|
|
|
["minecraft:copper_ore"] = "copper",
|
|
|
|
["minecraft:deepslate_copper_ore"] = "ds-copper",
|
|
|
|
["minecraft:gold_ore"] = "gold",
|
|
|
|
["minecraft:deepslate_gold_ore"] = "ds-gold",
|
|
|
|
["minecraft:redstone_ore"] = "redstone",
|
|
|
|
["minecraft:deepslate_redstone_ore"] = "ds-redstone",
|
|
|
|
["minecraft:emerald_ore"] = "emerald",
|
|
|
|
["minecraft:deepslate_emerald_ore"] = "ds-emerald",
|
|
|
|
["minecraft:lapis_ore"] = "lapis",
|
|
|
|
["minecraft:deepslate_lapis_ore"] = "ds-lapis",
|
|
|
|
["minecraft:diamond_ore"] = "diamond",
|
|
|
|
["minecraft:deepslate_diamond_ore"] = "ds-diamond",
|
|
|
|
|
|
|
|
-- ["create:ochrum"] =,
|
|
|
|
-- ["create:zinc_ore"] =,
|
|
|
|
-- ["create:deepslate_zinc_ore"] =,
|
|
|
|
-- ["create_new_age:thorium_ore"] =,
|
|
|
|
|
|
|
|
-- ["powah:deepslate_uraninite_ore_poor"] =,
|
|
|
|
-- ["powah:deepslate_uraninite_ore"] =,
|
|
|
|
-- ["powah:deepslate_uraninite_ore_dense"] =,
|
|
|
|
-- ["powah:uraninite_ore_poor"] =,
|
|
|
|
-- ["powah:uraninite_ore"] =,
|
|
|
|
-- ["powah:uraninite_ore_dense"] =,
|
|
|
|
}
|
|
|
|
|
|
|
|
function oreIcon(t)
|
|
|
|
local i = "generic"
|
|
|
|
if ORE_ICONS[t] then
|
|
|
|
i = ORE_ICONS[t]
|
|
|
|
end
|
|
|
|
|
|
|
|
return ICON_BASE .. "ore-" .. i .. ".png"
|
|
|
|
end
|
|
|
|
|
|
|
|
function vecToStr(v)
|
|
|
|
return v.x .. "," .. v.y .. "," .. v.z
|
|
|
|
end
|
|
|
|
|
|
|
|
function markerSet(msg)
|
|
|
|
return "autominer_" .. msg.name
|
|
|
|
end
|
|
|
|
|
2024-01-16 22:47:14 +00:00
|
|
|
Chat = {}
|
|
|
|
function Chat.new(prefix)
|
|
|
|
local self = setmetatable({}, { __index = Chat })
|
|
|
|
|
|
|
|
self.chat = peripheral.find("chatBox")
|
|
|
|
self.prefix = prefix
|
|
|
|
self.lastSend = 0
|
|
|
|
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
function Chat:send(msg, target)
|
|
|
|
local delta = os.clock() - self.lastSend
|
|
|
|
if delta < 1 then
|
|
|
|
local amount = 1 - delta + 0.1
|
|
|
|
sleep(amount)
|
|
|
|
end
|
|
|
|
|
|
|
|
local msgJSON = textutils.serializeJSON(msg)
|
|
|
|
-- print(msgJSON)
|
|
|
|
if target then
|
|
|
|
assert(self.chat.sendFormattedMessageToPlayer(msgJSON, target, self.prefix))
|
|
|
|
else
|
|
|
|
assert(self.chat.sendFormattedMessage(msgJSON, self.prefix))
|
|
|
|
end
|
|
|
|
self.lastSend = os.clock()
|
|
|
|
end
|
|
|
|
|
|
|
|
MineMonitor = {}
|
|
|
|
function MineMonitor.new(chat)
|
|
|
|
local self = setmetatable({}, { __index = MineMonitor })
|
|
|
|
|
|
|
|
self.chat = chat
|
|
|
|
|
|
|
|
self.cart = peripheral.find("cartographer")
|
|
|
|
self.cart.refreshIntegrations()
|
|
|
|
|
|
|
|
peripheral.find("modem", rednet.open)
|
|
|
|
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
2024-01-17 01:28:48 +00:00
|
|
|
function MineMonitor:prepareMap(msg)
|
|
|
|
local map = DIM_MAP[msg.dimension]
|
|
|
|
assert(map)
|
|
|
|
assert(self.cart.setCurrentMap(map))
|
|
|
|
|
|
|
|
local id = markerSet(msg)
|
|
|
|
local sets = self.cart.getMarkerSets()
|
|
|
|
assert(sets)
|
|
|
|
|
|
|
|
local found = false
|
|
|
|
for _, s in ipairs(sets) do
|
|
|
|
if s == id then
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not found then
|
|
|
|
assert(self.cart.addMarkerSet(id, "AutoMiner " .. msg.name))
|
|
|
|
end
|
|
|
|
return id
|
|
|
|
end
|
|
|
|
|
2024-01-16 22:47:14 +00:00
|
|
|
function MineMonitor:setPosMarker(msg)
|
2024-01-15 13:14:17 +00:00
|
|
|
local id = markerSet(msg)
|
|
|
|
local mId = id .. "_pos"
|
2024-01-16 22:47:14 +00:00
|
|
|
self.cart.removeMarker(id, mId)
|
|
|
|
self.cart.addPOIMarker(
|
2024-01-15 13:14:17 +00:00
|
|
|
id, mId, msg.name, msg.name .. "'s position",
|
|
|
|
msg.pos.x, msg.pos.y, msg.pos.z,
|
|
|
|
ICON_BASE .. "turtle.png")
|
|
|
|
end
|
|
|
|
|
2024-01-16 22:47:14 +00:00
|
|
|
function MineMonitor:handleStart(msg)
|
|
|
|
self.chat:send({
|
2024-01-15 13:14:17 +00:00
|
|
|
{text = msg.name, color = "green"},
|
|
|
|
{text = " @ ", color = "white"},
|
|
|
|
{text = vecToStr(msg.pos), color = "aqua"},
|
2024-01-17 01:28:48 +00:00
|
|
|
{text = " in ", color = "white"},
|
|
|
|
{text = msg.dimension, color = "aqua"},
|
2024-01-15 13:14:17 +00:00
|
|
|
{text = " found ", color = "white"},
|
|
|
|
{text = tostring(msg.oreCount), color = "red"},
|
|
|
|
{text = " ores (", color = "white"},
|
|
|
|
{text = tostring(#msg.veins), color = "red"},
|
|
|
|
{text = " veins) on iteration ", color = "white"},
|
|
|
|
{text = tostring(msg.i), color = "green"},
|
|
|
|
{text = "!", color = "white"},
|
2024-01-16 22:47:14 +00:00
|
|
|
})
|
2024-01-15 13:14:17 +00:00
|
|
|
|
2024-01-17 01:28:48 +00:00
|
|
|
local id = self:prepareMap(msg)
|
2024-01-16 22:47:14 +00:00
|
|
|
self.cart.clearMarkerSet(id)
|
|
|
|
self:setPosMarker(msg)
|
2024-01-15 13:14:17 +00:00
|
|
|
|
2024-01-16 22:47:14 +00:00
|
|
|
local veinPoints = {}
|
2024-01-15 13:14:17 +00:00
|
|
|
for i, v in ipairs(msg.veins) do
|
2024-01-16 22:47:14 +00:00
|
|
|
table.insert(veinPoints, v.pos)
|
|
|
|
self.cart.addPOIMarker(
|
2024-01-15 13:14:17 +00:00
|
|
|
id, id .. "_vein_" .. i, v.count .. " " .. v.type, "Vein of " .. v.count .. " " .. v.type,
|
|
|
|
v.pos.x, v.pos.y, v.pos.z,
|
|
|
|
oreIcon(v.type))
|
|
|
|
end
|
|
|
|
|
2024-01-16 22:47:14 +00:00
|
|
|
if #veinPoints >= 2 then
|
|
|
|
self.cart.addLineMarker(
|
|
|
|
id, id .. "_vein_path", "Mining path #" .. msg.i, "Current mining path",
|
|
|
|
"#FF00FF", 0.7, 3,
|
|
|
|
veinPoints)
|
|
|
|
end
|
2024-01-15 13:14:17 +00:00
|
|
|
end
|
|
|
|
|
2024-01-16 22:47:14 +00:00
|
|
|
function MineMonitor:handleVein(msg)
|
|
|
|
self.chat:send({
|
2024-01-15 13:14:17 +00:00
|
|
|
{text = msg.name, color = "green"},
|
|
|
|
{text = " @ ", color = "white"},
|
|
|
|
{text = vecToStr(msg.pos), color = "aqua"},
|
2024-01-17 01:28:48 +00:00
|
|
|
{text = " in ", color = "white"},
|
|
|
|
{text = msg.dimension, color = "aqua"},
|
2024-01-15 13:14:17 +00:00
|
|
|
{text = " is mining ", color = "white"},
|
|
|
|
{text = tostring(msg.oreCount), color = "red"},
|
|
|
|
{text = " ", color = "white"},
|
|
|
|
{text = msg.oreType, color = "dark_purple"},
|
|
|
|
{text = " (vein ", color = "white"},
|
|
|
|
{text = tostring(msg.i), color = "red"},
|
|
|
|
{text = " / ", color = "white"},
|
|
|
|
{text = tostring(msg.total), color = "red"},
|
|
|
|
{text = ")!", color = "white"},
|
2024-01-16 22:47:14 +00:00
|
|
|
}, TARGET)
|
2024-01-15 13:14:17 +00:00
|
|
|
|
2024-01-17 01:28:48 +00:00
|
|
|
local id = self:prepareMap(msg)
|
2024-01-16 22:47:14 +00:00
|
|
|
self:setPosMarker(msg)
|
2024-01-15 13:14:17 +00:00
|
|
|
if msg.i ~= 1 then
|
2024-01-16 22:47:14 +00:00
|
|
|
self.cart.removeMarker(id, id .. "_vein_" .. (msg.i - 1))
|
2024-01-15 13:14:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-16 22:47:14 +00:00
|
|
|
function MineMonitor:handleRecall(msg)
|
|
|
|
self.chat:send({
|
|
|
|
{text = msg.name, color = "green"},
|
|
|
|
{text = " @ ", color = "white"},
|
|
|
|
{text = vecToStr(msg.pos), color = "aqua"},
|
2024-01-17 01:28:48 +00:00
|
|
|
{text = " in ", color = "white"},
|
|
|
|
{text = msg.dimension, color = "aqua"},
|
2024-01-16 22:47:14 +00:00
|
|
|
{text = " is recalling to ", color = "white"},
|
|
|
|
{text = vecToStr(msg.to), color = "green"},
|
|
|
|
{text = "!", color = "white"},
|
|
|
|
})
|
|
|
|
|
2024-01-17 01:28:48 +00:00
|
|
|
local id = self:prepareMap(msg)
|
2024-01-16 22:47:14 +00:00
|
|
|
self.cart.clearMarkerSet(id)
|
|
|
|
|
|
|
|
self:setPosMarker({
|
|
|
|
name = msg.name,
|
|
|
|
pos = msg.to,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function MineMonitor:loop()
|
|
|
|
while true do
|
|
|
|
local _, sender, msg = os.pullEvent("mine_monitor_message")
|
|
|
|
local handler = nil
|
2024-01-15 13:14:17 +00:00
|
|
|
if msg.type == "iterationStart" then
|
2024-01-16 22:47:14 +00:00
|
|
|
handler = self.handleStart
|
2024-01-15 13:14:17 +00:00
|
|
|
elseif msg.type == "veinStart" then
|
2024-01-16 22:47:14 +00:00
|
|
|
handler = self.handleVein
|
|
|
|
elseif msg.type == "ackRecall" then
|
|
|
|
handler = self.handleRecall
|
2024-01-15 13:14:17 +00:00
|
|
|
end
|
2024-01-16 22:47:14 +00:00
|
|
|
|
|
|
|
if handler then
|
|
|
|
handler(self, msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function MineMonitor:netLoop()
|
|
|
|
while true do
|
|
|
|
local sender, msg = rednet.receive(PROTOCOL)
|
|
|
|
os.queueEvent("mine_monitor_message", sender, msg)
|
2024-01-15 13:14:17 +00:00
|
|
|
end
|
|
|
|
end
|
2024-01-16 22:47:14 +00:00
|
|
|
|
|
|
|
function MineMonitor:run()
|
|
|
|
parallel.waitForAll(
|
|
|
|
function() self:loop() end,
|
|
|
|
function() self:netLoop() end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
local chat = Chat.new("AutoMine")
|
|
|
|
local mineMon = MineMonitor.new(chat)
|
|
|
|
mineMon:run()
|