Add support for multiple droppers: discover and cache available dropper peripherals for location-based dispensing
This commit is contained in:
@@ -645,6 +645,7 @@ local cache = {
|
|||||||
barrelOk = false,
|
barrelOk = false,
|
||||||
furnaceCount = 0,
|
furnaceCount = 0,
|
||||||
furnaceStatus = {}, -- per-furnace { name, type, input, fuel, output, active }
|
furnaceStatus = {}, -- per-furnace { name, type, input, fuel, output, active }
|
||||||
|
droppers = {}, -- list of available dropper peripherals for dispensing
|
||||||
}
|
}
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
@@ -895,6 +896,21 @@ local function refreshCache(onProgress)
|
|||||||
cache.dropperOk = peripheral.wrap(DROPPER_NAME) ~= nil
|
cache.dropperOk = peripheral.wrap(DROPPER_NAME) ~= nil
|
||||||
cache.barrelOk = peripheral.wrap(BARREL_NAME) ~= nil
|
cache.barrelOk = peripheral.wrap(BARREL_NAME) ~= nil
|
||||||
|
|
||||||
|
-- Discover all droppers on the network (for location-based dispensing)
|
||||||
|
local droppers = {}
|
||||||
|
for _, name in ipairs(peripheral.getNames()) do
|
||||||
|
if peripheral.getType(name) == "minecraft:dropper" and name ~= COMPOST_DROPPER then
|
||||||
|
local isDefault = (name == DROPPER_NAME)
|
||||||
|
table.insert(droppers, { name = name, isDefault = isDefault })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Sort so default dropper comes first
|
||||||
|
table.sort(droppers, function(a, b)
|
||||||
|
if a.isDefault ~= b.isDefault then return a.isDefault end
|
||||||
|
return a.name < b.name
|
||||||
|
end)
|
||||||
|
cache.droppers = droppers
|
||||||
|
|
||||||
-- Furnace count already computed from single-pass above
|
-- Furnace count already computed from single-pass above
|
||||||
cache.furnaceCount = #furnaces
|
cache.furnaceCount = #furnaces
|
||||||
|
|
||||||
@@ -2937,6 +2953,7 @@ local function broadcastState()
|
|||||||
barrelOk = cache.barrelOk,
|
barrelOk = cache.barrelOk,
|
||||||
furnaceCount = cache.furnaceCount,
|
furnaceCount = cache.furnaceCount,
|
||||||
furnaceStatus = cache.furnaceStatus,
|
furnaceStatus = cache.furnaceStatus,
|
||||||
|
droppers = cache.droppers,
|
||||||
},
|
},
|
||||||
activity = activity,
|
activity = activity,
|
||||||
alerts = activeAlerts,
|
alerts = activeAlerts,
|
||||||
|
|||||||
Reference in New Issue
Block a user