Advertisement
Corbinhol

Tree Farm Monitor

Nov 14th, 2022 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. --Tree Analyzer
  2.  
  3. local inventory = peripheral.wrap("back");
  4. function getAmount()
  5. return inventory.getItemDetail(2).count;
  6. end
  7.  
  8. local count = 1;
  9.  
  10. local oldAmount = getAmount();
  11. local newAmount = 0;
  12. local sum = 0;
  13. local average = 0;
  14.  
  15.  
  16.  
  17. function parseTime(timeInSeconds)
  18. if timeInSeconds < 60 then
  19. if timeInSeconds < 10 then return 0 .. timeInSeconds;
  20. else return timeInSeconds;
  21. end
  22. elseif timeInSeconds < 3600 then
  23. local minutes = math.floor(timeInSeconds / 60);
  24. local seconds = timeInSeconds % 60;
  25. if minutes < 10 then minutes = 0 .. minutes end
  26. if seconds < 10 then seconds = 0 .. seconds end
  27. return minutes .. ":" .. seconds;
  28. elseif timeInSeconds < 86400 then
  29. local hours = math.floor((timeInSeconds / 60) / 60)
  30. local minutes = math.floor((timeInSeconds / 60) % 60);
  31. local seconds = timeInSeconds % 60;
  32. if hours < 10 then hours = 0 .. hours end
  33. if minutes < 10 then minutes = 0 .. minutes end
  34. if seconds < 10 then seconds = 0 .. seconds end
  35. return hours .. ":" .. minutes .. ":" .. seconds;
  36. else
  37. local seconds = timeInSeconds % 60;
  38. local minutes = math.floor((timeInSeconds / 60) % 60);
  39. local hours = math.floor(((timeInSeconds / 60) / 60) % 24)
  40. local days = math.floor(((timeInSeconds / 60) / 60) / 24)
  41.  
  42. if days < 10 then days = 0 .. days end
  43. if hours < 10 then hours = 0 .. hours end
  44. if minutes < 10 then minutes = 0 .. minutes end
  45. if seconds < 10 then seconds = 0 .. seconds end
  46.  
  47. return days .. ":" .. hours .. ":" .. minutes .. ":" .. seconds;
  48. end
  49. end
  50.  
  51. term.clear();
  52. term.setCursorPos(1,1);
  53. term.write("Uptime: ");
  54. term.setCursorPos(1,2);
  55. term.write("Average Increase Per Second: ")
  56. term.setCursorPos(1,3);
  57. term.write("Amount Of Wood: ");
  58.  
  59. function updateScreen()
  60. term.setCursorPos(9, 1);
  61. term.write(parseTime(count));
  62. term.setCursorPos(30, 2);
  63. term.write(math.floor(average));
  64. term.setCursorPos(17,3);
  65. term.write(getAmount());
  66.  
  67. end
  68. while true do
  69. local dif = getAmount() - oldAmount;
  70. oldAmount = getAmount();
  71. sum = sum + dif;
  72. average = sum / count;
  73. sleep(1);
  74. updateScreen();
  75. count = count + 1;
  76.  
  77. end
  78.  
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement