node-minecraft-data icon indicating copy to clipboard operation
node-minecraft-data copied to clipboard

loader: pass tags through to mcData

Open VasilisDragon opened this issue 5 months ago • 0 comments

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.tags passthrough. Plain map like materials; 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 generated Tags interface (the typings generator walks schemas/) can replace it.
  • doc/api.md — mcData.tags section with the undefined-when-absent caveat.
  • test/load.js — per-version shape contract: tags is either undefined or registry → tag → array. Currently exercises the undefined path on every version; picks up real data automatically on bump.

Verified locally

  • Full npm test chain 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 + dataPaths entry applied to the submodule and generate:data re-run, require('minecraft-data')('1.21.8').tags returns the full object (194 block / 179 item / 2 fluid / 39 entity_type tags; minecraft:diamond_ore resolvable through both minecraft:mineable/pickaxe and minecraft:needs_iron_tool — the minecraft-data#987 case), while ('1.21.1').tags and ('bedrock_1.18.0').tags stay undefined. 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 schemas export in index.js and swapping the structural typing for the generated Tags interface — both need the tags schema present in the submodule, so they belong in a follow-up after the first post-schema submodule bump.

VasilisDragon avatar Jun 12 '26 19:06 VasilisDragon