Advertisement
davedumas0

buildvraft power

May 25th, 2023
1,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.97 KB | None | 0 0
  1. -- Load the components
  2. local component = require("component")
  3. local gpu = component.gpu
  4. local sides = require("sides")
  5. local computer = require("computer")
  6.  
  7. -- Load the energy cube
  8. local energyCube = component.elite_energy_cube
  9. local tankController = component.tank_controller
  10.  
  11. local engine_1_tank_bank_1 = "08a57843-b7b5-4a5f-be68-6693ede070ef"  
  12. local engine_2_tank_bank_1 = "a72b707d-9902-4b4e-b33d-c59c91057cd4"
  13. local engine_3_tank_bank_1 = "9ad89be2-98f6-488f-b07c-e6438f3a639e"
  14. local engine_4_tank_bank_1 = "bebbcce8-435f-448c-a6bd-5b5e8566c39c"
  15.  
  16. local engine_1_tank_bank_2 = "fa76b96e-5c83-4944-be81-4d2ceb3dbb61"
  17. local engine_2_tank_bank_2 = "f04fbbe0-fd11-4748-9eaf-a95d7a1409ec"
  18. local engine_3_tank_bank_2 = "fcd32370-6b57-4c50-b224-97afb2598de6"
  19. local engine_4_tank_bank_2 = "14470fcc-cb6d-4acd-90c1-4975ed9ce48f"
  20.  
  21.  
  22.  
  23. -- Variables
  24. local energy = 0
  25. local maxEnergy = 0
  26.  
  27. local fluidLevel = 0
  28. local maxFluidLevel = 0
  29.  
  30. -- Thresholds for bundled wire outputs
  31. local offThreshold = 11000000 -- Energy threshold to turn the engine off
  32. local onThreshold = 1800000 -- Energy threshold to turn the engine on
  33. local totalDischarge = 0
  34. local totalCharge = 0
  35. local dischargeCount = 0
  36. local chargeCount = 0
  37.  
  38. local fuelConsumptionSamples = {} -- Table to store fuel consumption samples
  39. local maxFuelSamples = 10 -- Maximum number of fuel samples to keep
  40. local fuelConsumptionRate = 0 -- Fuel consumption rate
  41.  
  42.  
  43. -- Progress bar object
  44. local progressBar = {
  45.     x = 25,
  46.     y = 6,
  47.     width = 120,
  48.     height = 5,
  49.     progress = 0,
  50.     maxProgress = 100,
  51.     backgroundColor = 0x808080,
  52.     filledColor = 0x00BFFF,
  53.     shadowColor = 0x404040,
  54.     highlightColor = 0xFFFFFF,
  55.     orientation = "horizontal" -- Default orientation is horizontal
  56. }
  57.  
  58. -- Function to load the progress bar
  59. local function loadProgressBar()
  60.     progressBar.x = 25
  61.     progressBar.y = 6
  62.     progressBar.width = 120
  63.     progressBar.height = 5
  64.     progressBar.maxProgress = maxEnergy
  65. end
  66.  
  67. -- Function to update the progress bar
  68. local function updateProgressBar()
  69.     progressBar.progress = energy
  70. end
  71.  
  72. -- Function to draw the progress bar
  73. local function drawProgressBar()
  74.     local filledWidth = math.floor((progressBar.progress / progressBar.maxProgress) * progressBar.width)
  75.  
  76.     -- Set color for filled part
  77.     gpu.setBackground(progressBar.filledColor)
  78.     gpu.fill(progressBar.x, progressBar.y, filledWidth, progressBar.height, ' ')
  79.    
  80.     -- Set color for unfilled part
  81.     gpu.setBackground(progressBar.backgroundColor)
  82.     gpu.fill(progressBar.x + filledWidth, progressBar.y, progressBar.width - filledWidth, progressBar.height, ' ')
  83.  
  84.     -- Draw threshold line
  85.     local offThresholdX = math.floor((offThreshold / progressBar.maxProgress) * progressBar.width) + progressBar.x
  86.     local onThresholdX = math.floor((onThreshold / progressBar.maxProgress) * progressBar.width) + progressBar.x
  87.     gpu.setBackground(0xFF0000) -- Red color for off threshold
  88.     gpu.fill(offThresholdX, progressBar.y + progressBar.height / 2, 1, 1, ' ')
  89.     gpu.setBackground(0x00FF00) -- Green color for on threshold
  90.     gpu.fill(onThresholdX, progressBar.y + progressBar.height / 2, 1, 1, ' ')
  91.    
  92.     -- Reset color to white
  93.     gpu.setBackground(progressBar.highlightColor)
  94. end
  95.  
  96. -- Fluid tank object
  97. local fluidTank = {
  98.     x = 120,
  99.     y = 5,
  100.     width = 15,
  101.     height = 8,
  102.     tankCapacity = 0,
  103.     fluidAmount = 0,
  104.     fluidName = "",
  105. }
  106.  
  107. -- Function to load the fluid tank
  108. local function loadFluidTank()
  109.     fluidTank.tankCapacity = tankController.getTankCapacity(3)
  110.     local fluidInTank = tankController.getFluidInTank(3)
  111.     if fluidInTank[1] then
  112.         fluidTank.fluidAmount = fluidInTank[1].amount
  113.         fluidTank.fluidName = fluidInTank[1].name
  114.     else
  115.         fluidTank.fluidAmount = 0
  116.         fluidTank.fluidName = "Empty"
  117.     end
  118. end
  119.  
  120. -- Function to update the fluid tank
  121. local function updateFluidTank()
  122.     fluidTank.fluidAmount = tankController.getTankLevel(3)
  123.     local fluidInTank = tankController.getFluidInTank(3)
  124.     if fluidInTank[1] then
  125.         fluidTank.fluidName = fluidInTank[1].name
  126.     else
  127.         fluidTank.fluidName = "Empty"
  128.     end
  129. end
  130.  
  131. -- Function to draw the fluid tank
  132. local function drawFluidTank()
  133.     -- Calculate fluid level height
  134.     local fluidLevelHeight = math.floor((fluidTank.fluidAmount / fluidTank.tankCapacity) * (fluidTank.height - 2))
  135.     if fluidLevelHeight > fluidTank.height - 2 then
  136.         fluidLevelHeight = fluidTank.height - 2
  137.     end
  138.     -- Draw fluid tank background
  139.     gpu.setBackground(fluidTank.backgroundColor)
  140.     gpu.fill(fluidTank.x, fluidTank.y, fluidTank.width, fluidTank.height, ' ')
  141.    
  142.     -- Draw fluid level if tank is not empty
  143.     if fluidTank.fluidAmount > 1 then
  144.         gpu.setBackground(fluidTank.filledColor)
  145.         gpu.fill(fluidTank.x + 1, fluidTank.y + fluidTank.height - fluidLevelHeight - 1, fluidTank.width - 2, fluidLevelHeight, ' ')
  146.         gpu.setBackground(fluidTank.highlightColor)
  147.        
  148.     end
  149.    
  150.     -- Draw unfilled part of the tank
  151.     gpu.setBackground(fluidTank.highlightColor)
  152.     gpu.fill(fluidTank.x + 1, fluidTank.y + 1, fluidTank.width - 2, fluidTank.height - fluidLevelHeight - 2, ' ')
  153.    
  154.     -- Draw fluid name and amount
  155.     gpu.setForeground(fluidTank.highlightColor)
  156.     gpu.set(fluidTank.x - 2, fluidTank.y - 1, "Fluid: " .. fluidTank.fluidName)
  157.     gpu.set(fluidTank.x, fluidTank.y + fluidTank.height, "Amount: " .. fluidTank.fluidAmount .. " mB")
  158. end
  159.  
  160. -- Engine object
  161. local engine = {
  162.     body = {x = 100, y = 11, width = 1, height = 3, color = 0xFFFFFF},
  163.     head = {x = 100+1, y = 11, width = 1, height = 3, color = 0xC0C0C0}, -- Silver (0xC0C0C0) or White (0xFFFFFF)
  164.     core = {x = 100+1, y = 11+1, width = 4, height = 1, color = 0x8B4513},
  165. }
  166.  
  167. -- Function to load the engine
  168. local function loadEngine()
  169.     engine.core.x = engine.core.x
  170.     engine.core.y = engine.core.y
  171.     engine.body.x = engine.body.x
  172.     engine.body.y = engine.body.y
  173.     engine.head.x = engine.head.x
  174.     engine.head.y = engine.head.y
  175. end
  176.  
  177. -- Function to update the engine
  178. local function updateEngine()
  179.     if engine.movement == nil then
  180.         engine.movement = 0
  181.         engine.direction = true
  182.     end
  183.    
  184.     if engine.direction then
  185.         engine.head.x = engine.head.x + 1
  186.     else
  187.         engine.head.x = engine.head.x - 1
  188.     end
  189.    
  190.     engine.movement = engine.movement + 1
  191.    
  192.     if engine.movement >= 3 then
  193.         engine.movement = 0
  194.         engine.direction = not engine.direction
  195.         resetCycle() -- Reset the cycle when the engine completes a cycle
  196.     end
  197. end
  198.  
  199. -- Function to draw the engine
  200. local function drawEngine()
  201.     -- Draw core
  202.     gpu.setBackground(engine.core.color)
  203.     gpu.fill(engine.core.x, engine.core.y, engine.core.width, engine.core.height, ' ')
  204.     -- Draw body
  205.     gpu.setBackground(engine.body.color)
  206.     gpu.fill(engine.body.x, engine.body.y, engine.body.width, engine.body.height, ' ')
  207.     -- Draw head
  208.     gpu.setBackground(engine.head.color)
  209.     gpu.fill(engine.head.x, engine.head.y, engine.head.width, engine.head.height, ' ')
  210.     -- Reset color to white
  211.     gpu.setBackground(0xFFFFFF)
  212. end
  213.  
  214. -- Graph object
  215. local graph = {
  216.     x = progressBar.x,
  217.     y = progressBar.y + progressBar.height + 10,
  218.     width = progressBar.width,
  219.     height = 10,
  220.     data = {},
  221.     maxDataPoints = 100,
  222. }
  223.  
  224. -- Function to add data to the graph
  225. local function addGraphData(value)
  226.     table.insert(graph.data, 1, value)
  227.     if #graph.data > graph.maxDataPoints then
  228.         table.remove(graph.data)
  229.     end
  230. end
  231.  
  232. -- Function to draw the graph
  233. local function drawGraph()
  234.     -- Draw graph background
  235.     gpu.setBackground(0x808080)
  236.     gpu.fill(graph.x, graph.y, graph.width, graph.height, ' ')
  237.  
  238.     -- Calculate scale and offset for mapping data to graph coordinates
  239.     local minData = math.min(table.unpack(graph.data))
  240.     local maxData = math.max(table.unpack(graph.data))
  241.     local scale = (maxData - minData) / graph.height
  242.     local xOffset = graph.width / (#graph.data - 1)
  243.  
  244.     -- Draw data points
  245.     gpu.setBackground(0x00BFFF)
  246.     for i = 2, #graph.data do
  247.         local x1 = graph.x + (i - 2) * xOffset
  248.         local x2 = graph.x + (i - 1) * xOffset
  249.         local y1 = graph.y + graph.height - math.floor((graph.data[i - 1] - minData) / scale)
  250.         local y2 = graph.y + graph.height - math.floor((graph.data[i] - minData) / scale)
  251.         gpu.fill(x1, y1, 1, 1, ' ')
  252.         gpu.fill(x2, y2, 1, 1, ' ')
  253.         gpu.fill(x1, y1, math.abs(x2 - x1) + 1, math.abs(y2 - y1) + 1, ' ')
  254.     end
  255.  
  256.     -- Reset color to white
  257.     gpu.setBackground(0xFFFFFF)
  258. end
  259.  
  260. -- Function to load the program components
  261. local function load()
  262.     maxEnergy = energyCube.getMaxEnergyStored()
  263.     gpu.setResolution(160, 50) -- Set screen resolution
  264.     loadProgressBar()
  265.     loadEngine()
  266.     loadFluidTank()
  267. end
  268.  
  269. -- Function to update the program components
  270. local function update()
  271.     -- Check bundled inputs
  272.     local orangeInput = component.redstone.getBundledInput(3, 1) or 0
  273.     local whiteInput = component.redstone.getBundledInput(3, 0) or 0
  274.  
  275.     -- Check if animation should run
  276.     local shouldAnimate = orangeInput > 1 or whiteInput > 1
  277.  
  278.     -- Update energy and progress bar
  279.     energy = energyCube.getEnergyStored()
  280.     updateProgressBar()
  281.  
  282.     -- Calculate discharge and charge rates
  283.     local currentTick = computer.uptime()
  284.     local lastSample = energySamples[#energySamples]
  285.     if lastSample then
  286.         local deltaTime = currentTick - lastSample.tick
  287.         local deltaEnergy = energy - lastSample.energy
  288.  
  289.         if deltaTime > 0 then
  290.             if deltaEnergy > 0 then
  291.                 chargeRate = deltaEnergy / deltaTime
  292.                 dischargeRate = 0
  293.             elseif deltaEnergy < 0 then
  294.                 dischargeRate = -deltaEnergy / deltaTime
  295.                 chargeRate = 0
  296.             end
  297.         end
  298.         if deltaEnergy > 0 then
  299.             chargeRate = deltaEnergy / deltaTime
  300.             totalCharge = totalCharge + chargeRate
  301.             chargeCount = chargeCount + 1
  302.             dischargeRate = 0
  303.         elseif deltaEnergy < 0 then
  304.             dischargeRate = -deltaEnergy / deltaTime
  305.             totalDischarge = totalDischarge + dischargeRate
  306.             dischargeCount = dischargeCount + 1
  307.             chargeRate = 0
  308.         end
  309.     end
  310.  
  311.     -- Store energy sample
  312.     table.insert(energySamples, 1, { tick = currentTick, energy = energy })
  313.     if #energySamples > maxSamples then
  314.         table.remove(energySamples)
  315.     end
  316.  
  317.     if shouldAnimate then
  318.         updateEngine()
  319.     end
  320.  
  321.     -- Check thresholds and set bundled wire outputs
  322.     if energy <= onThreshold then
  323.         -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  324.         component.redstone.setBundledOutput(3, 0, 255)
  325.         component.redstone.setBundledOutput(3, 1, 255) -- Disable orange wire output
  326.     elseif energy >= offThreshold then
  327.         -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  328.         component.redstone.setBundledOutput(3, 0, 0) -- Disable orange wire output
  329.         component.redstone.setBundledOutput(3, 1, 0) -- Disable white wire output
  330.     end
  331.  
  332.     updateFluidTank()
  333. end
  334.  
  335. -- Function to draw the program components
  336. local function draw()
  337.     -- Clear screen
  338.     gpu.setBackground(0x000000)
  339.     gpu.setForeground(0xFFFFFF)
  340.     gpu.fill(1, 1, 160, 50, ' ')
  341.     drawProgressBar()
  342.     gpu.setBackground(0x000000)
  343.     gpu.setForeground(0xFFFFFF)
  344.     gpu.set(progressBar.x, progressBar.y + progressBar.height + 1, "Current Energy: " .. tostring(energy))
  345.     gpu.set(progressBar.x, progressBar.y + progressBar.height + 2, "Max Energy: " .. tostring(maxEnergy))
  346.     drawEngine()
  347.  
  348.     -- Render discharge and charge rates
  349.     local boxX = 25
  350.     local boxY = progressBar.y + progressBar.height + 5
  351.     local boxWidth = 48
  352.     local boxHeight = 10
  353.     local averageDischarge = totalDischarge / (dischargeCount > 0 and dischargeCount or 1)
  354.     local averageCharge = totalCharge / (chargeCount > 0 and chargeCount or 1)
  355.    
  356.     -- Draw gray box
  357.     gpu.setBackground(0x808080)
  358.     gpu.fill(boxX, boxY, boxWidth, boxHeight, ' ')
  359.  
  360.     -- Render discharge rate
  361.     local dischargeText = string.format("Discharge Rate: %.2f RF/t", dischargeRate)
  362.     gpu.setBackground(0x808080)
  363.     gpu.setForeground(0xFFFFFF)
  364.     gpu.set(boxX + 2, boxY + 1, dischargeText)
  365.  
  366.     -- Render charge rate
  367.     local chargeText = string.format("Charge Rate: %.2f RF/t", chargeRate)
  368.     gpu.setBackground(0x808080)
  369.     gpu.setForeground(0xFFFFFF)
  370.     gpu.set(boxX + 2, boxY + 2, chargeText)
  371.  
  372.     -- Render average discharge rate
  373.     local averageDischargeText = string.format("Average Discharge Rate: %.2f RF/t", averageDischarge)
  374.     gpu.setBackground(0x808080)
  375.     gpu.setForeground(0xFFFFFF)
  376.     gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  377.  
  378.     -- Render average charge rate
  379.     local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
  380.     gpu.setBackground(0x808080)
  381.     gpu.setForeground(0xFFFFFF)
  382.     gpu.set(boxX + 2, boxY + 4, averageChargeText)
  383.  
  384.     -- Reset color to white
  385.     gpu.setBackground(0xFFFFFF)
  386.     -- Render fuel consumption rate
  387.     local fuelConsumptionText = string.format("Fuel Consumption Rate: %.2f units/tick", fuelConsumptionRate)
  388.     gpu.setBackground(0x808080)
  389.     gpu.setForeground(0xFFFFFF)
  390.     gpu.set(boxX + 2, boxY + 5, fuelConsumptionText)
  391.    
  392.     drawFluidTank()
  393. end
  394.  
  395. -- Main function to run the program
  396. local function main()
  397.     load()
  398.     while true do
  399.         update()
  400.         draw()
  401.         os.sleep(0.1) -- Wait for 0.1 seconds before updating again
  402.     end
  403. end
  404.  
  405. -- Run the program
  406. main()
  407. -- Load the components
  408. local component = require("component")
  409. local gpu = component.gpu
  410. local sides = require("sides")
  411. local computer = require("computer")
  412.  
  413. -- Load the energy cube
  414. local energyCube = component.elite_energy_cube
  415. local tankController = component.tank_controller
  416.  
  417. -- Variables
  418. local energy = 0
  419. local maxEnergy = 0
  420.  
  421. local fluidLevel = 0
  422. local maxFluidLevel = 0
  423.  
  424. -- Thresholds for bundled wire outputs
  425. local offThreshold = 11000000 -- Energy threshold to turn the engine off
  426. local onThreshold = 1800000 -- Energy threshold to turn the engine on
  427. local totalDischarge = 0
  428. local totalCharge = 0
  429. local dischargeCount = 0
  430. local chargeCount = 0
  431.  
  432.  
  433.  
  434.  
  435. -- Progress bar object
  436. local progressBar = {
  437.     x = 25,
  438.     y = 6,
  439.     width = 120,
  440.     height = 5,
  441.     progress = 0,
  442.     maxProgress = 100,
  443.     backgroundColor = 0x808080,
  444.     filledColor = 0x00BFFF,
  445.     shadowColor = 0x404040,
  446.     highlightColor = 0xFFFFFF,
  447.     orientation = "horizontal" -- Default orientation is horizontal
  448. }
  449.  
  450. function progressBar:load(x, y, width, height, maxProgress)
  451.     self.x = x or self.x
  452.     self.y = y or self.y
  453.     self.width = width or self.width
  454.     self.height = height or self.height
  455.     self.maxProgress = maxProgress or self.maxProgress
  456.     self.orientation = orientation or self.orientation
  457. end
  458.  
  459. -- Progress bar update
  460. function progressBar:update(progress)
  461.     self.progress = progress
  462. end
  463.  
  464. -- Progress bar draw
  465. function progressBar:draw()
  466.     local filledWidth = math.floor((self.progress / self.maxProgress) * self.width)
  467.  
  468.     -- Set color for filled part
  469.     gpu.setBackground(0x00BFFF)
  470.     gpu.fill(self.x, self.y, filledWidth, self.height, ' ')
  471.    
  472.     -- Set color for unfilled part
  473.     gpu.setBackground(0x808080)
  474.     gpu.fill(self.x + filledWidth, self.y, self.width - filledWidth, self.height, ' ')
  475.  
  476.     -- Draw threshold line
  477.     local offThresholdX = math.floor((offThreshold / self.maxProgress) * self.width) + self.x
  478.     local onThresholdX = math.floor((onThreshold / self.maxProgress) * self.width) + self.x
  479.     gpu.setBackground(0xFF0000) -- Red color for off threshold
  480.     gpu.fill(offThresholdX, self.y + self.height / 2, 1, 1, ' ')
  481.     gpu.setBackground(0x00FF00) -- Green color for on threshold
  482.     gpu.fill(onThresholdX, self.y + self.height / 2, 1, 1, ' ')
  483.    
  484.     -- Reset color to white
  485.     gpu.setBackground(0xFFFFFF)
  486. end
  487.  
  488. -- Fluid tank object
  489. local fluidTank = {
  490.     x = 120,
  491.     y = 5,
  492.     width = 15,
  493.     height = 8,
  494.     tankCapacity = 0,
  495.     fluidAmount = 0,
  496.     fluidName = "",
  497. }
  498.  
  499. -- Fluid tank load
  500. function fluidTank:load()
  501.     self.tankCapacity = tankController.getTankCapacity(3)
  502.     local fluidInTank = tankController.getFluidInTank(3)
  503.     if fluidInTank[1] then
  504.         self.fluidAmount = fluidInTank[1].amount
  505.         self.fluidName = fluidInTank[1].name
  506.     else
  507.         self.fluidAmount = 0
  508.         self.fluidName = "Empty"
  509.     end
  510. end
  511.  
  512.  
  513. -- Fluid tank update
  514. function fluidTank:update()
  515.     self.fluidAmount = tankController.getTankLevel(3)
  516.     local fluidInTank = tankController.getFluidInTank(3)
  517.     if fluidInTank[1] then
  518.         self.fluidName = fluidInTank[1].name
  519.     else
  520.         self.fluidName = "Empty"
  521.     end
  522. end
  523.  
  524. -- Fluid tank draw
  525. function fluidTank:draw()
  526.     -- Calculate fluid level height
  527.     local fluidLevelHeight = math.floor((self.fluidAmount / self.tankCapacity) * (self.height - 2))
  528.     if fluidLevelHeight > self.height - 2 then
  529.         fluidLevelHeight = self.height - 2
  530.     end
  531.     -- Draw fluid tank background
  532.     gpu.setBackground(0x808080)
  533.     gpu.fill(self.x, self.y, self.width, self.height, ' ')
  534.    
  535.     -- Draw fluid level if tank is not empty
  536.     if self.fluidAmount > 1 then
  537.         gpu.setBackground(0xFFFF00)
  538.         gpu.fill(self.x + 1, self.y + self.height - fluidLevelHeight - 1, self.width - 2, fluidLevelHeight, ' ')
  539.         gpu.setBackground(0x000000)
  540.        
  541.     end
  542.    
  543.     -- Draw unfilled part of the tank
  544.     gpu.setBackground(0x000000)
  545.     gpu.fill(self.x + 1, self.y + 1, self.width - 2, self.height - fluidLevelHeight - 2, ' ')
  546.    
  547.     -- Draw fluid name and amount
  548.    
  549.     gpu.setForeground(0xFFFFFF)
  550.     gpu.set(self.x-2, self.y - 1, "Fluid: " .. self.fluidName)
  551.     gpu.set(self.x, self.y + self.height, "Amount: " .. self.fluidAmount .. " mB")
  552. end
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560. -- Engine object
  561. local engine = {
  562.     body = {x = 100, y = 11, width = 1, height = 3, color = 0xFFFFFF},
  563.     head = {x = 100+1, y = 11, width = 1, height = 3, color = 0xC0C0C0}, -- Silver (0xC0C0C0) or White (0xFFFFFF)
  564.     core = {x = 100+1, y = 11+1, width = 4, height = 1, color = 0x8B4513},
  565. }
  566.  
  567. -- Engine load
  568. function engine:load()
  569.     self.core.x = engine.core.x
  570.     self.core.y = engine.core.y
  571.     self.body.x = engine.body.x
  572.     self.body.y = engine.body.y
  573.     self.head.x = engine.head.x
  574.     self.head.y = engine.head.y
  575. end
  576.  
  577. function resetCycle()
  578.     totalDischarge = 0
  579.     totalCharge = 0
  580.     dischargeCount = 0
  581.     chargeCount = 0
  582. end
  583.  
  584.  
  585. -- Engine update
  586. function engine:update()
  587.     if self.movement == nil then
  588.         self.movement = 0
  589.         self.direction = true
  590.     end
  591.    
  592.     if self.direction then
  593.         self.head.x = self.head.x + 1
  594.     else
  595.         self.head.x = self.head.x - 1
  596.     end
  597.    
  598.     self.movement = self.movement + 1
  599.    
  600.     if self.movement >= 3 then
  601.         self.movement = 0
  602.         self.direction = not self.direction
  603.         resetCycle() -- Reset the cycle when the engine completes a cycle
  604.     end
  605. end
  606.  
  607. -- Engine draw
  608. function engine:draw()
  609.     -- Draw core
  610.     gpu.setBackground(self.core.color)
  611.     gpu.fill(self.core.x, self.core.y, self.core.width, self.core.height, ' ')
  612.     -- Draw body
  613.     gpu.setBackground(self.body.color)
  614.     gpu.fill(self.body.x, self.body.y, self.body.width, self.body.height, ' ')
  615.     -- Draw head
  616.     gpu.setBackground(self.head.color)
  617.     gpu.fill(self.head.x, self.head.y, self.head.width, self.head.height, ' ')
  618.     -- Reset color to white
  619.     gpu.setBackground(0xFFFFFF)
  620. end
  621.  
  622. local graph = {
  623.     x = progressBar.x,
  624.     y = progressBar.y + progressBar.height + 10,
  625.     width = progressBar.width,
  626.     height = 10,
  627.     data = {},
  628.     maxDataPoints = 100,
  629. }
  630.  
  631. -- Graph add data
  632. function graph:addData(value)
  633.     table.insert(self.data, 1, value)
  634.     if #self.data > self.maxDataPoints then
  635.         table.remove(self.data)
  636.     end
  637. end
  638.  
  639. -- Graph draw
  640. function graph:draw()
  641.     -- Draw graph background
  642.     gpu.setBackground(0x808080)
  643.     gpu.fill(self.x, self.y, self.width, self.height, ' ')
  644.  
  645.     -- Calculate scale and offset for mapping data to graph coordinates
  646.     local minData = math.min(table.unpack(self.data))
  647.     local maxData = math.max(table.unpack(self.data))
  648.     local scale = (maxData - minData) / self.height
  649.     local xOffset = self.width / (#self.data - 1)
  650.  
  651.     -- Draw data points
  652.     gpu.setBackground(0x00BFFF)
  653.     for i = 2, #self.data do
  654.         local x1 = self.x + (i - 2) * xOffset
  655.         local x2 = self.x + (i - 1) * xOffset
  656.         local y1 = self.y + self.height - math.floor((self.data[i - 1] - minData) / scale)
  657.         local y2 = self.y + self.height - math.floor((self.data[i] - minData) / scale)
  658.         gpu.fill(x1, y1, 1, 1, ' ')
  659.         gpu.fill(x2, y2, 1, 1, ' ')
  660.         gpu.fill(x1, y1, math.abs(x2 - x1) + 1, math.abs(y2 - y1) + 1, ' ')
  661.     end
  662.  
  663.     -- Reset color to white
  664.     gpu.setBackground(0xFFFFFF)
  665. end
  666.  
  667.  
  668. function getAverageChargeRate()
  669.     local total = 0
  670.     for i = 1, #chargeRateSamples do
  671.         total = total + chargeRateSamples[i]
  672.     end
  673.     return total / (#chargeRateSamples > 0 and #chargeRateSamples or 1)
  674. end
  675.  
  676. function getAverageDischargeRate()
  677.     local total = 0
  678.     for i = 1, #dischargeRateSamples do
  679.         total = total + dischargeRateSamples[i]
  680.     end
  681.     return total / (#dischargeRateSamples > 0 and #dischargeRateSamples or 1)
  682. end
  683.  
  684.  
  685. local function enableWireBank(bank)
  686.     component.redstone.setBundledOutput(3, bank, 255)
  687. end
  688.  
  689. -- Function to disable a specific bank of bundled wire outputs
  690. local function disableWireBank(bank)
  691.     component.redstone.setBundledOutput(3, bank, 0)
  692. end
  693.  
  694. --[[
  695.     ╔════════════════════════════╗
  696.     ║ MAIN PROGRAM INITIALIZATION║
  697.     ╚════════════════════════════╝
  698. --]]
  699. function load()
  700.     maxEnergy = energyCube.getMaxEnergyStored()
  701.     gpu.setResolution(160, 50) -- Set screen resolution
  702.     progressBar:load(25, 6, 48, 5, maxEnergy) -- Initialize progress bar
  703.     engine:load() -- Initialize engine
  704.     fluidTank:load()
  705. end
  706.  
  707. --[[
  708.     ╔═══════════════════════╗
  709.     ║ MAIN PROGRAM LOOP     ║
  710.     ╚═══════════════════════╝
  711. --]]
  712. local energySamples = {} -- Table to store energy samples
  713. local sampleRate = 10 -- Number of ticks between energy samples
  714. local maxSamples = 10 -- Maximum number of energy samples to keep
  715. local dischargeRate = 0 -- Energy discharge rate
  716. local chargeRate = 0 -- Energy charge rate
  717.  
  718. local sampleSize = 10 -- Number of samples to use when calculating average rates
  719. local chargeRateSamples = {} -- Table to store charge rate samples
  720. local dischargeRateSamples = {} -- Table to store discharge rate samples
  721.  
  722. function update()
  723.     -- Check bundled inputs
  724.     local orangeInput = component.redstone.getBundledInput(3, 1) or 0
  725.     local whiteInput = component.redstone.getBundledInput(3, 0) or 0
  726.  
  727.     -- Check if animation should run
  728.     local shouldAnimate = orangeInput > 1 or whiteInput > 1
  729.  
  730.     -- Update energy and progress bar
  731.     energy = energyCube.getEnergyStored()
  732.     progressBar:update(energy)
  733.  
  734.     -- Calculate discharge and charge rates
  735.     local currentTick = computer.uptime()
  736.     local lastSample = energySamples[#energySamples]
  737.     if lastSample then
  738.         local deltaTime = currentTick - lastSample.tick
  739.         local deltaEnergy = energy - lastSample.energy
  740.  
  741.         if deltaTime > 0 then
  742.             if deltaEnergy > 0 then
  743.                 chargeRate = deltaEnergy / deltaTime
  744.                 dischargeRate = 0
  745.             elseif deltaEnergy < 0 then
  746.                 dischargeRate = -deltaEnergy / deltaTime
  747.                 chargeRate = 0
  748.             end
  749.         end
  750.         if deltaEnergy > 0 then
  751.             chargeRate = deltaEnergy / deltaTime
  752.             totalCharge = totalCharge + chargeRate
  753.             chargeCount = chargeCount + 1
  754.             dischargeRate = 0
  755.         elseif deltaEnergy < 0 then
  756.             dischargeRate = -deltaEnergy / deltaTime
  757.             totalDischarge = totalDischarge + dischargeRate
  758.             dischargeCount = dischargeCount + 1
  759.             chargeRate = 0
  760.         end
  761.     end
  762.  
  763.     -- Store energy sample
  764.     table.insert(energySamples, 1, { tick = currentTick, energy = energy })
  765.     if #energySamples > maxSamples then
  766.         table.remove(energySamples)
  767.     end
  768.    
  769.     if shouldAnimate then
  770.         engine:update()
  771.     end
  772.  
  773.     -- Check thresholds and set bundled wire outputs
  774.     if energy <= onThreshold then
  775.         -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  776.         enableWireBank(0)
  777.         enableWireBank(1) -- Disable orange wire output
  778.     elseif energy >= offThreshold  then
  779.         -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  780.         disableWireBank(0) -- Disable orange wire output
  781.         disableWireBank(1) -- Disable white wire output
  782.    
  783.     end
  784.     fluidTank:update()
  785.     -- Render discharge and charge rates
  786.     local boxX = 25
  787.     local boxY = progressBar.y + progressBar.height + 5
  788.     local boxWidth = 48
  789.     local boxHeight = 10
  790.     local averageDischarge = totalDischarge / (dischargeCount > 0 and dischargeCount or 1)
  791.     local averageCharge = totalCharge / (chargeCount > 0 and chargeCount or 1)
  792.    
  793.     -- Draw gray box
  794.     gpu.setBackground(0x808080)
  795.     gpu.fill(boxX, boxY, boxWidth, boxHeight, ' ')
  796.  
  797.     -- Render discharge rate
  798.     local dischargeText = string.format("Discharge Rate: %.2f RF/t", dischargeRate)
  799.     gpu.setBackground(0x808080)
  800.     gpu.setForeground(0xFFFFFF)
  801.     gpu.set(boxX + 2, boxY + 1, dischargeText)
  802.  
  803.     -- Render charge rate
  804.     local chargeText = string.format("Charge Rate: %.2f RF/t", chargeRate)
  805.     gpu.setBackground(0x808080)
  806.     gpu.setForeground(0xFFFFFF)
  807.     gpu.set(boxX + 2, boxY + 2, chargeText)
  808.  
  809.     -- Render average discharge rate
  810.     local averageDischargeText = string.format("Average Discharge Rate: %.2f RF/t", averageDischarge)
  811.     gpu.setBackground(0x808080)
  812.     gpu.setForeground(0xFFFFFF)
  813.     gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  814.  
  815.     -- Render average charge rate
  816.     local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
  817.     gpu.setBackground(0x808080)
  818.     gpu.setForeground(0xFFFFFF)
  819.     gpu.set(boxX + 2, boxY + 4, averageChargeText)
  820.  
  821.     -- Reset color to white
  822.     gpu.setBackground(0xFFFFFF)
  823.     -- Calculate fuel consumption rate
  824.     local currentFuel = fluidTank.getFluidAmount()
  825.     local lastFuelSample = fuelConsumptionSamples[#fuelConsumptionSamples]
  826.     if lastFuelSample then
  827.         local deltaFuel = lastFuelSample.fuel - currentFuel
  828.         if deltaFuel > 0 then
  829.             fuelConsumptionRate = deltaFuel / deltaTime
  830.         else
  831.             fuelConsumptionRate = 0
  832.         end
  833.     end
  834.  
  835. -- Store fuel consumption sample
  836. table.insert(fuelConsumptionSamples, 1, { tick = currentTick, fuel = currentFuel })
  837. if #fuelConsumptionSamples > maxFuelSamples then
  838.     table.remove(fuelConsumptionSamples)
  839. end
  840.  
  841.     drawFluidTank()
  842. end
  843.  
  844. -- Main function to run the program
  845. local function main()
  846.     load()
  847.     while true do
  848.         update()
  849.         draw()
  850.         os.sleep(0.1) -- Wait for 0.1 seconds before updating again
  851.     end
  852. end
  853.  
  854. -- Run the program
  855. main()
  856. -- Load the components
  857. local component = require("component")
  858. local gpu = component.gpu
  859. local sides = require("sides")
  860. local computer = require("computer")
  861.  
  862. -- Load the energy cube
  863. local energyCube = component.elite_energy_cube
  864. local tankController = component.proxy("a72b707d-9902-4b4e-b33d-c59c91057cd4")
  865.  
  866. -- Variables
  867. local energy = 0
  868. local maxEnergy = 0
  869.  
  870. local fluidLevel = 0
  871. local maxFluidLevel = 0
  872.  
  873. -- Thresholds for bundled wire outputs
  874. local offThreshold = 11000000 -- Energy threshold to turn the engine off
  875. local onThreshold = 1800000 -- Energy threshold to turn the engine on
  876. local totalDischarge = 0
  877. local totalCharge = 0
  878. local dischargeCount = 0
  879. local chargeCount = 0
  880.  
  881.  
  882.  
  883.  
  884. -- Progress bar object
  885. local progressBar = {
  886.     x = 25,
  887.     y = 6,
  888.     width = 120,
  889.     height = 5,
  890.     progress = 0,
  891.     maxProgress = 100,
  892.     backgroundColor = 0x808080,
  893.     filledColor = 0x00BFFF,
  894.     shadowColor = 0x404040,
  895.     highlightColor = 0xFFFFFF,
  896.     orientation = "horizontal" -- Default orientation is horizontal
  897. }
  898.  
  899. function progressBar:load(x, y, width, height, maxProgress)
  900.     self.x = x or self.x
  901.     self.y = y or self.y
  902.     self.width = width or self.width
  903.     self.height = height or self.height
  904.     self.maxProgress = maxProgress or self.maxProgress
  905.     self.orientation = orientation or self.orientation
  906. end
  907.  
  908. -- Progress bar update
  909. function progressBar:update(progress)
  910.     self.progress = progress
  911. end
  912.  
  913. -- Progress bar draw
  914. function progressBar:draw()
  915.     local filledWidth = math.floor((self.progress / self.maxProgress) * self.width)
  916.  
  917.     -- Set color for filled part
  918.     gpu.setBackground(0x00BFFF)
  919.     gpu.fill(self.x, self.y, filledWidth, self.height, ' ')
  920.    
  921.     -- Set color for unfilled part
  922.     gpu.setBackground(0x808080)
  923.     gpu.fill(self.x + filledWidth, self.y, self.width - filledWidth, self.height, ' ')
  924.  
  925.     -- Draw threshold line
  926.     local offThresholdX = math.floor((offThreshold / self.maxProgress) * self.width) + self.x
  927.     local onThresholdX = math.floor((onThreshold / self.maxProgress) * self.width) + self.x
  928.     gpu.setBackground(0xFF0000) -- Red color for off threshold
  929.     gpu.fill(offThresholdX, self.y + self.height / 2, 1, 1, ' ')
  930.     gpu.setBackground(0x00FF00) -- Green color for on threshold
  931.     gpu.fill(onThresholdX, self.y + self.height / 2, 1, 1, ' ')
  932.    
  933.     -- Reset color to white
  934.     gpu.setBackground(0xFFFFFF)
  935. end
  936.  
  937. -- Fluid tank object
  938. local fluidTank = {
  939.     x = 120,
  940.     y = 5,
  941.     width = 15,
  942.     height = 8,
  943.     tankCapacity = 0,
  944.     fluidAmount = 0,
  945.     fluidName = "",
  946. }
  947.  
  948. -- Fluid tank load
  949. function fluidTank:load()
  950.     self.tankCapacity = tankController.getTankCapacity(3)
  951.     local fluidInTank = tankController.getFluidInTank(3)
  952.     if fluidInTank[1] then
  953.         self.fluidAmount = fluidInTank[1].amount
  954.         self.fluidName = fluidInTank[1].name
  955.     else
  956.         self.fluidAmount = 0
  957.         self.fluidName = "Empty"
  958.     end
  959. end
  960.  
  961.  
  962. -- Fluid tank update
  963. function fluidTank:update()
  964.     self.fluidAmount = tankController.getTankLevel(3)
  965.     local fluidInTank = tankController.getFluidInTank(3)
  966.     if fluidInTank[1] then
  967.         self.fluidName = fluidInTank[1].name
  968.     else
  969.         self.fluidName = "Empty"
  970.     end
  971. end
  972.  
  973. -- Fluid tank draw
  974. function fluidTank:draw()
  975.     -- Calculate fluid level height
  976.     local fluidLevelHeight = math.floor((self.fluidAmount / self.tankCapacity) * (self.height - 2))
  977.     if fluidLevelHeight > self.height - 2 then
  978.         fluidLevelHeight = self.height - 2
  979.     end
  980.     -- Draw fluid tank background
  981.     gpu.setBackground(0x808080)
  982.     gpu.fill(self.x, self.y, self.width, self.height, ' ')
  983.    
  984.     -- Draw fluid level if tank is not empty
  985.     if self.fluidAmount > 1 then
  986.         gpu.setBackground(0xFFFF00)
  987.         gpu.fill(self.x + 1, self.y + self.height - fluidLevelHeight - 1, self.width - 2, fluidLevelHeight, ' ')
  988.         gpu.setBackground(0x000000)
  989.        
  990.     end
  991.    
  992.     -- Draw unfilled part of the tank
  993.     gpu.setBackground(0x000000)
  994.     gpu.fill(self.x + 1, self.y + 1, self.width - 2, self.height - fluidLevelHeight - 2, ' ')
  995.    
  996.     -- Draw fluid name and amount
  997.    
  998.     gpu.setForeground(0xFFFFFF)
  999.     gpu.set(self.x-2, self.y - 1, "Fluid: " .. self.fluidName)
  1000.     gpu.set(self.x, self.y + self.height, "Amount: " .. self.fluidAmount .. " mB")
  1001. end
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009. -- Engine object
  1010. local engine = {
  1011.     body = {x = 100, y = 11, width = 1, height = 3, color = 0xFFFFFF},
  1012.     head = {x = 100+1, y = 11, width = 1, height = 3, color = 0xC0C0C0}, -- Silver (0xC0C0C0) or White (0xFFFFFF)
  1013.     core = {x = 100+1, y = 11+1, width = 4, height = 1, color = 0x8B4513},
  1014. }
  1015.  
  1016. -- Engine load
  1017. function engine:load()
  1018.     self.core.x = engine.core.x
  1019.     self.core.y = engine.core.y
  1020.     self.body.x = engine.body.x
  1021.     self.body.y = engine.body.y
  1022.     self.head.x = engine.head.x
  1023.     self.head.y = engine.head.y
  1024. end
  1025.  
  1026. function resetCycle()
  1027.     totalDischarge = 0
  1028.     totalCharge = 0
  1029.     dischargeCount = 0
  1030.     chargeCount = 0
  1031. end
  1032.  
  1033.  
  1034. -- Engine update
  1035. function engine:update()
  1036.     if self.movement == nil then
  1037.         self.movement = 0
  1038.         self.direction = true
  1039.     end
  1040.    
  1041.     if self.direction then
  1042.         self.head.x = self.head.x + 1
  1043.     else
  1044.         self.head.x = self.head.x - 1
  1045.     end
  1046.    
  1047.     self.movement = self.movement + 1
  1048.    
  1049.     if self.movement >= 3 then
  1050.         self.movement = 0
  1051.         self.direction = not self.direction
  1052.         resetCycle() -- Reset the cycle when the engine completes a cycle
  1053.     end
  1054. end
  1055.  
  1056. -- Engine draw
  1057. function engine:draw()
  1058.     -- Draw core
  1059.     gpu.setBackground(self.core.color)
  1060.     gpu.fill(self.core.x, self.core.y, self.core.width, self.core.height, ' ')
  1061.     -- Draw body
  1062.     gpu.setBackground(self.body.color)
  1063.     gpu.fill(self.body.x, self.body.y, self.body.width, self.body.height, ' ')
  1064.     -- Draw head
  1065.     gpu.setBackground(self.head.color)
  1066.     gpu.fill(self.head.x, self.head.y, self.head.width, self.head.height, ' ')
  1067.     -- Reset color to white
  1068.     gpu.setBackground(0xFFFFFF)
  1069. end
  1070.  
  1071. local graph = {
  1072.     x = progressBar.x,
  1073.     y = progressBar.y + progressBar.height + 10,
  1074.     width = progressBar.width,
  1075.     height = 10,
  1076.     data = {},
  1077.     maxDataPoints = 100,
  1078. }
  1079.  
  1080. -- Graph add data
  1081. function graph:addData(value)
  1082.     table.insert(self.data, 1, value)
  1083.     if #self.data > self.maxDataPoints then
  1084.         table.remove(self.data)
  1085.     end
  1086. end
  1087.  
  1088. -- Graph draw
  1089. function graph:draw()
  1090.     -- Draw graph background
  1091.     gpu.setBackground(0x808080)
  1092.     gpu.fill(self.x, self.y, self.width, self.height, ' ')
  1093.  
  1094.     -- Calculate scale and offset for mapping data to graph coordinates
  1095.     local minData = math.min(table.unpack(self.data))
  1096.     local maxData = math.max(table.unpack(self.data))
  1097.     local scale = (maxData - minData) / self.height
  1098.     local xOffset = self.width / (#self.data - 1)
  1099.  
  1100.     -- Draw data points
  1101.     gpu.setBackground(0x00BFFF)
  1102.     for i = 2, #self.data do
  1103.         local x1 = self.x + (i - 2) * xOffset
  1104.         local x2 = self.x + (i - 1) * xOffset
  1105.         local y1 = self.y + self.height - math.floor((self.data[i - 1] - minData) / scale)
  1106.         local y2 = self.y + self.height - math.floor((self.data[i] - minData) / scale)
  1107.         gpu.fill(x1, y1, 1, 1, ' ')
  1108.         gpu.fill(x2, y2, 1, 1, ' ')
  1109.         gpu.fill(x1, y1, math.abs(x2 - x1) + 1, math.abs(y2 - y1) + 1, ' ')
  1110.     end
  1111.  
  1112.     -- Reset color to white
  1113.     gpu.setBackground(0xFFFFFF)
  1114. end
  1115.  
  1116.  
  1117. function getAverageChargeRate()
  1118.     local total = 0
  1119.     for i = 1, #chargeRateSamples do
  1120.         total = total + chargeRateSamples[i]
  1121.     end
  1122.     return total / (#chargeRateSamples > 0 and #chargeRateSamples or 1)
  1123. end
  1124.  
  1125. function getAverageDischargeRate()
  1126.     local total = 0
  1127.     for i = 1, #dischargeRateSamples do
  1128.         total = total + dischargeRateSamples[i]
  1129.     end
  1130.     return total / (#dischargeRateSamples > 0 and #dischargeRateSamples or 1)
  1131. end
  1132.  
  1133.  
  1134. local function enableWireBank(bank)
  1135.     component.redstone.setBundledOutput(3, bank, 255)
  1136. end
  1137.  
  1138. -- Function to disable a specific bank of bundled wire outputs
  1139. local function disableWireBank(bank)
  1140.     component.redstone.setBundledOutput(3, bank, 0)
  1141. end
  1142.  
  1143. --[[
  1144.     ╔════════════════════════════╗
  1145.     ║ MAIN PROGRAM INITIALIZATION║
  1146.     ╚════════════════════════════╝
  1147. --]]
  1148. function load()
  1149.     maxEnergy = energyCube.getMaxEnergyStored()
  1150.     gpu.setResolution(160, 50) -- Set screen resolution
  1151.     progressBar:load(25, 6, 48, 5, maxEnergy) -- Initialize progress bar
  1152.     engine:load() -- Initialize engine
  1153.     fluidTank:load()
  1154. end
  1155.  
  1156. --[[
  1157.     ╔═══════════════════════╗
  1158.     ║ MAIN PROGRAM LOOP     ║
  1159.     ╚═══════════════════════╝
  1160. --]]
  1161. local energySamples = {} -- Table to store energy samples
  1162. local sampleRate = 10 -- Number of ticks between energy samples
  1163. local maxSamples = 10 -- Maximum number of energy samples to keep
  1164. local dischargeRate = 0 -- Energy discharge rate
  1165. local chargeRate = 0 -- Energy charge rate
  1166.  
  1167. local sampleSize = 10 -- Number of samples to use when calculating average rates
  1168. local chargeRateSamples = {} -- Table to store charge rate samples
  1169. local dischargeRateSamples = {} -- Table to store discharge rate samples
  1170.  
  1171. function update()
  1172.     -- Check bundled inputs
  1173.     local orangeInput = component.redstone.getBundledInput(3, 1) or 0
  1174.     local whiteInput = component.redstone.getBundledInput(3, 0) or 0
  1175.  
  1176.     -- Check if animation should run
  1177.     local shouldAnimate = orangeInput > 1 or whiteInput > 1
  1178.  
  1179.     -- Update energy and progress bar
  1180.     energy = energyCube.getEnergyStored()
  1181.     progressBar:update(energy)
  1182.  
  1183.     -- Calculate discharge and charge rates
  1184.     local currentTick = computer.uptime()
  1185.     local lastSample = energySamples[#energySamples]
  1186.     if lastSample then
  1187.         local deltaTime = currentTick - lastSample.tick
  1188.         local deltaEnergy = energy - lastSample.energy
  1189.  
  1190.         if deltaTime > 0 then
  1191.             if deltaEnergy > 0 then
  1192.                 chargeRate = deltaEnergy / deltaTime
  1193.                 dischargeRate = 0
  1194.             elseif deltaEnergy < 0 then
  1195.                 dischargeRate = -deltaEnergy / deltaTime
  1196.                 chargeRate = 0
  1197.             end
  1198.         end
  1199.         if deltaEnergy > 0 then
  1200.             chargeRate = deltaEnergy / deltaTime
  1201.             totalCharge = totalCharge + chargeRate
  1202.             chargeCount = chargeCount + 1
  1203.             dischargeRate = 0
  1204.         elseif deltaEnergy < 0 then
  1205.             dischargeRate = -deltaEnergy / deltaTime
  1206.             totalDischarge = totalDischarge + dischargeRate
  1207.             dischargeCount = dischargeCount + 1
  1208.             chargeRate = 0
  1209.         end
  1210.     end
  1211.  
  1212.     -- Store energy sample
  1213.     table.insert(energySamples, 1, { tick = currentTick, energy = energy })
  1214.     if #energySamples > maxSamples then
  1215.         table.remove(energySamples)
  1216.     end
  1217.    
  1218.     if shouldAnimate then
  1219.         engine:update()
  1220.     end
  1221.  
  1222.     -- Check thresholds and set bundled wire outputs
  1223.     if energy <= onThreshold then
  1224.         -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  1225.         enableWireBank(0)
  1226.         enableWireBank(1) -- Disable orange wire output
  1227.     elseif energy >= offThreshold  then
  1228.         -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  1229.         disableWireBank(0) -- Disable orange wire output
  1230.         disableWireBank(1) -- Disable white wire output
  1231.    
  1232.     end
  1233.     fluidTank:update()
  1234.  
  1235. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement