Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Bean Counter Scoreboard
- -- by Fenthis
- local pdirs = { "top", "bottom", "front", "back", "left", "right" }
- local monitor
- local modem
- -- Status channel
- local status_channel = 21231
- local monitor_scale = 1.0
- for i = 1, #pdirs do
- p = peripheral.wrap(pdirs[i])
- if p then
- if p.getSize then
- monitor = p
- end
- if p.transmit then
- modem = p
- end
- end
- end
- if not monitor then
- error("Can not find the monitor!")
- end
- if not modem then
- print("WARNING: No modem found, unable to broadcast updates.")
- end
- if not item_map then
- dofile("item_map.lua")
- end
- -- Initialize the monitor
- function center(str, y)
- monitor.setCursorPos((mx - #str) / 2, y)
- monitor.write(str)
- end
- function setup_monitor()
- monitor.clear()
- monitor.setTextScale(monitor_scale)
- mx, my = monitor.getSize()
- cols = math.floor(mx / 25)
- col_width = math.floor(mx / cols)
- rows = my - 2
- center("Incoming Mining Results", 1)
- monitor.setCursorPos(1,2)
- monitor.write(string.rep("-", mx))
- line = ""
- for i = 1, cols do
- line = line .. string.rep(" ", col_width - 1)
- if i ~= cols then
- line = line .. "|"
- end
- end
- for i = 3, my do
- monitor.setCursorPos(1,i)
- monitor.write(line)
- end
- end
- --- Pads str to length len with char from right
- -- Because string.format("%-10s", ...) is broken in Minecraft QQ
- string.lpad = function(str, len, char)
- if char == nil then char = ' ' end
- return string.sub(str .. string.rep(char, len - #str), 1, len)
- end
- string.rpad = function(str, len, char)
- if char == nil then char = ' ' end
- return string.sub(string.rep(char, len - #str) .. str, 1, len)
- end
- function sorter(a, b)
- return sortlist[a]
- end
- function display(data)
- local sortlist = {}
- function sorter(a, b)
- return data[sortlist[a]] < data[sortlist[b]]
- end
- for k, v in pairs(data) do
- table.insert(sortlist, k)
- end
- table.sort(sortlist, sorter)
- for i = 1, #sortlist do
- k = sortlist[i]
- v = data[sortlist[i]]
- col = math.floor((i - 1) / rows)
- row = ((i - 1) % rows)
- monitor.setCursorPos(
- 1 + (col * col_width),
- 3 + row)
- monitor.write(
- string.lpad(item_map:get_name_by_uuid(k), col_width - 7) ..
- " " ..
- string.rpad(tostring(v), 5)
- )
- i = i + 1
- end
- end
- setup_monitor()
- -- Initialize the Modem
- modem.open(status_channel)
- --
- print("Starting... press Q to exit.")
- -- Main Loop
- while true do
- e, modem, chan, reply, text = os.pullEvent()
- if e == "modem_message" then
- data = textutils.unserialize(text)
- display(data)
- elseif e == "char" and (modem == "Q" or modem == "q") then
- return
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement