Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local a=http.get"https://raw.githubusercontent.com/rxi/json.lua/bee7ee3431133009a97257bde73da8a34e53c15c/json.lua"local b=fs.open("/libs/json.lua","w")b.write(a.readAll())a.close()b.close()
- local json = require("/libs/json")
- local worldurl = "https://dynmap.switchcraft.pw/up/world/world/"
- local tX, tY = term.getSize()
- local reqdelay = 1
- local errdelay = 10
- local world = {}
- local function writeAt(text, x, y, tc, bg)
- term.setCursorPos(x, y)
- term.setTextColor(tc or colors.white)
- term.setBackgroundColor(bg or colors.black)
- term.write(text)
- end
- local function getMinecraftTime(servertime)
- return {
- hours = ((servertime / 1000) + 6) % 24,
- minutes = ((servertime / 1000) % 1) * 60,
- isDay = (servertime >= 0 and servertime < 13700),
- }
- end
- local function getWorld(world)
- if world == "world" then return "Overworld"
- elseif world == "-some-other-bogus-world-" then return "Nether"
- elseif world == "DIM1" then return "The End"
- else return "? "..world
- end
- end
- local function draw(world)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, tY)
- term.setTextColor(colors.red)
- term.write('<---')
- local time = getMinecraftTime(world.servertime)
- local weather = "Sunny"
- if world.hasStorm then weather = "Raining"
- if world.isThundering then weather = "Thunderstorm"
- end
- end
- writeAt(("%d players online | %#2d:%02d (%s) | %s"):format(world.currentcount, time.hours, time.minutes, time.isDay and "Day" or "Night", weather), 1, 1)
- for id, player in pairs(world.players) do
- local bg = (id % 2 == 0) and colors.black or colors.gray
- local cy = 2+id
- term.setCursorPos(1, cy)
- term.setBackgroundColor(bg)
- term.clearLine()
- writeAt("\16 "..player.name, 1, cy, nil, bg)
- writeAt(("| \3%#2d \4%#2d |"):format(player.health, player.armor), 20, cy, nil, bg)
- writeAt(getWorld(player.world), 32, cy, nil, bg)
- writeAt(("| %#5d, %#3d, %#5d"):format(math.floor(player.x), math.floor(player.y), math.floor(player.z)), 42, cy, nil, bg)
- end
- end
- local timeout = os.startTimer(0)
- while true do
- local event, url, data, data2 = os.pullEvent()
- if event == "http_success" then
- local recv = data.readAll()
- data.close()
- world = json.decode(recv)
- if world then
- draw(world)
- timeout = os.startTimer(reqdelay)
- else
- printError("Could not decode json: "..recv)
- timeout = os.startTimer(errdelay)
- end
- elseif event == "http_failure" then
- printError("Could not connect to "..url)
- timeout = os.startTimer(errdelay)
- elseif event == "timer" and url == timeout then http.request(worldurl)
- elseif event == "term_resize" then
- tX, tY = term.getSize()
- draw(world)
- elseif event == "monitor_touch" then
- if data < 5 and data2 == tY then
- break
- end
- elseif event == "key" then
- if url == keys.q then
- sleep(0)
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement