Advertisement
Mojokojo69

AUTOSMELTER CLOCK

Aug 21st, 2023 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. -- Variables
  2. local monitor = peripheral.find("monitor")
  3. local running = true
  4. local paused = true -- Initially paused
  5. local direction = "bottom"
  6. local delay = 2
  7. local ingots = 0 -- Counter for the number of ingots smelted
  8. local targetIngots = nil -- Target number of ingots before shutdown (optional)
  9.  
  10.  
  11. -- Function to print current status
  12. local function printStatus()
  13. print("------ STATUS ------")
  14. print("DIRECTION: " .. string.upper(direction))
  15. print(string.format("DELAY: %.2f SECONDS", delay)) -- Display delay with 2 decimal places
  16. print("TARGET INGOTS: " .. (targetIngots and tostring(math.floor(targetIngots)) or "UNDEFINED")) -- Remove decimal places
  17. print("INGOTS SMELTED: " .. tostring(math.floor(ingots))) -- Remove decimal places
  18. print("--------------------")
  19. end
  20.  
  21. local function printStatusMonitor()
  22. local idleMessage1 = "- IDLE-"
  23. local idleMessage2 = "-IDLE -"
  24. local smeltingMessage = " ---[ SMELTING ]---"
  25. local frame = 1
  26. while true do -- Keep the loop running to switch between animations
  27. monitor.clear()
  28. monitor.setCursorPos(1, 1)
  29. if targetIngots then
  30. monitor.write("INGOTS:")
  31. monitor.setCursorPos(1, 2)
  32. monitor.write(tostring(math.floor(ingots)) .. "/" .. tostring(math.floor(targetIngots))) -- Remove decimal places
  33. else
  34. monitor.write("INGOTS:")
  35. monitor.setCursorPos(1, 2)
  36. monitor.write(tostring(math.floor(ingots))) -- Remove decimal places
  37. end
  38.  
  39. monitor.setCursorPos(1, 3)
  40. if paused then
  41. -- Idle Animation
  42. if frame == 1 then
  43. monitor.write(" \\ ")
  44. monitor.setCursorPos(1, 4)
  45. monitor.write(idleMessage1)
  46. monitor.setCursorPos(1, 5)
  47. monitor.write(" \\ ")
  48. elseif frame == 2 then
  49. monitor.write(" | ")
  50. monitor.setCursorPos(1, 4)
  51. monitor.write(idleMessage1)
  52. monitor.setCursorPos(1, 5)
  53. monitor.write(" | ")
  54. elseif frame == 3 then
  55. monitor.write(" / ")
  56. monitor.setCursorPos(1, 4)
  57. monitor.write(idleMessage2)
  58. monitor.setCursorPos(1, 5)
  59. monitor.write(" / ")
  60. elseif frame == 4 then
  61. monitor.write(" | ")
  62. monitor.setCursorPos(1, 4)
  63. monitor.write(idleMessage2)
  64. monitor.setCursorPos(1, 5)
  65. monitor.write(" | ")
  66. end
  67. else
  68. monitor.setCursorPos(1, 4)
  69. -- Animation for Smelt Mode (Scrolling Message)
  70. local displayMessage = smeltingMessage:sub(frame, frame + 15)
  71. monitor.write(displayMessage)
  72. frame = frame + 1
  73. if frame > #smeltingMessage then
  74. frame = 1
  75. end
  76. end
  77.  
  78. -- Increment the frame and loop back to the start if necessary
  79. frame = frame + 1
  80. if paused and frame > 4 then
  81. frame = 1
  82. end
  83.  
  84. sleep(0.2) -- Wait for 0.2 seconds
  85. end
  86. end
  87.  
  88.  
  89. -- Functions for Command Handling
  90. function handleStartCommand()
  91. write("Enter the target number of ingots to smelt (or press Enter to skip): ")
  92. targetIngots = tonumber(read()) or targetIngots
  93. paused = false
  94. print("Smelting initiated. The auto smelter is now running.")
  95. printStatus()
  96. end
  97.  
  98. function handlePauseCommand()
  99. paused = true
  100. print("Smelting paused. The auto smelter is now idle.")
  101. printStatus()
  102. end
  103.  
  104. function handleResumeCommand()
  105. paused = false
  106. print("Smelting resumed. The auto smelter is now running.")
  107. printStatus()
  108. end
  109.  
  110. function handleExitCommand()
  111. running = false
  112. print("Exiting program. Goodbye!")
  113. end
  114.  
  115. function handleStopCommand()
  116. paused = true
  117. ingots = 0
  118. print("Smelting stopped. The auto smelter is now idle.")
  119. printStatus()
  120. end
  121.  
  122. function handleDirectionCommand()
  123. write("Enter the direction to output the redstone signal (top, bottom, left, right, front, back): ")
  124. local newDirection = read()
  125. if newDirection == "top" or newDirection == "bottom" or newDirection == "left" or newDirection == "right" or newDirection == "front" or newDirection == "back" then
  126. direction = newDirection
  127. print("Direction changed to " .. string.upper(direction) .. ".")
  128. printStatus()
  129. else
  130. print("INVALID DIRECTION. PLEASE TRY AGAIN.")
  131. end
  132. end
  133.  
  134. function handleDelayCommand()
  135. write("Enter the delay in seconds between each redstone signal (or press Enter to skip): ")
  136. local newDelay = tonumber(read())
  137. if newDelay then
  138. delay = newDelay
  139. print("Delay changed to " .. delay .. " seconds.")
  140. printStatus()
  141. else
  142. print("INVALID DELAY. PLEASE TRY AGAIN.")
  143. end
  144. end
  145.  
  146. function handleTargetCommand()
  147. write("Enter the target number of ingots to smelt (or press Enter to skip): ")
  148. local newTarget = tonumber(read())
  149. if newTarget then
  150. targetIngots = newTarget
  151. print("Target ingots changed to " .. targetIngots .. ".")
  152. printStatus()
  153. else
  154. print("INVALID TARGET. PLEASE TRY AGAIN.")
  155. end
  156. end
  157.  
  158. function handleIngotsCommand()
  159. print("Ingots smelted: " .. ingots)
  160. end
  161.  
  162. function handleHelpCommand()
  163. print("AVAILABLE COMMANDS:")
  164. print(" START - OPTIONAL SET TARGET: <start 10>")
  165. print(" PAUSE - SUSPEND SMELTING")
  166. print(" RESUME - ACTIVATE SMELTING")
  167. print(" STOP - RESET SMELTING")
  168. print(" STATUS - DISPLAY CURRENT STATUS")
  169. print(" DIRECTION - MODIFY SIGNAL DIRECTION")
  170. print(" DELAY - ADJUST TIME BETWEEN SMELTS")
  171. print(" TARGET - SET TARGET NUMBER OF INGOTS")
  172. print(" INGOTS - DISPLAY NUMBER OF INGOTS SMELTED")
  173. print(" HELP - DISPLAY THIS HELP MESSAGE")
  174. print(" EXIT - TERMINATE PROGRAM")
  175. end
  176.  
  177. -- Function to handle redstone signal
  178. local function redstoneSignal()
  179. while running do
  180. if not paused then
  181. redstone.setOutput(direction, true)
  182. sleep(delay)
  183. redstone.setOutput(direction, false)
  184. sleep(delay)
  185. ingots = ingots + 1 -- Increment the ingot counter
  186. -- Check if target ingots reached
  187. if targetIngots and ingots >= targetIngots then
  188. print("TARGET INGOTS REACHED. TERMINATING PROGRAM.")
  189. running = false
  190. end
  191. else
  192. sleep(1) -- Wait a bit before checking pause status again
  193. end
  194. end
  195. end
  196.  
  197. -- Welcome message
  198. print("==========================================")
  199. print("= WELCOME TO THE AUTOSMELTER CLOCK v1.0 =")
  200. print("= RARE Corp. =")
  201. print("==========================================")
  202. print("This program operates like a redstone clock.")
  203. print("Type 'start' to begin smelting.")
  204. print("Type 'pause' to pause the smelter.")
  205. print("Type 'help' to see all other commands.")
  206. print("------------------------------------------")
  207. printStatus()
  208. print("------------------------------------------")
  209.  
  210. -- Start the redstone signal function in a separate thread
  211. parallel.waitForAny(
  212. redstoneSignal,
  213. printStatusMonitor,
  214. function()
  215. while running do
  216. write("ENTER COMMAND: ")
  217. local command = read()
  218.  
  219. -- Command Handling
  220. if command == "start" then handleStartCommand()
  221. elseif command == "pause" then handlePauseCommand()
  222. elseif command == "resume" then handleResumeCommand()
  223. elseif command == "stop" then handleStopCommand()
  224. elseif command == "status" then printStatus()
  225. elseif command == "direction" then handleDirectionCommand()
  226. elseif command == "delay" then handleDelayCommand()
  227. elseif command == "target" then handleTargetCommand()
  228. elseif command == "ingots" then handleIngotsCommand()
  229. elseif command == "exit" then handleExitCommand()
  230. elseif command == "help" then handleHelpCommand()
  231. else print("UNKNOWN COMMAND. PLEASE TRY AGAIN.") end
  232. end
  233. end
  234. )
  235.  
  236. -- Clean up and ensure redstone signal is off
  237. redstone.setOutput(direction, false)
  238. monitor.clear()
  239. print("System shutting down. Thank you for using the Auto Smelter Clock v1.0.")
  240. print("Total ingots smelted this session: " .. ingots) -- Display the final ingot count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement