Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- storage = peripheral.find("enderstorage:ender_chest")
- if storage == nill then
- print("Pas d'ender chest")
- storage = peripheral.find("minecraft:chest")
- if storage == nill then
- print("Pas de chest")
- error("Aucun systeme de stockage trouve")
- else
- print("Chest trouve")
- end
- else
- print("Ender chest trouve")
- end
- monitor = peripheral.find("monitor") or error("Pas de moniteur")
- monitor.clear()
- monitor.setBackgroundColor(colors.black)
- size = monitor.getSize()
- function count(chest)
- local item
- --parcours des items du chest
- ind = 4
- for i=1, #chest.list() do
- item = chest.getItemDetail(i)
- monitor.setCursorPos(1,ind)
- itemName = item.displayName
- itemCount = item.count
- itemMax = item.maxCount
- monitor.write(itemName.." - "..itemCount.."/"..itemMax)
- ind=ind+1
- monitor.setCursorPos(1,ind)
- ind=ind+1
- percent = math.floor((itemCount/itemMax)*100).."%"
- percentLength = string.len(percent)
- --size defined on top, width of the monitor
- ratio = size/itemMax
- itemCount = itemCount*ratio
- itemMax = itemMax*ratio
- for j=1, percentLength, 1 do
- monitor.blit(string.sub(percent, j,j), "0","d")
- end
- for j=percentLength,itemCount,1 do
- monitor.blit (" ","d","d")
- end
- for j=itemCount,itemMax-1,1 do
- monitor.blit(" ","e","e")
- end
- end
- end
- function stored(chest)
- local cpt = 0
- for i=1, #chest.list() do
- cpt = cpt+chest.getItemDetail(i).count
- end
- return cpt
- end
- --refresh toutes les 5 secondes
- while true do
- monitor.clear()
- monitor.setCursorPos(1,1)
- monitor.write("Chest usage percent")
- monitor.setCursorPos(1,2)
- local slots =(storage.size()*64)
- local used = (math.floor(stored(storage)))
- local percent = math.floor((used/slots)*100).."%"
- local ratio = size/slots
- print(ratio)
- slots = slots*ratio
- used = used*ratio
- for i=1,string.len(percent) ,1 do
- monitor.blit( string.sub(percent,i,i),"0","d")
- end
- for i=string.len(percent), used,1 do
- monitor.blit(" ","d","d")
- end
- for i=used, slots, 1 do
- monitor.blit(" ","9","9")
- end
- monitor.setCursorPos(1,3)
- monitor.write("Detail")
- count(storage)
- os.sleep(5)
- end
Add Comment
Please, Sign In to add comment