View difference between Paste ID: XZnym2VL and pPrGf2Xh
SHOW: | | - or go back to the newest paste.
1
monitor = peripheral.wrap("left")
2
3
chest1 = peripheral.wrap("chest_1")
4
chest2 = peripheral.wrap("chest_2")
5
6-
letters = "abcdefghijklmnopqrstuvwxyz"
6+
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
7
8
items = {}
9
sortedItems = {}
10
tableLength = 0
11
12
function addChest(chest)
13
  for i = 1, chest.getInventorySize(), 1 do
14
    item = chest.getStackInSlot(i)
15
    if item ~= null then
16
      if items[item["display_name"]] == null then
17
        itemEntry = {}
18
        itemEntry["name"] = item["display_name"]
19
        itemEntry["qty"] = item["qty"]
20
        items[item["display_name"]] = itemEntry
21
        tableLength = tableLength + 1
22
        sortedItems[tableLength] = itemEntry
23
      else
24
        items[item["display_name"]]["qty"] = items[item["display_name"]]["qty"] + item["qty"] 
25
      end
26
    end
27
  end
28
end
29
30
function addChests()
31
  tableLength = 0
32
  items = {}
33
  sortedItems = {}
34
  addChest(chest1)
35
  addChest(chest2)
36
end
37
38
function sort()
39
  for i = tableLength - 1, 1, -1 do
40
    for j = 1, i, 1 do
41-
      print(j)
41+
      if string.find(letters, string.sub(sortedItems[j]["name"], 1, 1)) > string.find(letters, string.sub(sortedItems[j + 1]["name"], 1, 1)) then
42-
      if string.find(letters, string.sub(sortedItems[j]["name"], 1, 1), 0) > string.find(letters, string.sub(sortedItems[j]["name"], 1, 1), 0) then
42+
43
        sortedItems[j] = sortedItems[j+1]
44
        sortedItems[j+1] = temp
45
      end
46-
      end 
46+
47
  end  
48
end
49
50
function refreshMonitor()
51
  monitor.setTextScale(0.5)
52
  monitor.setCursorPos(1, 1)
53
  monitor.clear()
54
  for k, v in pairs(sortedItems) do
55
    monitor.write(v["name"] .. ": " .. v["qty"])
56
    x, y = monitor.getCursorPos()
57
    monitor.setCursorPos(1, y + 1)
58
  end
59
end
60
61
while true do
62
  addChests()
63
  sort()
64
  refreshMonitor()
65
  sleep(5)
66
end