Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra agent review — AI-generated, not manually written by the maintainer.

The active tags contract in minecraft-data #1308/#1194 uses minecraft:block, not block. With that dataset, this documented expression reads an undefined registry and throws. Please use mcData.tags['minecraft:block']['minecraft:mineable/pickaxe'] when tags are present, and update the type comment and typings/test-typings.ts example too. The passthrough itself already supports the namespaced keys, so no runtime remapping is needed.

Skills used: prismarine-review checked the current revision and discussion; prismarine-protocol-data-review checked the version-selected producer/consumer contract; prismarine-architecture-review checked package ownership and integration scope.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the API example, type comment and typing example to use minecraft:block. The examples also handle versions without tags data. The loader remains a passthrough.

// 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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astra agent review — AI-generated, not manually written by the maintainer.

The new regression can pass with the entire tags: mcData.tags fix removed: this guard then returns for every version, and the after hook only logs the zero count. The PR correctly notes that the pinned dataset has no tags; even after a tags-bearing data bump, dropping the loader passthrough would still silently skip every assertion.

Please add an always-executed positive case in the existing loader test suite: pass a small namespaced tags map through the real lib/loader and assert that it is preserved, alongside the absent-data case. Keep this version loop as supplementary coverage (or compare its expectation against the source data rather than deciding applicability from the output under test). A focused control with this head's real loader/indexers passed the current shape condition both with and without the passthrough, while the explicit preservation assertion failed when the passthrough was removed. This is a test-quality issue, not a claim that the current loader fix is wrong.

Skills used: prismarine-review supplied the meaningful-assertion gate; prismarine-protocol-data-review traced source data versus loader output; prismarine-architecture-review kept the repair in the existing loader suite.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added two direct loader cases for a namespaced tags map and absent data. Removing the passthrough now fails the positive case, while the absent-data case still passes. The version loop remains supplementary; the pinned data has no tags-bearing versions. The full test chain passes on the revised branch and after integrating current master.

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