Tawok

ShowStorage

May 6th, 2022
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local chestType = "TYPE HERE"
  2. local enderChest = peripheral.find(chestType)
  3. if enderChest == nill then
  4.     error("Chest "..chestType.." non trouvé, verifier configuration (l1)")
  5.     else
  6.     print(chestType.."trouve")
  7.     end
  8.  
  9. monitor = peripheral.find("monitor") or error("Pas de moniteur")
  10. monitor.clear()
  11. monitor.setBackgroundColor(colors.black)
  12. size = monitor.getSize()
  13.  
  14.  
  15. function count(chest)
  16.    local item
  17.        --parcours des items du chest
  18.    ind = 4
  19.    for i=1, #chest.list() do
  20.         item = chest.getItemDetail(i)
  21.         monitor.setCursorPos(1,ind)
  22.         itemName = item.displayName
  23.         itemCount = item.count
  24.         itemMax = item.maxCount
  25.         monitor.write(itemName.." - "..itemCount.."/"..itemMax)
  26.         ind=ind+1
  27.         monitor.setCursorPos(1,ind)
  28.         ind=ind+1
  29.         percent = math.floor((itemCount/itemMax)*100).."%"
  30.         percentLength = string.len(percent)
  31.         --size defined on top, width of the monitor
  32.         ratio = size/itemMax
  33.         itemCount = itemCount*ratio
  34.         itemMax = itemMax*ratio
  35.         for j=1, percentLength, 1  do
  36.             monitor.blit(string.sub(percent, j,j), "0","d")
  37.         end
  38.         for j=percentLength,itemCount,1 do
  39.             monitor.blit (" ","d","d")
  40.         end
  41.         for j=itemCount,itemMax-1,1 do
  42.             monitor.blit(" ","e","e")
  43.         end
  44.     end
  45. end
  46.  
  47.  
  48. function stored(chest)
  49.     local cpt = 0
  50.     local list = {}
  51.     list = chest.list()
  52.     for i=1, chest.size(), 1 do
  53.         if list[i] ~= nil then
  54.             cpt = cpt+list[i].count
  55.         end
  56.     end
  57.     return cpt
  58. end
  59.  
  60.  
  61. --refresh toutes les 5 secondes
  62.  
  63. while true do
  64.     redstone.setAnalogOutput("right", 0)
  65.    
  66.     monitor.clear()
  67.     monitor.setCursorPos(1,1)
  68.     monitor.write("Chest usage percent")
  69.     monitor.setCursorPos(1,2)
  70.     local slots =(enderChest.size()*64)
  71.     local used = (math.floor(stored(enderChest)))
  72.     local percent = math.floor((used/slots)*100).."%"
  73.     local ratio =  size/slots
  74.     slots = slots*ratio
  75.     used = used*ratio
  76.     for i=1,string.len(percent) ,1 do
  77.        monitor.blit( string.sub(percent,i,i),"0","d")
  78.     end
  79.     for i=string.len(percent), used,1 do
  80.         monitor.blit(" ","d","d")
  81.     end
  82.     for i=used, slots, 1 do
  83.         monitor.blit(" ","9","9")
  84.     end
  85.    
  86.     monitor.setCursorPos(1,3)
  87.     monitor.write("Detail")
  88.     count(enderChest)
  89.     print(stored(enderChest))
  90.     print(slots*32)
  91.     check = stored(enderChest)
  92.     while check > slots*32 do
  93.         print(check.." > "..slots*32)
  94.         check = stored(enderChest)
  95.         redstone.setOutput("right", true)
  96.     end
  97.        
  98.     os.sleep(1)
  99.  
  100. end
  101.    
  102.      
Add Comment
Please, Sign In to add comment