View difference between Paste ID: nN9gjJ1g and LwvspBRs
SHOW: | | - or go back to the newest paste.
1
local monitor = peripheral.wrap("left")
2
local chest = peripheral.wrap("right")
3
local modemSide = "back"
4
local targetID = 5296
5
6
local itemAliases = {
7
  ["projecte:item.pe_matter"] = "Red Matter",
8
  ["projecte:rm_furnace"] = "RM Furnace",
9
  ["projecte:matter_block"] = "RM Block"
10
}
11
12
local function getItemAlias(itemName)
13
  return itemAliases[itemName] or itemName
14
end
15
16
local function formatEMCValue(emc)
17
  local billion = emc / 1000000000 
18
  return string.format("%.2fB", billion)
19
end
20
21
local function getEMCValue(itemName, itemCount)
22
  local emcValue = 0
23
24
  if itemName == "Red Matter" then
25
    emcValue = itemCount * 466944
26
  elseif itemName == "RM Furnace" then
27
    emcValue = itemCount * 10059784
28
  elseif itemName == "RM Block" then
29
    emcValue = itemCount * 1867776
30
  end
31
32
  return emcValue
33
end
34
35
local function getItemsWithPrefix(prefix, items)
36
  local filteredItems = {}
37
38
  for slot, item in pairs(items) do
39
    local itemName = item.name
40
    if string.sub(itemName, 1, #prefix) == prefix then
41
      local alias = getItemAlias(itemName)
42
      local itemCount = item.count or 0  -- Make sure itemCount exists, default to 0 if not
43
      local emc = getEMCValue(alias, itemCount)
44
      table.insert(filteredItems, { name = alias, count = itemCount, emc = emc })
45
    end
46
  end
47
48
  return filteredItems
49
end
50
51
while true do
52
  monitor.clear()
53
  monitor.setBackgroundColor(colors.black)
54
  monitor.setTextColor(colors.red)
55
  monitor.setCursorPos(1, 1)
56
  monitor.write("Chest Contents")
57
58
  rednet.open(modemSide)
59
60
  -- Calculate total EMC value
61
  local totalEMC = 0
62
  local items = chest.list()
63
  local filteredItems = getItemsWithPrefix("projecte:", items)
64
65
  for _, item in ipairs(filteredItems) do
66
    totalEMC = totalEMC + item.emc
67
  end
68
69
  -- Display total EMC value
70
  monitor.setCursorPos(1, 3)
71
  monitor.write("Total EMC: " .. formatEMCValue(totalEMC))
72
73
  -- Send total EMC value via Rednet
74
  rednet.send(targetID, totalEMC)
75
76
  rednet.close(modemSide)
77
78
  local row = 5  -- İlk öğenin yazılacağı satır numarası
79
80
  -- Display individual item details
81
  for _, item in ipairs(filteredItems) do
82
    monitor.setCursorPos(1, row)
83
    monitor.write(item.name .. ": " .. item.count)
84
    row = row + 1  -- Bir sonraki öğe için satır numarasını arttır
85
    monitor.setCursorPos(1, row)
86
    monitor.write("EMC: " .. formatEMCValue(item.emc))
87
    row = row + 2  -- Bir sonraki öğe için boş bir satır bırak
88
  end
89
90
  sleep(3)
91
end
92