Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- AE2 Stockpile Manager - Menu System Module
- local menu = {}
- -- Helper function for formatted printing
- local function printf(format, ...)
- print(string.format(format, ...))
- end
- -- Clear screen and show header
- local function showHeader(testMode, hasMonitor)
- term.clear()
- term.setCursorPos(1, 1)
- print("=== AE2 Stockpile Manager ===")
- if testMode then
- print("*** RUNNING IN TEST MODE ***")
- end
- if hasMonitor then
- print("Monitor: Connected")
- end
- print()
- end
- -- Show main menu
- function menu.showMainMenu(testMode, hasMonitor)
- showHeader(testMode, hasMonitor)
- print("1. View Current Settings")
- print("2. Add/Edit Item Configuration")
- print("3. Remove Item Configuration")
- print("4. Start Monitoring")
- print("5. Test Crafting Request")
- print("6. View AE2 System Status")
- print("7. Toggle Test Mode (" .. (testMode and "ON" or "OFF") .. ")")
- print("8. Exit")
- print()
- write("Select option: ")
- return read()
- end
- -- Show current settings
- function menu.viewSettings(settings)
- term.clear()
- term.setCursorPos(1, 1)
- print("=== Current Item Configurations ===")
- print()
- if #settings == 0 then
- print("No items configured")
- else
- print("Item Name Target Threshold")
- print("----------------------------------------")
- for i, config in pairs(settings) do
- local name = config.item:gsub("minecraft:", "")
- printf("%-28s %-9d %d", name, config.target, config.threshold)
- end
- end
- print()
- print("Press any key to continue...")
- os.pullEvent("key")
- end
- -- Add or edit item configuration
- function menu.addEditItem(config, ae2, display, currentCraftingJobs, running)
- term.clear()
- term.setCursorPos(1, 1)
- print("=== Add/Edit Item Configuration ===")
- print()
- print("Examples: iron_ingot, gold_ingot, diamond, redstone")
- print("Tip: You can omit 'minecraft:' prefix")
- print()
- write("Item name: ")
- local itemName = read()
- if itemName == "" then
- print("Invalid item name")
- os.sleep(2)
- return
- end
- -- Auto-add minecraft: prefix if not present
- if not itemName:find(":") then
- itemName = "minecraft:" .. itemName
- end
- -- Check if item exists in AE2 system
- local item = ae2.findItem(itemName, false)
- if not item and not config.isTestMode() then
- print("WARNING: Item not found in AE2 system")
- write("Continue anyway? (y/n): ")
- local confirm = read()
- if confirm:lower() ~= "y" then
- return
- end
- end
- -- Check if item is craftable
- local craftableItem = ae2.findItem(itemName, true)
- if not craftableItem and not config.isTestMode() then
- print("WARNING: Item is not craftable in AE2 system")
- write("Continue anyway? (y/n): ")
- local confirm = read()
- if confirm:lower() ~= "y" then
- return
- end
- end
- write("Target quantity: ")
- local target = tonumber(read())
- if not target or target <= 0 then
- print("Invalid target quantity")
- os.sleep(2)
- return
- end
- write("Threshold (craft when below): ")
- local threshold = tonumber(read())
- if not threshold or threshold <= 0 or threshold >= target then
- print("Invalid threshold (must be positive and less than target)")
- os.sleep(2)
- return
- end
- -- Add the item configuration
- if config.addItem(itemName, target, threshold) then
- print("Configuration saved!")
- local quantities = ae2.getCurrentQuantities()
- local systemStatus = ae2.isConnected() and (config.isTestMode() and "test" or "online") or "offline"
- display.update(config.getSettings(), currentCraftingJobs, running, quantities, systemStatus)
- else
- print("Failed to save configuration!")
- end
- os.sleep(2)
- end
- -- Remove item configuration
- function menu.removeItem(config, ae2, display, currentCraftingJobs, running)
- term.clear()
- term.setCursorPos(1, 1)
- print("=== Remove Item Configuration ===")
- print()
- local settings = config.getSettings()
- if #settings == 0 then
- print("No items configured")
- os.sleep(2)
- return
- end
- print("Configured Items:")
- for i, itemConfig in pairs(settings) do
- print(i .. ". " .. itemConfig.item)
- end
- print()
- write("Enter number to remove (0 to cancel): ")
- local choice = tonumber(read())
- if choice and choice > 0 and choice <= #settings then
- local removed = config.removeItem(choice)
- if removed then
- print("Removed: " .. removed.item)
- local quantities = ae2.getCurrentQuantities()
- display.update(config.getSettings(), currentCraftingJobs, running, quantities)
- else
- print("Failed to remove item")
- end
- os.sleep(2)
- end
- end
- -- Show AE2 system status
- function menu.viewSystemStatus(ae2, hasMonitor)
- term.clear()
- term.setCursorPos(1, 1)
- print("=== AE2 System Status ===")
- print()
- local systemInfo = ae2.getSystemInfo()
- print("Connection Type: " .. systemInfo.type)
- if systemInfo.connected then
- print("System connected and operational")
- print()
- print("Available Items: " .. systemInfo.itemCount)
- if systemInfo.itemCount > 0 then
- print("Sample items:")
- local count = 0
- for name, amount in pairs(systemInfo.quantities) do
- if count < 5 then
- local displayName = name:gsub("minecraft:", "")
- printf(" %-20s: %d", displayName, amount)
- count = count + 1
- end
- end
- if systemInfo.itemCount > 5 then
- print(" ... and " .. (systemInfo.itemCount - 5) .. " more items")
- end
- end
- print()
- print("Craftable Items: " .. systemInfo.craftableCount)
- if systemInfo.craftableCount > 0 then
- print("Sample craftable items:")
- local count = 0
- for name, item in pairs(systemInfo.craftable) do
- if count < 3 then
- local displayName = name:gsub("minecraft:", "")
- print(" " .. displayName)
- count = count + 1
- end
- end
- if systemInfo.craftableCount > 3 then
- print(" ... and " .. (systemInfo.craftableCount - 3) .. " more")
- end
- end
- else
- print("No connection established")
- print()
- print("To get full AE2 integration:")
- print("1. Install Advanced Peripherals mod")
- print("2. Craft and place an ME Bridge")
- print("3. Connect ME Bridge to your ME system")
- end
- print()
- if hasMonitor then
- print("Monitor: Connected and displaying real-time status")
- else
- print("Monitor: Not connected (optional)")
- end
- print()
- print("Press any key to continue...")
- os.pullEvent("key")
- end
- return menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement