# Adding a machine Each machine is two new files. Never edit shared files (`assets/*`, `tools/*`, `tests/run.mjs`, `index.html`, `assets/catalog.js`) in a machine branch. `assets/catalog.js` is generated and is regenerated after merges. If the engine lacks something, put a local helper in your spec and note the gap in `NOTES.md`. ## Files ``` machines/.js spec: GTCalc.register({...}) machines/.html thin shell: loads ../assets/{style.css,engine.js,charts.js,ui.js} and .js ``` Scaffold both: ```sh node tools/new-machine.mjs mega-chemical-reactor --name "Mega Chemical Reactor" \ --controller MTEMegaChemicalReactor --mod GregTech --category "Chemistry" --tier IV ``` `--source` is looked up from the controller class if omitted. The scaffold contains `TODO` placeholders; validation fails until they are replaced. `machines/ebf.js` (heat, custom calculator overrides, sweeps) and `machines/lcr.js` (perfect OC, comparison table) are the reference specs. ## Spec fields | Field | Required | Meaning | |---|---|---| | `id` | yes | kebab-case, equals the file name | | `name`, `summary` | yes | display name; one line (≤ 160 chars) for the index card | | `description` | no | HTML lede under the title (defaults to `summary`) | | `mod` | yes | one of `GTCalc.MODS` | | `category` | yes | one of `GTCalc.CATEGORIES` | | `tier` | yes | `GT.VN` name of the tier the machine is available from (index filter) | | `controller`, `source` | yes | Java class name and path relative to `src/main/java`; the build checks that the class exists there | | `tags` | no | search keywords | | `inputs` | yes | list of controls (below) | | `compute(values, GT)` | yes | pure function, returns the result object (below) | | `sweeps` | no | charts: `{ id, title, description, input, values?, xLabel, y: { label, log, format }, series: [{ label, value }] , type: 'line'|'bar' }`, up to 4 series. `value` is a key of `result.values` or `(values, result) => number`. Points whose compute returns errors are gaps. | | `notes` | yes | HTML: how it is calculated, with sparse `File.java:line` citations, and what is not modelled | | `examples` | yes | `[{ name, inputs, expect, source, tolerance? }]`, see "Examples" | | `mount(el, ctx)` | no | custom page: replaces the generic inputs/results area (see "Custom pages") | Inputs (`id` must be an identifier; every input except `hatches` needs a `default`): - `{ type: 'number', id, label, unit?, default, min?, max?, integer?, step? }` - `{ type: 'select' | 'segmented', id, label, options: [{ value, label }] | (GT) => [...], default }` - `{ type: 'toggle', id, label, default: false }` - `{ type: 'tier', id, label, min?, max?, default }`: value is the tier index 0..14 - `{ type: 'coil', id, label, min?, max?, default }`: value is `HeatingCoilLevel.getTier()` (Cupronickel 0 … Eternal 13); `GT.coilByTier(t).heat` - `{ type: 'hatches', id, label, kinds: ['energy', 'multi', 'laser'], extended?, default: [{ kind, tier, count, amps? }] }`: value is the hatch list; pass it to `GT.hatchPower(list, { extended })`. List only the hatch kinds the structure accepts (`HatchElement.Energy` = regular only; `ExoticEnergy` = multi-amp and laser too). Set `extended: true` for `MTEExtendedPowerMultiBlockBase` subclasses. - `{ type: 'group', label, inputs: [...] }`: fieldset - Any input: `hint` (string or `(values, GT) => string`), `disabled(values, GT)`, `visible(values, GT)` Result of `compute`: ```js { values: { ... }, // machine-readable numbers/strings; examples and sweeps read these tiles: [{ label, value, unit?, sub?, tone?: 'hero'|'good'|'bad'|'muted', format?: 'num'|'si'|'ticks'|'pct'|fn }], ocline: ['html line', ...], // optional formula trace tables: [{ title, columns: [{ label, num }], rows: [[...]], current? }], warnings: ['html', ...], errors: ['html', ...], info: ['html', ...], } ``` All inputs are stored in the URL hash, so links can be shared. ## Engine (`assets/engine.js`, global `GT`) - `new GT.ProcessingLogic()` ports `ProcessingLogic`, with the same setters: `setMaxParallel`, `setEuModifier`, `setSpeedBonus`, `setAvailableVoltage/Amperage`, `setUnlimitedTierSkips`, `setMaxTierSkips`, `enablePerfectOverclock`, `setOverclock(time, power)`, `setAmperageOC`, `setBatchSize`. Also `setPower(GT.hatchPower(...))`, plus `setInputLimit(n)` and `setVoidProtectionLimit(n)` in place of item matching. To port a Java override, override the method on the instance: `validateRecipe(r)` returns `{ ok: false, result, value }` on failure, and `createOverclockCalculator(r)` / `createParallelHelper(r)` / `calculateDuration(r, helper, calc)` work as in Java (see `machines/ebf.js`). `process({ eut, duration, specialValue })` returns `{ ok, result, eut, duration, parallel, overclocks, heatOverclocks, regularOverclocks, laserOverclocks, subTickMultiplier, durationMultiplier, recipesPerSecond, euPerRecipe, calculator, helper }`. - `GT.OverclockCalculator` and `GT.ParallelHelper` port the Java classes with the same setter names. Use them directly when a machine bypasses `ProcessingLogic`. - `GT.hatchPower(list, { extended })` returns `{ voltage, amperage, maxInputVoltage (sum of V), maxInputAmps, totalEu, useSingleAmp }`. - Constants and helpers: `GT.V`, `GT.VP`, `GT.VN`, `GT.TIER.IV`, `GT.getTier`, `GT.getTiersAbove`, `GT.log4`, `GT.powInt`, `GT.toInt`, `GT.toLong`, `GT.COILS`, `GT.fmt.*`, `GT.resultText(res)`. - Java casts: `(int)` of a double → `GT.toInt`; `(long)` → `GT.toLong` (BigInt); long division → `GT.ldiv`; `(float)` → `Math.fround`. `getMaxInputVoltage()` is a sum of hatch voltages (`ExoticEnergyInputHelper.java:67-74`); `getTier` of that sum drives most `parallel per tier` formulas. ## Build and test ```sh node tools/build.mjs --validate # in a machine worktree: validates specs and shells, writes nothing timeout 120 node tests/run.mjs # engine tests, Java fixtures, every machine's examples (< 60 s) timeout 120 node tests/run.mjs ebf # only tests whose name contains "ebf" node tools/build.mjs # after merging: regenerate assets/catalog.js ``` Build and tests load each machine file in its own context, as a browser page does, so top-level helper names in different specs cannot collide. The suite also renders pages in a small DOM stub (`tests/lib/dom-stub.mjs`); a spec whose `compute()` returns tiles and values renders without extra work. Open `machines/.html` directly from disk (`file://`) or through any static server. ## Citations and verification - State only what you verified in the 2.9.0 source (`gt5-2.9.0/src/main/java`). Cite `File.java:line` in `notes` and in `NOTES.md`. In code comments, cite only where the line is not obvious, and keep comments sparse. - The 10 existing calculators (`dashboard-2.9.0/new/*.html`, `NOTES-*.md`) specify mechanics that were already verified. They do not specify the design. - Recipe values come from the 2.9.0 dump (`gt_recipes.json`, queried with `jq` or `uv run python`; never load it whole into context). Where the dump and the source disagree, the source wins. - Examples: at least one, ideally 3–5, covering the edge cases (single hatch, sub-tick, batch, insufficient heat/voltage). Every example needs `source`: how the expected values were obtained. Preferred method: run the unmodified Java `OverclockCalculator` with the machine's parameters: ```sh TMPDIR=/tmp/ tools/java-ref/run.sh "" case recipeEUt=1920 duration=2500 voltage=8192 amperage=4 \ recipeHeat=4000 machineHeat=5801 heatOC=true heatDiscount=true maxParallel=1 batch=128 ``` Keys: `recipeEUt duration voltage amperage maxParallel euMod speed timeRed powerInc amperageOC laserOC maxTierSkips maxOC maxRegOC recipeHeat machineHeat heatOC heatDiscount batch inputLimit underOneTick`. The output has `plain` (calculator alone) and `process` (ParallelHelper + `applyRecipe` path: parallel, EU/t, final duration). Machine-specific values (heat capacity, parallel formula, speed bonus) still need a hand derivation from the Java lines. Write that derivation in `source` or `NOTES.md`. - `expect` keys are keys of `result.values` (or `errors` / `warnings` for counts). Comparison is exact unless `tolerance` (relative) is given. ## Custom pages Set `mount(el, ctx)` for machines the generic form does not fit (several linked machines, module systems, non-recipe models). The framework still renders the header, notes and footer. Inside `mount`, use `ctx.values` (state from the URL hash), `ctx.writeHash()`, `ctx.ui.renderControls(container, inputs, values, onChange)`, `ctx.ui.renderTiles`, `ctx.ui.renderMessages`, `ctx.ui.renderTable`, `ctx.charts.line/bar`. Keep `compute()` and `examples` so the test runner can still check the numbers. ## Finish Commit `machines/.js` and `machines/.html`. Append findings and dead ends to `NOTES.md` under a heading for your machine. Do not commit `assets/catalog.js`; if the full build rewrote it, run `git checkout assets/catalog.js`.