Advertisement
davedumas0

oppencomputers buildcraft controll

May 26th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.25 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. local term = require("term")
  7. -- Load the energy cube
  8. local energyCube = component.elite_energy_cube
  9. local engine_4_bank_2 = "14470fcc-cb6d-4acd-90c1-4975ed9ce48f"
  10. local engine_3_bank_2 = "fcd32370-6b57-4c50-b224-97afb2598de6"
  11. local engine_2_bank_2 = "f04fbbe0-fd11-4748-9eaf-a95d7a1409ec"
  12. local engine_1_bank_2 = "fa76b96e-5c83-4944-be81-4d2ceb3dbb61"
  13. local engine_1_bank_1 = "08a57843-b7b5-4a5f-be68-6693ede070ef"
  14. local engine_2_bank_1 = "a72b707d-9902-4b4e-b33d-c59c91057cd4"
  15. local engine_3_bank_1 = "9ad89be2-98f6-488f-b07c-e6438f3a639e"
  16. local engine_4_bank_1 = "bebbcce8-435f-448c-a6bd-5b5e8566c39c"
  17.  
  18.  
  19. -- Variables
  20. local energy = 0
  21. local maxEnergy = 0
  22.  
  23. local fluidLevel = 0
  24. local maxFluidLevel = 0
  25.  
  26. -- Thresholds for bundled wire outputs
  27. local offThreshold = 11000000 -- Energy threshold to turn the engine off
  28. local onThreshold = 1800000 -- Energy threshold to turn the engine on
  29. local totalDischarge = 0
  30. local totalCharge = 0
  31. local dischargeCount = 0
  32. local chargeCount = 0
  33.  
  34.  
  35.  
  36.  
  37. -- Progress bar object
  38. local progressBar = {
  39. x = 25,
  40. y = 6,
  41. width = 120,
  42. height = 5,
  43. progress = 0,
  44. maxProgress = 100,
  45. backgroundColor = 0x808080,
  46. filledColor = 0x00BFFF,
  47. shadowColor = 0x404040,
  48. highlightColor = 0xFFFFFF,
  49. orientation = "horizontal" -- Default orientation is horizontal
  50. }
  51.  
  52. function progressBar:load(x, y, width, height, maxProgress)
  53. self.x = x or self.x
  54. self.y = y or self.y
  55. self.width = width or self.width
  56. self.height = height or self.height
  57. self.maxProgress = maxProgress or self.maxProgress
  58. self.orientation = orientation or self.orientation
  59. end
  60.  
  61. -- Progress bar update
  62. function progressBar:update(progress)
  63. self.progress = progress
  64. end
  65.  
  66. -- Progress bar draw
  67. function progressBar:draw()
  68. local filledWidth = math.floor((self.progress / self.maxProgress) * self.width)
  69.  
  70. -- Set color for filled part
  71. gpu.setBackground(0x00BFFF)
  72. gpu.fill(self.x, self.y, filledWidth, self.height, ' ')
  73.  
  74. -- Set color for unfilled part
  75. gpu.setBackground(0x808080)
  76. gpu.fill(self.x + filledWidth, self.y, self.width - filledWidth, self.height, ' ')
  77.  
  78. -- Draw threshold line
  79. local offThresholdX = math.floor((offThreshold / self.maxProgress) * self.width) + self.x
  80. local onThresholdX = math.floor((onThreshold / self.maxProgress) * self.width) + self.x
  81. gpu.setBackground(0xFF0000) -- Red color for off threshold
  82. gpu.fill(offThresholdX, self.y + self.height / 2, 1, 1, ' ')
  83. gpu.setBackground(0x00FF00) -- Green color for on threshold
  84. gpu.fill(onThresholdX, self.y + self.height / 2, 1, 1, ' ')
  85.  
  86. -- Reset color to white
  87. gpu.setBackground(0xFFFFFF)
  88. end
  89.  
  90. -- Fluid tank object
  91. local fluidTank = {
  92. x = 120,
  93. y = 5,
  94. width = 15,
  95. height = 8,
  96. tankCapacity = 0,
  97. fluidAmount = 0,
  98. fluidName = "",
  99. }
  100.  
  101. -- Fluid tank load
  102. function fluidTank:load()
  103. self.tankCapacity = tankController.getTankCapacity(1)
  104. local fluidInTank = tankController.getFluidInTank(1)
  105. if fluidInTank[1] then
  106. self.fluidAmount = fluidInTank[1].amount
  107. self.fluidName = fluidInTank[1].name
  108. else
  109. self.fluidAmount = 0
  110. self.fluidName = "Empty"
  111. end
  112. end
  113.  
  114.  
  115. -- Fluid tank update
  116. function fluidTank:update()
  117. self.fluidAmount = tankController.getTankLevel(1)
  118. local fluidInTank = tankController.getFluidInTank(1)
  119. if fluidInTank[1] then
  120. self.fluidName = fluidInTank[1].name
  121. else
  122. self.fluidName = "Empty"
  123. end
  124. end
  125.  
  126. -- Fluid tank draw
  127. function fluidTank:draw()
  128. -- Calculate fluid level height
  129. local fluidLevelHeight = math.floor((self.fluidAmount / self.tankCapacity) * (self.height - 2))
  130. if fluidLevelHeight > self.height - 2 then
  131. fluidLevelHeight = self.height - 2
  132. end
  133. -- Draw fluid tank background
  134. gpu.setBackground(0x808080)
  135. gpu.fill(self.x, self.y, self.width, self.height, ' ')
  136.  
  137. -- Draw fluid level if tank is not empty
  138. if self.fluidAmount > 1 then
  139. gpu.setBackground(0xFFFF00)
  140. gpu.fill(self.x + 1, self.y + self.height - fluidLevelHeight - 1, self.width - 2, fluidLevelHeight, ' ')
  141. gpu.setBackground(0x000000)
  142.  
  143. end
  144.  
  145. -- Draw unfilled part of the tank
  146. gpu.setBackground(0x000000)
  147. gpu.fill(self.x + 1, self.y + 1, self.width - 2, self.height - fluidLevelHeight - 2, ' ')
  148.  
  149. -- Draw fluid name and amount
  150.  
  151. gpu.setForeground(0xFFFFFF)
  152. gpu.set(self.x-2, self.y - 1, "Fluid: " .. self.fluidName)
  153. gpu.set(self.x, self.y + self.height, "Amount: " .. self.fluidAmount .. " mB")
  154. end
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. -- Engine object
  163. local engine = {
  164.  
  165. body = {x = 100, y = 11, width = 1, height = 3, color = 0xFFFFFF},
  166. head = {x = 100+1, y = 11, width = 1, height = 3, color = 0xC0C0C0}, -- Silver (0xC0C0C0) or White (0xFFFFFF)
  167. core = {x = 100+1, y = 11+1, width = 4, height = 1, color = 0x8B4513},
  168. infoPanel = {x = 100+6, y = 11, width = 33, height = 14, color = 0xC0C0C0},
  169. }
  170.  
  171. engine_1_bank_1_temp = component.proxy(engine_1_bank_1).getFluidInTank(1)
  172. engine_1_bank_1_fuel = engine_1_bank_1_temp[1]
  173. engine_1_bank_1_coolant = engine_1_bank_1_temp[2]
  174. engine_2_bank_1_temp = component.proxy(engine_2_bank_1).getFluidInTank(1)
  175. engine_2_bank_1_fuel = engine_2_bank_1_temp[1]
  176. engine_2_bank_1_coolant = engine_2_bank_1_temp[2]
  177. engine_3_bank_1_temp = component.proxy(engine_3_bank_1).getFluidInTank(1)
  178. engine_3_bank_1_fuel = engine_3_bank_1_temp[1]
  179. engine_3_bank_1_coolant = engine_3_bank_1_temp[2]
  180. engine_4_bank_1_temp = component.proxy(engine_4_bank_1).getFluidInTank(1)
  181. engine_4_bank_1_fuel = engine_4_bank_1_temp[1]
  182. engine_4_bank_1_coolant = engine_4_bank_1_temp[2]
  183.  
  184.  
  185. engine_1_bank_2_temp = component.proxy(engine_1_bank_2).getFluidInTank(1)
  186. engine_1_bank_2_fuel = engine_1_bank_2_temp[1]
  187. engine_1_bank_2_coolant = engine_1_bank_2_temp[2]
  188. engine_2_bank_2_temp = component.proxy(engine_2_bank_2).getFluidInTank(1)
  189. engine_2_bank_2_fuel = engine_2_bank_2_temp[1]
  190. engine_2_bank_2_coolant = engine_2_bank_2_temp[2]
  191. engine_3_bank_2_temp = component.proxy(engine_3_bank_2).getFluidInTank(1)
  192. engine_3_bank_2_fuel = engine_3_bank_2_temp[1]
  193. engine_3_bank_2_coolant = engine_3_bank_2_temp[2]
  194. engine_4_bank_2_temp = component.proxy(engine_4_bank_2).getFluidInTank(1)
  195. engine_4_bank_2_fuel = engine_4_bank_2_temp[1]
  196. engine_4_bank_2_coolant = engine_4_bank_2_temp[2]
  197.  
  198.  
  199. -- Engine load
  200. function engine:load()
  201. self.core.x = engine.core.x
  202. self.core.y = engine.core.y
  203. self.body.x = engine.body.x
  204. self.body.y = engine.body.y
  205. self.head.x = engine.head.x
  206. self.head.y = engine.head.y
  207. self.infoPanelContent = engine.infoPanelContent
  208. self.infoPanel.x = engine.infoPanel.x
  209. self.infoPanel.y = engine.infoPanel.y
  210. end
  211.  
  212. function resetCycle()
  213. totalDischarge = 0
  214. totalCharge = 0
  215. dischargeCount = 0
  216. chargeCount = 0
  217. end
  218.  
  219.  
  220. -- Engine update
  221. function engine:update()
  222. if self.movement == nil then
  223. self.movement = 0
  224. self.direction = true
  225. end
  226.  
  227. if self.direction then
  228. self.head.x = self.head.x + 1
  229. else
  230. self.head.x = self.head.x - 1
  231. end
  232.  
  233. self.movement = self.movement + 1
  234.  
  235. if self.movement >= 3 then
  236. self.movement = 0
  237. self.direction = not self.direction
  238. resetCycle() -- Reset the cycle when the engine completes a cycle
  239. end
  240. engine_1_bank_1_temp = component.proxy(engine_1_bank_1).getFluidInTank(1)
  241. engine_1_bank_1_fuel = engine_1_bank_1_temp[1]
  242. engine_1_bank_1_coolant = engine_1_bank_1_temp[2]
  243. engine_2_bank_1_temp = component.proxy(engine_2_bank_1).getFluidInTank(1)
  244. engine_2_bank_1_fuel = engine_2_bank_1_temp[1]
  245. engine_2_bank_1_coolant = engine_2_bank_1_temp[2]
  246. engine_3_bank_1_temp = component.proxy(engine_3_bank_1).getFluidInTank(1)
  247. engine_3_bank_1_fuel = engine_3_bank_1_temp[1]
  248. engine_3_bank_1_coolant = engine_3_bank_1_temp[2]
  249. engine_4_bank_1_temp = component.proxy(engine_4_bank_1).getFluidInTank(1)
  250. engine_4_bank_1_fuel = engine_4_bank_1_temp[1]
  251. engine_4_bank_1_coolant = engine_4_bank_1_temp[2]
  252.  
  253.  
  254. engine_1_bank_2_temp = component.proxy(engine_1_bank_2).getFluidInTank(1)
  255. engine_1_bank_2_fuel = engine_1_bank_2_temp[1]
  256. engine_1_bank_2_coolant = engine_1_bank_2_temp[2]
  257. engine_2_bank_2_temp = component.proxy(engine_2_bank_2).getFluidInTank(1)
  258. engine_2_bank_2_fuel = engine_2_bank_2_temp[1]
  259. engine_2_bank_2_coolant = engine_2_bank_2_temp[2]
  260. engine_3_bank_2_temp = component.proxy(engine_3_bank_2).getFluidInTank(1)
  261. engine_3_bank_2_fuel = engine_3_bank_2_temp[1]
  262. engine_3_bank_2_coolant = engine_3_bank_2_temp[2]
  263. engine_4_bank_2_temp = component.proxy(engine_4_bank_2).getFluidInTank(1)
  264. engine_4_bank_2_fuel = engine_4_bank_2_temp[1]
  265. engine_4_bank_2_coolant = engine_4_bank_2_temp[2]
  266.  
  267.  
  268. end
  269.  
  270. -- Engine draw
  271. function engine:draw()
  272. -- Draw core
  273. gpu.setBackground(self.core.color)
  274. gpu.fill(self.core.x, self.core.y, self.core.width, self.core.height, ' ')
  275. -- Draw body
  276. gpu.setBackground(self.body.color)
  277. gpu.fill(self.body.x, self.body.y, self.body.width, self.body.height, ' ')
  278. -- Draw head
  279. gpu.setBackground(self.head.color)
  280. gpu.fill(self.head.x, self.head.y, self.head.width, self.head.height, ' ')
  281. gpu.setBackground(self.infoPanel.color)
  282. gpu.fill(self.infoPanel.x, self.infoPanel.y, self.infoPanel.width, self.infoPanel.height, ' ')
  283.  
  284. gpu.setForeground(0x228B22)
  285. term.setCursor(self.infoPanel.x+(self.infoPanel.width/2)-string.len("engine bank 1")/2, self.infoPanel.y)
  286. term.write("engine bank 1")
  287.  
  288. gpu.setForeground(0x000000)
  289.  
  290. term.setCursor(self.infoPanel.x+1, self.infoPanel.y+1)
  291. term.write("engine 1 fuel type:"..engine_1_bank_1_fuel.name)
  292.  
  293. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 1 fuel:")+5)/2, self.infoPanel.y+2)
  294. term.write("engine 1 fuel:"..engine_1_bank_1_fuel.amount)
  295.  
  296. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 1 coolant:")+5)/2, self.infoPanel.y+3)
  297. term.write("engine 1 coolant:"..engine_1_bank_1_coolant.amount)
  298.  
  299. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 2 fuel:")+5)/2, self.infoPanel.y+5)
  300. term.write("engine 2 fuel:"..engine_2_bank_1_fuel.amount)
  301.  
  302. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 2 coolant:")+5)/2, self.infoPanel.y+6)
  303. term.write("engine 2 coolant:"..engine_2_bank_1_coolant.amount)
  304.  
  305. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 3 fuel:")+5)/2, self.infoPanel.y+8)
  306. term.write("engine 3 fuel:"..engine_3_bank_1_fuel.amount)
  307.  
  308. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 3 coolant:")+5)/2, self.infoPanel.y+9)
  309. term.write("engine 3 coolant:"..engine_3_bank_1_coolant.amount)
  310.  
  311. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 4 fuel:")+5)/2, self.infoPanel.y+11)
  312. term.write("engine 4 fuel:"..engine_4_bank_1_fuel.amount)
  313.  
  314. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 4 coolant:")+5)/2, self.infoPanel.y+12)
  315. term.write("engine 4 coolant:"..engine_4_bank_1_coolant.amount)
  316.  
  317. gpu.setBackground(self.infoPanel.color)
  318. gpu.fill(self.infoPanel.x, self.infoPanel.y+self.infoPanel.height+1, self.infoPanel.width, self.infoPanel.height, ' ')
  319.  
  320. gpu.setForeground(0x228B22)
  321. term.setCursor(self.infoPanel.x+(self.infoPanel.width/2)-string.len("engine bank 2")/2, self.infoPanel.y+self.infoPanel.height+1)
  322. term.write("engine bank 2")
  323.  
  324. gpu.setForeground(0x000000)
  325.  
  326. term.setCursor(self.infoPanel.x+1, self.infoPanel.y+1+self.infoPanel.height+1)
  327. term.write("engine 1 fuel type:"..engine_1_bank_2_fuel.name)
  328.  
  329. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 1 fuel:")+5)/2, self.infoPanel.y+2+self.infoPanel.height+1)
  330. term.write("engine 1 fuel:"..engine_1_bank_2_fuel.amount)
  331.  
  332. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 1 coolant:")+5)/2, self.infoPanel.y+3+self.infoPanel.height+1)
  333. term.write("engine 1 coolant:"..engine_1_bank_2_coolant.amount)
  334.  
  335. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 2 fuel:")+5)/2, self.infoPanel.y+5+self.infoPanel.height+1)
  336. term.write("engine 2 fuel:"..engine_2_bank_2_fuel.amount)
  337.  
  338. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 2 coolant:")+5)/2, self.infoPanel.y+6+self.infoPanel.height+1)
  339. term.write("engine 2 coolant:"..engine_2_bank_2_coolant.amount)
  340.  
  341. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 3 fuel:")+5)/2, self.infoPanel.y+8+self.infoPanel.height+1)
  342. term.write("engine 3 fuel:"..engine_3_bank_2_fuel.amount)
  343.  
  344. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 3 coolant:")+5)/2, self.infoPanel.y+9+self.infoPanel.height+1)
  345. term.write("engine 3 coolant:"..engine_3_bank_2_coolant.amount)
  346.  
  347. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 4 fuel:")+5)/2, self.infoPanel.y+11+self.infoPanel.height+1)
  348. term.write("engine 4 fuel:"..engine_4_bank_2_fuel.amount)
  349.  
  350. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 4 coolant:")+5)/2, self.infoPanel.y+12+self.infoPanel.height+1)
  351. term.write("engine 4 coolant:"..engine_4_bank_2_coolant.amount)
  352.  
  353. -- Reset color to white
  354. gpu.setBackground(0xFFFFFF)
  355.  
  356.  
  357. end
  358.  
  359. local graph = {
  360. x = progressBar.x,
  361. y = progressBar.y + progressBar.height + 10,
  362. width = progressBar.width,
  363. height = 10,
  364. data = {},
  365. maxDataPoints = 100,
  366. }
  367.  
  368. -- Graph add data
  369. function graph:addData(value)
  370. table.insert(self.data, 1, value)
  371. if #self.data > self.maxDataPoints then
  372. table.remove(self.data)
  373. end
  374. end
  375.  
  376. -- Graph draw
  377. function graph:draw()
  378. -- Draw graph background
  379. gpu.setBackground(0x808080)
  380. gpu.fill(self.x, self.y, self.width, self.height, ' ')
  381.  
  382. -- Calculate scale and offset for mapping data to graph coordinates
  383. local minData = math.min(table.unpack(self.data))
  384. local maxData = math.max(table.unpack(self.data))
  385. local scale = (maxData - minData) / self.height
  386. local xOffset = self.width / (#self.data - 1)
  387.  
  388. -- Draw data points
  389. gpu.setBackground(0x00BFFF)
  390. for i = 2, #self.data do
  391. local x1 = self.x + (i - 2) * xOffset
  392. local x2 = self.x + (i - 1) * xOffset
  393. local y1 = self.y + self.height - math.floor((self.data[i - 1] - minData) / scale)
  394. local y2 = self.y + self.height - math.floor((self.data[i] - minData) / scale)
  395. gpu.fill(x1, y1, 1, 1, ' ')
  396. gpu.fill(x2, y2, 1, 1, ' ')
  397. gpu.fill(x1, y1, math.abs(x2 - x1) + 1, math.abs(y2 - y1) + 1, ' ')
  398. end
  399.  
  400. -- Reset color to white
  401. gpu.setBackground(0xFFFFFF)
  402. end
  403.  
  404.  
  405.  
  406.  
  407. -- Function to enable a specific bank of bundled wire outputs connected to engines
  408. local function enableWireBank(bank)
  409. component.redstone.setBundledOutput(3, bank, 255)
  410. end
  411.  
  412. -- Function to disable a specific bank of bundled wire outputs connected to engines
  413. local function disableWireBank(bank)
  414. component.redstone.setBundledOutput(3, bank, 0)
  415. end
  416.  
  417. -- Function to enable a specific bank of bundled wire outputs connected to fuel tank
  418. local function enableFuelPump(bank)
  419. component.redstone.setBundledOutput(1, bank, 255)
  420. end
  421.  
  422. -- Function to disable a specific bank of bundled wire outputs connected to engines
  423. local function disableFuelPump(bank)
  424. component.redstone.setBundledOutput(1, bank, 0)
  425. end
  426.  
  427. --[[
  428. ╔════════════════════════════╗
  429. ║ MAIN PROGRAM INITIALIZATION║
  430. ╚════════════════════════════╝
  431. --]]
  432. function load()
  433. maxEnergy = energyCube.getMaxEnergyStored()
  434. gpu.setResolution(160, 50) -- Set screen resolution
  435. progressBar:load(25, 6, 48, 5, maxEnergy) -- Initialize progress bar
  436. engine:load() -- Initialize engine
  437. --fluidTank:load()
  438. end
  439.  
  440. --[[
  441. ╔═══════════════════════╗
  442. ║ MAIN PROGRAM LOOP ║
  443. ╚═══════════════════════╝
  444. --]]
  445. local energySamples = {} -- Table to store energy samples
  446. local sampleRate = 10 -- Number of ticks between energy samples
  447. local maxSamples = 10 -- Maximum number of energy samples to keep
  448. local dischargeRate = 0 -- Energy discharge rate
  449. local chargeRate = 0 -- Energy charge rate
  450.  
  451. local sampleSize = 10 -- Number of samples to use when calculating average rates
  452. local chargeRateSamples = {} -- Table to store charge rate samples
  453. local dischargeRateSamples = {} -- Table to store discharge rate samples
  454.  
  455. function update()
  456. -- Check bundled inputs
  457. local orangeInput = component.redstone.getBundledInput(3, 1) or 0
  458. local whiteInput = component.redstone.getBundledInput(3, 0) or 0
  459.  
  460. -- Check if animation should run
  461. local shouldAnimate = orangeInput > 1 or whiteInput > 1
  462.  
  463. -- Update energy and progress bar
  464. energy = energyCube.getEnergyStored()
  465. progressBar:update(energy)
  466.  
  467. -- Calculate discharge and charge rates
  468. local currentTick = computer.uptime()
  469. local lastSample = energySamples[#energySamples]
  470. if lastSample then
  471. local deltaTime = currentTick - lastSample.tick
  472. local deltaEnergy = energy - lastSample.energy
  473.  
  474. if deltaTime > 0 then
  475. if deltaEnergy > 0 then
  476. chargeRate = deltaEnergy / deltaTime
  477. dischargeRate = 0
  478. elseif deltaEnergy < 0 then
  479. dischargeRate = -deltaEnergy / deltaTime
  480. chargeRate = 0
  481. end
  482. end
  483. if deltaEnergy > 0 then
  484. chargeRate = deltaEnergy / deltaTime
  485. totalCharge = totalCharge + chargeRate
  486. chargeCount = chargeCount + 1
  487. dischargeRate = 0
  488. elseif deltaEnergy < 0 then
  489. dischargeRate = -deltaEnergy / deltaTime
  490. totalDischarge = totalDischarge + dischargeRate
  491. dischargeCount = dischargeCount + 1
  492. chargeRate = 0
  493. end
  494. end
  495.  
  496. -- Store energy sample
  497. table.insert(energySamples, 1, { tick = currentTick, energy = energy })
  498. if #energySamples > maxSamples then
  499. table.remove(energySamples)
  500. end
  501.  
  502. if shouldAnimate then
  503. engine:update()
  504. end
  505.  
  506. -- Check thresholds and set bundled wire outputs
  507. if energy <= onThreshold then
  508. -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  509. enableWireBank(0)
  510. enableWireBank(1) -- Disable orange wire output
  511. elseif energy >= offThreshold then
  512. -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  513. disableWireBank(0) -- Disable orange wire output
  514. disableWireBank(1) -- Disable white wire output
  515.  
  516. end
  517. --fluidTank:update()
  518.  
  519. end
  520.  
  521.  
  522.  
  523. function draw()
  524. -- Clear screen
  525. gpu.setBackground(0x000000)
  526. gpu.setForeground(0xFFFFFF)
  527. gpu.fill(1, 1, 160, 50, ' ')
  528. progressBar:draw()
  529. gpu.setBackground(0x000000)
  530. gpu.setForeground(0xFFFFFF)
  531. gpu.set(progressBar.x, progressBar.y + progressBar.height + 1, "Current Energy: " .. tostring(energy))
  532. gpu.set(progressBar.x, progressBar.y + progressBar.height + 2, "Max Energy: " .. tostring(maxEnergy))
  533. engine:draw()
  534.  
  535. -- Render discharge and charge rates
  536. local boxX = 25
  537. local boxY = progressBar.y + progressBar.height + 5
  538. local boxWidth = 48
  539. local boxHeight = 10
  540. local averageDischarge = totalDischarge / (dischargeCount > 0 and dischargeCount or 1)
  541. local averageCharge = totalCharge / (chargeCount > 0 and chargeCount or 1)
  542.  
  543. -- Draw gray box
  544. gpu.setBackground(0x808080)
  545. gpu.fill(boxX, boxY, boxWidth, boxHeight, ' ')
  546.  
  547. local averageDischarge = totalDischarge / (dischargeCount > 0 and dischargeCount or 1)
  548. local averageCharge = totalCharge / (chargeCount > 0 and chargeCount or 1)
  549.  
  550. local averageDischargeText = string.format("Average Discharge Rate: %.2f RF/t", averageDischarge)
  551. gpu.setBackground(0x808080)
  552. gpu.setForeground(0xFFFFFF)
  553. gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  554.  
  555. local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
  556. gpu.setBackground(0x808080)
  557. gpu.setForeground(0xFFFFFF)
  558. gpu.set(boxX + 2, boxY + 4, averageChargeText)
  559.  
  560.  
  561. -- Render discharge rate
  562. local dischargeText = string.format("Discharge Rate: %.2f RF/t", dischargeRate)
  563. gpu.setBackground(0x808080)
  564. gpu.setForeground(0xFFFFFF)
  565. gpu.set(boxX + 2, boxY + 1, dischargeText)
  566.  
  567. -- Render charge rate
  568. local chargeText = string.format("Charge Rate: %.2f RF/t", chargeRate)
  569. gpu.setBackground(0x808080)
  570. gpu.setForeground(0xFFFFFF)
  571. gpu.set(boxX + 2, boxY + 2, chargeText)
  572. local averageDischargeText = string.format("Average Discharge Rate: %.2f RF/t", averageDischarge)
  573. gpu.setBackground(0x808080)
  574. gpu.setForeground(0xFFFFFF)
  575. gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  576.  
  577. local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
  578. gpu.setBackground(0x808080)
  579. gpu.setForeground(0xFFFFFF)
  580. gpu.set(boxX + 2, boxY + 4, averageChargeText)
  581. -- Reset color to white
  582. gpu.setBackground(0xFFFFFF)
  583. --fluidTank:draw()
  584. end
  585.  
  586. --[[
  587. ╔═══════════════════════════╗
  588. ║MAIN PROGRAM INITIALIZATION║
  589. ╚═══════════════════════════╝
  590. --]]
  591. function main()
  592. load()
  593. while true do
  594. update()
  595. draw()
  596. os.sleep(0.05) -- Wait for 0.1 seconds before updating again
  597. end
  598. end
  599.  
  600. -- Run the program
  601. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement