Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- local monitor = peripheral.find("monitor")
- local running = true
- local paused = true -- Initially paused
- local direction = "bottom"
- local delay = 2
- local ingots = 0 -- Counter for the number of ingots smelted
- local targetIngots = nil -- Target number of ingots before shutdown (optional)
- -- Function to print current status
- local function printStatus()
- print("------ STATUS ------")
- print("DIRECTION: " .. string.upper(direction))
- print(string.format("DELAY: %.2f SECONDS", delay)) -- Display delay with 2 decimal places
- print("TARGET INGOTS: " .. (targetIngots and tostring(math.floor(targetIngots)) or "UNDEFINED")) -- Remove decimal places
- print("INGOTS SMELTED: " .. tostring(math.floor(ingots))) -- Remove decimal places
- print("--------------------")
- end
- local function printStatusMonitor()
- local idleMessage1 = "- IDLE-"
- local idleMessage2 = "-IDLE -"
- local smeltingMessage = " ---[ SMELTING ]---"
- local frame = 1
- while true do -- Keep the loop running to switch between animations
- monitor.clear()
- monitor.setCursorPos(1, 1)
- if targetIngots then
- monitor.write("INGOTS:")
- monitor.setCursorPos(1, 2)
- monitor.write(tostring(math.floor(ingots)) .. "/" .. tostring(math.floor(targetIngots))) -- Remove decimal places
- else
- monitor.write("INGOTS:")
- monitor.setCursorPos(1, 2)
- monitor.write(tostring(math.floor(ingots))) -- Remove decimal places
- end
- monitor.setCursorPos(1, 3)
- if paused then
- -- Idle Animation
- if frame == 1 then
- monitor.write(" \\ ")
- monitor.setCursorPos(1, 4)
- monitor.write(idleMessage1)
- monitor.setCursorPos(1, 5)
- monitor.write(" \\ ")
- elseif frame == 2 then
- monitor.write(" | ")
- monitor.setCursorPos(1, 4)
- monitor.write(idleMessage1)
- monitor.setCursorPos(1, 5)
- monitor.write(" | ")
- elseif frame == 3 then
- monitor.write(" / ")
- monitor.setCursorPos(1, 4)
- monitor.write(idleMessage2)
- monitor.setCursorPos(1, 5)
- monitor.write(" / ")
- elseif frame == 4 then
- monitor.write(" | ")
- monitor.setCursorPos(1, 4)
- monitor.write(idleMessage2)
- monitor.setCursorPos(1, 5)
- monitor.write(" | ")
- end
- else
- monitor.setCursorPos(1, 4)
- -- Animation for Smelt Mode (Scrolling Message)
- local displayMessage = smeltingMessage:sub(frame, frame + 15)
- monitor.write(displayMessage)
- frame = frame + 1
- if frame > #smeltingMessage then
- frame = 1
- end
- end
- -- Increment the frame and loop back to the start if necessary
- frame = frame + 1
- if paused and frame > 4 then
- frame = 1
- end
- sleep(0.2) -- Wait for 0.2 seconds
- end
- end
- -- Functions for Command Handling
- function handleStartCommand()
- write("Enter the target number of ingots to smelt (or press Enter to skip): ")
- targetIngots = tonumber(read()) or targetIngots
- paused = false
- print("Smelting initiated. The auto smelter is now running.")
- printStatus()
- end
- function handlePauseCommand()
- paused = true
- print("Smelting paused. The auto smelter is now idle.")
- printStatus()
- end
- function handleResumeCommand()
- paused = false
- print("Smelting resumed. The auto smelter is now running.")
- printStatus()
- end
- function handleExitCommand()
- running = false
- print("Exiting program. Goodbye!")
- end
- function handleStopCommand()
- paused = true
- ingots = 0
- print("Smelting stopped. The auto smelter is now idle.")
- printStatus()
- end
- function handleDirectionCommand()
- write("Enter the direction to output the redstone signal (top, bottom, left, right, front, back): ")
- local newDirection = read()
- if newDirection == "top" or newDirection == "bottom" or newDirection == "left" or newDirection == "right" or newDirection == "front" or newDirection == "back" then
- direction = newDirection
- print("Direction changed to " .. string.upper(direction) .. ".")
- printStatus()
- else
- print("INVALID DIRECTION. PLEASE TRY AGAIN.")
- end
- end
- function handleDelayCommand()
- write("Enter the delay in seconds between each redstone signal (or press Enter to skip): ")
- local newDelay = tonumber(read())
- if newDelay then
- delay = newDelay
- print("Delay changed to " .. delay .. " seconds.")
- printStatus()
- else
- print("INVALID DELAY. PLEASE TRY AGAIN.")
- end
- end
- function handleTargetCommand()
- write("Enter the target number of ingots to smelt (or press Enter to skip): ")
- local newTarget = tonumber(read())
- if newTarget then
- targetIngots = newTarget
- print("Target ingots changed to " .. targetIngots .. ".")
- printStatus()
- else
- print("INVALID TARGET. PLEASE TRY AGAIN.")
- end
- end
- function handleIngotsCommand()
- print("Ingots smelted: " .. ingots)
- end
- function handleHelpCommand()
- print("AVAILABLE COMMANDS:")
- print(" START - OPTIONAL SET TARGET: <start 10>")
- print(" PAUSE - SUSPEND SMELTING")
- print(" RESUME - ACTIVATE SMELTING")
- print(" STOP - RESET SMELTING")
- print(" STATUS - DISPLAY CURRENT STATUS")
- print(" DIRECTION - MODIFY SIGNAL DIRECTION")
- print(" DELAY - ADJUST TIME BETWEEN SMELTS")
- print(" TARGET - SET TARGET NUMBER OF INGOTS")
- print(" INGOTS - DISPLAY NUMBER OF INGOTS SMELTED")
- print(" HELP - DISPLAY THIS HELP MESSAGE")
- print(" EXIT - TERMINATE PROGRAM")
- end
- -- Function to handle redstone signal
- local function redstoneSignal()
- while running do
- if not paused then
- redstone.setOutput(direction, true)
- sleep(delay)
- redstone.setOutput(direction, false)
- sleep(delay)
- ingots = ingots + 1 -- Increment the ingot counter
- -- Check if target ingots reached
- if targetIngots and ingots >= targetIngots then
- print("TARGET INGOTS REACHED. TERMINATING PROGRAM.")
- running = false
- end
- else
- sleep(1) -- Wait a bit before checking pause status again
- end
- end
- end
- -- Welcome message
- print("==========================================")
- print("= WELCOME TO THE AUTOSMELTER CLOCK v1.0 =")
- print("= RARE Corp. =")
- print("==========================================")
- print("This program operates like a redstone clock.")
- print("Type 'start' to begin smelting.")
- print("Type 'pause' to pause the smelter.")
- print("Type 'help' to see all other commands.")
- print("------------------------------------------")
- printStatus()
- print("------------------------------------------")
- -- Start the redstone signal function in a separate thread
- parallel.waitForAny(
- redstoneSignal,
- printStatusMonitor,
- function()
- while running do
- write("ENTER COMMAND: ")
- local command = read()
- -- Command Handling
- if command == "start" then handleStartCommand()
- elseif command == "pause" then handlePauseCommand()
- elseif command == "resume" then handleResumeCommand()
- elseif command == "stop" then handleStopCommand()
- elseif command == "status" then printStatus()
- elseif command == "direction" then handleDirectionCommand()
- elseif command == "delay" then handleDelayCommand()
- elseif command == "target" then handleTargetCommand()
- elseif command == "ingots" then handleIngotsCommand()
- elseif command == "exit" then handleExitCommand()
- elseif command == "help" then handleHelpCommand()
- else print("UNKNOWN COMMAND. PLEASE TRY AGAIN.") end
- end
- end
- )
- -- Clean up and ensure redstone signal is off
- redstone.setOutput(direction, false)
- monitor.clear()
- print("System shutting down. Thank you for using the Auto Smelter Clock v1.0.")
- print("Total ingots smelted this session: " .. ingots) -- Display the final ingot count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement