Advertisement
dengmahalYT

Minceraft CC:ME

Dec 29th, 2022 (edited)
1,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. local bridge = peripheral.find("meBridge")
  2.  
  3. if bridge == nil then error("meBridge not found") end
  4. function wrapPs(peripheralName)
  5.   periTab={}
  6.   sideTab={}
  7.   if peripheralName==nil then
  8.     print("Error")
  9.   end
  10.   local peripherals = peripheral.getNames()
  11.   local i2 = 1
  12.   for i =1, #peripherals do
  13.     if peripheral.getType(peripherals[i])==peripheralName then
  14.       periTab[i2]=peripheral.wrap(peripherals[i])
  15.       sideTab[i2]=peripherals[i]
  16.       i2=i2+1
  17.     end
  18.   end
  19.   if periTab~={} then
  20.     return periTab,sideTab
  21.   else
  22.   return nil
  23.   end
  24. end
  25.  
  26. function CenterT(text, line, txtback , txtcolor, pos)
  27.     if text==nil then
  28.         text="null"
  29.     end
  30.   monX,monY = mon.getSize()
  31.   mon.setBackgroundColor(txtback)
  32.   mon.setTextColor(txtcolor)
  33.   length = string.len(text)
  34.   dif = math.floor(monX-length)
  35.   x = math.floor(dif/2)
  36.  
  37.   if pos == "head" then
  38.     mon.setCursorPos(x+1, line)
  39.     mon.write(text)
  40.   elseif pos == "left" then
  41.     mon.setCursorPos(2,line)
  42.     mon.write(text)
  43.   elseif pos == "right" then
  44.     mon.setCursorPos(monX-length, line)
  45.     mon.write(text)
  46.   end
  47. end
  48. function sort(a,b)
  49.     return a.amount>b.amount    
  50. end
  51. me = wrapPs("meBridge")[1]
  52. mon = wrapPs("monitor")[1]
  53. while true do
  54.     sleep(3)
  55.    
  56.    
  57.     local itemcount=0
  58.     local fluidcount=0
  59.     local allitems=me.listItems()
  60.     local allfuilds=me.listFluid()
  61.     for i,v in pairs(allfuilds) do
  62.         fluidcount=fluidcount+v.amount
  63.     end
  64.      for i,v in pairs(allitems) do
  65.         itemcount=itemcount+v.amount
  66.     end
  67.     table.sort(allitems,sort)
  68.     table.sort(allfuilds,sort)
  69.     if #allitems==0 then
  70.        for i=1,10,1 do
  71.           allitems[i]={amount=0,name="minecraft:air",displayName="air",nbt={}}  
  72.        end
  73.     end
  74.      if #allfuilds==0 then
  75.        for i=1,10,1 do
  76.           allfuilds[i]={amount=0,name="minecraft:air",displayName="air"}  
  77.        end
  78.     end
  79.     mon.clear()
  80.     for i=1,10,1 do
  81.         local v=allitems[i]
  82.         CenterT(v.displayName ,i+6, colors.black, colors.lightGray,"left")
  83.         CenterT(tostring(v.amount) ,i+6, colors.black, colors.lightGray,"right")
  84.     end
  85.    
  86.     for i=1,10,1 do
  87.         local v=allfuilds[i]
  88.         if v==nil then
  89.            v={}
  90.            v.displayName="air"
  91.            v.amount=0
  92.         end
  93.         CenterT(v.displayName ,i+17, colors.black, colors.lightGray,"left")
  94.         CenterT(tostring(v.amount).."mb" ,i+17, colors.black, colors.lightGray,"right")
  95.     end
  96.     local maxeng=tonumber(me.getMaxEnergyStorage())*2
  97.     local engstor=tonumber(me.getEnergyStorage())*2
  98.     local enguse=tonumber(me.getEnergyUsage())*2
  99.      CenterT("ME Monitor v0.1 by deng" ,1, colors.black, colors.lightGray,"head")
  100.      CenterT("Energy: "..math.floor(engstor/100000)/10 .."MFE/"..math.floor(maxeng/100000)/10 .."MFE" ,2, colors.black, colors.lightBlue,"left")
  101.      CenterT(math.floor(enguse/10)/100 .."KFE/t" ,3, colors.black, colors.lightBlue,"right")
  102.      CenterT("Items: "..itemcount.."/".."??",4,colors.black,colors.white,"left")--me.getMaxItemDiskStorage().." ("..math.floor(((itemcount/me.getMaxItemDiskStorage())*10000)+.5)/100 .."%)",3,colors.black,colors.white,"left")
  103.      CenterT("Fluids: "..fluidcount.."mb/".."??",5, colors.black, colors.blue,"left")--me.getMaxFluidDiskStorage().."mb".." ("..math.floor(((fluidcount/me.getMaxFluidDiskStorage())*10000)+.5)/100 .."%)" ,4, colors.black, colors.blue,"left")
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement