Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration
- local reactor_name = "fusionReactorLogicAdapter_1" -- Name of the reactor peripheral
- local alarm_side = "top" -- Face to send redstone if reactor is off
- local alarm_side2 = "back" -- Additional face to send redstone when reactor is off
- local start_side = "right" -- Face to send pulse to start the reactor (changed to right by default)
- local redstone_pulse_time = 1 -- Duration of the pulse in seconds
- -- Startup animation for console
- local function showStartupAnimation()
- term.clear()
- term.setCursorPos(1,1)
- print(" Fusion Reactor Controler by Le_Jiww")
- print(" [Developed for my bro: BigBlow]")
- print("")
- -- Loading animation
- io.write(" System initialization")
- for i = 1, 5 do
- io.write(".")
- sleep(0.2)
- end
- print("\n")
- sleep(0.5)
- -- Display startup information
- print(" > Connecting to fusion reactor...")
- sleep(0.3)
- print(" > Initializing monitor...")
- sleep(0.3)
- print(" > Configuring redstone signals...")
- sleep(0.5)
- print("\n [SYSTEM READY]")
- print("\n Reactor monitoring in progress...\n")
- end
- -- Execute startup animation
- showStartupAnimation()
- -- Monitor initialization
- local monitor = peripheral.find("monitor")
- if not monitor then
- error("No monitor detected")
- end
- -- Get screen dimensions
- local screen_width, screen_height = monitor.getSize()
- -- Reactor initialization
- local reactor = peripheral.wrap(reactor_name)
- if not reactor then
- error("Reactor not detected: " .. reactor_name)
- end
- monitor.clear()
- monitor.setTextScale(1)
- monitor.setTextColor(colors.white)
- -- Button coordinates (adjusted for better central position)
- local button_x1, button_y1 = 12, 12 -- Center position and lower down
- local button_x2, button_y2 = 28, 15
- -- Tracking variables
- local last_ignited = nil
- local ignition_in_progress = false -- Prevents double sending the signal
- local animation_frame = 0
- local pulse_animation = 0 -- Pulsing animation for activity indicator
- local rotation_animation = 0 -- Rotation animation for activity indicator
- -- Function to format numbers with spaces
- local function formatNumber(n)
- return tostring(n):reverse():gsub("(%d%d%d)", "%1 "):reverse():gsub("^ ", "")
- end
- -- Function to format large numbers with K, M, G, etc.
- local function formatCompact(n)
- if n >= 1000000000 then
- return string.format("%.2fG", n / 1000000000)
- elseif n >= 1000000 then
- return string.format("%.2fM", n / 1000000)
- elseif n >= 1000 then
- return string.format("%.2fK", n / 1000)
- else
- return string.format("%.1f", n)
- end
- end
- -- Characters for rotation animation
- local rotation_chars = {"|", "/", "-", "\\"}
- -- Function to update only the values (without redrawing the frames)
- local function updateReactorValues()
- if not reactor.isIgnited() then return end
- -- Get reactor data
- local production = reactor.getProductionRate()
- local productionRF = production / 2.5
- -- Variables for additional data
- local plasmaTemp, caseTemp, injectionRate, efficiency, fuel = nil, nil, nil, nil, nil
- -- Try to get plasma temperature
- local success, result = pcall(function() return reactor.getPlasmaTemperature() end)
- if success and result then plasmaTemp = result end
- -- Try to get case temperature
- success, result = pcall(function() return reactor.getCaseTemperature() end)
- if success and result then caseTemp = result end
- -- Try to get injection rate
- success, result = pcall(function() return reactor.getInjectionRate() end)
- if success and result then injectionRate = result end
- -- Try to get efficiency
- success, result = pcall(function() return reactor.getEfficiency() end)
- if success and result then
- efficiency = result
- else
- efficiency = math.min(98.5, 50 + productionRF / 50000)
- end
- -- Try to get fuel
- success, result = pcall(function() return reactor.getFuel() end)
- if success and result then fuel = result end
- -- Update values only (not labels)
- monitor.setBackgroundColor(colors.black)
- -- Update activity indicator (rotation animation)
- rotation_animation = (rotation_animation + 1) % 4
- local rotation_char = rotation_chars[rotation_animation + 1]
- monitor.setCursorPos(screen_width - 4, 2)
- monitor.setTextColor(colors.lime)
- monitor.write(rotation_char)
- -- 1. Energy production (update value only with slight variation for animation)
- local variation = math.random(-15, 15) / 10 -- Random variation of ±1.5%
- local displayedRF = productionRF * (1 + variation/100)
- monitor.setCursorPos(20, 10)
- monitor.setTextColor(colors.yellow)
- monitor.write(formatCompact(displayedRF).." RF/t ")
- -- 2. Efficiency (update value only with slight variation)
- local effVariation = math.random(-2, 2) / 10 -- Random variation of ±0.2%
- local displayedEff = efficiency + effVariation
- monitor.setCursorPos(20, 11)
- monitor.setTextColor(colors.yellow)
- monitor.write(string.format("%.1f%% ", displayedEff))
- -- Efficiency bar animation (pulsation)
- local bar_length = 18
- pulse_animation = (pulse_animation + 0.2) % 10
- local pulse_factor = 1 + math.sin(pulse_animation) * 0.05 -- Pulsing variation of ±5%
- local bar_progress = math.min(1, (productionRF * pulse_factor) / 1000000)
- local filled_length = math.floor(bar_progress * bar_length)
- monitor.setCursorPos(13, 12)
- for i = 1, bar_length do
- if i <= filled_length then
- if i >= bar_length - 1 and pulse_animation > 5 then
- monitor.setBackgroundColor(colors.yellow) -- Flashing overload effect
- else
- monitor.setBackgroundColor(colors.lime)
- end
- monitor.write(" ")
- else
- monitor.setBackgroundColor(colors.gray)
- monitor.write(" ")
- end
- end
- monitor.setBackgroundColor(colors.black)
- -- 3. Plasma temperature (if available, with animation)
- if plasmaTemp then
- local tempVariation = math.random(-50, 50) / 10 -- Random variation of ±5
- local displayedTemp = plasmaTemp / 1000000 + tempVariation/100
- monitor.setCursorPos(20, 13)
- monitor.setTextColor(colors.orange)
- monitor.write(string.format("%.2f MK ", displayedTemp))
- end
- -- 4. Injection rate (if available, with slight variation)
- if injectionRate then
- local injVariation = math.random(-5, 5) -- Random variation of ±5
- monitor.setCursorPos(20, 14)
- monitor.setTextColor(colors.yellow)
- monitor.write(string.format("%d mB/t ", injectionRate + injVariation))
- end
- -- 5. Fuel (if available, with simulated consumption)
- if fuel then
- monitor.setCursorPos(20, 15)
- monitor.setTextColor(colors.yellow)
- monitor.write(string.format("%d mB ", fuel))
- end
- -- Reset colors
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- end
- -- Definition of characters for borders
- local h_line = "\140" -- Horizontal line
- local v_line = "\149" -- Vertical line
- local tl_corner = "\151" -- Top left corner
- local tr_corner = "\152" -- Top right corner
- local bl_corner = "\154" -- Bottom left corner
- local br_corner = "\153" -- Bottom right corner
- -- Function to draw a box with border
- local function drawBox(x1, y1, x2, y2, bg_color, border_color)
- monitor.setBackgroundColor(bg_color or colors.black)
- monitor.setTextColor(border_color or colors.cyan)
- -- Corners
- monitor.setCursorPos(x1, y1)
- monitor.write(tl_corner)
- monitor.setCursorPos(x2, y1)
- monitor.write(tr_corner)
- monitor.setCursorPos(x1, y2)
- monitor.write(bl_corner)
- monitor.setCursorPos(x2, y2)
- monitor.write(br_corner)
- -- Horizontal lines
- for x = x1 + 1, x2 - 1 do
- monitor.setCursorPos(x, y1)
- monitor.write(h_line)
- monitor.setCursorPos(x, y2)
- monitor.write(h_line)
- end
- -- Vertical lines
- for y = y1 + 1, y2 - 1 do
- monitor.setCursorPos(x1, y)
- monitor.write(v_line)
- monitor.setCursorPos(x2, y)
- monitor.write(v_line)
- end
- -- Interior
- monitor.setBackgroundColor(bg_color or colors.black)
- for y = y1 + 1, y2 - 1 do
- monitor.setCursorPos(x1 + 1, y)
- for x = x1 + 1, x2 - 1 do
- monitor.write(" ")
- end
- end
- end
- -- Function to draw a centered title in a box
- local function drawTitle(text, x1, x2, y, color)
- local width = x2 - x1 - 1
- local text_x = x1 + math.floor((width - #text) / 2) + 1
- monitor.setTextColor(color or colors.yellow)
- monitor.setCursorPos(text_x, y)
- monitor.write(text)
- monitor.setTextColor(colors.white)
- end
- -- Function to display information
- local function displayInfo()
- local ignited = reactor.isIgnited()
- local should_redraw = (last_ignited ~= ignited) or (not last_ignited)
- -- Only animate the status icon, not the entire screen
- animation_frame = (animation_frame + 1) % 8
- -- Avoid redrawing the entire screen each time
- if not should_redraw then
- -- Selective update for animated elements only
- if ignited then
- -- Update only the flashing status with a more visible animation
- monitor.setCursorPos(13, 5)
- if animation_frame < 4 then
- monitor.setTextColor(colors.lime)
- monitor.write("IGNITED ")
- monitor.setTextColor(colors.yellow)
- monitor.write("*")
- else
- monitor.setTextColor(colors.green)
- monitor.write("IGNITED ")
- monitor.setTextColor(colors.orange)
- monitor.write("+")
- end
- -- Rotation animation in the upper right corner
- monitor.setCursorPos(screen_width - 4, 2)
- monitor.setTextColor(colors.lime)
- monitor.write(rotation_chars[(rotation_animation + 1) % 4 + 1])
- -- Update data without clearing the entire screen
- updateReactorValues()
- return
- end
- end
- -- Otherwise, redraw the entire screen
- monitor.clear()
- -- Big frame surrounding the entire screen
- drawBox(1, 1, screen_width, screen_height, colors.black, colors.blue)
- -- Title at the top with styling
- drawTitle("FUSION REACTOR CONTROL", 1, screen_width, 2, colors.yellow)
- -- Rotation animation in the upper right corner (program activity indicator)
- monitor.setCursorPos(screen_width - 4, 2)
- monitor.setTextColor(colors.lime)
- monitor.write(rotation_chars[(animation_frame % 4) + 1])
- -- Status box
- drawBox(3, 4, screen_width - 3, 6, colors.black, colors.cyan)
- drawTitle("REACTOR STATUS", 3, screen_width - 3, 4, colors.white)
- monitor.setCursorPos(5, 5)
- monitor.write("Status:")
- monitor.setCursorPos(13, 5)
- if ignited then
- -- Flashing animation for "IGNITED"
- if animation_frame < 4 then
- monitor.setTextColor(colors.lime)
- monitor.write("IGNITED ")
- monitor.setTextColor(colors.yellow)
- monitor.write("*")
- else
- monitor.setTextColor(colors.green)
- monitor.write("IGNITED ")
- monitor.setTextColor(colors.orange)
- monitor.write("+")
- end
- redstone.setOutput(alarm_side, false) -- Disable redstone on primary face
- redstone.setOutput(alarm_side2, false) -- Disable redstone on secondary face
- ignition_in_progress = false -- Reset state after ignition
- else
- monitor.setTextColor(colors.red)
- monitor.write("STOPPED")
- redstone.setOutput(alarm_side, true) -- Enable redstone on primary face
- redstone.setOutput(alarm_side2, true) -- Enable redstone on secondary face
- end
- -- Reset color to white
- monitor.setTextColor(colors.white)
- if ignited then
- -- Energy production box
- drawBox(3, 8, screen_width - 3, 16, colors.black, colors.cyan)
- monitor.setTextColor(colors.white)
- drawTitle("REACTOR TELEMETRY", 3, screen_width - 3, 8, colors.white)
- -- Get reactor data
- local production = reactor.getProductionRate()
- local productionRF = production / 2.5 -- Convert J to RF
- -- Let's try to get additional data (with error protection)
- local plasmaTemp, caseTemp, injectionRate, efficiency, fuel = nil, nil, nil, nil, nil
- -- Try to get temperature (may not be available depending on version)
- local success, result = pcall(function() return reactor.getPlasmaTemperature() end)
- if success and result then plasmaTemp = result end
- -- Try to get case temperature
- success, result = pcall(function() return reactor.getCaseTemperature() end)
- if success and result then caseTemp = result end
- -- Try to get injection rate
- success, result = pcall(function() return reactor.getInjectionRate() end)
- if success and result then injectionRate = result end
- -- Try to get efficiency
- success, result = pcall(function() return reactor.getEfficiency() end)
- if success and result then
- efficiency = result
- else
- -- Simulate an efficiency value based on production
- efficiency = math.min(98.5, 50 + productionRF / 50000)
- end
- -- Try to get fuel
- success, result = pcall(function() return reactor.getFuel() end)
- if success and result then fuel = result end
- -- Display data
- local line = 0
- -- 1. Energy production (with slight variation for animation)
- line = 10
- monitor.setCursorPos(5, line)
- monitor.write("Generation:")
- monitor.setCursorPos(20, line)
- monitor.setTextColor(colors.yellow)
- -- Add a slight variation to give the impression of change
- local variation = math.random(-15, 15) / 10 -- Random variation of ±1.5%
- local displayedRF = productionRF * (1 + variation/100)
- monitor.write(formatCompact(displayedRF).." RF/t")
- -- 2. Efficiency (with slight variation)
- line = 11
- monitor.setCursorPos(5, line)
- monitor.setTextColor(colors.white)
- monitor.write("Efficiency:")
- monitor.setCursorPos(20, line)
- monitor.setTextColor(colors.yellow)
- local effVariation = math.random(-2, 2) / 10 -- Random variation of ±0.2%
- monitor.write(string.format("%.1f%%", efficiency + effVariation))
- -- Visual production bar (with pulsation effect)
- line = 12
- monitor.setCursorPos(5, line)
- monitor.setTextColor(colors.white)
- monitor.write("Output:")
- local bar_length = 18
- pulse_animation = (pulse_animation + 0.2) % 10
- local pulse_factor = 1 + math.sin(pulse_animation) * 0.05 -- Pulsing variation of ±5%
- local bar_progress = math.min(1, (productionRF * pulse_factor) / 1000000) -- Scale to adjust
- local filled_length = math.floor(bar_progress * bar_length)
- monitor.setCursorPos(13, line)
- for i = 1, bar_length do
- if i <= filled_length then
- if i >= bar_length - 1 and pulse_animation > 5 then
- monitor.setBackgroundColor(colors.yellow) -- Flashing overload effect
- else
- monitor.setBackgroundColor(colors.lime)
- end
- monitor.write(" ")
- else
- monitor.setBackgroundColor(colors.gray)
- monitor.write(" ")
- end
- end
- monitor.setBackgroundColor(colors.black)
- -- 3. Plasma temperature (if available, with animation)
- if plasmaTemp then
- line = 13
- monitor.setCursorPos(5, line)
- monitor.setTextColor(colors.white)
- monitor.write("Plasma Temp:")
- monitor.setCursorPos(20, line)
- monitor.setTextColor(colors.orange)
- -- Add a variation to show that it changes
- local tempVariation = math.random(-50, 50) / 10 -- Random variation of ±5
- monitor.write(string.format("%.2f MK", plasmaTemp / 1000000 + tempVariation/100))
- end
- -- 4. Injection rate (if available, with slight variation)
- if injectionRate then
- line = 14
- monitor.setCursorPos(5, line)
- monitor.setTextColor(colors.white)
- monitor.write("Inj. Rate:")
- monitor.setCursorPos(20, line)
- monitor.setTextColor(colors.yellow)
- local injVariation = math.random(-5, 5) -- Random variation of ±5
- monitor.write(string.format("%d mB/t", injectionRate + injVariation))
- end
- -- 5. Fuel (if available, with simulated consumption)
- if fuel then
- line = 15
- monitor.setCursorPos(5, line)
- monitor.setTextColor(colors.white)
- monitor.write("Fuel:")
- monitor.setCursorPos(20, line)
- monitor.setTextColor(colors.yellow)
- monitor.write(string.format("%d mB", fuel))
- end
- else
- if ignition_in_progress then
- -- Information box during ignition with improved animation
- drawBox(3, 8, screen_width - 3, 15, colors.black, colors.cyan)
- drawTitle("IGNITION SEQUENCE", 3, screen_width - 3, 8, colors.white)
- -- More elaborate "Loading" animation with progress bars
- local progress_chars = {"[= ]", "[== ]", "[=== ]", "[==== ]",
- "[===== ]", "[====== ]", "[=======]", "[======= ]",
- "[===== ]", "[==== ]", "[=== ]", "[== ]",
- "[= ]", "[ ]"}
- local char = progress_chars[animation_frame % #progress_chars + 1]
- -- Status line with animation icon
- monitor.setCursorPos(5, 10)
- monitor.setTextColor(colors.yellow)
- monitor.write("Reactor ignition in progress")
- -- Animation on separate line
- monitor.setCursorPos(15, 11)
- monitor.write(char)
- monitor.setCursorPos(5, 13)
- monitor.setTextColor(colors.white)
- monitor.write("Please wait...")
- else
- -- Clear any previous UI elements in this area
- for y = 8, 16 do
- monitor.setCursorPos(3, y)
- monitor.setBackgroundColor(colors.black)
- for x = 3, screen_width - 3 do
- monitor.write(" ")
- end
- end
- -- Draw proper button centered on screen
- local button_color = colors.blue
- if animation_frame % 8 > 5 then
- button_color = colors.lightBlue -- Subtle flashing animation
- end
- -- Draw frame around button
- drawBox(button_x1 - 1, button_y1 - 1, button_x2 + 1, button_y2 + 1, colors.black, colors.gray)
- -- Fill button with color
- for y = button_y1, button_y2 do
- monitor.setCursorPos(button_x1, y)
- monitor.setBackgroundColor(button_color)
- for x = button_x1, button_x2 do
- monitor.write(" ")
- end
- end
- -- Button text
- local button_text = "START REACTOR"
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(button_x1 + math.floor((button_x2 - button_x1 - #button_text) / 2), button_y1 + 1)
- monitor.write(button_text)
- -- Reset background color
- monitor.setBackgroundColor(colors.black)
- end
- end
- -- Footer
- monitor.setTextColor(colors.lightGray)
- monitor.setCursorPos(3, screen_height - 1)
- monitor.write("Fusion Reactor Controler by Le_Jiww")
- -- Reset default colors
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- last_ignited = ignited
- end
- -- Function to handle button click
- local function checkTouch()
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- -- Check if we're in the right state to start the reactor
- if not reactor.isIgnited() and not ignition_in_progress then
- -- Improved button hit detection with better margins
- if x >= button_x1 - 1 and x <= button_x2 + 1 and y >= button_y1 - 1 and y <= button_y2 + 1 then
- -- Set "ignition in progress" state
- ignition_in_progress = true
- -- Log to console for debugging
- print("Button pressed - starting reactor ignition sequence")
- -- Visual effect for the click - change button color to cyan
- for y_pos = button_y1, button_y2 do
- monitor.setCursorPos(button_x1, y_pos)
- monitor.setBackgroundColor(colors.cyan)
- for x_pos = button_x1, button_x2 do
- monitor.write(" ")
- end
- end
- -- Button text
- local button_text = "STARTING..."
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(button_x1 + math.floor((button_x2 - button_x1 - #button_text) / 2), button_y1 + 1)
- monitor.write(button_text)
- sleep(0.2) -- Brief pause for visual effect
- -- Send redstone pulse on the chosen face
- redstone.setOutput(start_side, true)
- sleep(redstone_pulse_time)
- redstone.setOutput(start_side, false)
- -- Update display to show ignition sequence
- displayInfo()
- end
- end
- end
- end
- -- Information on console about how to restart
- print("Monitor interface initialized")
- print("Reactor startup configured to send redstone signal to: " .. start_side .. " face")
- print("Reactor stop signals configured for: " .. alarm_side .. " and " .. alarm_side2 .. " faces")
- print("Touch the START REACTOR button on monitor to activate the reactor")
- print("Running main loop...")
- -- Continuous update loop
- parallel.waitForAny(
- function()
- while true do
- displayInfo()
- sleep(0.25) -- Reduce delay for smoother animation
- end
- end,
- checkTouch
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement