Skip to content

feat: Add primitive support for sound api #1422

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

Open
wants to merge 6 commits into
base: dev/3.0.0
Choose a base branch
from

Conversation

Timongcraft
Copy link
Contributor

@Timongcraft Timongcraft commented Sep 3, 2024

With this PR, the Adventure-provided sound API is partially implemented.

It adds the ability to play sounds for a player (from the player itself or other players on the same server) and to stop sounds,
while making the methods fail silently if the sound can't be played/stopped.

What this PR implements:

  • A method to play back (custom) sounds for a specific player (from the player itself or other players) for 1.19.3+
    (- This also enables the respective methods on the registered server, by forwarding it to the players)
  • A method to stop (custom) sounds for players with version 1.19.3+

What this PR doesn't implement:

  • A method to play back (custom) sounds for a specific player at a position or another entity for players of all versions
  • A method to play back (custom) sounds (globally) at a specific location for players of all versions
  • A easily way to access a list of vanilla sounds
    - A method to play back (custom) sounds for a specific player for players with version 1.19.2 and below
    - A method to stop (custom) sounds for players with version 1.19.2 and below

Clarification:
This PR only implements a sound API for version 1.19.3+ because only in this version is the server able to play a (vanilla) sound for a player without requiring a version-dependent id for the sound.

@Timongcraft

This comment was marked as resolved.

@Timongcraft Timongcraft marked this pull request as ready for review September 15, 2024 19:08
@Timongcraft Timongcraft force-pushed the feature/sound-api branch 2 times, most recently from e91c70a to 87b0e57 Compare October 26, 2024 12:45
@nicolube
Copy link

nicolube commented Dec 8, 2024

What is the state of this? I would like to have this feature very much.

@Timongcraft
Copy link
Contributor Author

From my end, it is finished, although I would think it makes more sense to make the methods fail silently again.

@Timongcraft
Copy link
Contributor Author

Timongcraft commented Dec 8, 2024

We could also look into playing sounds from another player, but if so, I think that should be discussed first.

@nicolube
Copy link

@astei Could this be reviewed pls.

@nicolube
Copy link

@4drian3d Since it has been approved, can this also be merged?

@TheXplore
Copy link

What is the state of this? We are currently discussing implementing this ourselves, but we would way prefer having it implemented in upstream.

@Timongcraft
Copy link
Contributor Author

Apart from maybe adding Javadoc to the RegisteredServer, this PR is ready from my end.

@TheXplore
Copy link

@4drian3d Do you think additional Javadoc entries are required? Is there an estimate when this might get merged?

fix: implement the correct playSound method
fix: bumped "since" version
@nicolube
Copy link

nicolube commented Apr 1, 2025

@electronicboy
Sry for the ping, but what is blocking this from being merged?

* <b>This method is not currently implemented in Velocity
* and will not perform any actions.</b>
* <p>Note: This method is currently only implemented for players from version 1.19.3 and above
* and requires a present {@link #getCurrentServer}. Additionally, it only supports {@link Sound.Emitter#self()} for now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're tracking all the entity IDs now, other emitters could be supported right? Not a requirement for this PR, just a future thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, like other players but I found out this:

I did not add support to use other players as emitter, as custom sounds played like that will just appear like if they were coming from the player itself.

And thought it wasn't worth it, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like you were testing with sounds with the wrong number of channels - they definitely should follow the player.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym? I used the player entity sound packet with a entity id of another player, in I think 1.21.4, and it just acted like the sound was coming from the player I sent the packet to. But I could test again.

Copy link
Contributor Author

@Timongcraft Timongcraft May 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, in my testing (new setup, 1.21.4, with paper and with changed velocity code) when using another player as emitter it only is played from the other player if it is 1. a vanilla sound, and 2. uses the stream parameter like music_disc.cat but not minecraft:item.goat_horn.sound.2.
And thus I did not find it useful and too complicated to understand to include.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a stereo sound it will never play following the entity and instead will play globally. https://bugs.mojang.com/browse/MC-146721

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks, didn't know about that.
I'll test and implement it again.
Would it make sense to add that to the adventure javadoc, I'd open a pr if you want?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be a good addition to the Sound class yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be a good addition to the Sound class yes.

Why the 'Sound' class instead of the specific 'playSound' method in 'Audience'?

@Timongcraft
Copy link
Contributor Author

Even though the sound should be ignored for invalid entity ids, I still choose to test for the current server and thus require it on the receiver because afaik they are not that unique and if there's some other entity with that id exists, it could cause unwanted consequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants