Advertisement
dengmahalYT

Minecraft CC:ME storage monitor

Apr 10th, 2025 (edited)
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.78 KB | Gaming | 0 0
  1. ---@diagnostic disable: undefined-global, unused-local
  2. local itemrows=33
  3. local fluidrows=0
  4. --local gasrows=0
  5.  
  6. local bridge = peripheral.find("meBridge")
  7. if bridge == nil then error("meBridge not found du idiot hastess vergessin") end
  8. local function wrapPs(peripheralName)
  9.     local periTab={}
  10.     local sideTab={}
  11.     if peripheralName==nil then
  12.         print("Error")
  13.     end
  14.     local peripherals = peripheral.getNames()
  15.     local i2 = 1
  16.     for i =1, #peripherals do
  17.         if peripheral.getType(peripherals[i])==peripheralName then
  18.             periTab[i2]=peripheral.wrap(peripherals[i])
  19.             sideTab[i2]=peripherals[i]
  20.             i2=i2+1
  21.         end
  22.     end
  23.     if periTab~={} then
  24.         return periTab,sideTab
  25.     else
  26.         return nil
  27.     end
  28. end
  29. local me = wrapPs("meBridge")[1]
  30. local mon = wrapPs("monitor")[1]
  31. if mon==nil then
  32.     error("no monitor")
  33. end
  34. local function CenterT(text, line, txtback , txtcolor, pos)
  35.     if text==nil then
  36.         text="null"
  37.     end
  38.     local monX,monY = mon.getSize()
  39.     mon.setBackgroundColor(txtback)
  40.     mon.setTextColor(txtcolor)
  41.     local length = string.len(text)
  42.     local dif = math.floor(monX-length)
  43.     local x = math.floor(dif/2)
  44.     if pos == "head" then
  45.         mon.setCursorPos(x+1, line)
  46.         mon.write(text)
  47.     elseif pos == "left" then
  48.         mon.setCursorPos(2,line)
  49.         mon.write(text)
  50.     elseif pos == "right" then
  51.         mon.setCursorPos(monX-length, line)
  52.         mon.write(text)
  53.     end
  54. end
  55. local function sort(a,b)
  56.     return a.count>b.count
  57. end
  58. local function swap(tab, firstindex, secondindex)
  59.     local temp = tab[firstindex]
  60.     tab[firstindex] = tab[secondindex]
  61.     tab[secondindex] = temp
  62. end
  63.  
  64. local function partition(tab, left, right)
  65.     local pivv = tab[right].count
  66.     local partitionindex = left
  67.     for i = left, right-1 do
  68.         if tab[i].count < pivv then
  69.             swap(tab, i, partitionindex)
  70.             partitionindex = partitionindex + 1
  71.         end
  72.     end
  73.     swap(tab, right, partitionindex)
  74.     return partitionindex
  75. end
  76.  
  77. local function quicksort(tab, left, right)
  78.     left = left or 1
  79.     right = right or #tab
  80.     if left >= right then
  81.         return tab
  82.     end
  83.     local pivi = partition(tab, left, right)
  84.     quicksort(tab, left, pivi-1)
  85.     quicksort(tab, pivi+1, right)
  86.     return tab
  87. end
  88.  
  89. local allitems=me.listItems()
  90. local allfuilds=me.listFluid()
  91. --local allgas=me.listGas()
  92. while true do
  93.     local itemcount=me.getUsedItemStorage()
  94.     local fluidcount=me.getUsedFluidStorage()
  95.     allitems=me.listItems()
  96.     allfuilds=me.listFluid()
  97.     local itypes=0
  98.     local iutypes=#allitems
  99.     local ftypes=0
  100.     local futypes=#allfuilds
  101.     --allgas=me.listGas()
  102.     if itemrows>0 then
  103.         allitems=quicksort(allitems)
  104.     end
  105.     if fluidrows>0 then
  106.         allfuilds=quicksort(allfuilds)
  107.     end
  108.     --if gasrows>0 then
  109.     --    quicksort(allgas)
  110.     --end
  111.     if #allitems==0 then
  112.         for i=1,itemrows,1 do
  113.             allitems[i]={count=0,name="minecraft:air",displayName="air",nbt={}}
  114.         end
  115.     end
  116.     if #allfuilds==0 then
  117.         for i=1,fluidrows,1 do
  118.             allfuilds[i]={count=0,name="minecraft:air",displayName="air"}
  119.         end
  120.     end
  121.     --if #allgas==0 then
  122.     --    for i=1,fluidrows,1 do
  123.     --        allgas[i]={count=0,name="minecraft:air",displayName="air"}
  124.     --    end
  125.     --end
  126.     mon.clear()
  127.     for i=1,itemrows,1 do
  128.         local v=allitems[iutypes-i+1]
  129.         CenterT(string.gsub(v.displayName,"   ","") ,i+6, colors.black, colors.lightGray,"left")
  130.         CenterT(tostring(v.count) ,i+6, colors.black, colors.lightGray,"right")
  131.     end
  132.     for i=1,fluidrows,1 do
  133.         local v=allfuilds[futypes-i+1]
  134.         if v==nil then
  135.             v={}
  136.             v.displayName="air"
  137.             v.count=0
  138.         end
  139.         CenterT(string.gsub(v.displayName,"   ","") ,i+7+itemrows, colors.black, colors.lightGray,"left")
  140.         CenterT(tostring(v.count).."mb" ,i+7+itemrows, colors.black, colors.lightGray,"right")
  141.     end
  142.     --for i=1,gasrows,1 do
  143.     --    local v=allgas[i]
  144.     --    CenterT(v.displayName ,i+8+itemrows, colors.black, colors.lightGray,"left")
  145.     --    CenterT(tostring(v.count).."mb" ,i+7+itemrows, colors.black, colors.lightGray,"right")
  146.     --end
  147.     --local gtypes=0
  148.     --local gutypes=#allgas
  149.     local cells=me.listCells()
  150.     for i=1,#cells do
  151.         if cells[i].cellType=="item" then
  152.             itypes=itypes+63
  153.         elseif cells[i].cellType=="fluid" then
  154.             ftypes=ftypes+18
  155.         --elseif cells[i].celltype=="gas" then
  156.         --    ftypes=ftypes+63
  157.         end
  158.     end
  159.     local maxeng=tonumber(me.getMaxEnergyStorage())*2
  160.     local engstor=tonumber(me.getEnergyStorage())*2
  161.     local enguse=tonumber(me.getEnergyUsage())*2
  162.     local maxi=me.getTotalItemStorage()
  163.     local maxf=me.getTotalFluidStorage()
  164.     CenterT("ME Storage Monitor v0.2 by dengmahal" ,1, colors.black, colors.lightGray,"head")
  165.     CenterT("Energy: "..math.floor(engstor/10000+.5)/100 .."MFE/"..math.floor(maxeng/10000)/100 .."MFE" ,2, colors.black, colors.lightBlue,"left")
  166.     CenterT(math.floor(enguse/10+.5)/100 .."KFE/t",2, colors.black, colors.lightBlue,"right")
  167.     CenterT("Items: "..itemcount.."/"..maxi.."\t"..tostring(math.floor((itemcount/maxi)*1000+0.5)/10).."%",4,colors.black,colors.white,"left")
  168.     CenterT("Fluids: "..fluidcount.."mb/"..maxf.."mb\t"..tostring(math.floor((fluidcount/maxf)*1000+0.5)/10).."%",5, colors.black, colors.blue,"left")
  169.     CenterT(""..iutypes.."/"..itypes.."\t "..tostring(math.floor((iutypes/itypes)*1000+0.5)/10).."%",4,colors.black,colors.white,"right")
  170.     CenterT(""..futypes.."/"..ftypes.."\t "..tostring(math.floor((futypes/ftypes)*1000+0.5)/10).."%",5,colors.black,colors.blue,"right")
  171.     sleep(5)
  172. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement