Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- AE2Warehouse.lua
- -- Version 1.8.5
- -- Author: Modified by AshGrey
- -- Date: 2024-10-16
- -------------------------------------------------------------------------------
- -- INITIALIZATION
- -------------------------------------------------------------------------------
- local aeBridge = peripheral.find("meBridge")
- if not aeBridge then error("AE2 Bridge not found.") end
- print("AE2 Bridge initialized.")
- local colony = peripheral.find("colonyIntegrator")
- if not colony then error("Colony Integrator not found.") end
- if not colony.isInColony() then error("Colony Integrator is not in a colony.") end
- print("Colony Integrator initialized.")
- local modem = peripheral.wrap("left") -- Adjust for your setup
- if not modem then error("Ender Modem not found.") end
- print("Ender Modem initialized.")
- local storage = "up"
- print("Storage initialized.")
- -------------------------------------------------------------------------------
- -- FUNCTIONS
- -------------------------------------------------------------------------------
- -- Function to transmit updated logs to the wireless monitor
- function transmitToMonitor(logData)
- modem.transmit(1, 1, logData) -- Send data on channel 1
- end
- -- Function to build the missing items log
- function buildLogMessage(missingItems)
- local logLines = {"Missing Items:"}
- for itemName, count in pairs(missingItems) do
- table.insert(logLines, itemName .. ": " .. count)
- end
- return table.concat(logLines, "\n") -- Combine lines with newlines
- end
- -- Handle export requests and log missing items
- function exportOrLogMissing(itemName, needed, provided, missingItems)
- local toCraft = needed - provided
- if toCraft > 0 then
- missingItems[itemName] = (missingItems[itemName] or 0) + toCraft
- end
- end
- -- Main function to process builder requests
- function handleBuilderRequests()
- local requests = colony.getRequests() or {}
- local missingItems = {}
- for _, req in ipairs(requests) do
- if req and req.items and req.items[1] then
- local itemName = req.items[1].name
- local needed = req.count or 0
- print("Processing request:", itemName, "x", needed)
- local provided = exportItem(itemName, needed)
- exportOrLogMissing(itemName, needed, provided, missingItems)
- end
- end
- -- Send the updated log to the monitor
- local logMessage = buildLogMessage(missingItems)
- transmitToMonitor(logMessage)
- end
- -- Export item from AE2 network
- function exportItem(name, count)
- local itemData = { name = name, count = count }
- local success, err = aeBridge.exportItem(itemData, storage)
- if success then
- print("Exported:", name, "x", count)
- return count
- else
- print("Failed to export:", name, "| Error:", err)
- return 0
- end
- end
- -------------------------------------------------------------------------------
- -- MAIN LOOP
- -------------------------------------------------------------------------------
- print("Starting AE2 Warehouse and Builder Monitor...")
- while true do
- local time = os.time()
- if time >= 6 and time < 18 then
- handleBuilderRequests()
- else
- print("Nighttime detected. Pausing...")
- end
- sleep(30)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement