Guest User

AIO

a guest
Jul 11th, 2014
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.33 KB | None | 0 0
  1. -- ComputerCraft/OpenPeripherals Base Monitoring Program for MC 1.6.4
  2. -- Thanks: Fogger, @EsperNet: #OpenMods, #computercraft @Freenode: #lua
  3.  
  4. -- The color palette. You can add more.
  5. local palette = {["white"] = 1, ["orange"] = 2, ["magenta"] = 4, ["lightBlue"] = 8, ["yellow"] = 16,
  6. ["lime"] = 32, ["pink"] = 64, ["gray"] = 128, ["lightGray"] = 256, ["cyan"] = 512, ["purple"] = 1024,
  7. ["blue"] = 2048, ["brown"] = 4096, ["green"] = 8192, ["red"] = 16384, ["black"] = 32768}
  8.  
  9. -- *** CONFIG SECTION **
  10. -- MONITORS (the only required config change)
  11. local left = "monitor_22" -- first main display monitor
  12. local right = "monitor_23" -- second main display monitor
  13. local aux_1 = "monitor_5" -- auxiliary monitor for total power/capacity reading
  14. -- VARIOUS
  15. local activeMsg, inactiveMsg, pendingMsg = "USING", "INACT", "PENDI"
  16. local textSize = 1 -- increments of 0.5
  17. local isGPS = true -- should we look for and display a nearby GPS?
  18. -- MACHINE and PERIPHERAL NAMES --
  19. -- Use the same # of characters for each so that formatting is aligned
  20. local name_comp = "CMPRESR" -- compressor
  21. local name_furnace = "FURNACE" -- electric furnace
  22. local name_ext = "EXTRCTR" -- extractor
  23. local name_mace = "MACERTR" -- macerator
  24. local name_washer = "ORWASHR" -- ore washer
  25. local name_centrifuge = "THR_CTR" -- thermal centrifuge
  26. local name_former = "MTL_FRM" -- metal former
  27. local name_recycler = "RECYCLR" -- recycler
  28. local name_canning = "CAN_MCN" -- canning machine
  29. -- Name these whatever you wish, but it may not fit or alter alignment of other items
  30. local name_mfsu = "MFSU"
  31. -- COLORS
  32. local hc = palette.lightBlue -- default heading color
  33. local tc = palette.white -- default text color
  34. local color_reading = palette.lime -- power readings for example
  35. local color_inactive = palette.gray -- inactive reading for machines
  36. local color_active = palette.red -- active reading for machines
  37. local color_machines = palette.orange -- machine names
  38. local color_ores = palette.pink -- ore name color
  39. -- TEXT POSITIONS
  40. local pwrX_Reading = 20 -- X pos to display power readings
  41. local machineDisplayXPos = 6 -- X pos to start displaying machines
  42. local offsetPos = 2 -- left margin offset for text
  43. local mStatusPos = 11
  44. local orePos = 18
  45. -- SPECIAL CHARACTERS
  46. local separator = " | "
  47. local spacer = " : "
  48. -----------------------------------------------
  49.  
  50. local pversion = "1.3.5.1b"
  51.  
  52. local waitTime = {9,13}
  53. local timer = {0,0,0,0,0,0,0,0,0,0,0}
  54. local supported_Power = {"mfsu","cesu","mfe","batbox"}
  55. local supported_Machines = {"macerator","furnace","orewashing","thermalcentrifuge", "extractor",
  56. "compressor", "canning", "recycler", "metalformer"}
  57. local sleepAmt = 0.2
  58. local numFormat = 1 -- don't use it (yet) for multiple formatting types
  59. -- MACHINE SLOTS --
  60. local ic2ItemUsed = 7 -- input slot for most ic2 machines
  61. local ic2ItemCreated = 2 -- output slot for most ic2 machines
  62. local oreWashItemUsed = 9 -- input slot for orewasher
  63. local thermCentrItemUsed = 9 -- input slot for thermal centrifuge
  64.  
  65. -- Load API ---
  66. if fs.exists("marik") then shell.run("rm marik") end
  67. print("Updating API...")
  68. shell.run("pastebin get Th8tne6p marik")
  69. os.loadAPI("marik")
  70. ---------------
  71.  
  72. term.clear()
  73. print("Base Monitoring Program v" .. pversion)
  74. print("Starting...")
  75.  
  76. machines = peripheral.getNames() -- load a list of peripherals into a table
  77. table.sort(machines) -- so it displays in non-random manner
  78.  
  79. n,count = marik.numOfMachines()
  80. print("Total peripherals detected: " .. count)
  81. print("Power storage devices: " .. n)
  82. print("Checking peripheral connections...")
  83.  
  84. -- Monitors
  85. local mon = peripheral.wrap(left)
  86. local mon2 = peripheral.wrap(right)
  87. mon.clear()
  88. mon2.clear()
  89. mon.setTextScale(textSize)
  90. mon2.setTextScale(textSize)
  91.  
  92. -- MONITOR 1 x,y Positions
  93. local machinesInfoCol = 6 -- machines info HEADING
  94. local GPS_x = 25 -- right side GPS info
  95. local GPS_y = 58
  96.  
  97. -- MONITOR 2 x,y Positions
  98. local tankPosStart = 1 -- to replace the rest of these
  99.  
  100. -- MONITOR 1 - Write lines that won't be cleared
  101. marik.cString(offsetPos, 1, hc, left, "-- Main Power --")
  102. marik.cString(offsetPos, machinesInfoCol, hc, left, "-- Machines Info --")
  103.  
  104. -- MONITOR 2 - Write lines that won't be cleared
  105. marik.cString(offsetPos, 1, hc, right, "-- RailCraft Tank Information --")
  106.  
  107. function dispAE()
  108.  
  109.     -- AE TERMINAL (not working yet)
  110.     mon2.setTextColor(tc)
  111.     mon2.setCursorPos(offsetPos,aeCraftCol)
  112.    
  113.     beingCrafted = aeController.getJobList()
  114.     if beingCrafted.name ~= nil then
  115.         timer[1] = os.clock()
  116.         mon2.clearLine()
  117.         mon2.write("Currently Crafting: " .. beingCrafted.name)
  118.     elseif beingCrafted.name == nil then
  119.             mon2.clearLine()
  120.             mon2.write("Currently Crafting: Nothing")
  121.     else
  122.             mon2.clearLine()
  123.             mon2.write("Currently Crafting: Unknown")
  124.     end
  125. end
  126.  
  127. function pFormat(pName)
  128. -- Renames peripherals for formatting purposes
  129.  
  130.     if string.find(pName, "compressor") then
  131.         pName = name_comp
  132.     elseif string.find(pName, "electric_furnace") then
  133.         pName = name_furnace
  134.     elseif string.find(pName, "extractor") then
  135.         pName = name_ext
  136.     elseif string.find(pName, "macerator") then
  137.         pName = name_mace
  138.     elseif string.find(pName, "orewashing") then
  139.         pName = name_washer
  140.     elseif string.find(pName, "thermalcentrifuge") then
  141.         pName = name_centrifuge
  142.     elseif string.find(pName, "canning") then
  143.         pName = name_canning
  144.     elseif string.find(pName, "recycler") then
  145.         pName = name_recycler
  146.     elseif string.find(pName, "former") then
  147.         pName = name_former
  148.     elseif string.find(pName, "mfsu") then
  149.         pName = name_mfsu
  150.     end
  151. return pName
  152. end
  153.  
  154. function firstToUpper(str)
  155.     return (str:gsub("^%l", string.upper))
  156. end
  157.  
  158.  
  159. function dispTanks()
  160. mon.setCursorPos(offsetPos, 1)
  161. mon2.setCursorPos(offsetPos,1)
  162.  
  163.     for i=2, #machines do
  164.     -- RC Tanks --------------------------------------------
  165.         if string.find(machines[i], "rcirontankvalvetile")
  166.             or string.find(machines[i], "rcsteeltankvalvetile") then                       
  167.            
  168.             if peripheral.isPresent(machines[i]) then
  169.                 periph = peripheral.wrap(machines[i])
  170.  
  171.                 fluidRaw, fluidName, fluidAmount, fluidCapacity, fluidID = marik.getTank(periph)                           
  172.            
  173.                 if fluidName == nil then
  174.                     mon2.setTextColor(tc)
  175.                     x,y = mon2.getCursorPos()
  176.                     mon2.setCursorPos(offsetPos, (y+2))
  177.                     mon2.clearLine()
  178.                     mon2.write("Empty Tank")                   
  179.                 elseif fluidName ~= nil then
  180.                     mon2.setTextColor(tc)
  181.                     x,y = mon2.getCursorPos()
  182.                     mon2.setCursorPos(offsetPos, (y+2))
  183.                     mon2.clearLine()
  184.                     marik.cString(offsetPos,(y+1), tc, right, ",")
  185.                     nameFL = firstToUpper(marik.comma(fluidName):match("[^.]*"))
  186.                     mon2.write("Tank (" .. nameFL .. ") :  " .. marik.getBuckets(fluidAmount) .. " buckets")
  187.                 end
  188.             end
  189.         end
  190.     end
  191. end
  192.  
  193. function dispPower()
  194.  
  195.     for i=1, #machines do
  196.   -- IC2 Power -------------------------------------------
  197.     for s=1, #supported_Power do
  198.         if string.find(machines[i], supported_Power[s]) then
  199.  
  200.             periph = peripheral.wrap(machines[i])              
  201.             local storedEU = periph.getEUStored()
  202.             local capacity = periph.getEUCapacity()
  203.  
  204.                 -- modify these later for multiple storage peripherals
  205.                 local totalStorage = storedEU
  206.                 local totalCapacity = capacity
  207.  
  208.                 marik.appendString(left, tc, "Total EU       " .. separator, true, offsetPos, 2)
  209.                 marik.appendString(left, color_reading, (marik.comma(totalStorage)), false, pwrX_Reading, 2)
  210.                
  211.                 marik.appendString(left, tc, "Total Capacity " .. separator, true, offsetPos, 3)
  212.                 marik.appendString(left, color_reading, (marik.comma(totalCapacity)), false, pwrX_Reading, 3)
  213.  
  214.                 marik.appendString(left, tc, pFormat(machines[i]) .. " Storage   " .. separator, true, offsetPos, 4)
  215.                 marik.appendString(left, color_reading, (marik.comma(storedEU)), false, pwrX_Reading, 4)
  216.  
  217.             end
  218.         end
  219.     end
  220. end
  221.  
  222.  
  223. function dispIC2()
  224.  
  225. machineDispStart = machineDisplayXPos -- screen start positon
  226.    
  227.     for i=1, #machines do
  228.     -- IC2 Machines -----------------------------------------
  229.         local m
  230.         for m=1, #supported_Machines do
  231.             -- check if the machine is a supported machine
  232.             if string.find(machines[i], supported_Machines[m]) then
  233.            
  234.                 -- check if the peripheral is connected
  235.                 -- if peripheral.isPresent(machines[i]) then
  236.                     periph = peripheral.wrap(machines[i])
  237.  
  238.                         -- determine what slot to use for the machines' input                              
  239.                         if string.find(machines[i], "thermalcentrifuge") then itemStackUsed = periph.getStackInSlot(thermCentrItemUsed)
  240.                         elseif string.find(machines[i], "orewashing") then itemStackUsed = periph.getStackInSlot(oreWashItemUsed)
  241.                         else itemStackUsed = periph.getStackInSlot(ic2ItemUsed)
  242.                         end
  243.                        
  244.                         machineDispStart = machineDispStart + 1 -- move this down?
  245.  
  246.                         -- if there's something in the input slot
  247.                         if itemStackUsed ~= nil then
  248.                             itemName = marik.itemRename(itemStackUsed.name)
  249.                             timer[2] = os.clock()
  250.                        
  251.                             -- display machine, active message and itemName
  252.                             marik.appendString(left, color_ores, itemName, true, orePos, machineDispStart) -- append the itemName
  253.                             str = (pFormat(peripheral.getType(machines[i])))
  254.                             marik.appendString(left, tc, str, false, offsetPos, machineDispStart) -- append the [      ] that contains the itemName
  255.                             marik.appendString(left, color_active, activeMsg, false, 11, machineDispStart) -- append the activeMsg                         
  256.  
  257.                         -- if there is nothing in the input slot
  258.                         elseif itemStackUsed == nil then       
  259.                             if os.clock() - timer[2] > waitTime[1] then -- clear the message only if it has been waitTime[1] seconds
  260.                                
  261.                                 --display machine and inactive message
  262.                                 marik.appendString(left, color_inactive, inactiveMsg, true, mStatusPos, machineDispStart) -- append INACTIVE
  263.                                 str = (pFormat(peripheral.getType(machines[i])))
  264.                                 marik.appendString(left, tc, str, false, offsetPos, machineDispStart) -- append the [      ] that contains the itemName
  265.                                
  266.                             end
  267.            
  268.                         else
  269.                             -- marik.appendString(left, color_active, "***TEST CASE***", false, offsetPos, machineDispStart)
  270.                     end
  271.                 -- end
  272.             end
  273.         end
  274.     end
  275. end
  276.  
  277.  
  278. -- Loop Start
  279. while true do
  280.  
  281. mon.setTextColor(tc)
  282. if marik.GPSinfo() then
  283.     mon.setCursorPos(GPS_y, GPS_x)
  284.     mon.write("GPS: Online")
  285. else
  286.     mon.setCursorPos(GPS_y, GPS_x)
  287.     mon.write("GPS: Offline")
  288. end
  289.  
  290. dispTanks()
  291. dispPower()
  292. dispIC2()
  293.  
  294. sleep(sleepAmt)
  295.  
  296. end
Advertisement
Add Comment
Please, Sign In to add comment