Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local params = {}
- dofile("bs/apis/wrapper")
- -- initialization
- local function loadParams()
- local file = fs.open("/bs/files/bulk_Storage_Params", "r")
- local data = file.readAll()
- file.close()
- params = textutils.unserialize(data)
- end
- local function saveParams(table)
- local file = fs.open("/bs/files/bulk_Storage_Params", "w")
- file.write(textutils.serialize(table))
- file.close()
- end
- local function setMonitor()
- local returntable = {}
- ui.clear()
- returntable["name"] = ui.getInput("Type the name of the connected monitor") ui.clear()
- returntable["posX"] = ui.getInput("Set the starting position on the x-axis", true) ui.clear()
- returntable["width"] = ui.getInput("Set the width of the progressbar", true) ui.clear()
- returntable["color"] = ui.getInput("Choose a color (numeric) for the progressbar", true) ui.clear()
- return returntable
- end
- local function setChests()
- local chesttable = {}
- local nametable = peripheral.getNames()
- local I = 0
- for I = 1, #nametable do
- if peripheral.getType(nametable[I]) == "minecraft:chest" then
- table.insert(chesttable, nametable[I])
- end
- end
- ui.printing("Please put a stick named \"tag\" in every chest you want to track")
- ui.pressenter()
- local returntable = {}
- for I = 1, #chesttable do
- ui.clear()
- ui.printing("Searching chest "..I.."/"..#chesttable)
- if bs.chest.getIndexOf(chesttable[I], "minecraft:stick", "tag") ~= nil then
- table.insert(returntable, chesttable[I])
- end
- ui.clear()
- end
- return returntable
- end
- local function setParams()
- local paramt = {}
- paramt["monitor"] = setMonitor()
- paramt["name"] = ui.getInput("Enter the displayname for the progressbar")
- ui.clear()
- paramt["chests"] = setChests()
- return paramt
- end
- --implementation
- local function getOccSlotCount(chestname)
- local returncount = 0
- local chest = peripheral.wrap(chestname)
- for I = 1, chest.size() do
- local details = chest.getItemDetail(I)
- if details ~= nil then
- returncount = returncount + 1
- end
- end
- return returncount
- end
- local function getProcentage()
- local chesttable = params["chests"]
- local maxSlots = 0
- local occSlots = 0
- for I = 1, #chesttable do
- maxSlots = maxSlots + peripheral.wrap(chesttable[I]).size()
- occSlots = occSlots + getOccSlotCount(chesttable[I])
- end
- return math.ceil((occSlots / maxSlots) * 100)
- end
- -- start
- if args[1] == "true" then
- loadParams()
- ui.clear()
- print("Program is running\n\nCTRL + T to close")
- else
- params = setParams()
- ui.clear()
- saveParams(params)
- if bs.ui.yesOrNo("Load the Program at startup?") then
- bs.startup.add("bs/programs/Bulk_Storage", true, {true}, "Bulk "..params["name"])
- ui.clear()
- end
- end
- local monitor = peripheral.wrap(params["monitor"]["name"])
- local x, y = monitor.getSize()
- while true do
- local procentage = getProcentage()
- monitor.clear()
- monitor.setCursorPos(params["monitor"]["posX"] + bs.monitor.centralise(params["name"], params["monitor"]["width"]), 1)
- monitor.write(params["name"])
- bs.monitor.vertProgressbar(params["monitor"]["name"], procentage, params["monitor"]["posX"], params["monitor"]["width"], params["monitor"]["color"])
- monitor.setCursorPos(params["monitor"]["posX"] + bs.monitor.centralise(procentage.."%", params["monitor"]["width"]), y)
- monitor.write(procentage.."%")
- sleep(5)
- end
- print(textutils.serialize(params))
Add Comment
Please, Sign In to add comment