Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ function mcDataToNode (mcData) {

sounds: indexes.soundsById,
soundsByName: indexes.soundsByName,
soundsArray: mcData.sounds
soundsArray: mcData.sounds,

tags: mcData.tags
}
}
23 changes: 23 additions & 0 deletions test/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions typings/index-template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 1 addition & 0 deletions typings/test-typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Loading