Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cache = {}
- local chest = peripheral.find(...)
- -- Update the cache
- local function UpdateCache(chest)
- local funcs = {}
- local list = chest.list()
- -- Populate functions list
- for i = 1, chest.size() do
- if not list[i] then break end
- funcs[i] = function() -- for each slot, store nbtHash and label to cache
- cache[i] = {
- nbtHash = list[i].nbtHash,
- label = chest.getItemMeta(i).media.label -- note that this will throw an error if you insert a non-cassete to chest
- }
- end
- end
- cache = {} -- clear the cache then update it
- parallel.waitForAll(table.unpack(funcs))
- end
- -- Check if the contents of chest are different than cached
- local function CheckDiff(chest)
- local list = chest.list()
- for i = 1, chest.size() do -- if slot[i] is not equal to cache[i] then
- if list[i] and not cache[i] or cache[i] and not list[i] then return true end
- if cache[i].nbtHash ~= list[i].nbtHash then
- return true
- end
- end
- return false
- end
- -- main loop, check for differences, update if so.
- while true do
- if CheckDiff(chest) then
- UpdateCache()
- end
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement