(() => { 'use strict'; const POLL_MS = 1000; const $ = (id) => document.getElementById(id); let itemNames = {}; let lastInventorySignature = ''; let lastState = null; const escapeHTML = (value) => String(value ?? '').replace(/[&<>"']/g, (ch) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[ch]); function prettyName(name) { return String(name || 'unknown item').replace(/^minecraft:/, '') .replaceAll('_', ' ').replace(/\b\w/g, (letter) => letter.toUpperCase()); } function vectorText(pos) { if (!pos) return '—'; if (typeof pos === 'object' && ['x', 'y', 'z'].every((key) => key in pos)) { return `${Number(pos.x).toFixed(1)}, ${Number(pos.y).toFixed(1)}, ${Number(pos.z).toFixed(1)}`; } const match = String(pos).match(/-?\d+(?:\.\d+)?/g); return match && match.length >= 3 ? match.slice(0, 3).join(', ') : String(pos); } function dimensionName(name) { return String(name || 'unknown').replace(/^minecraft:/, '').replaceAll('_', ' ').toUpperCase(); } function formatMode(mode) { const modes = {0: 'Survival', 1: 'Creative', 2: 'Adventure', 3: 'Spectator'}; return modes[mode] || (mode == null ? '—' : String(mode)); } function textureCandidates(name) { const id = String(name || '').replace(/^minecraft:/, '').toLowerCase(); if (!/^[a-z0-9_]+$/.test(id) || id === 'air') return []; // Prefer bundled icons, then the same-origin asset proxy. The external // sources remain a last resort for uncached items on older bot processes. const local = `/static/item-icons/${encodeURIComponent(id)}.png`; const proxy = `/api/item-icon/${encodeURIComponent(id)}`; const root = 'https://assets.mcasset.cloud/26.3/assets/minecraft/textures'; const paths = [`item/${id}.png`, `block/${id}.png`]; const simplified = id.replace(/_(slab|stairs|wall|fence_gate|fence|door|trapdoor|button|pressure_plate|sign|hanging_sign|carpet|banner|bed|candle)$/, ''); if (simplified !== id) paths.push(`block/${simplified}.png`, `item/${simplified}.png`); return [local, proxy, ...[...new Set(paths)].map((path) => `${root}/${path}`)]; } function renderItemIcon(img, fallback, itemName) { const candidates = textureCandidates(itemName); let index = 0; const tryNext = () => { if (index >= candidates.length) { img.remove(); fallback.hidden = false; fallback.textContent = prettyName(itemName).slice(0, 2).toUpperCase(); return; } img.src = candidates[index++]; }; img.onerror = tryNext; img.onload = () => { fallback.hidden = true; }; tryNext(); } function inventorySignature(inv, partial) { return JSON.stringify([Boolean(partial), Object.entries(inv || {}).map(([slot, item]) => [ slot, item && item.present, item && item.item_id, item && item.item_count ])]); } function renderInventory(state) { const inv = state.inv || {}; const signature = inventorySignature(inv, state.inventory_partial); if (signature === lastInventorySignature) return; lastInventorySignature = signature; const grid = $('inventory-grid'); const items = []; let stackCount = 0; let totalCount = 0; for (let slot = 0; slot < 46; slot++) { const item = inv[String(slot)] || inv[slot]; if (item && item.present) { stackCount++; totalCount += Number(item.item_count || 0); } items.push({slot, item}); } grid.innerHTML = items.map(({slot, item}) => { const present = Boolean(item && item.present); const itemId = present ? item.item_id : null; const name = present ? (itemNames[String(itemId)] || `item_${itemId}`) : ''; const count = present ? Number(item.item_count || 0) : 0; const title = present ? `${prettyName(name)} × ${count} (id ${itemId}, slot ${slot})` : `Empty slot ${slot}`; return `
`; }).join(''); items.forEach(({slot, item}) => { if (!item || !item.present) return; const icon = grid.children[slot]?.querySelector('img'); const fallback = grid.children[slot]?.querySelector('.icon-fallback'); if (icon && fallback) renderItemIcon(icon, fallback, itemNames[String(item.item_id)] || `item_${item.item_id}`); }); $('inventory-count').textContent = `${totalCount} items`; $('inventory-slots').textContent = `${stackCount} / 46 slots`; $('inventory-warning').hidden = !state.inventory_partial; } function renderPlayers(state) { const players = Object.values(state.players || {}); $('player-count').textContent = String(players.length); if (!players.length) { $('player-list').innerHTML = '