Advertisement
HHM1573

Minecraft - OpenComputers - AE2OreMonitoring Program

Jun 1st, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3.  
  4. local gpu = component.gpu
  5.  
  6. local meInterface = component.me_interface
  7. local meExport = component.me_exportbus
  8.  
  9. local db = component.database
  10.  
  11.  
  12.  
  13. local oreDict = {
  14.     "Iron",
  15.     "Gold",
  16.     "Diamond",
  17.     "Emerald",
  18.     "Coal",
  19.     "Redstone",
  20.     "Nether Quartz"}
  21.    
  22. local oreNum = {}
  23.    
  24. local isFoundData = {}
  25.  
  26. local Text_Name_X = 2
  27. local Text_Num_X = Text_Name_X + 20
  28.  
  29. function Report_Component()
  30.     if gpu ~= nil then
  31.         print("Get GPU Succeed")
  32.     else
  33.         print("Get GPU Failed!!!")
  34.     end
  35.    
  36.     if meInterface ~= nil then
  37.         print("Get Interface Succeed")
  38.     else
  39.         print("Get Interface Failed!!!")
  40.     end
  41.    
  42.     if meExport ~= nil then
  43.         print("Get ExportBus Succeed")
  44.     else
  45.         print("Get ExportBus Failed!!!")
  46.     end
  47.    
  48.     if db ~= nil then
  49.         print("Get Database Succeed")
  50.     else
  51.         print("Get Database Failed!!!")
  52.     end
  53. end
  54.    
  55. function Add_Suffix(table_ore)
  56.     for key,value in ipairs(table_ore) do
  57.         table_ore[key] = value .. " Ore"
  58.     end
  59.     print("Add Suffix Proccess done")
  60. end
  61.  
  62. function Refresh_Database()
  63.     for key,value in ipairs(oreDict) do
  64.         --reset old data
  65.         isFoundData[key] = false
  66.         oreNum[key] = 0
  67.    
  68.         local label_item = {label = value}
  69.         local table_item = nil
  70.         table_item = meInterface.getItemsInNetwork(label_item)
  71.        
  72.         if table_item.n == 1 then
  73.             db.clear(key)
  74.             local isSuccessStore = meInterface.store(table_item[1], db.address, key, 1)
  75.             if isSuccessStore == true then
  76.                 isFoundData[key] = true
  77.                 oreNum[key] = table_item[1].size
  78.             end
  79.         end
  80.        
  81.     end
  82.     print("Refresh Database proccess done")
  83. end
  84.  
  85. function Print_OreInfo()
  86.     term.clear()
  87.     for key, value in pairs(oreDict) do
  88.         local Height = 2 + key
  89.         gpu.set(Text_Name_X, Height, value, false)
  90.        
  91.         if isFoundData[key] ~= true then
  92.             gpu.set(Text_Num_X, Height, "0", false)
  93.         else
  94.             local table_Item = db.get(key)
  95.             local itemNum = oreNum[key]
  96.             gpu.set(Text_Num_X, Height, tostring(itemNum), false)
  97.         end
  98.     end
  99. end
  100.  
  101.  
  102.  
  103. do
  104.     Report_Component()
  105.     Add_Suffix(oreDict)
  106.     while true do
  107.         Refresh_Database()
  108.         Print_OreInfo()
  109.         os.sleep(1)
  110.     end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement