Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---@diagnostic disable: undefined-global, unused-local
- local itemrows=33
- local fluidrows=0
- --local gasrows=0
- local bridge = peripheral.find("meBridge")
- if bridge == nil then error("meBridge not found du idiot hastess vergessin") end
- local function wrapPs(peripheralName)
- local periTab={}
- local sideTab={}
- if peripheralName==nil then
- print("Error")
- end
- local peripherals = peripheral.getNames()
- local i2 = 1
- for i =1, #peripherals do
- if peripheral.getType(peripherals[i])==peripheralName then
- periTab[i2]=peripheral.wrap(peripherals[i])
- sideTab[i2]=peripherals[i]
- i2=i2+1
- end
- end
- if periTab~={} then
- return periTab,sideTab
- else
- return nil
- end
- end
- local me = wrapPs("meBridge")[1]
- local mon = wrapPs("monitor")[1]
- if mon==nil then
- error("no monitor")
- end
- local function CenterT(text, line, txtback , txtcolor, pos)
- if text==nil then
- text="null"
- end
- local monX,monY = mon.getSize()
- mon.setBackgroundColor(txtback)
- mon.setTextColor(txtcolor)
- local length = string.len(text)
- local dif = math.floor(monX-length)
- local x = math.floor(dif/2)
- if pos == "head" then
- mon.setCursorPos(x+1, line)
- mon.write(text)
- elseif pos == "left" then
- mon.setCursorPos(2,line)
- mon.write(text)
- elseif pos == "right" then
- mon.setCursorPos(monX-length, line)
- mon.write(text)
- end
- end
- local function sort(a,b)
- return a.count>b.count
- end
- local function swap(tab, firstindex, secondindex)
- local temp = tab[firstindex]
- tab[firstindex] = tab[secondindex]
- tab[secondindex] = temp
- end
- local function partition(tab, left, right)
- local pivv = tab[right].count
- local partitionindex = left
- for i = left, right-1 do
- if tab[i].count < pivv then
- swap(tab, i, partitionindex)
- partitionindex = partitionindex + 1
- end
- end
- swap(tab, right, partitionindex)
- return partitionindex
- end
- local function quicksort(tab, left, right)
- left = left or 1
- right = right or #tab
- if left >= right then
- return tab
- end
- local pivi = partition(tab, left, right)
- quicksort(tab, left, pivi-1)
- quicksort(tab, pivi+1, right)
- return tab
- end
- local allitems=me.listItems()
- local allfuilds=me.listFluid()
- --local allgas=me.listGas()
- while true do
- local itemcount=me.getUsedItemStorage()
- local fluidcount=me.getUsedFluidStorage()
- allitems=me.listItems()
- allfuilds=me.listFluid()
- local itypes=0
- local iutypes=#allitems
- local ftypes=0
- local futypes=#allfuilds
- --allgas=me.listGas()
- if itemrows>0 then
- allitems=quicksort(allitems)
- end
- if fluidrows>0 then
- allfuilds=quicksort(allfuilds)
- end
- --if gasrows>0 then
- -- quicksort(allgas)
- --end
- if #allitems==0 then
- for i=1,itemrows,1 do
- allitems[i]={count=0,name="minecraft:air",displayName="air",nbt={}}
- end
- end
- if #allfuilds==0 then
- for i=1,fluidrows,1 do
- allfuilds[i]={count=0,name="minecraft:air",displayName="air"}
- end
- end
- --if #allgas==0 then
- -- for i=1,fluidrows,1 do
- -- allgas[i]={count=0,name="minecraft:air",displayName="air"}
- -- end
- --end
- mon.clear()
- for i=1,itemrows,1 do
- local v=allitems[iutypes-i+1]
- CenterT(string.gsub(v.displayName," ","") ,i+6, colors.black, colors.lightGray,"left")
- CenterT(tostring(v.count) ,i+6, colors.black, colors.lightGray,"right")
- end
- for i=1,fluidrows,1 do
- local v=allfuilds[futypes-i+1]
- if v==nil then
- v={}
- v.displayName="air"
- v.count=0
- end
- CenterT(string.gsub(v.displayName," ","") ,i+7+itemrows, colors.black, colors.lightGray,"left")
- CenterT(tostring(v.count).."mb" ,i+7+itemrows, colors.black, colors.lightGray,"right")
- end
- --for i=1,gasrows,1 do
- -- local v=allgas[i]
- -- CenterT(v.displayName ,i+8+itemrows, colors.black, colors.lightGray,"left")
- -- CenterT(tostring(v.count).."mb" ,i+7+itemrows, colors.black, colors.lightGray,"right")
- --end
- --local gtypes=0
- --local gutypes=#allgas
- local cells=me.listCells()
- for i=1,#cells do
- if cells[i].cellType=="item" then
- itypes=itypes+63
- elseif cells[i].cellType=="fluid" then
- ftypes=ftypes+18
- --elseif cells[i].celltype=="gas" then
- -- ftypes=ftypes+63
- end
- end
- local maxeng=tonumber(me.getMaxEnergyStorage())*2
- local engstor=tonumber(me.getEnergyStorage())*2
- local enguse=tonumber(me.getEnergyUsage())*2
- local maxi=me.getTotalItemStorage()
- local maxf=me.getTotalFluidStorage()
- CenterT("ME Storage Monitor v0.2 by dengmahal" ,1, colors.black, colors.lightGray,"head")
- CenterT("Energy: "..math.floor(engstor/10000+.5)/100 .."MFE/"..math.floor(maxeng/10000)/100 .."MFE" ,2, colors.black, colors.lightBlue,"left")
- CenterT(math.floor(enguse/10+.5)/100 .."KFE/t",2, colors.black, colors.lightBlue,"right")
- CenterT("Items: "..itemcount.."/"..maxi.."\t"..tostring(math.floor((itemcount/maxi)*1000+0.5)/10).."%",4,colors.black,colors.white,"left")
- CenterT("Fluids: "..fluidcount.."mb/"..maxf.."mb\t"..tostring(math.floor((fluidcount/maxf)*1000+0.5)/10).."%",5, colors.black, colors.blue,"left")
- CenterT(""..iutypes.."/"..itypes.."\t "..tostring(math.floor((iutypes/itypes)*1000+0.5)/10).."%",4,colors.black,colors.white,"right")
- CenterT(""..futypes.."/"..ftypes.."\t "..tostring(math.floor((futypes/ftypes)*1000+0.5)/10).."%",5,colors.black,colors.blue,"right")
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement