Advertisement
mikebald

AE Display

Jul 16th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. local itemMonitor = peripheral.wrap("monitor_3")
  2. local craftingMonitor = peripheral.wrap("monitor_4")
  3. local meAccess = peripheral.wrap("left")
  4. local meMonitor = peripheral.wrap("right")
  5. local monitor_MaxY = 50
  6. local monitor_MinY = 1
  7. local monitor_X_Scale = 50
  8. local monitorX = 1
  9. local monitorY = monitor_MinY
  10. local AEItems = {}
  11.  
  12. local watchItems = { ores={"Cobblestone","Obsidian","Ore"},
  13.     ingots={"Ingot"}
  14.     }
  15. -- id, name, rawName, dmg, maxSize, ench, qty
  16. -- containsItemType, countOfItemType, getAvailableItems
  17.  
  18.  
  19. function spairs(t, order)
  20.     local keys = {}
  21.     for k in pairs(t) do keys[#keys+1] = k end
  22.     if order then
  23.         table.sort(keys, function(a,b) return order(t, a, b) end)
  24.     else
  25.         table.sort(keys)
  26.     end
  27.     local i = 0
  28.     return function()
  29.         i = i + 1
  30.         if keys[i] then
  31.             return keys[i], t[keys[i]]
  32.         end
  33.     end
  34. end
  35.  
  36. function Load_FromAE()
  37.     AEItems = {}
  38.     local meItems = meAccess.getAvailableItems()
  39.     for _,v in pairs(meItems) do
  40.         AEItems[v["name"]] = v
  41.     end
  42. end
  43.  
  44. function Find_Items(itemSearch)
  45.     if #AEItems == 0 then Load_FromAE() end
  46.     local items = {}
  47.     for _,search in pairs(itemSearch) do
  48.         for k,v in pairs(AEItems) do
  49.             if string.find(k, search) ~= nil then -- or string.find(v["rawName"], search) ~= nil
  50.                 items[k] = v
  51.             end
  52.         end
  53.     end
  54.     return items
  55. end
  56.  
  57. function Display_ItemSubset(name, items)
  58.     itemMonitor.setCursorPos(monitorX, monitorY)
  59.     Output(name)
  60.     Output("--------------")
  61.     for k,v in pairs(items) do Output(k.."["..v["qty"].."]") end
  62.     Output("--------------")
  63. end
  64.  
  65. function Output(text)
  66.     monitor_X_Scale = math.max(monitor_X_Scale, #text + 2) -- some padding
  67.     AdvanceMonitorPosition()
  68.     itemMonitor.write(text)
  69. end
  70.  
  71. function AdvanceMonitorPosition()
  72.     monitorY = monitorY + 1
  73.     if monitorY > monitor_MaxY then
  74.         monitorY = monitor_MinY
  75.         monitorX = monitorX + monitor_X_Scale
  76.     end
  77.     itemMonitor.setCursorPos(monitorX, monitorY)
  78. end
  79.  
  80. function Show_Items(items)
  81.     itemMonitor.clear()
  82.     itemMonitor.setTextScale(0.5)
  83.     for k,v in spairs(items, function(t,a,b) return t[b] < t[a] end) do
  84.         itemMonitor.setCursorPos(x,y)
  85.         itemMonitor.write(k.." ["..v.."]")
  86.         y = y + 1
  87.         if y == 51 then
  88.             y = 1
  89.             x = x + 50
  90.         end            
  91.     end
  92. end
  93.  
  94. Load_FromAE()
  95. itemMonitor.clear()
  96. itemMonitor.setTextScale(.5)
  97. Display_ItemSubset("Ores", Find_Items(watchItems["ores"]))
  98. Display_ItemSubset("Ingots", Find_Items(watchItems["ingots"]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement