Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.wrap("left")
- local chest = peripheral.wrap("right")
- local modemSide = "back"
- local targetID = 5296
- local itemAliases = {
- ["projecte:item.pe_matter"] = "Red Matter",
- ["projecte:rm_furnace"] = "RM Furnace",
- ["projecte:matter_block"] = "RM Block"
- }
- local function getItemAlias(itemName)
- return itemAliases[itemName] or itemName
- end
- local function formatEMCValue(emc)
- local billion = emc / 1000000000
- return string.format("%.2fB", billion)
- end
- local function getEMCValue(itemName, itemCount)
- local emcValue = 0
- if itemName == "Red Matter" then
- emcValue = itemCount * 466944
- elseif itemName == "RM Furnace" then
- emcValue = itemCount * 10059784
- elseif itemName == "RM Block" then
- emcValue = itemCount * 1867776
- end
- return emcValue
- end
- local function getItemsWithPrefix(prefix, items)
- local filteredItems = {}
- for slot, item in pairs(items) do
- local itemName = item.name
- if string.sub(itemName, 1, #prefix) == prefix then
- local alias = getItemAlias(itemName)
- local itemCount = item.count or 0 -- Make sure itemCount exists, default to 0 if not
- local emc = getEMCValue(alias, itemCount)
- table.insert(filteredItems, { name = alias, count = itemCount, emc = emc })
- end
- end
- return filteredItems
- end
- while true do
- monitor.clear()
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.red)
- monitor.setCursorPos(1, 1)
- monitor.write("Chest Contents")
- rednet.open(modemSide)
- -- Calculate total EMC value
- local totalEMC = 0
- local items = chest.list()
- local filteredItems = getItemsWithPrefix("projecte:", items)
- for _, item in ipairs(filteredItems) do
- totalEMC = totalEMC + item.emc
- end
- -- Display total EMC value
- monitor.setCursorPos(1, 3)
- monitor.write("Total EMC: " .. formatEMCValue(totalEMC))
- -- Send total EMC value via Rednet
- rednet.send(targetID, totalEMC)
- rednet.close(modemSide)
- local row = 5 -- İlk öğenin yazılacağı satır numarası
- -- Display individual item details
- for _, item in ipairs(filteredItems) do
- monitor.setCursorPos(1, row)
- monitor.write(item.name .. ": " .. item.count)
- row = row + 1 -- Bir sonraki öğe için satır numarasını arttır
- monitor.setCursorPos(1, row)
- monitor.write("EMC: " .. formatEMCValue(item.emc))
- row = row + 2 -- Bir sonraki öğe için boş bir satır bırak
- end
- sleep(3)
- end
Add Comment
Please, Sign In to add comment