Margresse404

AE2_interaction_program

Jun 15th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. --Monitors stuff
  2. local monitors
  3. monitors = peripheral.wrap("left")
  4. function resetColors()
  5. monitors.setTextColor(colors.white)
  6. monitors.setBackgroundColor(colors.black)
  7. end
  8.  
  9. --Loading screen
  10. monitors.clear()
  11. monitors.setCursorPos(1,1)
  12. monitors.write("Loading....")
  13.  
  14.  
  15. local AE2
  16. AE2 = peripheral.wrap("tileinterface_4")
  17. local items
  18. local numberOfItems
  19. local coalSpeed = 0
  20. local coalSpeedValuesTable = {0,0,0,0,0,0,0,0,0,0}
  21. local averageTenMinuteMiningSpeed
  22.  
  23.  
  24. function regetItems()
  25. items = AE2.getAvailableItems(1)
  26. numberOfItems = #items
  27. end
  28.  
  29. function newLine()
  30. local x
  31. local y
  32. x, y = monitors.getCursorPos()
  33. y = y + 1
  34. monitors.setCursorPos(1,y)
  35. end
  36.  
  37. function getAverageCoal()
  38. local sum = 0
  39. for i = 1, #coalSpeedValuesTable, 1 do
  40. sum = sum + coalSpeedValuesTable[i]
  41. end
  42. averageTenMinuteMiningSpeed = sum / #coalSpeedValuesTable
  43. end
  44.  
  45. function addToList(table, number)
  46. for i = 1, #table - 1, 1 do
  47. j = i + 1
  48. table[i] = table[j]
  49. end
  50. table[#table] = number
  51. return table
  52. end
  53.  
  54. function writeToScreen(text)
  55. --Resetting screen
  56. monitors.clear()
  57. monitors.setCursorPos(1,1)
  58. --Header
  59. monitors.setBackgroundColor(colors.red)
  60. monitors.write("********************************")
  61. newLine()
  62. monitors.write(" AE2 Monitoring program ")
  63. newLine()
  64. monitors.write("********************************")
  65. newLine()
  66. monitors.setBackgroundColor(colors.black)
  67. monitors.setTextColor(colors.magenta)
  68. monitors.write("Written by Merlione404")
  69. resetColors()
  70. --Real information
  71. newLine()
  72. newLine()
  73. monitors.write("Mining coal at: "..coalSpeed.." per minute")
  74. newLine()
  75. monitors.write("Average of the last 10 minutes: "..averageTenMinuteMiningSpeed.." per minute")
  76. newLine()
  77. monitors.write(text)
  78. end
  79.  
  80. function getNBTHash(itemname)
  81. regetItems()
  82. for i = 1, numberOfItems, 1 do
  83. if items[i].fingerprint.id == itemname then
  84. return items[i].fingerprint.nbt_hash
  85. end
  86. end
  87. end
  88.  
  89. regetItems()
  90.  
  91. coalhash = getNBTHash("minecraft:coal")
  92. coal = {id = "minecraft:coal", dmg = 0, nbt_hash= coalhash}
  93.  
  94. local oldCoalNumber
  95. local newCoalNumber
  96.  
  97. while true do
  98. oldCoalNumber = AE2.getItemDetail(coal , false).qty
  99. sleep(60)
  100. coalSpeed = AE2.getItemDetail(coal , false).qty - oldCoalNumber
  101. coalSpeedValuesTable = addToList(coalSpeedValuesTable, coalSpeed)
  102. getAverageCoal()
  103. writeToScreen(".....")
  104.  
  105. end
Advertisement
Add Comment
Please, Sign In to add comment