Advertisement
TheYellowBush

ae2_menu.lua

Jul 8th, 2025 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.30 KB | None | 0 0
  1. -- AE2 Stockpile Manager - Menu System Module
  2.  
  3. local menu = {}
  4.  
  5. -- Helper function for formatted printing
  6. local function printf(format, ...)
  7.     print(string.format(format, ...))
  8. end
  9.  
  10. -- Clear screen and show header
  11. local function showHeader(testMode, hasMonitor)
  12.     term.clear()
  13.     term.setCursorPos(1, 1)
  14.     print("=== AE2 Stockpile Manager ===")
  15.     if testMode then
  16.         print("*** RUNNING IN TEST MODE ***")
  17.     end
  18.     if hasMonitor then
  19.         print("Monitor: Connected")
  20.     end
  21.     print()
  22. end
  23.  
  24. -- Show main menu
  25. function menu.showMainMenu(testMode, hasMonitor)
  26.     showHeader(testMode, hasMonitor)
  27.     print("1. View Current Settings")
  28.     print("2. Add/Edit Item Configuration")
  29.     print("3. Remove Item Configuration")
  30.     print("4. Start Monitoring")
  31.     print("5. Test Crafting Request")
  32.     print("6. View AE2 System Status")
  33.     print("7. Toggle Test Mode (" .. (testMode and "ON" or "OFF") .. ")")
  34.     print("8. Exit")
  35.     print()
  36.     write("Select option: ")
  37.     return read()
  38. end
  39.  
  40. -- Show current settings
  41. function menu.viewSettings(settings)
  42.     term.clear()
  43.     term.setCursorPos(1, 1)
  44.     print("=== Current Item Configurations ===")
  45.     print()
  46.    
  47.     if #settings == 0 then
  48.         print("No items configured")
  49.     else
  50.         print("Item Name                    Target    Threshold")
  51.         print("----------------------------------------")
  52.         for i, config in pairs(settings) do
  53.             local name = config.item:gsub("minecraft:", "")
  54.             printf("%-28s %-9d %d", name, config.target, config.threshold)
  55.         end
  56.     end
  57.    
  58.     print()
  59.     print("Press any key to continue...")
  60.     os.pullEvent("key")
  61. end
  62.  
  63. -- Add or edit item configuration
  64. function menu.addEditItem(config, ae2, display, currentCraftingJobs, running)
  65.     term.clear()
  66.     term.setCursorPos(1, 1)
  67.     print("=== Add/Edit Item Configuration ===")
  68.     print()
  69.     print("Examples: iron_ingot, gold_ingot, diamond, redstone")
  70.     print("Tip: You can omit 'minecraft:' prefix")
  71.     print()
  72.    
  73.     write("Item name: ")
  74.     local itemName = read()
  75.    
  76.     if itemName == "" then
  77.         print("Invalid item name")
  78.         os.sleep(2)
  79.         return
  80.     end
  81.    
  82.     -- Auto-add minecraft: prefix if not present
  83.     if not itemName:find(":") then
  84.         itemName = "minecraft:" .. itemName
  85.     end
  86.    
  87.     -- Check if item exists in AE2 system
  88.     local item = ae2.findItem(itemName, false)
  89.     if not item and not config.isTestMode() then
  90.         print("WARNING: Item not found in AE2 system")
  91.         write("Continue anyway? (y/n): ")
  92.         local confirm = read()
  93.         if confirm:lower() ~= "y" then
  94.             return
  95.         end
  96.     end
  97.    
  98.     -- Check if item is craftable
  99.     local craftableItem = ae2.findItem(itemName, true)
  100.     if not craftableItem and not config.isTestMode() then
  101.         print("WARNING: Item is not craftable in AE2 system")
  102.         write("Continue anyway? (y/n): ")
  103.         local confirm = read()
  104.         if confirm:lower() ~= "y" then
  105.             return
  106.         end
  107.     end
  108.    
  109.     write("Target quantity: ")
  110.     local target = tonumber(read())
  111.     if not target or target <= 0 then
  112.         print("Invalid target quantity")
  113.         os.sleep(2)
  114.         return
  115.     end
  116.    
  117.     write("Threshold (craft when below): ")
  118.     local threshold = tonumber(read())
  119.     if not threshold or threshold <= 0 or threshold >= target then
  120.         print("Invalid threshold (must be positive and less than target)")
  121.         os.sleep(2)
  122.         return
  123.     end
  124.    
  125.     -- Add the item configuration
  126.     if config.addItem(itemName, target, threshold) then
  127.         print("Configuration saved!")
  128.         local quantities = ae2.getCurrentQuantities()
  129.         local systemStatus = ae2.isConnected() and (config.isTestMode() and "test" or "online") or "offline"
  130.         display.update(config.getSettings(), currentCraftingJobs, running, quantities, systemStatus)
  131.     else
  132.         print("Failed to save configuration!")
  133.     end
  134.    
  135.     os.sleep(2)
  136. end
  137.  
  138. -- Remove item configuration
  139. function menu.removeItem(config, ae2, display, currentCraftingJobs, running)
  140.     term.clear()
  141.     term.setCursorPos(1, 1)
  142.     print("=== Remove Item Configuration ===")
  143.     print()
  144.    
  145.     local settings = config.getSettings()
  146.    
  147.     if #settings == 0 then
  148.         print("No items configured")
  149.         os.sleep(2)
  150.         return
  151.     end
  152.    
  153.     print("Configured Items:")
  154.     for i, itemConfig in pairs(settings) do
  155.         print(i .. ". " .. itemConfig.item)
  156.     end
  157.    
  158.     print()
  159.     write("Enter number to remove (0 to cancel): ")
  160.     local choice = tonumber(read())
  161.    
  162.     if choice and choice > 0 and choice <= #settings then
  163.         local removed = config.removeItem(choice)
  164.         if removed then
  165.             print("Removed: " .. removed.item)
  166.             local quantities = ae2.getCurrentQuantities()
  167.             display.update(config.getSettings(), currentCraftingJobs, running, quantities)
  168.         else
  169.             print("Failed to remove item")
  170.         end
  171.         os.sleep(2)
  172.     end
  173. end
  174.  
  175. -- Show AE2 system status
  176. function menu.viewSystemStatus(ae2, hasMonitor)
  177.     term.clear()
  178.     term.setCursorPos(1, 1)
  179.     print("=== AE2 System Status ===")
  180.     print()
  181.    
  182.     local systemInfo = ae2.getSystemInfo()
  183.    
  184.     print("Connection Type: " .. systemInfo.type)
  185.     if systemInfo.connected then
  186.         print("System connected and operational")
  187.         print()
  188.         print("Available Items: " .. systemInfo.itemCount)
  189.        
  190.         if systemInfo.itemCount > 0 then
  191.             print("Sample items:")
  192.             local count = 0
  193.             for name, amount in pairs(systemInfo.quantities) do
  194.                 if count < 5 then
  195.                     local displayName = name:gsub("minecraft:", "")
  196.                     printf("  %-20s: %d", displayName, amount)
  197.                     count = count + 1
  198.                 end
  199.             end
  200.             if systemInfo.itemCount > 5 then
  201.                 print("  ... and " .. (systemInfo.itemCount - 5) .. " more items")
  202.             end
  203.         end
  204.        
  205.         print()
  206.         print("Craftable Items: " .. systemInfo.craftableCount)
  207.         if systemInfo.craftableCount > 0 then
  208.             print("Sample craftable items:")
  209.             local count = 0
  210.             for name, item in pairs(systemInfo.craftable) do
  211.                 if count < 3 then
  212.                     local displayName = name:gsub("minecraft:", "")
  213.                     print("  " .. displayName)
  214.                     count = count + 1
  215.                 end
  216.             end
  217.             if systemInfo.craftableCount > 3 then
  218.                 print("  ... and " .. (systemInfo.craftableCount - 3) .. " more")
  219.             end
  220.         end
  221.     else
  222.         print("No connection established")
  223.         print()
  224.         print("To get full AE2 integration:")
  225.         print("1. Install Advanced Peripherals mod")
  226.         print("2. Craft and place an ME Bridge")
  227.         print("3. Connect ME Bridge to your ME system")
  228.     end
  229.    
  230.     print()
  231.     if hasMonitor then
  232.         print("Monitor: Connected and displaying real-time status")
  233.     else
  234.         print("Monitor: Not connected (optional)")
  235.     end
  236.    
  237.     print()
  238.     print("Press any key to continue...")
  239.     os.pullEvent("key")
  240. end
  241.  
  242. return menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement