Add world time to web dashboard
This commit is contained in:
@@ -57,6 +57,19 @@
|
||||
return modes[mode] || (mode == null ? '—' : String(mode));
|
||||
}
|
||||
|
||||
function formatWorldClock(ticks) {
|
||||
if (ticks == null) return '—';
|
||||
const time = Number(ticks);
|
||||
if (!Number.isFinite(time)) return '—';
|
||||
const dayTicks = ((Math.floor(time) % 24000) + 24000) % 24000;
|
||||
const minutes = Math.floor((((dayTicks + 6000) % 24000) / 1000) * 60);
|
||||
const hour24 = Math.floor(minutes / 60);
|
||||
const hour12 = hour24 % 12 || 12;
|
||||
const minute = minutes % 60;
|
||||
const period = hour24 < 12 ? 'AM' : 'PM';
|
||||
return `${String(hour12).padStart(2, '0')}:${String(minute).padStart(2, '0')} ${period}`;
|
||||
}
|
||||
|
||||
function textureCandidates(name) {
|
||||
const id = String(name || '').replace(/^minecraft:/, '').toLowerCase();
|
||||
if (!/^[a-z0-9_]+$/.test(id) || id === 'air') return [];
|
||||
@@ -451,6 +464,11 @@
|
||||
const center = state.chunk_state?.center;
|
||||
$('chunk-detail').textContent = center ? `Center ${center[0]}, ${center[1]} · radius ${state.chunk_state.radius ?? '—'}` : 'Waiting for world data';
|
||||
$('game-mode').textContent = formatMode(state.game_mode);
|
||||
const worldTime = online && state.time_base != null && state.time != null
|
||||
? Number(state.time) : NaN;
|
||||
$('world-time').textContent = Number.isFinite(worldTime)
|
||||
? `${Math.floor(worldTime).toLocaleString()} t · ${formatWorldClock(worldTime)}`
|
||||
: '—';
|
||||
$('job-state').textContent = prettyName(state.job_state || 'idle').toUpperCase();
|
||||
$('path-length').textContent = String(state.path?.length || 0);
|
||||
$('entity-count').textContent = `${Object.keys(state.mobs || {}).length} mobs · ${Object.keys(state.objects || {}).length} drops`;
|
||||
|
||||
Reference in New Issue
Block a user