Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.wrap("left")
- chest1 = peripheral.wrap("chest_1")
- chest2 = peripheral.wrap("chest_2")
- letters = "abcdefghijklmnopqrstuvwxyz"
- items = {}
- sortedItems = {}
- tableLength = 0
- function addChest(chest)
- for i = 1, chest.getInventorySize(), 1 do
- item = chest.getStackInSlot(i)
- if item ~= null then
- if items[item["display_name"]] == null then
- itemEntry = {}
- itemEntry["name"] = item["display_name"]
- itemEntry["qty"] = item["qty"]
- items[item["display_name"]] = itemEntry
- tableLength = tableLength + 1
- sortedItems[tableLength] = itemEntry
- else
- items[item["display_name"]]["qty"] = items[item["display_name"]]["qty"] + item["qty"]
- end
- end
- end
- end
- function addChests()
- tableLength = 0
- items = {}
- addChest(chest1)
- addChest(chest2)
- end
- function sort()
- sortedItems = {}
- for i = tableLength - 1, 1, -1 do
- for j = 1, i, 1 do
- print(j)
- if string.find(letters, string.sub(sortedItems[j]["name"], 1, 1), 0) > string.find(letters, string.sub(sortedItems[j]["name"], 1, 1), 0) then
- temp = sortedItems[j]
- sortedItems[j] = sortedItems[j+1]
- sortedItems[j+1] = temp
- end
- end
- end
- end
- function refreshMonitor()
- monitor.setTextScale(0.5)
- monitor.setCursorPos(1, 1)
- monitor.clear()
- for k, v in pairs(sortedItems) do
- monitor.write(v["name"] .. ": " .. v["qty"])
- x, y = monitor.getCursorPos()
- monitor.setCursorPos(1, y + 1)
- end
- end
- while true do
- addChests()
- sort()
- refreshMonitor()
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment