Margresse404

AE_V3_separate_functions_file

Jun 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. --Add needed functions
  2. os.loadAPI("scripts/functions")
  3.  
  4.  
  5.  
  6. --Monitors stuff
  7. local monitors
  8. monitors = peripheral.wrap("left")
  9.  
  10.  
  11. local timeSteps = 10
  12. local counter = 0
  13.  
  14.  
  15. --Loading screen
  16. monitors.clear()
  17. monitors.setCursorPos(1,1)
  18. monitors.write("Loading....")
  19.  
  20.  
  21. local AE2
  22. AE2 = peripheral.wrap("tileinterface_4")
  23. local items
  24. local numberOfItems
  25. local coalSpeed = 0
  26. local coalSpeedValuesTable = {0,0,0,0,0,0,0,0,0,0}
  27. local averageTenMinuteMiningSpeed
  28.  
  29. --Items to be monitored
  30. --SET THESE YOURSELF
  31. local itemsToBeMonitored = {"minecraft:coal", "appliedenergistics2:item.ItemMultiMaterial:1", "DraconicEvolution:draconiumIngot", "minecraft:cobblestone","minecraft:redstone"}
  32. local labels = {"coal", "charged certus", "draconium", "cobblestone", "redstone"}
  33. local itemObjects = functions.vector(#itemsToBeMonitored)
  34.  
  35. --The matrices that track the speed differences
  36. local speeds = functions.vector(#itemsToBeMonitored)
  37. local pastSpeeds = functions.matrix(#itemsToBeMonitored, timeSteps)
  38. local averageSpeeds = functions.vector(#itemsToBeMonitored)
  39.  
  40.  
  41. function regetItems()
  42. items = AE2.getAvailableItems(1)
  43. numberOfItems = #items
  44. end
  45.  
  46. function newLine()
  47. local x
  48. local y
  49. x, y = monitors.getCursorPos()
  50. y = y + 1
  51. monitors.setCursorPos(1,y)
  52. end
  53.  
  54.  
  55. function getAverages()
  56. local sum
  57. for i = 1, #itemsToBeMonitored, 1 do
  58. sum = 0
  59. for j = 1, #pastSpeeds[i], 1 do
  60. sum = sum + pastSpeeds[i][j]
  61. end
  62. averageSpeeds[i] = sum / #pastSpeeds[i]
  63. end
  64.  
  65. end
  66.  
  67. function addToList(table, number)
  68. for i = 1, #table - 1, 1 do
  69. j = i + 1
  70. table[i] = table[j]
  71. end
  72. table[#table] = number
  73. return table
  74. end
  75.  
  76. function printColoredNumber(number)
  77.  
  78. if number < 0 then
  79. monitors.setTextColor(colors.red)
  80. elseif number < 10 then
  81. monitors.setTextColor(colors.yellow)
  82. elseif number < 40 then
  83. monitors.setTextColor(colors.green)
  84. else
  85. monitors.setTextColor(colors.lime)
  86. end
  87. monitors.write(number)
  88. functions.resetColors(monitors)
  89. end
  90.  
  91. function writeToScreen(text)
  92. --Resetting screen
  93. monitors.clear()
  94. monitors.setCursorPos(1,1)
  95. --Header
  96. monitors.setBackgroundColor(colors.red)
  97. monitors.write("********************************")
  98. newLine()
  99. monitors.write(" AE2 Monitoring program ")
  100. newLine()
  101. monitors.write("********************************")
  102. newLine()
  103. monitors.setBackgroundColor(colors.black)
  104. monitors.setTextColor(colors.magenta)
  105. monitors.write("Written by Merlione404")
  106. functions.resetColors(monitors)
  107. --Real information
  108. newLine()
  109. newLine()
  110.  
  111. --Write something for each item to be monitored
  112. for i = 1, #itemsToBeMonitored, 1 do
  113. monitors.write("Current "..labels[i].." rate: ")
  114. printColoredNumber(speeds[i])
  115. monitors.write("/minute")
  116. newLine()
  117. if counter < timeSteps then
  118. monitors.write("Time average not yet available.")
  119. else
  120. monitors.write("Average of the last 10 minutes: "..averageSpeeds[i].." per minute")
  121. end
  122. newLine()
  123. end
  124.  
  125. monitors.write(text)
  126. end
  127.  
  128. function getNBTHash(itemname)
  129. regetItems()
  130. for i = 1, numberOfItems, 1 do
  131. if items[i].fingerprint.id == itemname then
  132. return items[i].fingerprint.nbt_hash
  133. end
  134. end
  135. end
  136.  
  137. regetItems()
  138.  
  139.  
  140.  
  141. -- Get hashes for all the items and create the item objects
  142. for i = 1, #itemsToBeMonitored, 1 do
  143. --Gets the hash for each items
  144. hash = getNBTHash(itemsToBeMonitored[i])
  145.  
  146. local tempItem = {id = itemsToBeMonitored[i], dmg = 0, nbt_hash = hash}
  147. itemObjects[i] = tempItem
  148. end
  149.  
  150. local oldAmount = functions.vector(#itemsToBeMonitored)
  151.  
  152. function getAmounts()
  153. tempVec = functions.vector(#itemsToBeMonitored)
  154. for i = 1, #itemsToBeMonitored, 1 do
  155. tempVec[i]= AE2.getItemDetail(itemObjects[i] , false).qty
  156. end
  157. return tempVec
  158. end
  159.  
  160. while true do
  161.  
  162.  
  163.  
  164. oldAmount = getAmounts()
  165. sleep(60)
  166. newAmount = getAmounts()
  167. speeds = functions.vectorMinus(newAmount,oldAmount)
  168.  
  169. for i = 1, #itemsToBeMonitored, 1 do
  170. pastSpeeds[i] = addToList(pastSpeeds[i], speeds[i])
  171. end
  172. getAverages()
  173. counter = counter + 1
  174. writeToScreen(".....")
  175.  
  176. end
Advertisement
Add Comment
Please, Sign In to add comment