April_The_Sergal

draconic reactor tweaks monitor revised

Feb 9th, 2026 (edited)
97
0
Never
6
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.66 KB | None | 0 0
  1. --peripheral config
  2. local sideGateOut = "right"
  3. local sideReactor = "back"
  4.  
  5. --output multiplier: set by modpack (default = 1.0), change this to the value of draconic evolution config (!!!not tested yet!!!)
  6. local outputMultiplier = 1.0
  7.  
  8.  
  9. --Do not change anything below
  10.  
  11.  
  12. local version = "1.0.2" --by electronx3
  13.  
  14. --constants
  15. local val_1div3 = 1.0/3.0
  16.  
  17.  
  18. --config
  19.  
  20. --emergency shutdown parameters
  21. local maxOvershoot = 200.0      --reactor will shutdown when temperature gets hotter than defaultTemp+maxOvershoot
  22. local minFuel = 0.05
  23.  
  24. --default parameters
  25. local defaultTemp = 8000.0
  26. local defaultField = 0.01
  27.  
  28. local maxTempInc = 400.0        --max. temperature increase per computer tick
  29. local maxOutflow = 16000000.0
  30.  
  31. local chargeInflow = 20000000
  32. local shutDownField = 0.1       --field strength while shutdown
  33.  
  34. local safeMode = true           --when set to false, the automatic emergency shutdown function is disabled
  35.  
  36.  
  37. --peripherals
  38. local reactor
  39. local gateIn
  40. local gateOut
  41. local mon
  42.  
  43. --info
  44. local info
  45.  
  46. local currentEmergency = false
  47. local currentField
  48. local currentFuel
  49.  
  50. local stableTicks = 0
  51. local screenPage = 0
  52. local openConfirmDialog = false
  53.  
  54. local manualStart = false
  55. local manualCharge = false
  56. local manualStop = false
  57.  
  58.  
  59. --the program
  60.  
  61. function updateInfo()
  62.     info = reactor.getReactorInfo()
  63.    
  64.     if info == nil or info == null then
  65.       error("Reactor has an invalid setup!")
  66.     end
  67.    
  68.     currentField = info.fieldStrength / info.maxFieldStrength
  69.     currentFuel = 1.0 - (info.fuelConversion / info.maxFuelConversion)
  70. end
  71.  
  72. function isEmergency()
  73.     currentEmergency = safeMode and not (info.temperature < 2000.0) and (info.status == "running" or info.status == "online" or info.status == "stopping") and (info.temperature > defaultTemp + maxOvershoot or currentField < 0.004 or currentFuel < minFuel)
  74.     return currentEmergency
  75. end
  76.  
  77. function calcInflow(targetStrength, fieldDrainRate)
  78.     return fieldDrainRate / (1.0 - targetStrength)
  79. end
  80.  
  81. --creators of the setupPeripherals function: https://github.com/acidjazz/drmon/blob/master/drmon.lua
  82. function setupPeripherals()
  83.     print("Setup peripherals...")
  84.     reactor = peripheral.wrap(sideReactor)
  85.     gateIn = periphSearch("flow_gate")
  86.     gateOut = peripheral.wrap(sideGateOut)
  87.    
  88.     if reactor == null then
  89.         error("No valid reactor was found!")
  90.     end
  91.     if gateIn == null then
  92.         error("No valid input fluxgate was found!")
  93.     end  
  94.     if gateOut == null then
  95.         error("No valid output fluxgate was found!")
  96.     end
  97.    
  98.     gateIn.setOverrideEnabled(true)
  99.     gateIn.setFlowOverride(0)
  100.     gateOut.setOverrideEnabled(true)
  101.     gateOut.setFlowOverride(0)
  102.    
  103.     local tmpMon = fetchPeriph("monitor")[1]
  104.     if tmpMon == null then
  105.         mon = null
  106.         print("WARN: No valid monitor was found!")
  107.  
  108.     else
  109.         monX, monY = tmpMon.getSize()
  110.         mon = {}
  111.         mon.monitor, mon.x, mon.y = tmpMon, monX, monY
  112.     end
  113.    
  114.     print("Done!")
  115. end
  116.  
  117. function periphSearch(type)
  118.     local names = peripheral.getNames()
  119.     local i, name
  120.     for i, name in pairs(names) do
  121.         if peripheral.getType(name) == type then
  122.             return peripheral.wrap(name)
  123.         end
  124.     end
  125.     return null
  126. end
  127.  
  128. function fetchPeriph(periphType)
  129.     local results = {}
  130.     local seen = {}
  131.  
  132.     for _, name in ipairs(peripheral.getNames()) do
  133.         if not seen[name] then
  134.             local pType = peripheral.getType(name)
  135.             if pType == "modem" then
  136.                 local modem = peripheral.wrap(name)
  137.                 if modem.isWireless and not modem.isWireless() and modem.getNamesRemote then
  138.                     for _, rName in ipairs(modem.getNamesRemote()) do
  139.                         if not seen[rName] and (periphType == nil or peripheral.getType(rName) == periphType) then
  140.                             seen[rName] = true
  141.                             table.insert(results, peripheral.wrap(rName))
  142.                         end
  143.                     end
  144.                 end
  145.             end
  146.             if periphType == nil or pType == periphType then
  147.                 seen[name] = true
  148.                 table.insert(results, peripheral.wrap(name))
  149.             end
  150.         end
  151.     end
  152.  
  153.     return results
  154. end
  155.  
  156. function clickListener()
  157.     if mon == null then
  158.         return
  159.     end
  160.    
  161.     while true do
  162.         event, side, xPos, yPos = os.pullEvent("monitor_touch")
  163.        
  164.         local cFlow = 0 --remove local later
  165.        
  166.         if yPos == mon.y and xPos >= 1 and xPos <= 4 then
  167.             openConfirmDialog = false
  168.             screenPage = (screenPage + 1) % 2
  169.         elseif screenPage == 1 then        
  170.             if yPos == 8 then
  171.                 local tmpTemp = defaultTemp
  172.            
  173.                 if xPos >= 2 and xPos <= 3 then
  174.                     tmpTemp = tmpTemp - 1.0
  175.                 elseif xPos >= 5 and xPos <= 6 then
  176.                     tmpTemp = tmpTemp - 10.0
  177.                 elseif xPos >= 9 and xPos <= 11 then
  178.                     tmpTemp = tmpTemp - 100.0
  179.                 elseif xPos >= 14 and xPos <= 16 then
  180.                     tmpTemp = 8000.0
  181.                 elseif xPos >= 19 and xPos <= 21 then
  182.                     tmpTemp = tmpTemp + 100.0
  183.                 elseif xPos >= 24 and xPos <= 25 then
  184.                     tmpTemp = tmpTemp + 10.0
  185.                 elseif xPos >= 27 and xPos <= 28 then
  186.                     tmpTemp = tmpTemp + 1.0
  187.                 end
  188.                
  189.                 if tmpTemp < 20.0 then
  190.                     tmpTemp = 20.0
  191.                 elseif tmpTemp > 20000.0 then
  192.                     tmpTemp = 20000.0
  193.                 end
  194.                
  195.                 defaultTemp = tmpTemp
  196.                 --print("new default temperature: " .. math.floor(defaultTemp) .. "°C")
  197.             elseif yPos == 12 then
  198.                 local tmpField = defaultField
  199.                
  200.                 if xPos >= 2 and xPos <= 3 then
  201.                     tmpField = tmpField - 0.001
  202.                 elseif xPos >= 5 and xPos <= 6 then
  203.                     tmpField = tmpField - 0.01
  204.                 elseif xPos >= 9 and xPos <= 11 then
  205.                     tmpField = tmpField - 0.1
  206.                 elseif xPos >= 14 and xPos <= 16 then
  207.                     tmpField = 0.01
  208.                 elseif xPos >= 19 and xPos <= 21 then
  209.                     tmpField = tmpField + 0.1
  210.                 elseif xPos >= 24 and xPos <= 25 then
  211.                     tmpField = tmpField + 0.01
  212.                 elseif xPos >= 27 and xPos <= 28 then
  213.                     tmpField = tmpField + 0.001
  214.                 end
  215.                
  216.                 if tmpField < 0.005 then
  217.                     tmpField = 0.005
  218.                 elseif tmpField > 0.6 then
  219.                     tmpField = 0.6
  220.                 end
  221.                
  222.                 defaultField = tmpField
  223.                 --print("new default field strength: " .. math.floor(defaultField*1000.0)/10.0 .. "%")
  224.             elseif yPos == 15 then             
  225.                 if openConfirmDialog then
  226.                     if xPos >= 25 and xPos <= 28 then
  227.                         openConfirmDialog = false
  228.                     elseif xPos >= 16 and xPos <= 22 then
  229.                         openConfirmDialog = false
  230.                         safeMode = false
  231.                         --print("WARN: Safe mode deactivated!")
  232.                     end
  233.                 elseif xPos >= 26 and xPos <= 28 then
  234.                     if safeMode then
  235.                         openConfirmDialog = true
  236.                     else
  237.                         safeMode = true
  238.                         --print("Safe mode activated!")
  239.                     end
  240.                 end
  241.             elseif yPos == 17 and info ~= null then
  242.                 if not currentEmergency then
  243.                     if (info.status == "running" or info.status == "online") and xPos >= 2 and xPos <= 5 then
  244.                         manualStop = true
  245.                     elseif (info.status == "cold" or info.status == "offline" or info.status == "cooling") and xPos >= 2 and xPos <= 7 then
  246.                         manualCharge = true
  247.                     elseif (info.status == "stopping" or info.status == "warming_up" or info.status == "charged") and xPos >= 2 and xPos <= 6 then
  248.                         manualStart = true
  249.                     elseif info.status == "warming_up" and xPos >= 9 and xPos <= 12 then
  250.                         manualStop = true
  251.                     end
  252.                 end
  253.                 if info.temperature < 2000.0 and xPos >= 26 and xPos <= 28 then
  254.                     print("Program stopped!")
  255.                     return
  256.                 end
  257.             end
  258.         end
  259.         saveConfig()
  260.     end
  261. end
  262.  
  263. --graphic stuff: inspired by https://github.com/acidjazz/drmon/blob/master/drmon.lua
  264. function gClear()
  265.   mon.monitor.setBackgroundColor(colors.black)
  266.   mon.monitor.clear()
  267.   mon.monitor.setCursorPos(1,1)
  268. end
  269. function gWrite(text, x, y, cl, clBg)
  270.     mon.monitor.setCursorPos(x, y)
  271.     mon.monitor.setTextColor(cl)
  272.     mon.monitor.setBackgroundColor(clBg)
  273.     mon.monitor.write(text)
  274. end
  275. function gWriteR(text, x, y, cl, clBg)
  276.     gWrite(text, mon.x - string.len(tostring(text)) - x, y, cl, clBg)
  277. end
  278. function gWriteLR(textL, textR, xL, xR, y, clL, clR, clBg)
  279.     gWrite(textL, xL, y, clL, clBg)
  280.     gWriteR(textR, xR, y, clR, clBg)
  281. end
  282. function gDrawLine(x, y, length, cl)
  283.     if length < 0 then
  284.         return
  285.     end
  286.     mon.monitor.setCursorPos(x, y)
  287.     mon.monitor.setBackgroundColor(cl)
  288.     mon.monitor.write(string.rep(" ", length))
  289. end
  290. function gDrawProgressBar(x, y, length, proportion, cl, clBg)
  291.     if proportion < 0.0 or proportion > 1.0 then
  292.         gDrawLine(x, y, length, cl)
  293.     else
  294.         gDrawLine(x, y, length, clBg)
  295.         gDrawLine(x, y, math.floor(proportion*length), cl)
  296.     end
  297. end
  298. function gDrawStandardProgressBar(y, proportion, cl)
  299.     gDrawProgressBar(2, y, mon.x-2, proportion, cl, colors.gray)
  300. end
  301.  
  302.  
  303. function update()
  304.     local newInflow = 0.0
  305.     local newOutflow = 0.0 
  306.    
  307.     while true do  
  308.         updateInfo()       
  309.         local isStable = false
  310.         local tmpShutDownField = math.max(shutDownField, defaultField)
  311.    
  312.         if peripheral.wrap(sideGateOut) == null then
  313.             reactor.stopReactor()
  314.             newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  315.             error("Output gate missing!")
  316.         end
  317.        
  318.         if manualStop then
  319.             manualStart = false
  320.             manualStop = false
  321.             manualCharge = false
  322.             reactor.stopReactor()
  323.         end
  324.        
  325.         if isEmergency() == true then
  326.             reactor.stopReactor()
  327.             newInflow = calcInflow(0.8, info.fieldDrainRate)
  328.             newOutflow = 0.0
  329.             manualStart = false
  330.             manualCharge = false
  331.         elseif info.status == "cold" or info.status == "offline" or info.status == "cooling" then
  332.             newInflow = 0.0
  333.             newOutflow = 0.0
  334.             if manualCharge then
  335.                 manualStart = false
  336.                 manualCharge = false
  337.                 reactor.chargeReactor()
  338.             end
  339.         elseif info.status == "charging" then
  340.             newInflow = chargeInflow
  341.             newOutflow = 0.0
  342.             manualStart = false
  343.             manualCharge = false
  344.         elseif info.status == "warming_up" or info.status == "charged" then
  345.             newInflow = chargeInflow
  346.             newOutflow = 0.0
  347.             if manualStart then
  348.                 manualStart = false
  349.                 manualCharge = false
  350.                 reactor.activateReactor()
  351.             end
  352.         elseif info.status == "running" or info.status == "online" then
  353.             manualStart = false
  354.             manualCharge = false
  355.             local temp = info.temperature
  356.            
  357.             if temp > defaultTemp - 6.0 and temp < defaultTemp + 5.0 then
  358.                 stableTicks = stableTicks + 1
  359.                 if stableTicks > 100 then
  360.                     isStable = true
  361.                 end
  362.             else
  363.                 stableTicks = 0
  364.             end
  365.        
  366.             if temp < defaultTemp then             
  367.                 local tempInc
  368.                 if temp < defaultTemp - 50.0 then
  369.                     tempInc = math.sqrt(defaultTemp - temp)
  370.                 elseif temp < defaultTemp - 0.5 then
  371.                     tempInc = math.sqrt(defaultTemp - temp)/2.0
  372.                 end
  373.            
  374.                 if tempInc == nil or tempInc < 0.0 then
  375.                     tempInc = 0
  376.                 elseif tempInc > maxTempInc then
  377.                     tempInc = maxTempInc
  378.                 end
  379.                
  380.                
  381.                 local t50 = temp/200.0
  382.                 local convLvl = (info.fuelConversion / info.maxFuelConversion)*1.3 - 0.3
  383.                
  384.                 local y = (t50^4)/(100.0-t50)*(1-convLvl) + 1000.0*(tempInc-convLvl) - 444.7
  385.                 local dSqrt = math.sqrt((50.0*y)^2 + (y/3.0)^3)
  386.                
  387.                 local x            
  388.                 local tmpValRoot = dSqrt - 50.0*y
  389.                 if tmpValRoot > 0.0 then
  390.                     x = math.pow(dSqrt + 50.0*y, val_1div3) - math.pow(tmpValRoot, val_1div3)
  391.                 else
  392.                     x = math.pow(dSqrt + 50.0*y, val_1div3) + math.pow(0.0-tmpValRoot, val_1div3)
  393.                 end
  394.                
  395.                 newOutflow = info.maxEnergySaturation*x/99.0 + info.energySaturation - info.maxEnergySaturation
  396.                 if newOutflow > maxOutflow then
  397.                     newOutflow = maxOutflow
  398.                 end
  399.             else
  400.                 newOutflow = 0.0
  401.             end
  402.        
  403.             if isStable == true then
  404.                 if currentField > defaultField + 0.05 then
  405.                     newInflow = 0.0
  406.                 elseif currentField > defaultField*1.2 then
  407.                     newInflow = calcInflow(defaultField*0.98, info.fieldDrainRate)
  408.                 elseif currentField > defaultField*0.97 then
  409.                     newInflow = calcInflow(defaultField, info.fieldDrainRate)
  410.                 else
  411.                     newInflow = calcInflow(defaultField*1.5, info.fieldDrainRate)
  412.                 end
  413.             else
  414.                 if currentField > tmpShutDownField then
  415.                     newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  416.                 else
  417.                     newInflow = calcInflow(tmpShutDownField*1.2, info.fieldDrainRate)
  418.                 end
  419.             end
  420.         elseif info.status == "stopping" then
  421.             if currentField > tmpShutDownField then
  422.                 newInflow = calcInflow(tmpShutDownField, info.fieldDrainRate)
  423.             else
  424.                 newInflow = calcInflow(tmpShutDownField*1.2, info.fieldDrainRate)
  425.             end
  426.             newOutflow = 0.0
  427.            
  428.             if manualStart then
  429.                 manualStart = false
  430.                 manualCharge = false
  431.                 reactor.activateReactor()
  432.             end
  433.         end
  434.        
  435.         if newInflow < 0.0 then
  436.             newInflow = 0.0
  437.         end
  438.         if newOutflow < 0.0 then
  439.             newOutflow = 0.0
  440.         end
  441.        
  442.         if newInflow > 0.0 then
  443.             newInflow = math.floor(newInflow)
  444.         else
  445.             newInflow = 0
  446.         end
  447.         local outflowMultiplied = 0
  448.         if newOutflow > 0.0 then
  449.             outflowMultiplied = math.floor(newOutflow*outputMultiplier)
  450.         else
  451.             newOutflow = 0.0
  452.         end
  453.         gateIn.setFlowOverride(newInflow)
  454.         gateOut.setFlowOverride(outflowMultiplied)
  455.        
  456.        
  457.         if mon ~= null then
  458.             gClear()
  459.            
  460.             if screenPage == 0 then
  461.                 local clTemp
  462.                 if info.temperature < defaultTemp*0.95 then
  463.                     clTemp = colors.green
  464.                 elseif info.temperature < defaultTemp + 1.0 then
  465.                     clTemp = colors.yellow
  466.                 elseif info.temperature < defaultTemp + maxOvershoot then
  467.                     clTemp = colors.orange
  468.                 else
  469.                     clTemp = colors.red
  470.                 end
  471.                
  472.                 gWriteLR("temperature:", math.floor(info.temperature*10.0)/10.0 .. "°C", 2, 0, 7, colors.white, clTemp, colors.black)
  473.                 gWriteLR("set: " .. math.floor(defaultTemp) .. "°C", "max: " .. math.floor(defaultTemp + maxOvershoot) .. "°C", 2, 0, 8, colors.white, colors.white, colors.black)
  474.                 gDrawStandardProgressBar(9, info.temperature/16000.0, clTemp)              
  475.                
  476.                 local clField
  477.                 if currentField > defaultField*1.05 then
  478.                     clField = colors.green
  479.                 elseif currentField > defaultField*0.95 then
  480.                     clField = colors.yellow
  481.                 else
  482.                     clField = colors.red
  483.                 end
  484.                
  485.                 gWriteLR("field strength:", math.floor(currentField*10000.0)/100.0 .. "%", 2, 0, 11, colors.white, clField, colors.black)
  486.                 gWriteLR("set: " .. math.floor(defaultField*1000)/10.0 .. "%", "min: 0.4%", 2, 0, 12, colors.white, colors.white, colors.black)
  487.                 gDrawStandardProgressBar(13, currentField, clField)
  488.                
  489.                 gWriteLR("status", info.status:upper(), 2, 0, 15, colors.white, colors.white, colors.black)
  490.                
  491.                 local clFuel
  492.                 if currentFuel > 0.15 then
  493.                     clFuel = colors.green
  494.                 elseif currentFuel > 0.05 then
  495.                     clFuel = colors.yellow
  496.                 elseif currentFuel > 0.01 then
  497.                     clFuel = colors.orange
  498.                 else
  499.                     clFuel = colors.red
  500.                 end
  501.                 gWriteLR("fuel:", math.floor(currentFuel*10000.0)/100.0 .. "%", 2, 0, 16, colors.white, clFuel, colors.black)
  502.             elseif screenPage == 1 then
  503.                 local clTemp
  504.                 if info.temperature < defaultTemp*0.95 then
  505.                     clTemp = colors.green
  506.                 elseif info.temperature < defaultTemp + 1.0 then
  507.                     clTemp = colors.yellow
  508.                 elseif info.temperature < defaultTemp + maxOvershoot then
  509.                     clTemp = colors.orange
  510.                 else
  511.                     clTemp = colors.red
  512.                 end
  513.                
  514.                 gWriteLR("temp: " .. math.floor(defaultTemp) .. " (" .. math.floor(defaultTemp + maxOvershoot) .. ")", math.floor(info.temperature*10.0)/10.0 .. "°C", 2, 0, 7, colors.white, clTemp, colors.black)
  515.                 gDrawStandardProgressBar(9, info.temperature/16000.0, clTemp)
  516.                
  517.                 gWrite("<", 2, 8, colors.white, colors.blue)
  518.                 gWrite("<<", 5, 8, colors.white, colors.blue)
  519.                 gWrite("<<<", 9, 8, colors.white, colors.blue)
  520.                 gWrite("res", 14, 8, colors.white, colors.blue)
  521.                 gWrite(">>>", 19, 8, colors.white, colors.blue)
  522.                 gWrite(">>", 24, 8, colors.white, colors.blue)
  523.                 gWrite(">", 28, 8, colors.white, colors.blue)              
  524.                
  525.                 local clField
  526.                 if currentField > defaultField*1.05 then
  527.                     clField = colors.green
  528.                 elseif currentField > defaultField*0.95 then
  529.                     clField = colors.yellow
  530.                 else
  531.                     clField = colors.red
  532.                 end
  533.                
  534.                 gWriteLR("field: " .. math.floor(defaultField*1000)/10.0 .. "% (0.4%)", math.floor(currentField*10000.0)/100.0 .. "%", 2, 0, 11, colors.white, clField, colors.black)
  535.                 gDrawStandardProgressBar(13, currentField, clField)
  536.                
  537.                 gWrite("<", 2, 12, colors.white, colors.blue)
  538.                 gWrite("<<", 5, 12, colors.white, colors.blue)
  539.                 gWrite("<<<", 9, 12, colors.white, colors.blue)
  540.                 gWrite("res", 14, 12, colors.white, colors.blue)
  541.                 gWrite(">>>", 19, 12, colors.white, colors.blue)
  542.                 gWrite(">>", 24, 12, colors.white, colors.blue)
  543.                 gWrite(">", 28, 12, colors.white, colors.blue)
  544.                
  545.                 if safeMode then
  546.                     if openConfirmDialog then
  547.                         gWrite("DISABLE?", 2, 15, colors.white, colors.black)
  548.                         gWrite("CONFIRM", 16, 15, colors.white, colors.green)
  549.                         gWrite("EXIT", 25, 15, colors.white, colors.red)
  550.                     else
  551.                         gWrite("safe mode:", 2, 15, colors.white, colors.black)
  552.                         gWrite("ON", 27, 15, colors.green, colors.black)
  553.                     end
  554.                 else
  555.                     gWrite("safe mode:", 2, 15, colors.white, colors.black)
  556.                     gWrite("OFF", 26, 15, colors.red, colors.black)
  557.                 end
  558.                
  559.                 if not currentEmergency then
  560.                     if info.status == "running" or info.status == "online" then
  561.                         gWrite("STOP", 2, 17, colors.white, colors.red)
  562.                     elseif info.status == "cold" or info.status == "offline" or info.status == "cooling" then
  563.                         gWrite("CHARGE", 2, 17, colors.white, colors.blue)
  564.                     elseif info.status == "stopping" or info.status == "charged" then
  565.                         gWrite("START", 2, 17, colors.white, colors.green)
  566.                     elseif info.status == "warming_up" then
  567.                         gWrite("START", 2, 17, colors.white, colors.green)
  568.                         gWrite("STOP", 9, 17, colors.white, colors.red)
  569.                     end
  570.                 end
  571.                
  572.                 if info.temperature < 2000.0 then
  573.                     gWrite("END", 26, 17, colors.white, colors.red)
  574.                 end
  575.             end
  576.            
  577.             gWriteLR("Draconic Control", "v" .. version, 2, 0, 1, colors.white, colors.white, colors.black)        
  578.            
  579.             gWriteLR("inflow:", newInflow .. " RF/t", 2, 0, 3, colors.white, colors.white, colors.black)
  580.             gWriteLR("outflow:", outflowMultiplied .. " RF/t", 2, 0, 4, colors.white, colors.white, colors.black)      
  581.             local gain = outflowMultiplied - newInflow
  582.             if gain > 0.0 then
  583.                 gWriteLR("-> gain:", gain .. " RF/t", 2, 0, 5, colors.white, colors.green, colors.black)
  584.             elseif gain < 0.0 then
  585.                 gWriteLR("-> gain:", gain .. " RF/t", 2, 0, 5, colors.white, colors.red, colors.black)
  586.             elseif gain == 0.0 then
  587.                 gWriteLR("-> gain:", "0 RF/t", 2, 0, 5, colors.white, colors.white, colors.black)
  588.             end
  589.            
  590.             gDrawLine(1, mon.y, 4, colors.gray)
  591.         end
  592.        
  593.         sleep(0.02)
  594.     end
  595. end
  596.  
  597. function setup()
  598.     term.clear()
  599.     print("Starting program...")   
  600.    
  601.     if fs.exists("config.txt") then
  602.         print("Loading config...")
  603.         loadConfig()
  604.         print("Done!")
  605.     else
  606.         print("Creating config...")
  607.         saveConfig()
  608.         print("Done!")
  609.     end
  610.  
  611.     if chargeInflow < 0 then
  612.         chargeInflow = 0
  613.     end
  614.    
  615.     stableTicks = 0
  616.    
  617.     setupPeripherals()
  618.     print("Started!")
  619. end
  620.  
  621. function saveConfig()
  622.     local config = fs.open("config.txt", "w")
  623.     config.writeLine(outputMultiplier*1000000.0)
  624.     config.writeLine(maxOvershoot)
  625.     config.writeLine(minFuel*100.0)
  626.     config.writeLine(defaultTemp)
  627.     config.writeLine(defaultField*1000.0)
  628.     config.writeLine(maxTempInc)
  629.     config.writeLine(maxOutflow)
  630.     config.writeLine(chargeInflow)
  631.     config.writeLine(shutDownField*1000.0)
  632.     config.close()
  633. end
  634. function loadConfig()
  635.     local config = fs.open("config.txt", "r")
  636.     outputMultiplier = tonumber(config.readLine())/1000000.0
  637.     maxOvershoot = tonumber(config.readLine())
  638.     minFuel = tonumber(config.readLine())/100.0
  639.     defaultTemp = tonumber(config.readLine())
  640.     defaultField = tonumber(config.readLine())/1000.0
  641.     maxTempInc = tonumber(config.readLine())
  642.     maxOutflow = tonumber(config.readLine())
  643.     chargeInflow = tonumber(config.readLine())
  644.     shutDownField = tonumber(config.readLine())/1000.0
  645.     config.close()
  646. end
  647.  
  648. function main()
  649.     setup()
  650.     if mon == null then
  651.         update()
  652.     else
  653.         parallel.waitForAny(update, clickListener)
  654.         gClear()
  655.         gWrite("Program stopped!", 1, 1, colors.white, colors.black)
  656.     end
  657. end
  658.  
  659. main()
Tags: minecraft lua
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment