Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ============================================================
- -- MineColonies Domum Ornamentum Material Stager v3
- -- Multi-Builder Edition
- -- ============================================================
- --
- -- PURPOSE
- -- Scans every active/staffed Builder's Hut in the colony,
- -- reads Domum Ornamentum requirements from BOTH:
- --
- -- 1. Builder Hut Required Resources
- -- 2. The Builder citizen's personal requests
- --
- -- For each Builder, duplicate demand is merged using MAX:
- --
- -- Hut needs Framed Block x25
- -- Builder requests Framed Block x25
- -- => that Builder contributes x25, NOT x50
- --
- -- Demand from DIFFERENT Builders is then ADDED:
- --
- -- Builder A needs x25
- -- Builder B needs x10
- -- => stage materials for x35
- --
- -- OUTPUT
- -- One shared inventory directly ABOVE the dedicated
- -- Architect-materials ME Bridge.
- --
- -- ME BRIDGE DISCOVERY
- -- All ME Bridges named builder_# are ignored.
- -- If exactly one other ME Bridge is present, it is used.
- --
- -- Optional: set OUTPUT_BRIDGE_CUSTOM_NAME below if you want
- -- to explicitly select a bridge by its anvil/custom name.
- --
- -- AE2
- -- BEFORE staging raw materials, the script checks AE2 for
- -- the exact requested Domum Ornamentum finished block.
- -- Existing finished blocks reduce the amount that needs
- -- raw materials staged.
- --
- -- Stored raw materials are exported immediately.
- -- Missing raw materials are autocrafted when possible.
- --
- -- IMPORTANT
- -- The material calculation is deliberately conservative:
- -- requested DO output count x occurrences of each material.
- -- This can stage extra material for Cutter recipes that yield
- -- multiple output blocks, but it should not under-supply them.
- --
- -- ============================================================
- -- ============================================================
- -- CONFIG
- -- ============================================================
- local OUTPUT_SIDE = "up"
- local POLL_INTERVAL = 5
- local CRAFT_RETRY_SECONDS = 30
- -- When the Colony Supplier removes a finished DO block from
- -- AE2, MineColonies may take a few seconds to notice it in the
- -- Builder storage. Keep temporary credit for recently-removed
- -- finished blocks so this script does not immediately stage
- -- unnecessary raw materials during that update window.
- local FINISHED_ITEM_HOLD_SECONDS = 20
- -- nil = automatically use the one ME Bridge that is NOT named
- -- builder_#, e.g. the bridge dedicated to this Architect setup.
- --
- -- Or set:
- -- local OUTPUT_BRIDGE_CUSTOM_NAME = "architect_materials"
- local OUTPUT_BRIDGE_CUSTOM_NAME = nil
- -- ============================================================
- -- PERIPHERALS
- -- ============================================================
- local colony = peripheral.find("colony_integrator")
- if not colony then
- error("Colony Integrator not found!")
- end
- local colonyName =
- colony.getColonyName()
- or "Unknown Colony"
- -- ============================================================
- -- FIND THE ARCHITECT ME BRIDGE
- -- ============================================================
- local function findArchitectBridge()
- local candidates = {}
- for _, peripheralName
- in ipairs(peripheral.getNames()) do
- if peripheral.getType(peripheralName)
- == "me_bridge" then
- local bridge =
- peripheral.wrap(peripheralName)
- local customName =
- bridge.getName
- and bridge.getName()
- or ""
- customName =
- tostring(customName or "")
- if OUTPUT_BRIDGE_CUSTOM_NAME then
- if customName
- == OUTPUT_BRIDGE_CUSTOM_NAME then
- return bridge,
- peripheralName,
- customName
- end
- else
- -- Colony supplier bridges are deliberately
- -- named builder_1, builder_2, builder_3, ...
- if not customName:match(
- "^builder_%d+$"
- ) then
- table.insert(
- candidates,
- {
- bridge = bridge,
- peripheralName =
- peripheralName,
- customName =
- customName
- }
- )
- end
- end
- end
- end
- if OUTPUT_BRIDGE_CUSTOM_NAME then
- error(
- "No ME Bridge found with custom name '"
- .. OUTPUT_BRIDGE_CUSTOM_NAME
- .. "'."
- )
- end
- if #candidates == 0 then
- error(
- "No non-builder ME Bridge found for "
- .. "architect_materials."
- )
- end
- if #candidates > 1 then
- local names = {}
- for _, candidate
- in ipairs(candidates) do
- table.insert(
- names,
- candidate.peripheralName
- .. "='"
- .. candidate.customName
- .. "'"
- )
- end
- error(
- "Multiple non-builder ME Bridges found: "
- .. table.concat(names, ", ")
- .. ". Set OUTPUT_BRIDGE_CUSTOM_NAME."
- )
- end
- local selected =
- candidates[1]
- return selected.bridge,
- selected.peripheralName,
- selected.customName
- end
- local me,
- mePeripheralName,
- meCustomName =
- findArchitectBridge()
- -- ============================================================
- -- RUNTIME STATE
- -- ============================================================
- -- staged[exact_DO_variant].materials[raw_material] = number sent
- --
- -- State is retained while that DO requirement remains active.
- -- When the requirement disappears completely, its state is
- -- forgotten so a future new request can be staged again.
- local staged = {}
- -- Do not repeatedly hammer AE2 with the same craft request.
- local craftRetry = {}
- -- Suppress duplicate terminal warnings.
- local warned = {}
- -- Tracks exact finished DO item stock changes in AE2.
- -- If stock suddenly drops, it was likely pulled by the Colony
- -- Supplier, so the previous amount remains credited briefly.
- local finishedItemState = {}
- -- ============================================================
- -- BASIC HELPERS
- -- ============================================================
- local function now()
- return os.epoch("utc") / 1000
- end
- local function num(value)
- if type(value) == "number" then
- return value
- end
- if value == true then
- return 1
- end
- return 0
- end
- local function posKey(pos)
- return tostring(pos.x)
- .. ","
- .. tostring(pos.y)
- .. ","
- .. tostring(pos.z)
- end
- local function samePos(a, b)
- return a
- and b
- and a.x == b.x
- and a.y == b.y
- and a.z == b.z
- end
- local function cleanName(name)
- if not name then
- return "Unknown Item"
- end
- name = tostring(name)
- name = name:gsub("^%[", "")
- name = name:gsub("%]$", "")
- return name
- end
- local function getDisplayName(
- item,
- fallback
- )
- if fallback
- and fallback ~= "" then
- return cleanName(fallback)
- end
- if item
- and item.displayName then
- return cleanName(
- item.displayName
- )
- end
- if item
- and item.name then
- return tostring(item.name)
- end
- return "Unknown Item"
- end
- local function isDomum(item)
- return item
- and type(item.name) == "string"
- and item.name:match(
- "^domum_ornamentum:"
- ) ~= nil
- end
- local function variantKey(item)
- if not item then
- return nil
- end
- if item.fingerprint then
- return "fp:"
- .. tostring(
- item.fingerprint
- )
- end
- return tostring(item.name)
- .. ":"
- .. textutils.serialize(
- item.components or {}
- )
- end
- -- ============================================================
- -- AE2 HELPERS
- -- ============================================================
- local function itemFilter(
- name,
- count
- )
- local filter = {
- name = name
- }
- if count then
- filter.count = count
- end
- return filter
- end
- local function storedCount(result)
- if not result then
- return 0
- end
- if type(result.count)
- == "number" then
- return result.count
- end
- if type(result.amount)
- == "number" then
- return result.amount
- end
- return 0
- end
- local function getStored(name)
- local ok, result =
- pcall(
- me.getItem,
- itemFilter(name)
- )
- if not ok
- or not result then
- return 0
- end
- return storedCount(result)
- end
- -- ============================================================
- -- EXACT FINISHED DOMUM ITEM LOOKUP
- -- ============================================================
- --
- -- Domum Ornamentum variants can share the same registry ID while
- -- differing by fingerprint/components. For the FINISHED block
- -- check, match the exact requested stack instead of only its name.
- -- ============================================================
- local function exactItemFilter(item)
- if item
- and item.fingerprint then
- return {
- fingerprint =
- item.fingerprint
- }
- end
- local filter = {
- name = item.name
- }
- if item.components
- and next(item.components) then
- filter.components =
- item.components
- end
- return filter
- end
- local function getExactFinishedStored(item)
- local ok, result =
- pcall(
- me.getItem,
- exactItemFilter(item)
- )
- if not ok
- or not result then
- return 0
- end
- return storedCount(result)
- end
- local function getEffectiveFinishedStored(
- key,
- item
- )
- local stored =
- getExactFinishedStored(
- item
- )
- local currentTime =
- now()
- local state =
- finishedItemState[key]
- if not state then
- state = {
- lastStored = stored,
- holdAmount = 0,
- holdUntil = 0
- }
- finishedItemState[key] =
- state
- end
- -- If exact finished stock drops, assume the Colony Supplier
- -- may just have exported it to Builder storage. Preserve the
- -- previous stock count briefly while MineColonies catches up.
- if stored < state.lastStored then
- state.holdAmount =
- math.max(
- state.holdAmount,
- state.lastStored
- )
- state.holdUntil =
- currentTime
- + FINISHED_ITEM_HOLD_SECONDS
- end
- state.lastStored =
- stored
- local effective =
- stored
- if currentTime
- < state.holdUntil then
- effective =
- math.max(
- effective,
- state.holdAmount
- )
- else
- state.holdAmount = 0
- state.holdUntil = 0
- end
- return effective
- end
- local function isCraftable(name)
- local ok, result =
- pcall(
- me.isCraftable,
- itemFilter(name)
- )
- return ok
- and result == true
- end
- local function isCrafting(name)
- local ok, result =
- pcall(
- me.isCrafting,
- itemFilter(name)
- )
- return ok
- and result == true
- end
- local function parseTransferred(result)
- if type(result) == "number" then
- return result
- end
- if type(result) == "table" then
- return result.count
- or result.amount
- or result.transferred
- or 0
- end
- return 0
- end
- local function exportItem(
- name,
- count
- )
- if count <= 0 then
- return 0
- end
- local ok, result, err =
- pcall(
- me.exportItem,
- itemFilter(
- name,
- count
- ),
- OUTPUT_SIDE
- )
- if not ok then
- print(
- "[EXPORT ERROR] "
- .. name
- .. ": "
- .. tostring(result)
- )
- return 0
- end
- local moved =
- parseTransferred(result)
- if moved <= 0
- and err then
- print(
- "[EXPORT ERROR] "
- .. name
- .. ": "
- .. tostring(err)
- )
- end
- return moved
- end
- local function craftItem(
- name,
- count
- )
- if count <= 0 then
- return false
- end
- local ok, result, err =
- pcall(
- me.craftItem,
- itemFilter(
- name,
- count
- )
- )
- if not ok then
- print(
- "[CRAFT ERROR] "
- .. name
- .. ": "
- .. tostring(result)
- )
- return false
- end
- if result then
- return true
- end
- if err then
- print(
- "[CRAFT ERROR] "
- .. name
- .. ": "
- .. tostring(err)
- )
- end
- return false
- end
- -- ============================================================
- -- FIND EVERY RELEVANT BUILDER HUT
- -- ============================================================
- --
- -- We avoid hardcoding Builder counts or hut coordinates.
- --
- -- Builder huts are discovered from:
- --
- -- A. Citizens whose job is MineColonies Builder
- -- B. Active BUILD / UPGRADE / REPAIR work orders
- --
- -- This captures every staffed Builder Hut plus any hut actively
- -- handling a construction order.
- -- ============================================================
- local function findBuilderHuts()
- local huts = {}
- -- --------------------------------------------------------
- -- STAFFED BUILDER HUTS
- -- --------------------------------------------------------
- local citizens =
- colony.getCitizens()
- or {}
- for _, citizen
- in ipairs(citizens) do
- local work =
- citizen.work
- if work
- and work.location
- and (
- tostring(work.job)
- == "com.minecolonies.job.builder"
- or tostring(work.name)
- == "com.minecolonies.building.builder"
- ) then
- local key =
- posKey(
- work.location
- )
- if not huts[key] then
- huts[key] = {
- pos = work.location,
- builder = citizen
- }
- else
- huts[key].builder =
- citizen
- end
- end
- end
- -- --------------------------------------------------------
- -- ACTIVE CONSTRUCTION WORK ORDERS
- -- --------------------------------------------------------
- local orders =
- colony.getWorkOrders()
- or {}
- for _, order
- in ipairs(orders) do
- local workType =
- tostring(
- order.workOrderType
- )
- if (
- workType == "BUILD"
- or workType == "UPGRADE"
- or workType == "REPAIR"
- )
- and type(order.builder)
- == "table" then
- local key =
- posKey(
- order.builder
- )
- if not huts[key] then
- huts[key] = {
- pos = order.builder,
- builder = nil
- }
- end
- huts[key].order =
- order
- end
- end
- -- --------------------------------------------------------
- -- IF A WORK-ORDER HUT DID NOT ALREADY HAVE A CITIZEN,
- -- MATCH ITS POSITION AGAINST ALL CITIZENS.
- -- --------------------------------------------------------
- for _, hut
- in pairs(huts) do
- if not hut.builder then
- for _, citizen
- in ipairs(citizens) do
- if citizen.work
- and citizen.work.location
- and samePos(
- citizen.work.location,
- hut.pos
- ) then
- hut.builder =
- citizen
- break
- end
- end
- end
- end
- local result = {}
- for _, hut
- in pairs(huts) do
- table.insert(
- result,
- hut
- )
- end
- table.sort(
- result,
- function(a, b)
- local aName =
- a.builder
- and a.builder.name
- or posKey(a.pos)
- local bName =
- b.builder
- and b.builder.name
- or posKey(b.pos)
- return string.lower(
- tostring(aName)
- )
- <
- string.lower(
- tostring(bName)
- )
- end
- )
- return result
- end
- local function requestIsClosed(request)
- local state =
- string.upper(
- tostring(
- request.state or ""
- )
- )
- return state:find(
- "COMPLETE",
- 1,
- true
- ) ~= nil
- or state:find(
- "CANCEL",
- 1,
- true
- ) ~= nil
- or state == "DONE"
- or state == "RESOLVED"
- end
- -- ============================================================
- -- DOMUM MATERIAL EXTRACTION
- -- ============================================================
- --
- -- Domum Ornamentum stores selected input textures/materials
- -- inside the requested item's component/custom-data structure.
- --
- -- We recursively locate branches whose key contains "texture"
- -- and collect resource-location strings from their VALUES.
- --
- -- Repeated material IDs are counted. If the same raw block is
- -- used in two Cutter material slots, it is staged twice per
- -- requested output.
- -- ============================================================
- local function validResourceId(value)
- return type(value) == "string"
- and value:match(
- "^[%w_.-]+:[%w_./-]+$"
- ) ~= nil
- end
- local function collectTextureValues(
- value,
- result
- )
- if type(value) == "string" then
- if validResourceId(value) then
- result[value] =
- (result[value] or 0)
- + 1
- end
- return
- end
- if type(value) ~= "table" then
- return
- end
- for _, child
- in pairs(value) do
- collectTextureValues(
- child,
- result
- )
- end
- end
- local function findTextureData(
- value,
- result
- )
- if type(value) ~= "table" then
- return
- end
- for key, child
- in pairs(value) do
- local keyName =
- string.lower(
- tostring(key)
- )
- if keyName:find(
- "texture",
- 1,
- true
- ) then
- collectTextureValues(
- child,
- result
- )
- elseif type(child)
- == "table" then
- findTextureData(
- child,
- result
- )
- end
- end
- end
- local function materialsFor(item)
- local result = {}
- if not item
- or type(item.components)
- ~= "table" then
- return result
- end
- findTextureData(
- item.components,
- result
- )
- -- Requested DO output is never its own raw material.
- if item.name then
- result[item.name] = nil
- end
- return result
- end
- -- ============================================================
- -- DEMAND HELPERS
- -- ============================================================
- local function ensureVariant(
- map,
- item,
- name
- )
- local key =
- variantKey(item)
- if not key then
- return nil
- end
- local entry =
- map[key]
- if not entry then
- entry = {
- key = key,
- item = item,
- name =
- getDisplayName(
- item,
- name
- ),
- hut = 0,
- builder = 0
- }
- map[key] =
- entry
- end
- return entry
- end
- -- ============================================================
- -- COLLECT ONE BUILDER HUT'S DO DEMAND
- -- ============================================================
- local function collectHutDemand(
- hut,
- allRequests
- )
- local localDemand = {}
- -- --------------------------------------------------------
- -- BUILDER HUT REQUIRED RESOURCES
- -- --------------------------------------------------------
- local resources =
- colony.getBuilderResources(
- hut.pos
- )
- or {}
- for _, resource
- in ipairs(resources) do
- local item =
- resource.item
- if isDomum(item) then
- local shortage =
- math.max(
- 0,
- num(resource.needs)
- - num(resource.available)
- - num(resource.delivering)
- )
- if shortage > 0 then
- local entry =
- ensureVariant(
- localDemand,
- item,
- resource.displayName
- )
- if entry then
- entry.hut =
- entry.hut
- + shortage
- end
- end
- end
- end
- -- --------------------------------------------------------
- -- THIS BUILDER'S PERSONAL REQUESTS
- -- --------------------------------------------------------
- if hut.builder
- and hut.builder.name then
- for _, request
- in ipairs(allRequests) do
- if not requestIsClosed(request)
- and tostring(
- request.target or ""
- ):find(
- hut.builder.name,
- 1,
- true
- )
- and type(request.items)
- == "table" then
- -- Prefer a DO variant already present in this
- -- Hut's Required Resources list.
- local chosen = nil
- for _, item
- in ipairs(request.items) do
- if isDomum(item)
- and localDemand[
- variantKey(item)
- ] then
- chosen = item
- break
- end
- end
- if not chosen then
- for _, item
- in ipairs(request.items) do
- if isDomum(item) then
- chosen = item
- break
- end
- end
- end
- if chosen then
- local entry =
- ensureVariant(
- localDemand,
- chosen,
- request.name
- )
- if entry then
- entry.builder =
- entry.builder
- + (
- tonumber(
- request.count
- )
- or 1
- )
- end
- end
- end
- end
- end
- -- --------------------------------------------------------
- -- MERGE WITHIN THIS BUILDER
- -- --------------------------------------------------------
- for _, entry
- in pairs(localDemand) do
- entry.quantity =
- math.max(
- entry.hut,
- entry.builder
- )
- end
- return localDemand
- end
- -- ============================================================
- -- COLLECT ALL BUILDERS
- -- ============================================================
- local function collectAllDemand()
- local huts =
- findBuilderHuts()
- local requests =
- colony.getRequests()
- or {}
- local totalDemand = {}
- for _, hut
- in ipairs(huts) do
- local localDemand =
- collectHutDemand(
- hut,
- requests
- )
- -- Demand from DIFFERENT Builder Huts is additive.
- for key, localEntry
- in pairs(localDemand) do
- local total =
- totalDemand[key]
- if not total then
- total = {
- key = key,
- item =
- localEntry.item,
- name =
- localEntry.name,
- quantity = 0,
- builders = 0
- }
- totalDemand[key] =
- total
- end
- if localEntry.quantity > 0 then
- total.quantity =
- total.quantity
- + localEntry.quantity
- total.builders =
- total.builders + 1
- end
- end
- end
- return totalDemand,
- huts
- end
- -- ============================================================
- -- STAGING STATE
- -- ============================================================
- local function syncStagingState(demand)
- local active = {}
- for key, entry
- in pairs(demand) do
- active[key] = true
- local materials =
- materialsFor(
- entry.item
- )
- local state =
- staged[key]
- if not state then
- state = {
- requested =
- entry.quantity,
- name =
- entry.name,
- materials = {}
- }
- staged[key] =
- state
- end
- -- --------------------------------------------------------
- -- CHECK FOR THE FINISHED DO BLOCK IN AE2 FIRST
- -- --------------------------------------------------------
- --
- -- Example:
- -- Builders currently need Framed Block x25
- -- AE2 already contains exact Framed Block x20
- --
- -- Only stage raw materials for the missing x5.
- --
- -- The lookup is exact by fingerprint/components so another
- -- DO variant with the same registry name does not count.
- local finishedStored =
- getEffectiveFinishedStored(
- key,
- entry.item
- )
- local missingFinished =
- math.max(
- 0,
- entry.quantity
- - finishedStored
- )
- -- Current aggregate across all Builders, minus exact
- -- finished blocks already available in AE2.
- --
- -- If demand rises, additional material is staged.
- -- If it falls below what has already been sent, nothing
- -- further is staged.
- state.requested =
- missingFinished
- state.name =
- entry.name
- state.totalDemand =
- entry.quantity
- state.finishedStored =
- finishedStored
- if missingFinished <= 0 then
- local coveredKey =
- "covered:" .. key
- if not warned[
- coveredKey
- ] then
- print(
- "[COVERED] "
- .. entry.name
- .. " x"
- .. tostring(
- entry.quantity
- )
- .. " already exists in AE2."
- )
- warned[
- coveredKey
- ] = true
- end
- else
- warned[
- "covered:" .. key
- ] = nil
- end
- for materialName,
- perOutput
- in pairs(materials) do
- if not state.materials[
- materialName
- ] then
- state.materials[
- materialName
- ] = {
- perOutput =
- perOutput,
- sent = 0
- }
- else
- state.materials[
- materialName
- ].perOutput =
- perOutput
- end
- end
- if next(materials)
- == nil then
- local warningKey =
- "parse:" .. key
- if not warned[
- warningKey
- ] then
- print("")
- print(
- "[PARSE ERROR] "
- .. entry.name
- .. " x"
- .. tostring(
- entry.quantity
- )
- )
- print(
- "Could not extract DO texture materials."
- )
- print(
- "Inspect this requested item's components "
- .. "before changing the parser."
- )
- warned[
- warningKey
- ] = true
- end
- else
- warned[
- "parse:" .. key
- ] = nil
- end
- end
- -- Fully vanished requirement = finished.
- for key
- in pairs(staged) do
- if not active[key] then
- staged[key] = nil
- finishedItemState[key] = nil
- warned["covered:" .. key] = nil
- end
- end
- end
- -- ============================================================
- -- PROCESS ONE RAW MATERIAL
- -- ============================================================
- local function stageMaterial(
- variant,
- materialName,
- materialState
- )
- local target =
- variant.requested
- * materialState.perOutput
- local remaining =
- target
- - materialState.sent
- if remaining <= 0 then
- return
- end
- -- --------------------------------------------------------
- -- EXPORT STORED MATERIAL
- -- --------------------------------------------------------
- local stored =
- getStored(
- materialName
- )
- if stored > 0 then
- local amount =
- math.min(
- stored,
- remaining
- )
- local moved =
- exportItem(
- materialName,
- amount
- )
- if moved > 0 then
- materialState.sent =
- materialState.sent
- + moved
- remaining =
- remaining - moved
- print(
- "[STAGED] "
- .. materialName
- .. " x"
- .. tostring(moved)
- .. " for "
- .. variant.name
- )
- end
- -- Output container did not accept the entire attempted
- -- transfer. Do not craft more until there is room.
- if moved < amount then
- return
- end
- end
- if remaining <= 0 then
- return
- end
- -- --------------------------------------------------------
- -- ALREADY CRAFTING
- -- --------------------------------------------------------
- if isCrafting(
- materialName
- ) then
- return
- end
- -- --------------------------------------------------------
- -- AUTOCRAFT
- -- --------------------------------------------------------
- if isCraftable(
- materialName
- ) then
- local retryAt =
- craftRetry[
- materialName
- ]
- or 0
- if now() >= retryAt then
- local started =
- craftItem(
- materialName,
- remaining
- )
- craftRetry[
- materialName
- ] =
- now()
- + CRAFT_RETRY_SECONDS
- if started then
- print(
- "[CRAFT] "
- .. materialName
- .. " x"
- .. tostring(
- remaining
- )
- )
- warned[
- "missing:"
- .. materialName
- ] = nil
- end
- end
- return
- end
- -- --------------------------------------------------------
- -- MISSING
- -- --------------------------------------------------------
- local warningKey =
- "missing:"
- .. materialName
- if not warned[
- warningKey
- ] then
- print(
- "[MISSING] "
- .. materialName
- .. " x"
- .. tostring(
- remaining
- )
- .. " is not stored or craftable in AE2."
- )
- warned[
- warningKey
- ] = true
- end
- end
- -- ============================================================
- -- PROCESS ALL ACTIVE DO VARIANTS
- -- ============================================================
- local function processStaging()
- for _, variant
- in pairs(staged) do
- for materialName,
- materialState
- in pairs(
- variant.materials
- ) do
- local ok, err =
- pcall(
- stageMaterial,
- variant,
- materialName,
- materialState
- )
- if not ok then
- print(
- "[ERROR] "
- .. materialName
- .. ": "
- .. tostring(err)
- )
- end
- end
- end
- end
- -- ============================================================
- -- STARTUP DISPLAY
- -- ============================================================
- term.clear()
- term.setCursorPos(
- 1,
- 1
- )
- print(
- "========================================"
- )
- print(
- " ARCHITECT MATERIAL STAGER v3"
- )
- print(
- "========================================"
- )
- print("")
- print(
- "Colony: "
- .. colonyName
- )
- print(
- "ME Bridge: "
- .. mePeripheralName
- )
- print(
- "Custom Name: "
- .. tostring(
- meCustomName
- )
- )
- print(
- "Output Side: UP"
- )
- print("")
- print(
- "Scanning all Builder Huts dynamically."
- )
- print(
- "Builder + Hut DO demand is merged per Hut."
- )
- print(
- "Demand from separate Builders is added."
- )
- print(
- "Finished DO stock in AE2 is checked first."
- )
- print("")
- print(
- "Press Ctrl+T to stop."
- )
- print("")
- -- ============================================================
- -- MAIN LOOP
- -- ============================================================
- local lastBuilderCount = nil
- while true do
- local ok,
- demand,
- huts =
- pcall(
- collectAllDemand
- )
- if not ok then
- print(
- "[ERROR] "
- .. tostring(demand)
- )
- else
- if lastBuilderCount
- ~= #huts then
- print(
- "[SCAN] Builder Huts: "
- .. tostring(
- #huts
- )
- )
- for index, hut
- in ipairs(huts) do
- local name =
- hut.builder
- and hut.builder.name
- or "Unassigned Builder"
- print(
- " "
- .. tostring(index)
- .. ". "
- .. name
- .. " @ "
- .. posKey(
- hut.pos
- )
- )
- end
- lastBuilderCount =
- #huts
- end
- syncStagingState(
- demand
- )
- processStaging()
- end
- sleep(
- POLL_INTERVAL
- )
- end
Add Comment
Please, Sign In to add comment