Skip to content

Commit

Permalink
Expose blockMappings (#257)
Browse files Browse the repository at this point in the history
* Expose blockMappings

* update types
  • Loading branch information
extremeheat authored Mar 4, 2023
1 parent fb4e146 commit c638af0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Example:
console.log(mcData.blocksByStateId[100]) // Object containing information for "Lava" (as Lava has a state range from 91 to 106)
```

### mcData.blockMappings

Contains a list of block mappings between pc/bedrock edition for the current Minecraft version

### mcData.blockStates

**_Bedrock edition only_**
Expand Down
2 changes: 1 addition & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function mcDataToNode (mcData) {
blocksByName: indexes.blocksByName,
blocksArray: mcData.blocks,
blocksByStateId: indexes.blocksByStateId,

blockMappings: mcData.blockMappings,
blockStates: mcData.blockStates, // bedrock

blockCollisionShapes: mcData.blockCollisionShapes,
Expand Down
9 changes: 8 additions & 1 deletion test/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,16 @@ describe('supportFeature', () => {
assert.equal(mcData1Dot17.supportFeature('itemSerializationUsesBlockId'), true)
})

it('works on bedrock', function () {
it('works on bedrock 1.18.0', function () {
const mcData = require('minecraft-data')('bedrock_1.18.0')
assert.equal(mcData.supportFeature('newRecipeSchema'), true)
assert.equal(mcData.supportFeature('fakeRecipeSchema'), false)
})

it('works on bedrock 1.19.1', function () {
const mcData = require('minecraft-data')('bedrock_1.19.1')
assert.equal(mcData.supportFeature('newRecipeSchema'), true)
assert.equal(mcData.supportFeature('fakeRecipeSchema'), false)
assert(mcData.blockMappings.length > 0)
})
})
6 changes: 5 additions & 1 deletion typings/index-template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ export interface LoginPacket {
export interface IndexedData {
isOlderThan(version: string): boolean
isNewerOrEqualTo(version: string): boolean

blocks: { [id: number]: Block }
blocksByName: { [name: string]: Block }
blocksByStateId: { [id: number]: Block }
blocksArray: Block[]
blockMappings: {
pc: { name: string, states: Record<string, string | number> },
pe: { name: string, states: Record<string, string | number> }
}[]
/**
* Bedrock edition only
*/
Expand Down

0 comments on commit c638af0

Please sign in to comment.