Skip to content

Commit

Permalink
Add access to sounds (#336)
Browse files Browse the repository at this point in the history
* Add access to sounds

* Add sounds into the example.js file

* Fix linter issues

* Actually implement sounds. And follow convention of those data

* Update api.md

---------

Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
  • Loading branch information
wgaylord and rom1504 authored Mar 17, 2024
1 parent d012dbb commit b20bb35
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
14 changes: 14 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ console.log(mcData.biomesByName['windswept_gravelly_hills']) // Object containin

Array of biomes

## Sounds

### mcData.sounds

Sounds indexed by id

### mcData.soundsByName

Sounds indexed by name

### mcData.soundsArray

Array of sounds

## Recipes

### mcData.recipes
Expand Down
4 changes: 4 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ console.log(require('minecraft-data')('1.16.4').mapIconsByName.player)
console.log(require('minecraft-data').legacy.pc.blocks['0:0'])

console.log(require('minecraft-data')('1.15.2').attributes['generic.movementSpeed'])

console.log(require('minecraft-data')('1.16').attributes['minecraft:generic.movement_speed'])
console.log(require('minecraft-data')('1.15.2').attributesByName.movementSpeed)
console.log(require('minecraft-data')('1.16').attributesByName.movementSpeed)

console.log(require('minecraft-data')('1.16.5').sounds[21])
console.log(require('minecraft-data')('1.16.5').soundsByName['ambient.underwater.loop.additions.ultra_rare'])
5 changes: 4 additions & 1 deletion lib/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ module.exports = function (mcData) {
mapIconsByName: indexer.buildIndexFromArray(mcData.mapIcons, 'name'),

attributesByName: indexer.buildIndexFromArray(mcData.attributes, 'name'),
attributesByResource: indexer.buildIndexFromArray(mcData.attributes, 'resource')
attributesByResource: indexer.buildIndexFromArray(mcData.attributes, 'resource'),

soundsById: mcData.sounds === undefined ? undefined : indexer.buildIndexFromArray(mcData.sounds, 'id'),
soundsByName: mcData.sounds === undefined ? undefined : indexer.buildIndexFromArray(mcData.sounds, 'name')

}
}
6 changes: 5 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ function mcDataToNode (mcData) {
mapIconsByName: indexes.mapIconsByName,
mapIconsArray: mcData.mapIcons,

tints: mcData.tints
tints: mcData.tints,

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

0 comments on commit b20bb35

Please sign in to comment.