node-minecraft-data
node-minecraft-data copied to clipboard
loader: pass tags through to mcData
Summary
Implements the loader half discussed in PrismarineJS/minecraft-data#412 and resolves #315 (block tags feature request, 2023): lib/loader.js returns a fixed object and never passed tags through, so mcData.tags (and registry.tags downstream) stayed undefined even once tags data exists. This adds the passthrough.
bin/generate_data.js already builds data.js getters from every dataPaths key, so the data side needs no change here — the loader's return object was the only gap. With the current submodule pin no version has tags data, so mcData.tags is undefined everywhere: this merges green now, stays inert, and activates automatically on the next submodule bump after minecraft-data#1080 (+ its schema) land.
Changes
lib/loader.js—tags: mcData.tagspassthrough. Plain map likematerials; no id index applies (tags are already name-keyed).typings/index-template.d.ts—tags?: { [registry: string]: { [tagName: string]: string[] } }. Structural type for now; once the tags schema is in the submodule, the generatedTagsinterface (the typings generator walksschemas/) can replace it.doc/api.md—mcData.tagssection with theundefined-when-absent caveat.test/load.js— per-version shape contract:tagsis eitherundefinedor registry → tag → array. Currently exercises theundefinedpath on every version; picks up real data automatically on bump.
Verified locally
- Full
npm testchain green with the change (generate:types, generate:data, lint, test:types, mocha — 1,735 passing). - End-to-end simulation of the post-#1080 world: with that PR's
tags.json+dataPathsentry applied to the submodule andgenerate:datare-run,require('minecraft-data')('1.21.8').tagsreturns the full object (194 block / 179 item / 2 fluid / 39 entity_type tags;minecraft:diamond_oreresolvable through bothminecraft:mineable/pickaxeandminecraft:needs_iron_tool— the minecraft-data#987 case), while('1.21.1').tagsand('bedrock_1.18.0').tagsstayundefined. No loader re-touch needed at bump time.
Out of scope
- A tag-based
digTime()/harvest path in prismarine-block. That needs a design decision on where tool-tier speeds live (see minecraft-data#412); this PR only makes the data reachable so that discussion can happen against something concrete. - The module-level
schemasexport inindex.jsand swapping the structural typing for the generatedTagsinterface — both need the tags schema present in the submodule, so they belong in a follow-up after the first post-schema submodule bump.