// Smelt window UI. The engine reports progress and a verdict for each mod; // this file only turns that into the four screens a player ever sees. (function () { const S = window.Sprites; const icon = { min: '', max: '', close: '', check: '', plus: '', folder: '', }; // What the engine reports for each mod it reads. const VERDICTS = { 'spyglass-zoom-2.1.jar': { name: 'Spyglass Zoom', verdict: 'works', kind: 'code', title: 'Ready for Minecraft on Rust', lines: [['ok', 'Zoom key and smooth zoom, rewritten in Rust']], out: 'spyglass-zoom.hnmod', size: '52 KB', added: 'Horizon asks you to trust new mods the first time it starts them.', }, 'corner-clock-1.3.jar': { name: 'Corner Clock', verdict: 'partly', kind: 'code', title: 'Ready, with one gap', lines: [['ok', 'The clock in the corner of your screen'], ['warn', 'Its settings menu doesn’t come over yet']], out: 'corner-clock.hnmod', size: '38 KB', added: 'Horizon asks you to trust new mods the first time it starts them.', }, 'copper-decor-1.0.jar': { name: 'Copper Decor', verdict: 'works', kind: 'content', title: 'Ready for Minecraft on Rust', lines: [['ok', '48 blocks, 31 recipes and all their textures'], ['ok', 'No code inside, so there’s nothing to trust']], out: 'copper-decor.hmod', size: '1.4 MB', added: 'Restart Horizon to see the new blocks.', }, 'shader-tweaks-0.9.jar': { name: 'Shader Tweaks', verdict: 'no', kind: 'none', title: 'This one can’t come over yet', lines: [['off', 'It changes how the game draws the world. Minecraft on Rust can’t load that kind of change yet.']], }, }; const PILL = { works: 'Works', partly: 'Partly', no: 'Won’t run' }; const STEPS = ['Reading the mod', 'Rewriting it in Rust', 'Packing it for Horizon']; const SEGMENTS = 24; const app = document.getElementById('app'); app.innerHTML = `
${S.svg('ingot', 20)}smelt
Java mods for Minecraft on Rust
${icon.min}${icon.max}${icon.close}
`; const zone = app.querySelector('.zone'); const stage = app.querySelector('.stage'); const toast = app.querySelector('#toast'); const devSwitch = app.querySelector('#dev'); const dash = ''; let current = null; let devOn = false; function set(cls, html) { zone.className = 'zone ' + cls; stage.classList.toggle('wide', cls === 'dev'); zone.innerHTML = html; } function idle(over) { hideToast(); set(over ? 'over' : 'dashed', `${dash}
${S.svg('jar', 48)}
${S.svg('ingot', 48)}

${over ? 'Release to smelt' : 'Drop a mod here'}

A Fabric or NeoForge .jar. It comes out as a Rust mod for Minecraft on Rust.

Works offline. Nothing leaves your PC.
`); const pick = zone.querySelector('#pick'); if (pick) pick.onclick = () => chooser.click(); } function smelting(file) { set('solid', `
${S.svg('jar', 96)}
${S.svg('ingot', 96)}
${file}
${''.repeat(SEGMENTS)}
${STEPS.map((s) => `${s}`).join('')}
`); } function progress(p, step) { const morph = zone.querySelector('.morph'); if (!morph) return; morph.style.setProperty('--p', p.toFixed(3)); const on = Math.round(p * SEGMENTS); zone.querySelectorAll('.bar i').forEach((seg, i) => { seg.classList.toggle('on', i < on); seg.classList.toggle('tip', i === on - 1 && p < 1); }); zone.querySelectorAll('.steps span').forEach((s, i) => { s.className = i < step ? 'past' : i === step ? 'now' : ''; }); } function result(v) { current = v; if (devOn && v.verdict !== 'no') return developer(v); const art = v.verdict === 'no' ? S.svg('slag', 96) : S.svg(v.kind === 'content' ? 'block' : 'ingot', 96); const artCls = v.verdict === 'no' ? 'no' : v.kind === 'content' ? 'content' : ''; const buttons = v.verdict === 'no' ? `` : ``; set('solid', `
${art}
${PILL[v.verdict]}

${v.title}

${v.out ? `
${S.svg(v.kind === 'content' ? 'block' : 'ingot', 16)}${v.out}${v.size}
` : ''}
${buttons}
${v.verdict === 'no' ? '' : ''}`); } // Developer mode: the same result with the code laid open. const JAVA = [ 'public class SpyglassZoom', ' implements ClientModInitializer {', ' static KeyBinding zoom;', ' static double fov = 1.0;', '', ' public void onInitializeClient() {', ' zoom = KeyBindingHelper.registerKeyBinding(', ' new KeyBinding("key.spyglass.zoom",', ' GLFW.GLFW_KEY_C, "Spyglass Zoom"));', '', ' ClientTickEvents.END_CLIENT_TICK', ' .register(client -> {', ' double target = zoom.isPressed()', ' ? 0.25 : 1.0;', ' fov += (target - fov) * 0.4;', ' });', ' }', '}', ]; const RUST = [ '// mixins/spyglass_zoom/runtime.rs', 'pub const ID: &str = "spyglass_zoom";', '', '#[derive(Default)]', 'pub struct Zoom { held: bool, fov: f64 }', '', '// hook: native_key', 'pub fn key(game: &Game, key: &str,', ' down: bool, z: &mut Zoom) {', ' let bound = game.native_mod_key(', ' ID, "zoom", "key.keyboard.c");', ' if key == bound { z.held = down; }', '}', '', '// hook: native_tick, 20 times a second', 'pub fn tick(z: &mut Zoom) {', ' let target = if z.held { 0.25 } else { 1.0 };', ' z.fov += (target - z.fov) * 0.4;', '}', ]; const TOKEN = /(\/\/.*$)|("[^"]*")|(#\[[^\]]*\])|\b(public|class|implements|static|double|void|new|pub|const|struct|fn|let|if|else|mut|bool|f64|str)\b|\b([A-Z][A-Za-z_]+)\b|\b(\d+\.\d+)\b/g; const esc = (t) => t.replace(/&/g, '&').replace(//g, '>'); function highlight(line) { let out = ''; let last = 0; line.replace(TOKEN, (m, comment, str, attr, kw, type, num, at) => { const cls = comment || attr ? 'tk-c' : str ? 'tk-s' : kw ? 'tk-k' : type ? 'tk-t' : 'tk-n'; out += esc(line.slice(last, at)) + `${esc(m)}`; last = at + m.length; return m; }); return out + esc(line.slice(last)); } function code(lines, hl) { return lines.map((l, i) => `${i + 1}${highlight(l)}`).join(''); } function developer(v) { set('dev', `
${v.name}${PILL[v.verdict]} spyglass-zoom-2.1.jar → ${v.out}
Code
SpyglassZoomrewritten
RendererMixinreplaced
ZoomConfigrewritten
Assets
lang/ · 3copied
textures/ · 2copied
Hooks used
native_key
native_tick
native_zoom
JavaSpyglassZoom.java
${code(JAVA, [13, 14, 15])}
Rustruntime.rs
${code(RUST, [17, 18])}
KeyBinding → native_mod_keyMapped automatically
END_CLIENT_TICK → native_tickMapped automatically
RendererMixin → native_zoomKnown pattern. Worth a quick look
`); } function showToast(html) { toast.innerHTML = html; toast.classList.add('show'); } function hideToast() { toast.classList.remove('show'); } zone.addEventListener('click', (e) => { const act = e.target.closest('[data-act]')?.dataset.act; if (act === 'again') idle(false); if (act === 'add') add(); }); function add() { const b = zone.querySelector('[data-act="add"]'); if (!b || !current) return; b.className = 'btn done'; b.innerHTML = `${icon.check}Added to Horizon`; showToast(current.added); } devSwitch.addEventListener('click', () => dev(!devOn)); function dev(on) { devOn = on; devSwitch.classList.toggle('on', on); if (current && zone.querySelector('.result, .dev')) result(current); } const wait = (ms) => new Promise((r) => setTimeout(r, ms)); async function run(file, pace = 1) { const v = VERDICTS[file] || { ...VERDICTS['spyglass-zoom-2.1.jar'], name: file.replace(/\.jar$/, '') }; smelting(file); await wait(300 * pace); const per = SEGMENTS / STEPS.length; for (let s = 0; s < STEPS.length; s++) { for (let k = 1; k <= per; k++) { progress((s * per + k) / SEGMENTS, s); await wait(((s === 1 ? 70 : 45) + (k % 3) * 12) * pace); } } progress(1, STEPS.length); await wait(380 * pace); result(v); } // Real drag and drop. let depth = 0; const busy = () => zone.classList.contains('solid') && zone.querySelector('.morph'); window.addEventListener('dragenter', (e) => { e.preventDefault(); if (!busy() && depth++ === 0) idle(true); }); window.addEventListener('dragover', (e) => e.preventDefault()); window.addEventListener('dragleave', () => { if (!busy() && --depth === 0) idle(false); }); window.addEventListener('drop', (e) => { e.preventDefault(); depth = 0; const f = e.dataTransfer.files[0]; if (f && !busy()) run(f.name); }); const chooser = Object.assign(document.createElement('input'), { type: 'file', accept: '.jar' }); chooser.onchange = () => chooser.files[0] && run(chooser.files[0].name); idle(false); window.smelt = { idle, run, add, dev, result: (file) => result(VERDICTS[file]), // Freeze the smelting screen at one moment (used for screenshots). at: (file, p, step) => { smelting(file); progress(p, step); }, }; })();