Advertisement
RandomShovel

[CC][Beta] Tank Monitor

Mar 17th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.31 KB | None | 0 0
  1. --[[  Config  ]]--
  2.  
  3. endertank = true
  4. -- If enabled, you must place it adjacent to the computer
  5. -- This is due to a wired modem not attaching to it
  6.  
  7. local debug_mode = false
  8.  
  9. local side = "top"
  10. -- Location of the wired modem
  11.  
  12. --[[  END OF CONFIG  ]]--
  13.  
  14.  
  15. --[[ DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING! ]]--
  16.  
  17. local net = peripheral.wrap(side)
  18.  
  19. --[[  Colour Matrix  ]]--
  20.  
  21. -- Currently contains all liquids from 1.6.4 Direwolf20 pack
  22. -- Yes this is a giant block of table!
  23. -- Hex-code colors are vanilla minecraft's colors
  24.  
  25. local liquidColors = {
  26. -- FORMAT: {rawName, color, display name, hex-code}
  27.  [1]={"Water", colors.blue, "Water", 0x2E388D},
  28.  [2]={"Lava", colors.orange, "Lava", 0xDB7D3E},
  29.  [3]={"Milk", colors.white, "Milk", 0xDDDDDD},
  30.  [4]={"Oil", colors.black, "Oil", 0x191616},
  31.  [5]={"Fuel", colors.yellow, "Fuel", 0xB1A627},
  32.  [6]={"Creosote Oil", colors.yellow, "Creosote", 0xB1A627},
  33.  [7]={"Acid", colors.lime, "Acid", 0x41AE38},
  34.  [8]={"Poison", colors.magenta, "Poison", 0xB350BC},
  35.  [9]={"Liquid Nitrogen", colors.lightBlue, "Nitrogen", 0x6B8AC9},
  36.  [10]={"Sap", colors.brown, "Sap", 0x4F321F},
  37.  [11]={"Resin", colors.brown, "Resin", 0x4F321F},
  38.  [12]={"Latex", colors.lightGray, "Latex", 0x9AA1A1},
  39.  [13]={"Turpentine", colors.brown, "Turpentine", 0x4F321F},
  40.  [14]={"Sewage", colors.brown, "Sewage", 0x4F321F},
  41.  [15]={"Sludge", colors.blue, "Sludge", 0x2E388D},
  42.  [16]={"Mob Essence", colors.green, "Mob Essence", 0x35461B},
  43.  [17]={"Biofuel", colors.purple, "Biofuel", 0x7E3DB5},
  44.  [18]={"Meat", colors.pink, "Meat", 0xD08499},
  45.  [19]={"Pink Slime", colors.pink, "Pink Slime", 0xD08499},
  46.  [20]={"Chocolate Milk", colors.brown, "Chocolate Milk", 0x4F321F},
  47.  [21]={"Mushroom Soup", colors.pink, "Mushroom Soup", 0xD08499},
  48.  [22]={"Molten Iron", colors.red, "Molten Iron", 0x963430},
  49.  [23]={"Molten Gold", colors.yellow, "Molten Gold", 0xB1A627},
  50.  [24]={"Molten Copper", colors.brown, "Molten Copper", 0x4F321F},
  51.  [25]={"Molten Tin", colors.white, "Molten Tin", 0xDDDDDD},
  52.  [26]={"Molten Aluminum", colors.pink, "Molten Aluminum", 0xD08499},
  53.  [27]={"Molten Cobalt", colors.blue, "Molten Cobalt", 0x2E388D},
  54.  [28]={"Molten Ardite", colors.brown, "Molten Ardite", 0x4F321F},
  55.  [29]={"Molten Bronze", colors.brown, "Molten Bronze", 0x4F321F},
  56.  [30]={"Molten Aluminum Brass", colors.yellow, "Molten Aluminum Brass", 0xB1A627},
  57.  [31]={"Molten Manyullyn", colors.purple, "Molten Manyullyn", 0x7E3DB5},
  58.  [32]={"Molten Alumite", colors.pink, "Molten Alumite", 0xD08499},
  59.  [33]={"Molten Obsidian", colors.black, "Molten Obsidian", 0x191616},
  60.  [34]={"Molten Steel", colors.gray, "Molten Steel", 0x404040},
  61.  [35]={"Molten Glass", colors.lightBlue, "Molten Glass", 0x6B8AC9},
  62.  [36]={"Seared Stone", colors.gray, "Seared Stone", 0x404040},
  63.  [37]={"Liquified Emerald", colors.lime, "Liquified Emerald", 0x41AE38},
  64.  [38]={"Blood", colors.red, "Blood", 0x963430},
  65.  [39]={"Molten Nickel", colors.yellow, "Molten Nickel", 0xB1A627},
  66.  [40]={"Molten Lead", colors.purple, "Molten Lead", 0x7E3DB5},
  67.  [41]={"Molten Silver", colors.lightBlue, "Molten Silver", 0x6B8AC9},
  68.  [42]={"fluid.platinum.molten", colors.lightBlue, "Molten Shiny", 0x6B8AC9},
  69.  [43]={"Molten Invar", colors.gray, "Molten Invar", 0x404040},
  70.  [44]={"Molten Electrum", colors.yellow, "Molten Electrum", 0xB1A627},
  71.  [45]={"Resonant Ender", colors.cyan, "Resonant Ender", 0x2E6E89},
  72.  [46]={"Liquid Blueslime", colors.lightBlue, "Liquid Slime", 0x6B8AC9},
  73.  [47]={"Liquid XP", colors.lime, "Liquid XP", 0x41AE38},
  74.  [48]={"Destabilized Redstone", colors.red, "Destabilized Redstone", 0x963430},
  75.  [49]={"Energized Glowstone", colors.yellow, "Energized Glowstone", 0xB1A627},
  76.  [50]={"Blazing Pyrotheum", colors.orange, "Blazing Pyrotheum", 0xDB7D3E},
  77.  [51]={"Gelid Cryotheum", colors.lightBlue, "Gelid Cryotheum", 0x6B8AC9},
  78.  [52]={"Liquifacted Coal", colors.black, "Liquifacted Coal", 0x191616},
  79.  [53]={"Spring Water", colors.lightBlue, "Spring Water", 0x6B8AC9},
  80.  [54]={"fluid.liquidEssence", colors.lightBlue, "Liquid Essence", 0x6B8AC9},
  81.  [55]={"Ethanol", colors.orange, "Ethanol", 0xDB7D3E},
  82.  [56]={"Biomass", colors.lime, "Biomass", 0x41AE38},
  83.  [57]={"Black Ink", colors.black, "Ink", 0x191616},
  84.  [58]={"Crushed Ice", colors.lightBlue, "Crushed Ice", 0x6B8AC9},
  85.  [59]={"Glue", colors.white, "Glue", 0xDDDDDD},
  86.  [60]={"Honey", colors.yellow, "Honey", 0xB1A627}
  87. }
  88.  
  89. local foundTanks = {}
  90. local enderTanks = {}
  91.  
  92.  
  93. --[[  Functions  ]]--
  94.  
  95. --[[  Tank Monitor API  ]]--
  96.  
  97. function enderCheck()
  98.  if endertank then
  99.   local sides = rs.getSides()
  100.   for i=1, #sides do
  101.    local currSide = peripheral.getType(sides[i])
  102.    if currSide == "ender_tank" then
  103.     table.insert(enderTanks, sides[i])
  104.    end
  105.   end
  106.  end
  107. end
  108.  
  109. function cs()
  110.  term.clear()
  111.  term.setCursorPos(1, 1)
  112. end
  113.  
  114. function findTerminal()
  115.  cs()
  116.  local sides = rs.getSides()
  117.  for i=1, #sides do
  118.   local currSide = tostring(peripheral.getType(sides[i]))
  119.   if string.find(currSide, "openperipheral_glassesbridge") then
  120.    fbridge = peripheral.wrap(sides[i])
  121.    print("Terminal mode active!")
  122.    print("I found an OpenPeripheral Glasses Bridge.")
  123.    break
  124.   end
  125.  end
  126. end
  127.  
  128. function debugArray()
  129.  local listing = 1
  130.  for tl=1, #liquidColors do
  131.    local cx, cy = term.getCursorPos()
  132.    local mx, my = term.getSize()
  133.    if listing < 10 then
  134.     write(" "..listing..") ")
  135.    elseif listing >= 10 then
  136.     write(listing..") ")
  137.    end
  138.    term.setCursorPos(mx/mx+6, cy)
  139.    write(liquidColors[tl][3])
  140.    term.setCursorPos(mx/mx+30, cy)
  141.    write(liquidColors[tl][4])
  142.    local pos = string.len(listing.."/") + 2
  143.    term.setCursorPos( mx-pos , cy )
  144.    print(listing.."/"..#liquidColors)
  145.    sleep(1)
  146.    local listing = listing + 1
  147.  end
  148. end
  149.  
  150. function findTanks()
  151.  local connectedPers = peripheral.getNames()
  152.  for i=1, #connectedPers do
  153.   if string.find(connectedPers[i], "tank") then
  154.    table.insert(foundTanks, connectedPers[i])
  155.   end
  156.  end
  157.  
  158.  if debug_mode then
  159.   print("")
  160.   for i=1, #foundTanks do
  161.    print(foundTanks[i])
  162.    sleep(0.1)
  163.   end
  164.   print("")
  165.  end
  166. end
  167.  
  168. function checkTanks()
  169.  if debug_mode then
  170.   -- Checks the array for the liquid in the tank
  171.   -- This is used for debugging
  172.   for a=1, #foundTanks do
  173.    for b=1, #liquidColors do
  174.     local tankDat = net.callRemote(foundTanks[a], "getTankInfo", "unknown")[1]
  175.     if string.lower(tankDat["rawName"]) == string.lower(liquidColors[b][1]) then
  176.      term.setTextColor(liquidColors[b][2])
  177.      print(liquidColors[b][3])
  178.      term.setTextColor(colors.white)
  179.      sleep(0.1)
  180.     end
  181.    end
  182.   end
  183.  
  184.   enderCheck()
  185.   if endertank then
  186.    for a=1, #enderTanks do
  187.     for b=1, #liquidColors do
  188.      local currEtank = peripheral.wrap(enderTanks[a])
  189.      local eTankDat = currEtank.getTankInfo("unknown")[1]
  190.      if string.lower(eTankDat["rawName"]) == string.lower(liquidColors[b][1]) then
  191.       term.setTextColor(liquidColors[b][2])
  192.       print("Ender: "..liquidColors[b][3])
  193.       term.setTextColor(colors.white)
  194.       sleep(0.1)
  195.      end
  196.     end
  197.    end
  198.   end
  199.  end
  200. end
  201.  
  202. function addTanks()
  203.  for a=1, #foundTanks do
  204.   for b=1, #liquidColors do
  205.    local currTank = net.callRemote(foundTanks[a], "getTankInfo", "unknown")[1]
  206.    if string.lower(currTank["rawName"]) == string.lower(liquidColors[b][1]) then
  207.     if liquidColors[b][5] and liquidColors[b][6] then
  208.      local currCap = liquidColors[b][5]
  209.      local currAm = liquidColors[b][6]
  210.      liquidColors[b][5] = currTank["capacity"] + currCap
  211.      liquidColors[b][6] = currTank["amount"] + currAm
  212.     else
  213.      liquidColors[b][5] = currTank["capacity"]
  214.      liquidColors[b][6] = currTank["amount"]
  215.     end
  216.    end
  217.   end
  218.  end
  219.    
  220.  for a=1, #enderTanks do
  221.   for b=1, #liquidColors do
  222.    local currEtank = peripheral.wrap(enderTanks[a])
  223.    local eTankDat = currEtank.getTankInfo("unknown")[1]
  224.    if string.lower(eTankDat["rawName"]) == string.lower(liquidColors[b][1]) then
  225.     if liquidColors[b][5] and liquidColors[b][6] then
  226.      local currECap = liquidColors[b][5]
  227.      local currEAm = liquidColors[b][6]
  228.      liquidColors[b][5] = eTankDat["capacity"] + currECap
  229.      liquidColors[b][6] = eTankDat["amount"] + currEAm
  230.     else
  231.      liquidColors[b][5] = eTankDat["capacity"]
  232.      liquidColors[b][6] = eTankDat["amount"]
  233.     end
  234.    end
  235.   end
  236.  end
  237.  
  238.  if debug_mode then
  239.   print("")
  240.   for a=1, #liquidColors do
  241.    if liquidColors[a][5] and liquidColors[a][6] then
  242.     term.setTextColor(liquidColors[a][2])
  243.     write(liquidColors[a][3]..": ")
  244.     write(formNum(liquidColors[a][6]).." / ")
  245.     print(formNum(liquidColors[a][5]))
  246.    end
  247.    sleep(0.1)
  248.   end
  249.  end
  250. end
  251.  
  252. function formNum(input)
  253.  local input2 = string.gsub(input, "(%d)(%d%d%d)$", "%1,%2", 1)
  254.  while true do
  255.   local input2, found = string.gsub(input2, "(%d)(%d%d%d),", "%1,%2,", 1)
  256.   if found == 0 then
  257.    return input2
  258.   end
  259.  end
  260. end
  261.  
  262. function bar()
  263.  local event, command = os.pullEvent("chat_command")
  264.  for a=1, #liquidColors do
  265.   if string.lower(command) == string.lower(liquidColors[a][3]) then
  266.    fbridge.clear()
  267.    x, y = 2, 2
  268.    local barBack = fbridge.addGradientBox(x, y, 102, 12, 0x666666, 0.5, 0x999999, 0.5, 1)
  269.    local currLiquid = liquidColors[a][3]..": "..liquidColors[a][6].." / "..liquidColors[a][5]
  270.    local barText = fbridge.addText(x, y+14, currLiquid, liquidColors[a][4])
  271.    barBack.setZ(0)
  272.    break
  273.   elseif a == #liquidColors then
  274.    if liqBar then
  275.     fbridge.clear()
  276.    end
  277.    local guiError = fbridge.addText(2, 2, "Invalid Liquid!", 0x963430)
  278.   end
  279.  end
  280.  return command
  281. end
  282.  
  283. function updateBar(command)
  284.  local errorActive = false
  285.  for a=1, #liquidColors do
  286.   if string.lower(command) == string.lower(liquidColors[a][3]) then
  287.    errorActive = false
  288.    break
  289.   else
  290.    errorActive = true
  291.   end
  292.  end
  293.  if not errorActive then
  294.   for a=1, #liquidColors do
  295.    if string.lower(command) == string.lower(liquidColors[a][3]) then
  296.     liqBar = fbridge.addGradientBox(x+1, y+1, 0, 10, 0x000000, 0.5, liquidColors[a][4], 0.7, 1)
  297.     liqBar.setZ(1)
  298.     break
  299.    end
  300.   end
  301.  end
  302.  for a=1, #liquidColors do
  303.   if string.lower(command) == string.lower(liquidColors[a][3]) then
  304.    liquidRatio = liquidColors[a][6] / liquidColors[a][5]
  305.    break
  306.   end
  307.  end
  308.  local liquidWidth = liquidRatio * 100
  309.  if not errorActive then
  310.   liqBar.setWidth(liquidWidth)
  311.  end
  312. end
  313.  
  314.  
  315. --[[  Main  ]]--
  316.  
  317. findTerminal()
  318. findTanks()
  319. checkTanks()
  320. addTanks()
  321.  
  322. while true do
  323.  local uCommand = bar()
  324.  updateBar(uCommand)
  325. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement