Advertisement
JackGrey

AE2xMineColoniesXCC 2.0 (WIP do not use)

Oct 16th, 2024 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. -- AE2Warehouse.lua
  2. -- Version 1.8.5
  3. -- Author: Modified by AshGrey
  4. -- Date: 2024-10-16
  5.  
  6. -------------------------------------------------------------------------------
  7. -- INITIALIZATION
  8. -------------------------------------------------------------------------------
  9.  
  10. local aeBridge = peripheral.find("meBridge")
  11. if not aeBridge then error("AE2 Bridge not found.") end
  12. print("AE2 Bridge initialized.")
  13.  
  14. local colony = peripheral.find("colonyIntegrator")
  15. if not colony then error("Colony Integrator not found.") end
  16. if not colony.isInColony() then error("Colony Integrator is not in a colony.") end
  17. print("Colony Integrator initialized.")
  18.  
  19. local modem = peripheral.wrap("left") -- Adjust for your setup
  20. if not modem then error("Ender Modem not found.") end
  21. print("Ender Modem initialized.")
  22.  
  23. local storage = "up"
  24. print("Storage initialized.")
  25.  
  26. -------------------------------------------------------------------------------
  27. -- FUNCTIONS
  28. -------------------------------------------------------------------------------
  29.  
  30. -- Function to transmit updated logs to the wireless monitor
  31. function transmitToMonitor(logData)
  32. modem.transmit(1, 1, logData) -- Send data on channel 1
  33. end
  34.  
  35. -- Function to build the missing items log
  36. function buildLogMessage(missingItems)
  37. local logLines = {"Missing Items:"}
  38. for itemName, count in pairs(missingItems) do
  39. table.insert(logLines, itemName .. ": " .. count)
  40. end
  41. return table.concat(logLines, "\n") -- Combine lines with newlines
  42. end
  43.  
  44. -- Handle export requests and log missing items
  45. function exportOrLogMissing(itemName, needed, provided, missingItems)
  46. local toCraft = needed - provided
  47. if toCraft > 0 then
  48. missingItems[itemName] = (missingItems[itemName] or 0) + toCraft
  49. end
  50. end
  51.  
  52. -- Main function to process builder requests
  53. function handleBuilderRequests()
  54. local requests = colony.getRequests() or {}
  55. local missingItems = {}
  56.  
  57. for _, req in ipairs(requests) do
  58. if req and req.items and req.items[1] then
  59. local itemName = req.items[1].name
  60. local needed = req.count or 0
  61. print("Processing request:", itemName, "x", needed)
  62.  
  63. local provided = exportItem(itemName, needed)
  64. exportOrLogMissing(itemName, needed, provided, missingItems)
  65. end
  66. end
  67.  
  68. -- Send the updated log to the monitor
  69. local logMessage = buildLogMessage(missingItems)
  70. transmitToMonitor(logMessage)
  71. end
  72.  
  73. -- Export item from AE2 network
  74. function exportItem(name, count)
  75. local itemData = { name = name, count = count }
  76. local success, err = aeBridge.exportItem(itemData, storage)
  77. if success then
  78. print("Exported:", name, "x", count)
  79. return count
  80. else
  81. print("Failed to export:", name, "| Error:", err)
  82. return 0
  83. end
  84. end
  85.  
  86. -------------------------------------------------------------------------------
  87. -- MAIN LOOP
  88. -------------------------------------------------------------------------------
  89.  
  90. print("Starting AE2 Warehouse and Builder Monitor...")
  91.  
  92. while true do
  93. local time = os.time()
  94. if time >= 6 and time < 18 then
  95. handleBuilderRequests()
  96. else
  97. print("Nighttime detected. Pausing...")
  98. end
  99. sleep(30)
  100. end
  101.  
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement