Add client dropper discovery and announcement functionality
This commit is contained in:
@@ -18,6 +18,8 @@ local SMELTER_MONITOR_SIDE = "top"
|
|||||||
local CLIENT_DROPPER_NAME = "" -- e.g. "minecraft:dropper_5"
|
local CLIENT_DROPPER_NAME = "" -- e.g. "minecraft:dropper_5"
|
||||||
local CLIENT_BARREL_NAME = "" -- e.g. "minecraft:barrel_3"
|
local CLIENT_BARREL_NAME = "" -- e.g. "minecraft:barrel_3"
|
||||||
|
|
||||||
|
local DROPPER_ANNOUNCE_INTERVAL = 30 -- seconds between dropper announcements
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
-- State (received from master)
|
-- State (received from master)
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
@@ -312,6 +314,53 @@ local function sendToMaster(message)
|
|||||||
networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message)
|
networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-------------------------------------------------
|
||||||
|
-- Client dropper discovery
|
||||||
|
-------------------------------------------------
|
||||||
|
|
||||||
|
local function discoverLocalDroppers()
|
||||||
|
local droppers = {}
|
||||||
|
-- Check configured dropper first
|
||||||
|
if CLIENT_DROPPER_NAME ~= "" then
|
||||||
|
local exists = peripheral.wrap(CLIENT_DROPPER_NAME) ~= nil
|
||||||
|
if exists then
|
||||||
|
table.insert(droppers, { name = CLIENT_DROPPER_NAME, isDefault = false, clientId = os.getComputerID() })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Also discover any other droppers on client's local network
|
||||||
|
for _, name in ipairs(peripheral.getNames()) do
|
||||||
|
local isDropper = name:match("^minecraft:dropper_")
|
||||||
|
if not isDropper and peripheral.hasType then
|
||||||
|
isDropper = peripheral.hasType(name, "minecraft:dropper")
|
||||||
|
end
|
||||||
|
if not isDropper then
|
||||||
|
isDropper = peripheral.getType(name) == "minecraft:dropper"
|
||||||
|
end
|
||||||
|
if isDropper then
|
||||||
|
-- Avoid duplicates with configured dropper
|
||||||
|
local isDuplicate = false
|
||||||
|
for _, d in ipairs(droppers) do
|
||||||
|
if d.name == name then isDuplicate = true; break end
|
||||||
|
end
|
||||||
|
if not isDuplicate then
|
||||||
|
table.insert(droppers, { name = name, isDefault = false, clientId = os.getComputerID() })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return droppers
|
||||||
|
end
|
||||||
|
|
||||||
|
local function announceDroppers()
|
||||||
|
local droppers = discoverLocalDroppers()
|
||||||
|
if #droppers > 0 then
|
||||||
|
sendToMaster({
|
||||||
|
type = "register_droppers",
|
||||||
|
clientId = os.getComputerID(),
|
||||||
|
droppers = droppers,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
-- Inventory Dashboard (identical to master)
|
-- Inventory Dashboard (identical to master)
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
@@ -1384,7 +1433,18 @@ local function main()
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Task 4: Client barrel auto-sort (sends to master only when barrel has items)
|
-- Task 4: Announce local droppers to master periodically
|
||||||
|
function()
|
||||||
|
-- Initial announcement after short delay
|
||||||
|
sleep(3)
|
||||||
|
pcall(announceDroppers)
|
||||||
|
while true do
|
||||||
|
sleep(DROPPER_ANNOUNCE_INTERVAL)
|
||||||
|
pcall(announceDroppers)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
-- Task 5: Client barrel auto-sort (sends to master only when barrel has items)
|
||||||
function()
|
function()
|
||||||
if CLIENT_BARREL_NAME == "" then return end
|
if CLIENT_BARREL_NAME == "" then return end
|
||||||
print("[OK] Client barrel: " .. CLIENT_BARREL_NAME)
|
print("[OK] Client barrel: " .. CLIENT_BARREL_NAME)
|
||||||
@@ -1400,7 +1460,7 @@ local function main()
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Task 5: Touch event listener (both monitors)
|
-- Task 6: Touch event listener (both monitors)
|
||||||
function()
|
function()
|
||||||
while true do
|
while true do
|
||||||
local event, side, x, y = os.pullEvent("monitor_touch")
|
local event, side, x, y = os.pullEvent("monitor_touch")
|
||||||
|
|||||||
Reference in New Issue
Block a user