Neon1432

Bulk_Storage

Jan 20th, 2022 (edited)
1,060
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local args = {...}
  2. local params = {}
  3. dofile("bs/apis/wrapper")
  4.  
  5.  
  6.  
  7. -- initialization
  8.  
  9.  
  10.  
  11. local function loadParams()
  12.     local file = fs.open("/bs/files/bulk_Storage_Params", "r")
  13.     local data = file.readAll()
  14.     file.close()
  15.     params = textutils.unserialize(data)
  16. end
  17.  
  18.  
  19.  
  20. local function saveParams(table)
  21.     local file = fs.open("/bs/files/bulk_Storage_Params", "w")
  22.     file.write(textutils.serialize(table))
  23.     file.close()
  24. end
  25.  
  26.  
  27.  
  28. local function setMonitor()
  29.     local returntable = {}
  30.     ui.clear()
  31.     returntable["name"] = ui.getInput("Type the name of the connected monitor") ui.clear()
  32.     returntable["posX"] = ui.getInput("Set the starting position on the x-axis", true) ui.clear()
  33.     returntable["width"] = ui.getInput("Set the width of the progressbar", true) ui.clear()
  34.     returntable["color"] = ui.getInput("Choose a color (numeric) for the progressbar", true) ui.clear()
  35.     return returntable
  36. end
  37.  
  38. local function setChests()
  39.     local chesttable = {}
  40.     local nametable = peripheral.getNames()
  41.  
  42.     local I = 0
  43.     for I = 1, #nametable do
  44.         if peripheral.getType(nametable[I]) == "minecraft:chest" then
  45.             table.insert(chesttable, nametable[I])
  46.         end
  47.     end
  48.  
  49.     ui.printing("Please put a stick named \"tag\" in every chest you want to track")
  50.     ui.pressenter()
  51.  
  52.     local returntable = {}
  53.     for I = 1, #chesttable do
  54.         ui.clear()
  55.         ui.printing("Searching chest "..I.."/"..#chesttable)
  56.         if bs.chest.getIndexOf(chesttable[I], "minecraft:stick", "tag") ~= nil then
  57.             table.insert(returntable, chesttable[I])
  58.         end
  59.         ui.clear()
  60.     end
  61.     return returntable
  62. end
  63.  
  64. local function setParams()
  65.     local paramt = {}
  66.     paramt["monitor"] = setMonitor()
  67.     paramt["name"] = ui.getInput("Enter the displayname for the progressbar")
  68.     ui.clear()
  69.     paramt["chests"] = setChests()
  70.     return paramt
  71. end
  72.  
  73.  
  74.  
  75. --implementation
  76.  
  77.  
  78.  
  79. local function getOccSlotCount(chestname)
  80.     local returncount = 0
  81.     local chest = peripheral.wrap(chestname)
  82.     for I = 1, chest.size() do
  83.         local details = chest.getItemDetail(I)
  84.         if details ~= nil then
  85.             returncount = returncount + 1
  86.         end
  87.     end
  88.     return returncount
  89. end
  90.  
  91.  
  92.  
  93. local function getProcentage()
  94.     local chesttable = params["chests"]
  95.     local maxSlots = 0
  96.     local occSlots = 0
  97.     for I = 1, #chesttable do
  98.         maxSlots = maxSlots + peripheral.wrap(chesttable[I]).size()
  99.         occSlots = occSlots + getOccSlotCount(chesttable[I])
  100.     end
  101.     return math.ceil((occSlots / maxSlots) * 100)
  102. end
  103.  
  104.  
  105.  
  106. -- start
  107.  
  108.  
  109. if args[1] == "true" then
  110.     loadParams()
  111.     ui.clear()
  112.     print("Program is running\n\nCTRL + T to close")
  113. else
  114.     params = setParams()
  115.     ui.clear()
  116.     saveParams(params)
  117.     if bs.ui.yesOrNo("Load the Program at startup?") then
  118.         bs.startup.add("bs/programs/Bulk_Storage", true, {true}, "Bulk "..params["name"])
  119.  
  120.         ui.clear()
  121.     end
  122. end
  123.  
  124. local monitor = peripheral.wrap(params["monitor"]["name"])
  125. local x, y = monitor.getSize()
  126.  
  127. while true do
  128.     local procentage = getProcentage()
  129.     monitor.clear()
  130.    
  131.     monitor.setCursorPos(params["monitor"]["posX"] + bs.monitor.centralise(params["name"], params["monitor"]["width"]), 1)
  132.     monitor.write(params["name"])
  133.  
  134.     bs.monitor.vertProgressbar(params["monitor"]["name"], procentage, params["monitor"]["posX"], params["monitor"]["width"], params["monitor"]["color"])
  135.  
  136.     monitor.setCursorPos(params["monitor"]["posX"] + bs.monitor.centralise(procentage.."%", params["monitor"]["width"]), y)
  137.     monitor.write(procentage.."%")
  138.     sleep(5)
  139. end
  140.  
  141. print(textutils.serialize(params))
  142.  
RAW Paste Data Copied