From 81a692272cbaf24118b7c4dd1fa57a3aeef70cfa Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 22 Feb 2025 20:57:40 +0300 Subject: [PATCH] fix: fix sound id mapping for some versions like 1.16.5 --- scripts/makeOptimizedMcData.mjs | 6 ++-- src/sounds/botSoundSystem.ts | 5 ++- src/sounds/soundsMap.ts | 63 +++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/scripts/makeOptimizedMcData.mjs b/scripts/makeOptimizedMcData.mjs index ebc97b59..eae0444b 100644 --- a/scripts/makeOptimizedMcData.mjs +++ b/scripts/makeOptimizedMcData.mjs @@ -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)) diff --git a/src/sounds/botSoundSystem.ts b/src/sounds/botSoundSystem.ts index fa4bb88c..059f7e65 100644 --- a/src/sounds/botSoundSystem.ts +++ b/src/sounds/botSoundSystem.ts @@ -21,7 +21,7 @@ const updateResourcePack = async () => { let musicInterval: ReturnType | 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) }) diff --git a/src/sounds/soundsMap.ts b/src/sounds/soundsMap.ts index bb849cca..7cdfe74d 100644 --- a/src/sounds/soundsMap.ts +++ b/src/sounds/soundsMap.ts @@ -48,6 +48,7 @@ interface ResourcePackSoundsJson { export class SoundMap { private readonly soundsPerName: Record + soundsIdToName: Record private readonly existingResourcePackPaths: Set 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' }