From 29bd9bfa72bfda2ca5293bee5cce46b409fe0fb1 Mon Sep 17 00:00:00 2001 From: Vasilis Dragon Date: Fri, 12 Jun 2026 11:20:30 -0500 Subject: [PATCH] loader: pass tags through to mcData lib/loader.js returns a fixed object, so the tags key emitted by dataPaths-driven data.js getters never reached mcData even once tags data exists in the submodule (minecraft-data#1080). Add the passthrough plus typings, docs, and a per-version shape contract test. With the current submodule pin no version has tags data, so mcData.tags is undefined everywhere: this is inert now and activates on the first submodule bump after minecraft-data#1080 and its schema land. Resolves #315. Loader half of the plan discussed in minecraft-data#412. --- doc/api.md | 13 +++++++++++++ lib/loader.js | 4 +++- test/load.js | 23 +++++++++++++++++++++++ typings/index-template.d.ts | 5 +++++ typings/test-typings.ts | 1 + 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/doc/api.md b/doc/api.md index c186a7c0..ca2c4713 100644 --- a/doc/api.md +++ b/doc/api.md @@ -226,6 +226,19 @@ console.log(mcData.materials['mineable/axe']) // Returns: { '702': 2, '707': 4, '712': 12, '717': 6, '722': 8, '727': 9 } ``` +## Tags + +### mcData.tags + +Registry tags indexed by registry kind (`block`, `item`, `fluid`, `entity_type`), then by namespaced tag name. Tag members are entry names with nested `#tag` references already flattened. `undefined` for versions without tags data. + +Example: + +```js +console.log(mcData.tags.block['minecraft:mineable/pickaxe']) +// Returns: [ 'minecraft:stone', 'minecraft:granite', ... ] +``` + ## Entities ### mcData.mobs diff --git a/lib/loader.js b/lib/loader.js index e8771668..88207ec1 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -85,6 +85,8 @@ function mcDataToNode (mcData) { sounds: indexes.soundsById, soundsByName: indexes.soundsByName, - soundsArray: mcData.sounds + soundsArray: mcData.sounds, + + tags: mcData.tags } } diff --git a/test/load.js b/test/load.js index 21209518..a1a4ea2f 100644 --- a/test/load.js +++ b/test/load.js @@ -54,6 +54,29 @@ describe('versions with block data have block state IDs', () => { }) }) +describe('versions with tags data expose them as registry->tag->members', () => { + const mcData = require('minecraft-data') + const versions = require('minecraft-data').versions + let withTags = 0 + for (const type in versions) { + for (const version of versions[type]) { + it(type + ' ' + version.minecraftVersion, () => { + const data = mcData(type + '_' + version.minecraftVersion) + if (!data || data.tags === undefined) return + withTags++ + for (const registry in data.tags) { + for (const tag in data.tags[registry]) { + assert.ok(Array.isArray(data.tags[registry][tag]), `${registry} ${tag} should map to an array`) + } + } + }) + } + } + after(() => { + console.log(withTags, 'versions with tags data') + }) +}) + describe('supportFeature', () => { it('dimensionIsAnInt is only accessible in 1.8 - 1.15.2', () => { const mcData1Dot9 = require('minecraft-data')('1.9') diff --git a/typings/index-template.d.ts b/typings/index-template.d.ts index 1a3bfd84..ee633930 100644 --- a/typings/index-template.d.ts +++ b/typings/index-template.d.ts @@ -144,6 +144,11 @@ export interface IndexedData { materials: { [name: string]: Material } + /** + * Registry tags keyed by registry kind (block, item, fluid, entity_type), then by namespaced tag name. undefined for versions without tags data + */ + tags?: { [registry: string]: { [tagName: string]: string[] } } + mobs: { [id: number]: Entity } objects: { [id: number]: Entity } entities: { [id: number]: Entity } diff --git a/typings/test-typings.ts b/typings/test-typings.ts index bca02f6f..ebd9e8b0 100644 --- a/typings/test-typings.ts +++ b/typings/test-typings.ts @@ -5,6 +5,7 @@ console.log(mcData.blocksByName['stone']) console.log(mcData.windows['minecraft:brewing_stand']) console.log(mcData.version) console.log(mcData.effectsByName['Haste']) +console.log(mcData.tags?.block['minecraft:mineable/pickaxe']) console.log(mcData.mobs[62]) console.log(mcData.objects[62])