Advertisement
Impshial

Tekkit Single Machine Monitor

Jul 25th, 2021 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.69 KB | None | 0 0
  1. -- Get all peripherals on the network
  2. local line
  3. local machineName
  4. local isActive = ""
  5. local machine
  6. local mainLoop
  7. local monX
  8. local monY
  9. local itemInSlot1
  10. local ps = {}
  11. local energy
  12. local energyMax
  13. local titleColor
  14.  
  15. -- Write startup message to Terminal
  16. term.clear()
  17.  
  18. -- Check to see if the API file exists
  19. if fs.exists("ImpAPI") == false then
  20.     term.setCursorPos(1,1)
  21.     term.setTextColor(colors.red)
  22.     term.write("Missing API File! Attempting to download...")
  23.     term.setTextColor(colors.white)
  24.     shell.run("pastebin get pwBMKNCb ImpAPI")   -- Go out and download it
  25.     sInput = nil
  26.     term.setCursorPos(1,5)
  27.     term.setTextColor(colors.green)
  28.     term.write("API Loaded.")
  29.     term.setCursorPos(1,7)
  30.     term.setTextColor(colors.white)
  31.     term.write("Press enter to continue...")
  32.     while true do
  33.        sInput = read()
  34.        if sInput ~= nil or sInput ~= "" then
  35.              break
  36.              
  37.        end
  38.     end
  39. end
  40.  
  41. os.loadAPI("ImpAPI")
  42.  
  43. machines=peripheral.getNames()
  44.  
  45. line = 1
  46.  
  47.  mon=ImpAPI.monitorSearch()
  48.  
  49.  function writeEnergy(line1, line2)
  50.     ImpAPI.CWrite(1, line1, mon, "Energy: ", colors.yellow)
  51.     ImpAPI.CWrite(3, line2, mon, energy.."/"..energyMax, colors.white)
  52.  end
  53.  
  54.  if mon then        -- Found it
  55.     ImpAPI.CTWrite(1,6,"Monitor Found!",colors.green)
  56.     ImpAPI.CTWrite(1,8,"System Running",colors.orange)
  57.    
  58. else            -- No monitor Present
  59.     ImpAPI.CTWrite(1,6,"Monitor Not Found!",colors.red)
  60.     ImpAPI.CTWrite(1,8,"Please Attach a Monitor",colors.red)
  61.     term.setCursorPos(1,9)
  62.     return
  63. end
  64.  
  65. mon.clear()
  66.  
  67. mon.setTextScale(0.5)
  68.  
  69. monX, monY = mon.getSize()
  70.  
  71. mainLoop = 1
  72.  
  73.  
  74.  
  75. while mainLoop > 0 do  
  76.    
  77.     for i = 1, #machines do
  78.  
  79.         if string.match(machines[i], "slaughter") then
  80.             machine=peripheral.wrap(machines[i])
  81.             machineName = "Slaughterhouse"
  82.             tankInfo = machine.getTankInfo("unknown")
  83.             titleColor = colors.brown
  84.             if machine.getEnergy() > 0 then
  85.                 isActive = true
  86.             else
  87.                 isActive = false
  88.             end
  89.         elseif string.match(machines[i], "grinder") then
  90.             machine=peripheral.wrap(machines[i])
  91.             machineName = "Grinder"
  92.             tankInfo = machine.getTankInfo("unknown")
  93.             titleColor = colors.green
  94.             if machine.getEnergy() > 0 then
  95.                 isActive = true
  96.             else
  97.                 isActive = false
  98.             end
  99.         elseif string.match(machines[i], "furnace") then
  100.             machine=peripheral.wrap(machines[i])
  101.             machineName = "Redstone Furnace"
  102.             titleColor = colors.gray
  103.             if machine.getStackInSlot(1) then
  104.                 isActive = true
  105.             else
  106.                 isActive = false
  107.             end
  108.         elseif string.match(machines[i], "sawmill") then
  109.             machine=peripheral.wrap(machines[i])
  110.             machineName = "Sawmill"
  111.             titleColor = colors.brown  
  112.             if machine.getStackInSlot(1) then
  113.                 isActive = true
  114.             else
  115.                 isActive = false
  116.             end
  117.         elseif string.match(machines[i], "pulverizer") then
  118.             machine=peripheral.wrap(machines[i])
  119.             machineName = "Pulverizer"
  120.             titleColor = colors.orange
  121.             if machine.getStackInSlot(1) then
  122.                 isActive = true
  123.             else
  124.                 isActive = false
  125.             end
  126.         elseif string.match(machines[i], "transposer") then
  127.             machine=peripheral.wrap(machines[i])
  128.             machineName = "Transposer"
  129.             tankInfo = machine.getTankInfo("unknown")  
  130.             titleColor = colors.blue
  131.             if machine.getStackInSlot(1) then
  132.                 isActive = true
  133.             else
  134.                 isActive = false
  135.             end
  136.         elseif string.match(machines[i], "crucible") then
  137.             machine=peripheral.wrap(machines[i])
  138.             machineName = "Crucible"
  139.             tankInfo = machine.getTankInfo("unknown")
  140.             titleColor = colors.gray
  141.             if machine.getStackInSlot(1) then
  142.                 isActive = true
  143.             else
  144.                 isActive = false
  145.             end
  146.         elseif string.match(machines[i], "harvester") then
  147.             machine=peripheral.wrap(machines[i])
  148.             machineName = "Harvester"
  149.             tankInfo = machine.getTankInfo("unknown")
  150.             titleColor = colors.yellow
  151.             if machine.getEnergy() > 0 then
  152.                 isActive = true
  153.             else
  154.                 isActive = false
  155.             end
  156.         elseif string.match(machines[i], "planter") then
  157.             machine=peripheral.wrap(machines[i])
  158.             machineName = "Planter"
  159.             titleColor = colors.yellow
  160.             if machine.getEnergy() > 0 then
  161.                 isActive = true
  162.             else
  163.                 isActive = false
  164.             end
  165.         elseif string.match(machines[i], "smelter") then
  166.             machine=peripheral.wrap(machines[i])
  167.             machineName = "Induction Smelter"
  168.             titleColor = colors.blue
  169.             if (machine.getStackInSlot(1)) and (machine.getStackInSlot(2)) then
  170.                 isActive = true
  171.             else
  172.                 isActive = false
  173.             end
  174.         end
  175.        
  176.         if machine then
  177.             energy = machine.getEnergy()
  178.             energyMax = machine.getMaxEnergy()
  179.            
  180.             monX, monY = mon.getSize()
  181.             centerPos = math.floor((monX - #machineName) / 2) + 1
  182.    
  183.             if isActive then
  184.                 ImpAPI.draw_line(1, 1, monX, titleColor, mon)
  185.             else
  186.                 ImpAPI.draw_line(1, 1, monX, colors.red, mon)
  187.             end
  188.             ImpAPI.CWrite(centerPos, 1, mon, machineName, colors.white)
  189.             ImpAPI.draw_line(1, 2, monX, colors.black, mon)
  190.        
  191.             if machineName == "Slaughterhouse" then
  192.                            
  193.                 psCap = 0
  194.                 psAmt = 0
  195.                 meatCap = 0
  196.                 meatAmt = 0
  197.                
  198.                 for k,v in pairs(tankInfo) do
  199.                     for o,c in pairs(v) do
  200.                         if c == "pinkslime" then
  201.                             for a,b in pairs(v) do
  202.                                 if a == "amount" then
  203.                                     psAmt = b
  204.                                 end
  205.                                
  206.                                 if a == "capacity" then
  207.                                     psCap = b
  208.                                 end
  209.                             end
  210.                         end
  211.                        
  212.                         if c == "meat" then
  213.                             for a,b in pairs(v) do
  214.                                 if a == "amount" then
  215.                                     meatAmt = b
  216.                                 end
  217.                                
  218.                                 if a == "capacity" then
  219.                                     meatCap = b
  220.                                 end
  221.                             end
  222.                         end
  223.                        
  224.                     end
  225.                 end
  226.                
  227.                 ImpAPI.CWrite(1, 3, mon, "Pink Slime: ", colors.pink)
  228.                 ImpAPI.CWrite(3, 4, mon, psAmt.."/"..psCap, colors.white)
  229.                
  230.                 ImpAPI.CWrite(1, 6, mon, "Liquid Meat: ", colors.orange)
  231.                 ImpAPI.CWrite(3, 7, mon, meatAmt.."/"..meatCap, colors.white)
  232.                
  233.                 writeEnergy(9,10)
  234.                
  235.             elseif machineName == "Grinder" then
  236.                                                    
  237.                 essCap = 0
  238.                 essAmt = 0
  239.                            
  240.                 for k,v in pairs(tankInfo) do
  241.                     for o,c in pairs(v) do
  242.                         if c == "mobessence" then
  243.                             for a,b in pairs(v) do
  244.                                 if a == "amount" then
  245.                                     essAmtAmt = b
  246.                                 end
  247.                                
  248.                                 if a == "capacity" then
  249.                                     essAmtCap = b
  250.                                 end
  251.                             end
  252.                         end
  253.                        
  254.                     end
  255.            
  256.                 end
  257.            
  258.                 ImpAPI.CWrite(1, 3, mon, "Mob Essence: ", colors.green)
  259.                 ImpAPI.CWrite(3, 4, mon, essAmt.."/"..essCap, colors.white)
  260.                
  261.                 writeEnergy(6,7)
  262.                
  263.             elseif machineName == "Pulverizer" then
  264.                 itemInSlot1 = ""
  265.                 itemQtyInSlot1 = 0
  266.                
  267.                 processing=machine.getStackInSlot(1)
  268.                
  269.                 if processing then
  270.                     for k,v in pairs(processing) do
  271.                         if k == "name" then
  272.                             itemInSlot1 = v
  273.                         elseif k == ("qty") then
  274.                             itemQtyInSlot1 = tostring(v)
  275.                         end
  276.                     end
  277.                 else
  278.                     itemInSlot1 = "nothing"
  279.                     itemQtyInSlot1 = 0
  280.                 end
  281.                
  282.                 ImpAPI.CWrite(1, 3, mon, "Processing: ", colors.green)
  283.                 ImpAPI.CWrite(3, 4, mon, itemInSlot1, colors.white)
  284.                
  285.                 ImpAPI.CWrite(1, 6, mon, "Qty: ", colors.green)
  286.                 ImpAPI.CWrite(3, 7, mon, itemQtyInSlot1, colors.white)
  287.                
  288.                 writeEnergy(9,10)
  289.                
  290.             elseif machineName == "Crucible" then
  291.                 itemInSlot1 = ""
  292.                 itemQtyInSlot1 = 0
  293.                
  294.                 processing=machine.getStackInSlot(1)
  295.                
  296.                 if processing then
  297.                     for k,v in pairs(processing) do
  298.                         if k == "name" then
  299.                             itemInSlot1 = v
  300.                         elseif k == ("qty") then
  301.                             itemQtyInSlot1 = tostring(v)
  302.                         end
  303.                     end
  304.                 else
  305.                     itemInSlot1 = "nothing"
  306.                     itemQtyInSlot1 = 0
  307.                 end
  308.                 fluidName = ""
  309.                 fluidCap = 0
  310.                 fluidAmt = 0
  311.                            
  312.                 for k,v in pairs(tankInfo) do
  313.                    
  314.                     for o,c in pairs(v) do
  315.                        
  316.                         if o == "name" then
  317.                             fluidName = c
  318.                        
  319.                         elseif o == "amount" then
  320.                             fluidAmt = c
  321.                        
  322.                         elseif o == "capacity" then
  323.                             fluidCap = c
  324.                         end
  325.                     end
  326.                 end
  327.            
  328.                 centerItem = math.floor((monX - #itemInSlot1) / 2) + 1
  329.                
  330.                
  331.                 ImpAPI.CWrite(1, 3, mon, "Processing: ", colors.green)
  332.                 ImpAPI.CWrite(centerItem, 4, mon, itemInSlot1, colors.white)
  333.                
  334.                 ImpAPI.CWrite(1, 6, mon, fluidName.." fluid: ", colors.green)
  335.                 ImpAPI.CWrite(3, 7, mon, fluidAmt.."/"..fluidCap, colors.white)
  336.                
  337.                 writeEnergy(9,10)
  338.            
  339.             elseif machineName == "Redstone Furnace" then
  340.                 itemInSlot1 = ""
  341.                 itemQtyInSlot1 = 0
  342.                
  343.                 processing=machine.getStackInSlot(1)
  344.                
  345.                 if processing then
  346.                     for k,v in pairs(processing) do
  347.                         if k == "name" then
  348.                             itemInSlot1 = v
  349.                         elseif k == ("qty") then
  350.                             itemQtyInSlot1 = tostring(v)
  351.                         end
  352.                     end
  353.                 else
  354.                     itemInSlot1 = "nothing"
  355.                     itemQtyInSlot1 = 0
  356.                 end
  357.                
  358.                 ImpAPI.CWrite(1, 3, mon, "Processing: ", colors.green)
  359.                 ImpAPI.CWrite(3, 4, mon, itemInSlot1, colors.white)
  360.                
  361.                 ImpAPI.CWrite(1, 6, mon, "Qty: ", colors.green)
  362.                 ImpAPI.CWrite(3, 7, mon, itemQtyInSlot1, colors.white)
  363.                
  364.                 writeEnergy(9,10)
  365.             elseif machineName == "Sawmill" then
  366.                 itemInSlot1 = ""
  367.                 itemQtyInSlot1 = 0
  368.                
  369.                 processing=machine.getStackInSlot(1)
  370.                
  371.                 if processing then
  372.                     for k,v in pairs(processing) do
  373.                         if k == "name" then
  374.                             itemInSlot1 = v
  375.                         elseif k == ("qty") then
  376.                             itemQtyInSlot1 = tostring(v)
  377.                         end
  378.                     end
  379.                 else
  380.                     itemInSlot1 = "nothing"
  381.                     itemQtyInSlot1 = 0
  382.                 end
  383.                
  384.                 ImpAPI.CWrite(1, 3, mon, "Processing: ", colors.green)
  385.                 ImpAPI.CWrite(3, 4, mon, itemInSlot1, colors.white)
  386.                
  387.                 ImpAPI.CWrite(1, 6, mon, "Qty: ", colors.green)
  388.                 ImpAPI.CWrite(3, 7, mon, itemQtyInSlot1, colors.white)
  389.                
  390.                 writeEnergy(9,10)
  391.             elseif machineName == "Induction Smelter" then
  392.                 itemInSlot1 = ""
  393.                 itemQtyInSlot1 = 0
  394.                 itemInSlot2 = ""
  395.                 itemQtyInSlot2 = 0
  396.                
  397.                 processing=machine.getStackInSlot(1)
  398.                 processing2=machine.getStackInSlot(2)
  399.                
  400.                 if processing then
  401.                     for k,v in pairs(processing) do
  402.                         if k == "name" then
  403.                             itemInSlot1 = v
  404.                         elseif k == ("qty") then
  405.                             itemQtyInSlot1 = tostring(v)
  406.                         end
  407.                     end
  408.                 else
  409.                     itemInSlot1 = "nothing"
  410.                     itemQtyInSlot1 = 0
  411.                 end
  412.                
  413.                 if processing2 then
  414.                     for k,v in pairs(processing2) do
  415.                         if k == "name" then
  416.                             itemInSlot2 = v
  417.                         elseif k == ("qty") then
  418.                             itemQtyInSlot2 = tostring(v)
  419.                         end
  420.                     end
  421.                 else
  422.                     itemInSlot2 = "nothing"
  423.                     itemQtyInSlot2 = 0
  424.                 end
  425.                
  426.                 ImpAPI.CWrite(1, 3, mon, "Processing: ", colors.green)
  427.                 ImpAPI.CWrite(3, 4, mon, itemInSlot1.." & "..itemInSlot2, colors.white)
  428.                
  429.                 ImpAPI.CWrite(1, 6, mon, "Qty 1/2: ", colors.green)
  430.                 ImpAPI.CWrite(3, 7, mon, itemQtyInSlot1.."/"..itemQtyInSlot2, colors.white)
  431.                
  432.                 writeEnergy(9,10)
  433.            
  434.             end
  435.         end
  436.        
  437.     end
  438.     -- Loop timer
  439.     sleep(.50)
  440.    
  441.    
  442. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement