Tawok

Untitled

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