Advertisement
PlowmanPlow

ComputerCraft - ME Network Status

Apr 26th, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.35 KB | None | 0 0
  1. local statusChannelID = 5
  2.  
  3. -- Find Modem
  4. local modem = nil
  5. for sideId, side in ipairs(redstone.getSides()) do
  6.    if peripheral.getType(side) ~= nil then print(side .. ": " .. peripheral.getType(side)) end
  7.    if peripheral.getType(side) == "modem" then
  8.       modem = peripheral.wrap(side);
  9.    end
  10. end
  11. if modem == nil then
  12.    error("Could not bind to modem. Is one attached?")
  13. end
  14. --if true then return end
  15.  
  16. -- Find ME Network Block
  17. local me = nil
  18. for sideId, side in ipairs(redstone.getSides()) do
  19.    local ptype = peripheral.getType(side)
  20.    if ptype == "tileinterface" or ptype == "tilecontroller" or ptype == "aemultipart" then
  21.       me = peripheral.wrap(side);
  22.    end
  23. end
  24. if me == nil then
  25.    error("Could not bind to ME Interface. Is one attached?")
  26. end
  27.  
  28. term.clear()
  29. term.setCursorPos(1,1)
  30. print("ME Status Monitor...")
  31. print()
  32. print("Press 'q' to quit")
  33.  
  34. local status = {}
  35. local energyUsage = me.getAvgPowerUsage()
  36. local pollTimer = os.startTimer(0)
  37. while true do
  38.    local event, p1, p2, p3, p4 = os.pullEvent()
  39.    if event == "key" then
  40.       if p1 == keys.q then
  41.          term.setCursorPos(1,11)
  42.          return
  43.       end
  44.    elseif event == "timer" and p1 == pollTimer then
  45.       local items = me.getAvailableItems()
  46.       local inv = {}
  47.       inv["Au"] = 0
  48.       inv["Fe"] = 0
  49.       inv["Cu"] = 0
  50.       inv["Sn"] = 0
  51.       inv["Ag"] = 0
  52.       inv["Pb"] = 0
  53.       inv["Sh"] = 0
  54.       inv["Bz"] = 0
  55.       inv["El"] = 0
  56.       inv["Sg"] = 0
  57.       inv["En"] = 0
  58.       inv["Al"] = 0
  59.       inv["RI"] = 0
  60.       inv["EA"] = 0
  61.       inv["VA"] = 0
  62.       inv["Ye"] = 0
  63.       for i, val in ipairs(items) do
  64.          if val.fingerprint.id == "minecraft:gold_ingot" then
  65.             inv["Au"] = val.size
  66.          elseif val.fingerprint.id == "minecraft:iron_ingot" then
  67.             inv["Fe"] = val.size
  68.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 64 then
  69.             inv["Cu"] = val.size
  70.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 65 then
  71.             inv["Sn"] = val.size
  72.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 66 then
  73.             inv["Ag"] = val.size
  74.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 67 then
  75.             inv["Pb"] = val.size
  76.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 69 then
  77.             inv["Sh"] = val.size
  78.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 73 then
  79.             inv["Bz"] = val.size
  80.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 71 then
  81.             inv["El"] = val.size
  82.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 74 then
  83.             inv["Sg"] = val.size
  84.          elseif val.fingerprint.id == "ThermalFoundation:material" and val.fingerprint.dmg == 76 then
  85.             inv["En"] = val.size
  86.          elseif val.fingerprint.id == "TConstruct:materials" and val.fingerprint.dmg == 11 then
  87.             inv["Al"] = val.size
  88.          elseif val.fingerprint.id == "IC2:itemIngot" and val.fingerprint.dmg == 3 then
  89.             inv["RI"] = val.size
  90.          elseif val.fingerprint.id == "EnderIO:itemAlloy" and val.fingerprint.dmg == 1 then
  91.             inv["EA"] = val.size
  92.          elseif val.fingerprint.id == "EnderIO:itemAlloy" and val.fingerprint.dmg == 2 then
  93.             inv["VA"] = val.size
  94.          elseif val.fingerprint.id == "BigReactors:BRIngot" and val.fingerprint.dmg == 0 then
  95.             inv["Ye"] = val.size
  96.          end
  97.       end
  98.       local data = textutils.serialize(inv)
  99.       energyUsage = me.getAvgPowerUsage()
  100.       status["ME Network Pwr"] = math.floor(energyUsage * 2) .. " RF/t"
  101.       local craftingCPUs = me.getCraftingCPUs()
  102.       status["ME Crafting CPUs"] = #craftingCPUs
  103.       local busyCPUCount = 0
  104.       for cpuId, cpu in ipairs(craftingCPUs) do
  105.          for key, val in pairs(cpu) do
  106.             if key == "busy" and val == true then busyCPUCount = busyCPUCount + 1 end
  107.          end
  108.       end
  109.       status["ME Crafting CPUs Busy"] = busyCPUCount
  110.       status["Inventory"] = inv
  111.       modem.transmit(statusChannelID, 0, textutils.serialize(status))
  112.       pollTimer = os.startTimer(5)
  113.    end
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement