Advertisement
davedumas0

buildcraft refinercontrol

Jul 31st, 2024
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.54 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local gpu = component.gpu
  4. local rs = component.redstone
  5. local modem = component.modem
  6.  
  7. -- Ensure the correct path to ButtonAPI.lua and ProgressBarAPI.lua
  8. local ButtonAPI = require("button")
  9. local ProgressBarAPI = require("ProgressBarAPI")
  10.  
  11. local Button = ButtonAPI
  12. local HandleClick = ButtonAPI.handleClick
  13. local SendCommand = ButtonAPI.sendCommand
  14. local ProgressBar = ProgressBarAPI.ProgressBar
  15.  
  16. local RsAddress = "b1e4214b-ab41-44c3-938a-13d4cb71f66f"
  17. local BatchSize = 4000 -- 4 buckets
  18. local ScreenSize = {x = 160, y = 50}
  19. local Temp_1 = component.getPrimary("tank_controller")
  20. local Temp_2 = Temp_1.address
  21.  
  22. -- UI Elements
  23. local Panels = {}
  24. Buttons = {}
  25. local ToggleStates = {["Heat Exchanger"] = false, ["Distillery"] = false}
  26. local CommandInProgress = false
  27.  
  28. local Colors = {
  29.     white = 0xffffff,
  30.     orange = 0xff6600,
  31.     magenta = 0xff00ff,
  32.     lightblue = 0x0099ff,
  33.     yellow = 0xffff00,
  34.     lime = 0x00ff00,
  35.     pink = 0xff3399,
  36.     gray = 0x737373,
  37.     lightgray = 0xa5a5a5,
  38.     silver = 0xc0c0c0,
  39.     cyan = 0x169c9d,
  40.     purple = 0x8932b7,
  41.     blue = 0x3c44a9,
  42.     brown = 0x825432,
  43.     green = 0x5d7c15,
  44.     red = 0xb02e26,
  45.     lightred = 0xffcccb,
  46.     lightorange = 0xbd8817,
  47.     black = 0x000000
  48. }
  49.  
  50. -- Function to set the primary tank controller
  51. function SetPrimaryTankController()
  52.     local currentPrimary = component.getPrimary("tank_controller")
  53.     if currentPrimary.address ~= PrimerTankAddress then
  54.         component.setPrimary("tank_controller", PrimerTankAddress)
  55.     end
  56. end
  57. SetPrimaryTankController()
  58.  
  59. -- This is a building with both a distiller and a heat exchanger
  60. local refinery = {
  61.     heatExchanger = {
  62.         isRunning = false,
  63.         productionData = {
  64.             ticksInOperation = 0,
  65.             totalFluidsheated = 0,
  66.             totalFluidsCooled = 0,
  67.             fluidsProcessed = {
  68.                 oil = {cool = 0, hot = 0, searing = 0},
  69.                 mixedLightFuels = {cool = 0, hot = 0, searing = 0},
  70.                 denseOil = {cool = 0, hot = 0, searing = 0},
  71.                 denseFuel = {cool = 0, hot = 0, searing = 0},
  72.                 lightFuel = {cool = 0, hot = 0, searing = 0},
  73.                 gaseousFuel = {cool = 0, hot = 0, searing = 0},
  74.                 residue = {cool = 0, hot = 0, searing = 0}
  75.             }
  76.         },
  77.         inputTank = {
  78.             allowedFluids = {
  79.                 oil = {cool = true, hot = true, searing = false},
  80.                 mixedLightFuels = {cool = false, hot = true, searing = false},
  81.                 denseOil = {cool = false, hot = true, searing = true},
  82.                 denseFuel = {cool = false, hot = true, searing = true}
  83.                 },
  84.             tankAddress = "53fecb07-0c2c-436b-8b2b-54e78dbd221c",
  85.             side = 4
  86.         },
  87.         outputTank = {
  88.            
  89.             tankAddress = "88f8bbd9-d711-45bd-8299-6f26d463e7a0",
  90.             side = 4
  91.         },
  92.         heatingMediumInputTank = {
  93.             allowedFluids = {
  94.                 oil = {cool = true, hot = true, searing = false},
  95.                 mixedLightFuels = {cool = false, hot = true, searing = false},
  96.                 denseOil = {cool = false, hot = true, searing = true},
  97.                 denseFuel = {cool = false, hot = true, searing = true}
  98.                 },
  99.             tankAddress = "88f8bbd9-d711-45bd-8299-6f26d463e7a0",
  100.             side = 5
  101.         },
  102.         heatingMediumOutputTank = {
  103.             worldPos = {},
  104.             tankAddress = "53fecb07-0c2c-436b-8b2b-54e78dbd221c",
  105.             side = 5
  106.         },
  107.         primerTank = {
  108.             worldPos = {x = -370, y = -206, z = 68},
  109.             tankAddress = "fda585ee-ebd3-4adf-a25c-928287641fd6",
  110.             side = 1
  111.         },
  112.         controls = {
  113.             enable = {rsSide = 2, bundleCableCannel = 1},
  114.             enablePrimerTank = {rsSide = 5, bundleCableChannel = 2},
  115.             enableVoidPrimer = {rsSide = 2, bundleCableChannel = 1}
  116.         }
  117.     },
  118.     distilery = {
  119.         isRunning = false,
  120.         inputTank = {
  121.             allowedFluids = {
  122.                 oil = {cool = false, hot = true, searing = false},
  123.                 mixedLightFuels = {cool = true, hot = false, searing = false},
  124.                 denseOil = {cool = false, hot = false, searing = true},
  125.                 },
  126.             worldPos = {x = -361, y = -198, z = 69, facing = 3, capacity = 4000}
  127.         },
  128.         outputTank1 = {
  129.             worldPos = {x = -361, y = -197, z = 69, facing = 5, capacity = 4000}
  130.         },
  131.         outputTank2 = {
  132.             worldPos = {x = -361, y = -197, z = 69, facing = 4, capacity = 4000}
  133.         },
  134.         productionData = {
  135.             ticksInOperation = 0,
  136.             totalFluidsProcessed = 0,
  137.             fluidsProcessed = {
  138.                 oil = {cool = 0, hot = 0, searing = 0},
  139.                 mixedLightFuels = {cool = 0, hot = 0, searing = 0},
  140.                 denseOil = {cool = 0, hot = 0, searing = 0}
  141.             },
  142.             fluidsProduced = {
  143.                 denseFuel = 0,
  144.                 lightFuel = 0,
  145.                 gaseousFuel = 0,
  146.                 residue = 0
  147.             }
  148.         },
  149.     }
  150. }
  151.  
  152. local storageTanks = {
  153.     mixedLightFuelsTanks = {
  154.         controllerAddress = "b8cc58b8-af0e-4873-b896-8597f4a4af6e",
  155.         hot_MixedFuelsTank = {pos = {x = -363, y = -213, z = 73}, side = 4},
  156.         cool_MixedFuelsTank = {pos = {x = -365, y = -213, z = 73}, side = 5},
  157.     },
  158.     refinedMixedLightFuels = {
  159.         controllerAddress = "a447a51d-b80f-4bd2-b58a-12934791eb4e",
  160.         cool_lightFuel = {pos = {x = -361, y = -213, z = 73}, side = 4},
  161.         cool_gaseousFuel = {pos = {x = -359, y = -213, z = 73}, side = 5},
  162.         cool_denseFuel = {pos = {x = -359, y = -213, z = 73}, side = 3}
  163.     },
  164.     denseFuels = {
  165.         controllerAddress = "07403ada-4b52-4fc5-a250-f5d398230a09",
  166.         hot_denseOil = {pos = {x = -361, y = -213, z = 73}, side = 4},
  167.         searing_denseFuel = {pos = {x = -355, y = -213, z = 73}, side = 5},
  168.         searing_residue = {pos = {x = -356, y = -214, z = 73}, side = 2}
  169.     },
  170.  
  171. }
  172.  
  173. -- Path definitions for the robot
  174. local RobotPaths = {
  175.     FromCoolOilToPrimer = {
  176.         Tank = {pos = {x = -373, y = -199, z = 68}},
  177.         PrimerTank = {pos = {x = -370, y = -206, z = 68}},
  178.         direction = 2,
  179.         path = {
  180.             [1] = {forward = 8, turnRight = 1},
  181.             [2] = {forward = 3, turnRight = 1},
  182.             [3] = {forward = 2}
  183.         }
  184.     },
  185.     FromPrimerToMixedLightFuelsHotTank = {
  186.         PrimerTank = {pos = {x = -370, y = -206, z = 68}},
  187.         HotMixedFuelsTank = {pos = {x = -363, y = -213, z = 73}},
  188.         direction = 2,
  189.         path = {
  190.             [1] = {up = 5, forward = 8, turnRight = 1},
  191.             [2] = {forward = 7, turnRight = 1}
  192.         }
  193.     },
  194.     FromMixedLightFuelsHotTankToMediumInput = {
  195.         MediumInputTank = {pos = {x = -366, y = -192, z = 71}},
  196.         HotMixedFuelsTank = {pos = {x = -363, y = -213, z = 73}},
  197.         direction = 2,
  198.         path = {
  199.             [1] = {up = 1, forward = 16, turnLeft = 1},
  200.             [2] = {forward = 2, down = 2},
  201.             [3] = {turnaround = 1, forward = 5, turnLeft = 1},
  202.             [4] = {forward = 5, down = 1}
  203.         }
  204.     },
  205.     FromMediumInputToMediumOutput = {
  206.         MediumInputTank = {pos = {x = -366, y = -192, z = 71}},
  207.         MediumOutputTank = {pos = {x = -366, y = -200, z = 71}},
  208.         direction = 2,
  209.         path = {
  210.             [1] = {turnaround = 1, forward = 8}
  211.         }
  212.     },
  213.     FromMediumInputToMixedLightFuelsCoolTank = {
  214.         MediumInputTank = {pos = {x = -366, y = -192, z = 71}},
  215.         CoolMixedFuelsTank = {pos = {x = -365, y = -213, z = 73}},
  216.         direction = 2,
  217.         path = {
  218.             [1] = {forward = 13, turnRight = 1},
  219.             [2] = {up = 2, forward = 4, turnRight = 1}
  220.         }
  221.     },
  222.     FromMixedLightFuelsCoolTankToDistillerInput = {
  223.         CoolMixedFuelsTank = {pos = {x = -365, y = -213, z = 73}},
  224.         DistillerInput = {pos = {x = -361, y = -198, z = 69}},
  225.         direction = 3,
  226.         path = {
  227.             [1] = {forward = 11, up = 1},
  228.             [2] = {forward = 4, down = 5, turnaround = 1},
  229.             [3] = {forward = 1, turnRight = 1},
  230.             [4] = {forward = 1, turnRight = 1}
  231.         }
  232.     }
  233. }
  234.  
  235.  
  236.  
  237.  
  238. -- Initialize the screen
  239. function InitScreen()
  240.     gpu.setResolution(ScreenSize.x, ScreenSize.y)
  241.     gpu.fill(1, 1, ScreenSize.x, ScreenSize.y, " ")
  242. end
  243.  
  244. -- Function to create a panel
  245. function CreatePanel(x, y, width, height, title)
  246.     table.insert(Panels, {x = x, y = y, width = width, height = height, title = title})
  247.     DrawPanel(#Panels)
  248. end
  249.  
  250. -- Function to draw a panel
  251. function DrawPanel(index)
  252.     local panel = Panels[index]
  253.     gpu.setBackground(0x333333)
  254.     gpu.fill(panel.x, panel.y, panel.width, panel.height, " ")
  255.     gpu.setBackground(0x000000)
  256.     gpu.set(panel.x + 1, panel.y, panel.title)
  257. end
  258.  
  259. -- Function to create a button using Button API
  260. function CreateButton(label, x, y, width, height, onClick, bgColor, fgColor)
  261.     local button = Button.new(label, x, y, width, height, onClick, bgColor, fgColor)
  262.     button:draw()
  263.     table.insert(Buttons, button)
  264. end
  265.  
  266. function GetTankData(tank, side)
  267.     local a = component.getPrimary("tank_controller")
  268.     if tank == a.address then
  269.         local theTank = component.tank_controller
  270.         local fluidData = theTank.getFluidInTank(side)
  271.         return fluidData[1]
  272.     else
  273.         local theTank = component.proxy(tank)
  274.         local fluidData = theTank.getFluidInTank(side)
  275.         return fluidData[1]
  276.     end
  277. end
  278.  
  279. -- Function to update heat exchanger production data
  280. function UpdateHeatExchangerProductionData(x, y)
  281.     local data = refinery.heatExchanger.productionData
  282.     gpu.set(x + 1, y + 1, "Ticks in Operation: " .. data.ticksInOperation)
  283.     gpu.set(x + 1, y + 2, "Total Fluids Heated: " .. data.totalFluidsheated .. "mB")
  284.     gpu.set(x + 1, y + 3, "Total Fluids Cooled: " .. data.totalFluidsCooled .. "mB")
  285. end
  286.  
  287. -- Function to update distillery production data
  288. function UpdateDistilleryProductionData(x, y)
  289.     local data = refinery.distilery.productionData
  290.     gpu.set(x + 1, y + 1, "Ticks in Operation: " .. data.ticksInOperation)
  291.     gpu.set(x + 1, y + 2, "Total Fluids Processed: " .. data.totalFluidsProcessed .. "mB")
  292.     gpu.set(x + 1, y + 3, "Fluids Produced:")
  293.     gpu.set(x + 2, y + 4, "Dense Fuel: " .. data.fluidsProduced.denseFuel .. "mB")
  294.     gpu.set(x + 2, y + 5, "Light Fuel: " .. data.fluidsProduced.lightFuel .. "mB")
  295.     gpu.set(x + 2, y + 6, "Gaseous Fuel: " .. data.fluidsProduced.gaseousFuel .. "mB")
  296.     gpu.set(x + 2, y + 7, "Residue: " .. data.fluidsProduced.residue .. "mB")
  297. end
  298.  
  299. -- Function to draw a simple real-time graph (placeholder)
  300. function DrawGraph(x, y, title)
  301.     gpu.setBackground(0x000000)
  302.     gpu.fill(x + 1, y + 1, 48, 8, " ") -- Clear graph area
  303.     -- Example of drawing a simple graph (replace with actual graph logic)
  304.     gpu.setForeground(0x00FF00)
  305.     for i = 1, 48 do
  306.         gpu.set(x + i, y + math.random(1, 8), "*")
  307.     end
  308.     gpu.setForeground(0xFFFFFF)
  309. end
  310.  
  311. -- Toggle function for heat exchanger production data panel
  312. function ToggleHeatExchangerPanel()
  313.     ToggleStates["Heat Exchanger"] = not ToggleStates["Heat Exchanger"]
  314. end
  315.  
  316. -- Toggle function for distillery production data panel
  317. function ToggleDistilleryPanel()
  318.     ToggleStates["Distillery"] = not ToggleStates["Distillery"]
  319. end
  320.  
  321. -- Example button callbacks
  322. function StartHeatExchanger()
  323.     -- Add the functionality to start the heat exchanger
  324. end
  325.  
  326. function LoadPrimerTank()
  327.    
  328. end
  329.  
  330. function CreatePrimerTankProgBar()
  331.     local tankData = GetTankData(refinery.heatExchanger.primerTank.tankAddress, refinery.heatExchanger.primerTank.side)
  332.     local progBar = ProgressBarAPI:new(5, 25, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "primer tank", "below")
  333.     return progBar
  334. end
  335.  
  336. function CreateCoolMixedLightFuelsProBar()
  337.     local tankData = GetTankData(storageTanks.mixedLightFuelsTanks.controllerAddress, storageTanks.mixedLightFuelsTanks.cool_MixedFuelsTank.side)
  338.     local ProgBar = ProgressBarAPI:new(5, 28, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "mixed fuels hot", "below")
  339.     return ProgBar
  340. end
  341.  
  342. function CreateHotMixedLightFuelsProBar()
  343.     local tankData = GetTankData(storageTanks.mixedLightFuelsTanks.controllerAddress, storageTanks.mixedLightFuelsTanks.cool_MixedFuelsTank.side)
  344.     local ProgBar = ProgressBarAPI:new(5, 31, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "mixed fuels cool", "below")
  345.     return ProgBar
  346. end
  347.  
  348. function CreateCoolLightFuelProBar()
  349.     local tankData = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_lightFuel.side)
  350.     local ProgBar = ProgressBarAPI:new(5, 34, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "light fuel cool", "below")
  351.     return ProgBar
  352. end
  353.  
  354. function CreateCoolGaseousFuelProBar()
  355.     local tankData = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_gaseousFuel.side)
  356.     local ProgBar = ProgressBarAPI:new(5, 37, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "gaseous fuel cool", "below")
  357.     return ProgBar
  358. end
  359.  
  360. function CreateCoolDenseFuelProBar()
  361.     local tankData = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_gaseousFuel.side)
  362.     local ProgBar = ProgressBarAPI:new(5, 40, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "dense fuel cool", "below")
  363.     return ProgBar
  364. end
  365.  
  366. function CreateHotDenseOilProBar()
  367.     local tankData = GetTankData(storageTanks.denseFuels.controllerAddress, storageTanks.denseFuels.hot_denseOil.side)
  368.     local ProgBar = ProgressBarAPI:new(5, 43, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "dense oil hot", "below")
  369.     return ProgBar
  370. end
  371.  
  372. function CreateSearingDenseFuelProBar()
  373.     local tankData = GetTankData(storageTanks.denseFuels.controllerAddress, storageTanks.denseFuels.searing_denseFuel.side)
  374.     local ProgBar = ProgressBarAPI:new(5, 46, 50, tankData.capacity, Colors.green, Colors.gray, Colors.lime, "horizontal", "forward", "dense fuel searing", "below")
  375.     return ProgBar
  376. end
  377.  
  378. function OpenComms()
  379.     modem.open(123)
  380. end
  381.  
  382. -- Initialize the screen
  383. InitScreen()
  384. CreatePanel(2, 2, 50, 10, "Heat Exchanger")
  385. CreatePanel(2, 14, 50, 10, "Distillery")
  386. CreatePanel(60, 14, 50, 10, "Heat Exchanger Production Data")
  387. CreatePanel(60, 26, 50, 10, "Distillery Production Data")
  388. CreateButton("Start Heat Exchanger", 60, 2, 22, 3, StartHeatExchanger)
  389. CreateButton("Load Primer Tank", 60, 6, 20, 3, LoadPrimerTank)
  390. CreateButton("Toggle HX Panel", 60, 38, 20, 3, ToggleHeatExchangerPanel) -- Button for toggling heat exchanger panel
  391. CreateButton("Toggle Dist Panel", 60, 42, 20, 3, ToggleDistilleryPanel) -- Button for toggling distillery panel
  392.  
  393. ProgBar_PrimerTank = CreatePrimerTankProgBar()
  394. ProgBar_HotMixedLightFuels = CreateHotMixedLightFuelsProBar()
  395. ProgBar_CoolMixedLightFuels = CreateCoolMixedLightFuelsProBar()
  396. ProgBar_CoolLightFuel = CreateCoolLightFuelProBar()
  397. ProgBar_CoolGaseousFuel = CreateCoolGaseousFuelProBar()
  398. ProgBar_CoolDenseFuel = CreateCoolDenseFuelProBar()
  399. ProgBar_HotDenseOil = CreateHotDenseOilProBar()
  400. ProgBar_SearingDenseFuel = CreateSearingDenseFuelProBar()
  401.  
  402. function ButtonCheck(buttonTable)
  403.     for i = 1, #buttonTable do
  404.         local eventData = {event.pull(0.01)}
  405.         if eventData[1] == "touch" then
  406.             if eventData[3] >= buttonTable[i].x and eventData[3] < buttonTable[i].x + buttonTable[i].width and eventData[4] >= buttonTable[i].y and eventData[4] < buttonTable[i].y + buttonTable[i].height then
  407.                 buttonTable[i].onClick()
  408.             end
  409.         end
  410.     end
  411. end
  412.  
  413. while true do
  414.     local temp_3 = GetTankData(refinery.heatExchanger.primerTank.tankAddress, refinery.heatExchanger.primerTank.side)
  415.     local temp_4 = GetTankData(storageTanks.mixedLightFuelsTanks.controllerAddress, storageTanks.mixedLightFuelsTanks.cool_MixedFuelsTank.side)
  416.     local temp_5 = GetTankData(storageTanks.mixedLightFuelsTanks.controllerAddress, storageTanks.mixedLightFuelsTanks.hot_MixedFuelsTank.side)
  417.     local temp_6 = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_lightFuel.side)
  418.     local temp_7 = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_gaseousFuel.side)
  419.     local temp_8 = GetTankData(storageTanks.refinedMixedLightFuels.controllerAddress, storageTanks.refinedMixedLightFuels.cool_denseFuel.side)
  420.     local temp_9 = GetTankData(storageTanks.denseFuels.controllerAddress, storageTanks.denseFuels.hot_denseOil.side)
  421.     local temp_10 = GetTankData(storageTanks.denseFuels.controllerAddress, storageTanks.denseFuels.searing_denseFuel.side)
  422.  
  423.     ProgBar_PrimerTank:update(temp_3.amount)
  424.     ProgBar_HotMixedLightFuels:update(temp_4.amount)  
  425.     ProgBar_CoolMixedLightFuels:update(temp_5.amount)
  426.     ProgBar_CoolLightFuel:update(temp_6.amount)
  427.     ProgBar_CoolGaseousFuel:update(temp_7.amount)  
  428.     ProgBar_CoolDenseFuel:update(temp_8.amount)
  429.     ProgBar_HotDenseOil:update(temp_9.amount)
  430.     ProgBar_SearingDenseFuel:update(temp_10.amount)
  431.     ButtonCheck(Buttons)
  432.     --os.sleep(0.01)
  433. end
  434.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement