Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --decalrations
- monitor = peripheral.find("monitor") or error("no monitor")
- chest = peripheral.find("ironchest:gold_chest") or error("no chest")
- width, height = monitor.getSize()
- itemsMax = 0
- --index : height/2 pour travailler au milieu du monitor
- index = height/2
- --Methodes
- --#initScreen
- --Pour initialiser le monitor
- function initScreen()
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(colors.gray)
- monitor.clear()
- monitor.setTextScale(0.5)
- monitor.setBackgroundColor(colors.black)
- monitor.setCursorPos(1,index-1)
- monitor.clearLine()
- monitor.setCursorPos(1,index+1)
- monitor.clearLine()
- monitor.setBackgroundColor(colors.gray)
- end
- --#Count
- --Pour conter le nombre total d'items dans le chest
- function Count(chest)
- --recuperation de la liste pour eviter les problemes de nullPointer
- local list = {}
- list = chest.list()
- size = chest.size()
- local cpt=0
- for i=1, size, 1 do
- if list[i]~=nil then
- --increase cpt only if not null
- cpt=cpt+list[i].count
- end
- end
- return cpt
- end
- --#ProgressBar
- --Pour afficher la barre de progression
- function ProgressBar(chest)
- --items : current number of items in chest
- local items = Count(chest)
- --itemMax : nombre d'items deposes
- local tmp = Count(chest)
- --si des items ont etes ajoutes
- if tmp>itemsMax then
- itemsMax=tmp
- --sinon c'est que ca decroit, rien ne change
- end
- monitor.setCursorPos(1,index)
- --status percent in decimal
- local status = 1-(items/itemsMax)
- local percent = math.floor(status*100).."%"
- --index pour savoir quand couper la progress barre
- local index = width*status
- --affichage terminal des infos donnees
- print("====")
- print((" MaxItems: %d\nCurrentItems: %d"):format(itemsMax,items))
- print(" Status: "..percent)
- print(("Width: %d // percent proportion: %d"):format(width, index))
- --partie ok de la progress bar
- for i=1, index, 1 do
- monitor.blit(" ","5","5")
- end
- end
- --main
- print(("w%d;h%d"):format(width,height))
- while true do
- initScreen()
- monitor.setCursorPos(1,1)
- monitor.write("Advancement")
- if Count(chest)==0 then
- print("No items in chest")
- itemsMax = 0
- else
- ProgressBar(chest)
- --Refresh every 1 second
- os.sleep(1)
- --remettre la backgroundcolor a grey car lors du clear
- --le monitor fill avec la derniere info de color (cf docu)
- monitor.setBackgroundColor(colors.gray)
- end
- end
Add Comment
Please, Sign In to add comment