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])