poke5555

Untitled

Apr 4th, 2025
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. -- Function to load the fluid drawer ID from a file
  2. local function loadTankID()
  3. local file = fs.open("tank.txt", "r")
  4. if file then
  5. local id = file.readLine()
  6. file.close()
  7. return id
  8. end
  9. return nil
  10. end
  11.  
  12. -- Function to save the fluid drawer ID to a file
  13. local function saveTankID(id)
  14. local file = fs.open("tank.txt", "w")
  15. file.writeLine(id)
  16. file.close()
  17. end
  18.  
  19. -- Function to wrap the fluid drawer
  20. local function wrapFluidDrawer(id)
  21. local drawer = peripheral.wrap(id)
  22. if not drawer then
  23. return nil
  24. end
  25. return drawer
  26. end
  27.  
  28. -- Check if we already have the fluid drawer ID saved
  29. local tankID = loadTankID()
  30.  
  31. -- If the fluid drawer ID is not saved, ask the user to input it
  32. if not tankID then
  33. print("Please enter the full block ID of the fluid drawer (e.g. 'modid:blockid_69')")
  34. print("Please enter the correct full block ID of the tank (e.g. 'modid:blockid_69')")
  35. print("You can find this ID by right-clicking the modem.")
  36. tankID = read() -- User input for the full ID
  37. saveTankID(tankID) -- Save the ID for future use
  38. end
  39.  
  40. -- Attempt to wrap the peripheral to access the fluid drawer
  41. local drawer = wrapFluidDrawer(tankID)
  42.  
  43. -- If the fluid drawer is not found, prompt the user again until it is detected
  44. while not drawer do
  45. print("No fluid storage drawer found with ID: " .. tankID)
  46. print("Please enter the correct full block ID of the tank (e.g. 'modid:blockid_69')")
  47. print("You can find this ID by right-clicking the modem.")
  48. tankID = read() -- User input for the correct ID
  49. saveTankID(tankID) -- Save the ID for future use
  50. drawer = wrapFluidDrawer(tankID) -- Try wrapping the fluid drawer again
  51. end
  52.  
  53. -- Function to get the fluid amount in the first tank
  54. local function getFluidAmount()
  55. local tanks = drawer.tanks() -- Get the tanks in the drawer
  56. if tanks and tanks[1] then -- Check if the first tank exists
  57. return tanks[1].amount -- Return the fluid amount in the first tank
  58. end
  59. return 0 -- If no fluid is found, return 0
  60. end
  61.  
  62. term.clear()
  63.  
  64. -- Initialize the starting fluid amount and cycle count
  65. local startFluidAmount = getFluidAmount()
  66. local lastTime = os.clock() -- Time of the first reading
  67. local cycleCount = 0 -- Initialize cycle count
  68.  
  69. while true do
  70. -- Track time and update every second
  71. local currentTime = os.clock() -- Get current time
  72. local elapsedTime = currentTime - lastTime -- Time elapsed since last check
  73.  
  74. if elapsedTime >= 1 then -- If 1 second has passed
  75. -- Increment the cycle count every second
  76. cycleCount = cycleCount + 1
  77. lastTime = currentTime -- Reset the last time to current time
  78.  
  79. -- Get the current fluid amount
  80. local fluidAmount = getFluidAmount()
  81.  
  82. -- Calculate the fluid rate in mB/t (adjusting for elapsed time)
  83. local fluidRate = (fluidAmount - startFluidAmount) / cycleCount / 20 -- 20 ticks per second
  84. local formattedFluidRate = string.format("%.3f", fluidRate)
  85.  
  86. -- Print the current statistics
  87. term.setCursorPos(1, 1)
  88. print("Average fluid rate: " .. formattedFluidRate .. " mB/t")
  89. print("Elapsed time: " .. cycleCount .. " seconds")
  90. print("Starting fluid amount: " .. startFluidAmount .. " mB")
  91. print("Current fluid amount: " .. fluidAmount .. " mB")
  92. end
  93. end
  94.  
Advertisement
Add Comment
Please, Sign In to add comment