Advertisement
Marikc0

[DEV] ComputerCraft OpenPeripherals Base Monitoring

Nov 9th, 2013
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.66 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. term.clear()
  5.  
  6. -- LOAD APIs -------------------------------------------
  7. print("Updating and Loading APIs...")
  8. if fs.exists("marik") then
  9.     shell.run("rm marik")
  10. end
  11.     shell.run("pastebin get sZ13tEft marik")
  12.     os.unloadAPI("marik")
  13.     os.loadAPI("marik")
  14.  
  15. if not fs.exists("config") then
  16.     print("Config does not exist. Use -newcfg")
  17. else
  18.     os.unloadAPI("config")
  19.     os.loadAPI("config")
  20. end
  21. --------------------------------------------------------
  22.  
  23. local palette = {["white"] = 1, ["orange"] = 2, ["magenta"] = 4, ["lightBlue"] = 8, ["yellow"] = 16,
  24. ["lime"] = 32, ["pink"] = 64, ["gray"] = 128, ["lightGray"] = 256, ["cyan"] = 512, ["purple"] = 1024,
  25. ["blue"] = 2048, ["brown"] = 4096, ["green"] = 8192, ["red"] = 16384, ["black"] = 32768}
  26. -- MONITORS
  27. left = config.left
  28. right = config.right
  29. aux1 = config.aux1
  30. -- VARIOUS
  31. local activeMsg, inactiveMsg, pendingMsg = "USING", "INACT", "PENDN"
  32. local textSize = 1 -- increments of 0.5
  33. isGPS = false
  34. -- MACHINE and PERIPHERAL NAMES --
  35. -- Use the same # of characters for each so that formatting is aligned
  36. name_comp = "CMPRESR" -- compressor
  37. name_furnace = "FURNACE" -- electric furnace
  38. name_ext = "EXTRCTR" -- extractor
  39. name_mace = "MACERTR" -- macerator
  40. name_washer = "ORWASHR" -- ore washer
  41. name_centrifuge = "THR_CTR" -- thermal centrifuge
  42. name_former = "MTL_FRM" -- metal former
  43. name_recycler = "RECYCLR" -- recycler
  44. name_canning = "CAN_MCN" -- canning machine
  45. -- OTHER Machine Names
  46. name_mfsu = "MFSU"
  47. name_batbox = "BTBX"
  48. -- COLORS
  49. local hc = palette.lightBlue -- default heading color
  50. local tc = palette.white -- default text color
  51. local color_reading = palette.lime -- power readings for example
  52. local color_inactive = palette.gray -- inactive reading for machines
  53. local color_active = palette.red -- active reading for machines
  54. local color_machines = palette.orange -- machine names
  55. local color_ores = palette.pink -- ore name color
  56. -- TEXT POSITIONS
  57. local pos_PwrReading = 20 -- pos to display power readings
  58. local pos_Machines = 7 -- pos to display machine heading
  59. local pos_MachineDisplay = 8 -- pos to start displaying machine activity
  60. local offsetPos = 2 -- left margin offset for text
  61. local pos_mStatus = 11 -- machine status
  62. local pos_Ore = 18 -- machine input item position
  63. local pos_TankStart = 1 -- RC tank position start
  64. local GPS_x = 25
  65. local GPS_y = 58
  66. local devicePos = 3 -- starting position of EU storage devices
  67. -- SPECIAL CHARACTERS
  68. local separator = " | "
  69. local spacer = " : "
  70. -------------------------------------------------------------------------
  71.  
  72. local waitTime = {9,13}
  73. local timer = {0,0,0,0,0,0,0,0,0,0,0}
  74. local supported_Power = {"mfsu","cesu","mfe","batbox"}
  75. local supported_Machines = {"macerator","furnace","orewashing","thermalcentrifuge", "extractor",
  76. "compressor", "canning", "recycler", "metalformer"}
  77. local sleepAmt = 0.2
  78. local ic2ItemUsed = 7 -- input slot for most ic2 machines
  79. local ic2ItemCreated = 2 -- output slot for most ic2 machines
  80. local oreWashItemUsed = 9 -- input slot for orewasher
  81. local thermCentrItemUsed = 9 -- input slot for thermal centrifuge
  82.  
  83. machines = marik.pLoad()
  84.  
  85. -- Monitors
  86. local mon = peripheral.wrap(left)
  87. local mon2 = peripheral.wrap(right)
  88. mon.clear()
  89. mon2.clear()
  90. mon.setTextScale(textSize)
  91. mon2.setTextScale(textSize)
  92.  
  93. function pFormat(pName)
  94. -- Renames peripherals for formatting purposes
  95.  
  96.     if string.find(pName, "compressor") then
  97.         pName = name_comp
  98.     elseif string.find(pName, "electric_furnace") then
  99.         pName = name_furnace
  100.     elseif string.find(pName, "extractor") then
  101.         pName = name_ext
  102.     elseif string.find(pName, "macerator") then
  103.         pName = name_mace
  104.     elseif string.find(pName, "orewashing") then
  105.         pName = name_washer
  106.     elseif string.find(pName, "thermalcentrifuge") then
  107.         pName = name_centrifuge
  108.     elseif string.find(pName, "canning") then
  109.         pName = name_canning
  110.     elseif string.find(pName, "recycler") then
  111.         pName = name_recycler
  112.     elseif string.find(pName, "former") then
  113.         pName = name_former
  114.     elseif string.find(pName, "mfsu") then
  115.         pName = name_mfsu
  116.     elseif string.find(pName, "batbox") then
  117.         pName = name_batbox
  118.     end
  119.  
  120. return pName
  121. end
  122.  
  123. function dispAE()
  124.  
  125.     -- AE TERMINAL (not working yet)
  126.     mon2.setTextColor(tc)
  127.     mon2.setCursorPos(offsetPos,aeCraftCol)
  128.    
  129.     beingCrafted = aeController.getJobList()
  130.     if beingCrafted.name ~= nil then
  131.         timer[1] = os.clock()
  132.         mon2.clearLine()
  133.         mon2.write("Currently Crafting: " .. beingCrafted.name)
  134.     elseif beingCrafted.name == nil then
  135.             mon2.clearLine()
  136.             mon2.write("Currently Crafting: Nothing")
  137.     else
  138.             mon2.clearLine()
  139.             mon2.write("Currently Crafting: Unknown")
  140.     end
  141. end
  142.  
  143. function dispTanks()
  144. mon.setCursorPos(offsetPos, 1)
  145. mon2.setCursorPos(offsetPos,1)
  146.  
  147.     for i=1, #machines do
  148.     -- RC Tanks --------------------------------------------
  149.         if string.find(machines[i], "rcirontankvalvetile")
  150.             or string.find(machines[i], "rcsteeltankvalvetile") then                       
  151.            
  152.             if peripheral.isPresent(machines[i]) then
  153.                 periph = peripheral.wrap(machines[i])
  154.            
  155.                 fluidRaw, fluidName, fluidAmount, fluidCapacity, fluidID = marik.getTank(periph)                           
  156.            
  157.                 if fluidName == nil then
  158.                 -- does not display empty tanks
  159.                 elseif fluidName ~= nil then
  160.                     mon2.setTextColor(tc)
  161.                     x,y = mon2.getCursorPos()
  162.                     mon2.setCursorPos(offsetPos, (y+1))
  163.                     mon2.clearLine()
  164.             -- marik.cString(offsetPos,(y+1), tc, right, " ")
  165.             mon2.write("Tank (" .. marik.comma(fluidName) .. ") : " .. marik.comma(fluidAmount) .. " / " .. marik.comma(fluidCapacity) .. " mb (" .. marik.getBuckets(fluidAmount) .. " buckets)")
  166.         end
  167.         end
  168.     end
  169.     end
  170. end
  171.  
  172. function dispPower()
  173.  
  174. local storedEU
  175. local capacity
  176. local totalStorage = 0
  177. local totalCapacity = 0
  178. local s
  179. local i
  180. pos_Power = devicePos
  181.  
  182.     for i=1, #machines do
  183.   -- IC2 Power -------------------------------------------
  184.     for s=1, #supported_Power do
  185.         if string.find(machines[i], supported_Power[s]) then
  186.  
  187.             periph = peripheral.wrap(machines[i])              
  188.             storedEU = periph.getEUStored()
  189.             capacity = periph.getEUCapacity()
  190.            
  191.             pos_Power = pos_Power + 1 -- everytime we find a power storage unit we display it 1 column lower
  192.  
  193.                 -- modify these later for multiple storage peripherals
  194.                 totalStorage = totalStorage + storedEU
  195.                 totalCapacity = totalCapacity + capacity
  196.  
  197.                 marik.appendString(left, tc, "EU Current     " .. separator, true, offsetPos, 2)
  198.                 marik.appendString(left, color_reading, (marik.comma(totalStorage)), false, pos_PwrReading, 2)
  199.                
  200.                 marik.appendString(left, tc, "EU Capacity    " .. separator, true, offsetPos, 3)
  201.                 marik.appendString(left, color_reading, (marik.comma(totalCapacity)), false, pos_PwrReading, 3)
  202.  
  203.                 -- to do: setup to display multiple power devices (also need to push the machine list down for each one)
  204.                 marik.appendString(left, tc, pFormat(machines[i]) .. " EU Stored " .. separator, true, offsetPos, (pos_Power))
  205.                 marik.appendString(left, color_reading, (marik.comma(storedEU)), false, pos_PwrReading, (pos_Power))
  206.  
  207.             end
  208.         end
  209.     end
  210. end
  211.  
  212. function dispIC2()
  213.  
  214. machineDispStart = pos_Power + 1 -- start machine display below the power display
  215. machines = marik.pLoad()
  216.    
  217.     for i=1, #machines do
  218.     -- IC2 Machines -----------------------------------------
  219.         local m
  220.         for m=1, #supported_Machines do
  221.             -- check if the machine is a supported machine
  222.             if string.find(machines[i], supported_Machines[m]) then
  223.                 -- check if the peripheral is connected
  224.                 -- if peripheral.isPresent(machines[i]) then
  225.                 periph = peripheral.wrap(machines[i])
  226.  
  227.                 -- determine what slot to use for the machines' input                              
  228.                 if string.find(machines[i], "thermalcentrifuge") then itemStackUsed = periph.getStackInSlot(thermCentrItemUsed)
  229.                 elseif string.find(machines[i], "orewashing") then itemStackUsed = periph.getStackInSlot(oreWashItemUsed)
  230.                 else itemStackUsed = periph.getStackInSlot(ic2ItemUsed)
  231.                 end
  232.                        
  233.                     -- if there's something in the input slot
  234.                     -- bug here.. displays only a few machines now if some are inactive
  235.                     if itemStackUsed ~= nil then
  236.                         itemName = marik.itemRename(itemStackUsed.name)
  237.                         timer[2] = os.clock()
  238.                    
  239.                         -- display machine, active message and itemName
  240.                         machineDispStart = machineDispStart + 1
  241.                        
  242.                         marik.appendString(left, color_ores, itemName, true, pos_Ore, machineDispStart) -- append the itemName
  243.                         str = (pFormat(peripheral.getType(machines[i])))
  244.                         marik.appendString(left, tc, str, false, offsetPos, machineDispStart) -- append the machine name to the beginning
  245.                         marik.appendString(left, color_active, activeMsg, false, pos_mStatus, machineDispStart) -- append ACTIVE                           
  246.  
  247.                     -- if there is nothing in the input slot
  248.                     elseif itemStackUsed == nil then
  249.                         if os.clock() - timer[2] > waitTime[1] then
  250.                        
  251.                             --display machine and inactive message
  252.                             machineDispStart = machineDispStart + 1
  253.                            
  254.                             marik.appendString(left, color_inactive, inactiveMsg, true, pos_mStatus, machineDispStart) -- append INACTIVE
  255.                             str = (pFormat(peripheral.getType(machines[i])))
  256.                             marik.appendString(left, tc, str, false, offsetPos, machineDispStart) -- append the machine name to the beginning
  257.                                
  258.                         end
  259.                     end
  260.             end
  261.         end
  262.     end
  263. end
  264. -- Loop Start
  265. while true do
  266.  
  267. mon.setTextColor(tc)
  268. if marik.GPSinfo() then
  269.     mon.setCursorPos(GPS_y, GPS_x)
  270.     mon.write("GPS: Online")
  271. else
  272.     mon.setCursorPos(GPS_y, GPS_x)
  273.     mon.write("GPS: Offline")
  274. end
  275.  
  276. machines = marik.pLoad()
  277.  
  278. dispTanks()
  279. dispPower()
  280. dispIC2()
  281.  
  282. sleep(sleepAmt)
  283.  
  284. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement