Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soundEffectHeard event is not emitted in 1.20.4 #3329

Open
1 task done
AkagawaTsurunaki opened this issue Mar 14, 2024 · 0 comments
Open
1 task done

soundEffectHeard event is not emitted in 1.20.4 #3329

AkagawaTsurunaki opened this issue Mar 14, 2024 · 0 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@AkagawaTsurunaki
Copy link

Versions

  • mineflayer: 4.20.0
  • server: fabric 1.20.4
  • mods:
    • fabricloader 0.15.7
      • mixinextras 0.3.5
    • java 17
    • minecraft 1.20.4
    • skinrestorer 1.2.4+1.20.2
  • node: 20.9.0

Detailed description of a problem

I'm developing a bot that can hear something from Minecraft. But I found soundEffectHeard event can not be emitted anyway. The following code snippet does not output the corresponding soundName at all.

bot.on('soundEffectHeard', async (soundName, position, volume, pitch) => {
  console.log(`${soundName}`) // No output at all
})

However, the hardcodedSoundEffectHeard event works well. The code snippet is as follows.

bot.on('hardcodedSoundEffectHeard', async (soundId, soundCategory, position, volume, pitch) => {
  console.log(`${soundId}`) // Ouput some numeric sound ID, like 80, 78, 1517...
})

What did you try yet?

Edit the source code and test

I have tried to edit the source code in mineflayer/lib/plugins/sound.js at line 7 to see what will happen.

function inject (bot) {
  bot._client.on('named_sound_effect', (packet) => {
    console.log('Test')
    const soundName = packet.soundName
    const pt = new Vec3(packet.x / 8, packet.y / 8, packet.z / 8)
    const volume = packet.volume
    const pitch = packet.pitch

    bot.emit('soundEffectHeard', soundName, pt, volume, pitch)
  })

 ...

Unfortunately, console.log('Test') does not output anything, inferring that this function is not being called for some reason.

Run command in Minecraft to play sounds

I also tried to run the /playsound command in Minecraft,

/playsound minecraft:entity.zombie.ambient neutral @a

and I can hear the sound being played correctly in Minecraft.

However, there is still no output of the corresponding soundName in JavaScript console.

Maybe because namedSound or this packet from server is not received correctly?

What I noticed at [Protocol - wiki.vg](https://wiki.vg/Protocol#Sound_Effect) is that soundname presents only if the sound ID is 0.

So I ran the command

/playsound 0 neutral @a

The server told me that "Played sound minecraft:0 to 2 players" but there is still no output of the corresponding soundName in JavaScript console.

Your current code

This is my code and it doesn't have any warnings or errors when I running it.

if (process.argv.length < 4 || process.argv.length > 6) {
    console.log('Usage : node guard.js <host> <port> [<name>] [<password>]')
    process.exit(1)
}

const mineflayer = require('mineflayer')
const {pathfinder, Movements, goals} = require('mineflayer-pathfinder')
const pvp = require('mineflayer-pvp').plugin

const bot = mineflayer.createBot({
    host: process.argv[2],
    port: parseInt(process.argv[3]),
    username: process.argv[4] ? process.argv[4] : 'Guard',
    password: process.argv[5]
})
bot.on('soundEffectHeard', async (soundName, position, volume, pitch) => {
  console.log(`${soundName}`)
})

bot.on('hardcodedSoundEffectHeard', async (soundId, soundCategory, position, volume, pitch) => {
  console.log(`${soundId}`)
})

Expected behavior

I want to be able to get soundName, position values from emitted soundEffectHeard event since I need to judge the sound source and position to set my bot's face orientation. While using hardcodedSoundEffectHeard event might work, it's not a good idea due to the sound ID might change for different Minecraft version.

Additional context

  • The bot joined the game and spawned properly. I can see the bot and I can interact with it.
  • Use command /playsound 0 neutral @a in Minecraft does not emit hardcodedSoundEffectHeard event.
@AkagawaTsurunaki AkagawaTsurunaki added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

1 participant