fix: fix sound id mapping for some versions like 1.16.5
This commit is contained in:
parent
78d923d817
commit
81a692272c
3 changed files with 49 additions and 25 deletions
|
|
@ -138,9 +138,9 @@ const dataTypeBundling = {
|
|||
protocol: {
|
||||
raw: true
|
||||
},
|
||||
sounds: {
|
||||
arrKey: 'name'
|
||||
}
|
||||
// sounds: {
|
||||
// arrKey: 'name'
|
||||
// }
|
||||
}
|
||||
|
||||
const notBundling = [...dataTypes.keys()].filter(x => !Object.keys(dataTypeBundling).includes(x))
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const updateResourcePack = async () => {
|
|||
let musicInterval: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
subscribeKey(miscUiState, 'gameLoaded', async () => {
|
||||
if (!miscUiState.gameLoaded || !loadedData.sounds) {
|
||||
if (!miscUiState.gameLoaded) {
|
||||
stopMusicSystem()
|
||||
soundMap?.quit()
|
||||
return
|
||||
|
|
@ -108,8 +108,7 @@ subscribeKey(miscUiState, 'gameLoaded', async () => {
|
|||
})
|
||||
|
||||
bot.on('hardcodedSoundEffectHeard', async (soundIdNum, soundCategory, position, volume, pitch) => {
|
||||
const fixOffset = versionToNumber('1.20.4') === versionToNumber(bot.version) ? -1 : 0
|
||||
const soundKey = loadedData.sounds[soundIdNum + fixOffset]?.name
|
||||
const soundKey = soundMap!.soundsIdToName[soundIdNum]
|
||||
if (soundKey === undefined) return
|
||||
await playGeneralSound(soundKey, position, volume, pitch)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ interface ResourcePackSoundsJson {
|
|||
|
||||
export class SoundMap {
|
||||
private readonly soundsPerName: Record<string, SoundEntry[]>
|
||||
soundsIdToName: Record<string, string>
|
||||
private readonly existingResourcePackPaths: Set<string>
|
||||
private activeResourcePackBasePath: string | undefined
|
||||
private activeResourcePackSoundsJson: ResourcePackSoundsJson | undefined
|
||||
|
|
@ -58,24 +59,28 @@ export class SoundMap {
|
|||
) {
|
||||
const allSoundsMajor = versionsMapToMajor(soundData.allSoundsMap)
|
||||
const soundsMap = allSoundsMajor[versionToMajor(version)] ?? Object.values(allSoundsMajor)[0]
|
||||
this.soundsPerName = Object.fromEntries(
|
||||
Object.entries(soundsMap).map(([id, soundsStr]) => {
|
||||
const sounds = soundsStr.split(',').map(s => {
|
||||
const [volume, name, weight] = s.split(';')
|
||||
if (isNaN(Number(volume))) throw new Error('volume is not a number')
|
||||
if (isNaN(Number(weight))) {
|
||||
// debugger
|
||||
throw new TypeError('weight is not a number')
|
||||
}
|
||||
return {
|
||||
file: name,
|
||||
weight: Number(weight),
|
||||
volume: Number(volume)
|
||||
}
|
||||
})
|
||||
return [id.split(';')[1], sounds]
|
||||
|
||||
// Create both mappings
|
||||
this.soundsIdToName = {}
|
||||
this.soundsPerName = {}
|
||||
|
||||
for (const [id, soundsStr] of Object.entries(soundsMap)) {
|
||||
const sounds = soundsStr.split(',').map(s => {
|
||||
const [volume, name, weight] = s.split(';')
|
||||
if (isNaN(Number(volume))) throw new Error('volume is not a number')
|
||||
if (isNaN(Number(weight))) throw new TypeError('weight is not a number')
|
||||
return {
|
||||
file: name,
|
||||
weight: Number(weight),
|
||||
volume: Number(volume)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
const [idPart, namePart] = id.split(';')
|
||||
this.soundsIdToName[idPart] = namePart
|
||||
|
||||
this.soundsPerName[namePart] = sounds
|
||||
}
|
||||
}
|
||||
|
||||
async updateActiveResourcePackBasePath (basePath: string | undefined) {
|
||||
|
|
@ -241,7 +246,6 @@ const blockSoundAliases: BlockSoundMap = {
|
|||
bamboo: 'grass',
|
||||
vine: 'grass',
|
||||
nether_sprouts: 'grass',
|
||||
nether_wart: 'grass',
|
||||
twisting_vines: 'grass',
|
||||
weeping_vines: 'grass',
|
||||
sweet_berry_bush: 'grass',
|
||||
|
|
@ -257,6 +261,28 @@ const blockSoundAliases: BlockSoundMap = {
|
|||
azalea_leaves: 'grass',
|
||||
flowering_azalea_leaves: 'grass',
|
||||
|
||||
// Dirt and ground blocks
|
||||
dirt: 'gravel',
|
||||
coarse_dirt: 'gravel',
|
||||
podzol: 'gravel',
|
||||
mycelium: 'gravel',
|
||||
farmland: 'gravel',
|
||||
dirt_path: 'gravel',
|
||||
rooted_dirt: 'rooted_dirt',
|
||||
|
||||
// Crop blocks
|
||||
wheat: 'crop',
|
||||
potatoes: 'crop',
|
||||
carrots: 'crop',
|
||||
beetroots: 'crop',
|
||||
melon_stem: 'crop',
|
||||
pumpkin_stem: 'crop',
|
||||
sweet_berries: 'crop',
|
||||
cocoa: 'crop',
|
||||
nether_wart: 'crop',
|
||||
torchflower_crop: 'crop',
|
||||
pitcher_crop: 'crop',
|
||||
|
||||
// Stone-like blocks
|
||||
cobblestone: 'stone',
|
||||
stone_bricks: 'stone',
|
||||
|
|
@ -394,7 +420,6 @@ const blockSoundAliases: BlockSoundMap = {
|
|||
soul_lantern: 'lantern',
|
||||
pointed_dripstone: 'pointed_dripstone',
|
||||
dripstone_block: 'dripstone_block',
|
||||
rooted_dirt: 'rooted_dirt',
|
||||
sculk_sensor: 'sculk_sensor',
|
||||
shroomlight: 'shroomlight'
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue