Minecraft:Commands/playsound: Difference between revisions
More actions
imported>RedX Undo revision 3474903 by ~2026-EndermanHoglinTadpole5639 (talk) -- test edit |
Fix template calls: add MC/ prefix |
||
| (One intermediate revision by the same user not shown) | |||
| Line 4: | Line 4: | ||
* 2 {{only|java|short=1}} | * 2 {{only|java|short=1}} | ||
* 1 {{only|bedrock|short=1}} | * 1 {{only|bedrock|short=1}} | ||
|others= | |others=Cheat only{{only|bedrock|short=1}} | ||
}} | }} | ||
Plays a specified | Plays a specified sound to a player, in a location, and in a specific volume and pitch. | ||
== Syntax == | == Syntax == | ||
| Line 16: | Line 16: | ||
== Arguments == | == Arguments == | ||
{{ | {{MC/Argument|sound|resource_location|sound: string|basic_string}} | ||
: Specifies the sound to play. | : Specifies the sound to play. | ||
: {{ | : {{MC/In|bedrock}}, {{lcfirst:{{MC/Arg desc|be=string}}}} Should be a sound definition defined in <samp>[[Minecraft:Sounds.json#Bedrock Edition values|sound_definitions.json]]</samp> (for example, <code>mob.pig.say</code>). | ||
: {{ | : {{MC/In|java}}, {{lcfirst:{{MC/Arg desc|je=resource_location}}}} Should be a '''Sound Event''' defined in <samp>[[Minecraft:Sounds.json#Sound events|sounds.json]]</samp> (for example, <code>entity.pig.ambient</code>). | ||
: A sound event may be affiliated with multiple sounds, and the sound that is actually produced is chosen at random from them, modified by their "weight", just as the game normally would. For example, the <code>entity.pig.ambient</code> sound event plays one of several pig sounds at random, because the event has multiple sounds associated with it. | : A sound event may be affiliated with multiple sounds, and the sound that is actually produced is chosen at random from them, modified by their "weight", just as the game normally would. For example, the <code>entity.pig.ambient</code> sound event plays one of several pig sounds at random, because the event has multiple sounds associated with it. | ||
:Resource packs may add their own events to sounds.json; the command successfully plays these. File names are ''not'' used by this command; it strictly uses the events defined in sounds.json (which may not even be similar to the original file names and paths), and thus a resource pack adding new sound files must define events for them (this is not necessary when replacing old sounds already defined in events). | |||
{{ | {{MC/El|je|short=1}}: {{MC/Code|<''source''>}} | ||
: Specifies the music category and options the sound falls under. Must be <code>master</code>, <code>music</code>, <code>record</code>, <code>weather</code>, <code>block</code>, <code>hostile</code>, <code>neutral</code>, <code>player</code>, <code>ambient</code>, <code>voice</code>, or <code>ui</code>. If omitted, <code>master</code> is used. | : Specifies the music category and options the sound falls under. Must be <code>master</code>, <code>music</code>, <code>record</code>, <code>weather</code>, <code>block</code>, <code>hostile</code>, <code>neutral</code>, <code>player</code>, <code>ambient</code>, <code>voice</code>, or <code>ui</code>. If omitted, <code>master</code> is used. | ||
{{ | {{MC/Argument|targets|entity|player: target|CommandSelector<Player>}} | ||
: Specifies the player(s) for whom the sound is going to be played. If not specified, defaults to the player who executes the command. | : Specifies the player(s) for whom the sound is going to be played. If not specified, defaults to the player who executes the command. | ||
: {{ | : {{MC/Arg desc|je=entity|amount=multiple|type=players|be=player}} | ||
{{ | {{MC/Argument|pos|vec3|position: x y z|CommandPositionFloat}} | ||
: Specifies the [[Minecraft:Coordinates|position]] to play the sounds from. | : Specifies the [[Minecraft:Coordinates|position]] to play the sounds from. | ||
: {{ | : {{MC/Arg desc|je=vec3|be=CommandPositionFloat}} | ||
{{ | {{MC/Argument|volume|float|volume: float|float}} | ||
: Specifies the distance that the sound can be heard. If not specified, defaults to 1. For values less than 1, the volume diminishes. For values greater than 1, the sound does not actually grow louder, but its audible range (a 16-block radius at 1) is multiplied by volume. There is always a gradual falloff to silence based on distance from the center of the sphere. For values equal to or less than 0, no player can hear the sound. | : Specifies the distance that the sound can be heard. If not specified, defaults to 1. For values less than 1, the volume diminishes. For values greater than 1, the sound does not actually grow louder, but its audible range (a 16-block radius at 1) is multiplied by volume. There is always a gradual falloff to silence based on distance from the center of the sphere. For values equal to or less than 0, no player can hear the sound. | ||
: {{ | : {{MC/Arg desc|je=float|min=0.0|be=Float}} | ||
{{ | {{MC/Argument|pitch|float|pitch: float|float}} | ||
: Specifies the pitch and speed of the sound. If not specified, defaults to 1. | : Specifies the pitch and speed of the sound. If not specified, defaults to 1. | ||
: {{ | : {{MC/Arg desc|je=float|min=0.0|max=2.0|be=Float}} | ||
: {{ | : {{MC/In|java}}, values less than 0.5 are equivalent to 0.5. Values lower than 1 lower the pitch and increase the duration; values greater than 1 raise the pitch and reduce the duration. The pitch value is a multiplier applied to the frequency, so if a value from 0.5 to 1 is doubled, the pitch goes an octave higher. (See {{slink|Note block|Usage}} for converting other intervals to pitch values, but be aware that 1 isn't F♯ for all sound effects.) | ||
: {{ | : {{MC/In|bedrock}}, only values between 0 and 256 work. Values above 256 are equivalent to the default value; values less than 0 default to 1, while values equal to 0 makes the sound inaudible. The value of the pitch is also the value for the speed multiplier, ex. if you set the pitch to 2 then the sound will play at double the pitch and double the speed. | ||
: Notice that in [[Minecraft:Bedrock Edition]], if you try to set a pitch value to a sound, then the speed of playing sound will be changed in turn. And the speed multiplier is just the value of this argument. | : Notice that in [[Minecraft:Bedrock Edition]], if you try to set a pitch value to a sound, then the speed of playing sound will be changed in turn. And the speed multiplier is just the value of this argument. | ||
{{ | {{MC/Argument|minVolume|float|minimumVolume: float|float}} | ||
: Specifies the volume for targets outside the sound's normal audible sphere. If a target is outside the normal sphere, the sound is instead centered some short distance (two blocks away) from the target, and this argument determines its volume. If not greater than 0, targets outside the normal audible sphere cannot hear the sound. | : Specifies the volume for targets outside the sound's normal audible sphere. If a target is outside the normal sphere, the sound is instead centered some short distance (two blocks away) from the target, and this argument determines its volume. If not greater than 0, targets outside the normal audible sphere cannot hear the sound. | ||
: If not specified, defaults to 0.0. | : If not specified, defaults to 0.0. | ||
: {{ | : {{MC/Arg desc|je=float|min=0.0|max=1.0|be=Float}} | ||
== Result == | == Result == | ||
| Line 57: | Line 57: | ||
{{Result table|<code><targets></code> or <code>player: target</code> fails to resolve to one or more online players.|fail}} | {{Result table|<code><targets></code> or <code>player: target</code> fails to resolve to one or more online players.|fail}} | ||
{{Result table|Nobody can hear the sound (<code>minVolume</code> or <code>minimumVolume: float</code> is not greater than 0.0, while all the targets are outside the normal audible sphere).}} | {{Result table|Nobody can hear the sound (<code>minVolume</code> or <code>minimumVolume: float</code> is not greater than 0.0, while all the targets are outside the normal audible sphere).}} | ||
{{Result table|One of the specified players cannot hear the sound{{ | {{Result table|One of the specified players cannot hear the sound{{MC/Needs testing}}.|N/A}} | ||
{{Result table|succeed}} | {{Result table|succeed}} | ||
{{Result table}} | {{Result table}} | ||
| Line 63: | Line 63: | ||
== Output == | == Output == | ||
{{Output table}} | {{MC/Output table}} | ||
{{Output table|edition=je|On fail|0|0|0}} | {{MC/Output table|edition=je|On fail|0|0|0}} | ||
{{Output table|On success|1|1|the number of players who can hear the sound}} | {{MC/Output table|On success|1|1|the number of players who can hear the sound}} | ||
{{Output table|edition=be|On fail|0}} | {{MC/Output table|edition=be|On fail|0}} | ||
{{Output table|On success|the number of targeted players}} | {{MC/Output table|On success|the number of targeted players}} | ||
{{Output table}} | {{MC/Output table}} | ||
== Examples == | == Examples == | ||
* To play the | * To play the creeper hissing sound 3 blocks behind the nearest player: | ||
** <code>/[[Minecraft:execute]] as @p at @s run playsound entity.creeper.primed hostile @s ^ ^ ^-3 1 0.5</code>{{only|java}} | ** <code>/[[Minecraft:execute]] as @p at @s run playsound entity.creeper.primed hostile @s ^ ^ ^-3 1 0.5</code>{{only|java}} | ||
** <code>/[[Minecraft:execute]] as @p at @s run playsound note.creeper @s ^ ^ ^-3 1 0.5</code>{{only|bedrock}} | ** <code>/[[Minecraft:execute]] as @p at @s run playsound note.creeper @s ^ ^ ^-3 1 0.5</code>{{only|bedrock}} | ||
| Line 78: | Line 78: | ||
=== ''Java Edition'' === | === ''Java Edition'' === | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|java}} | |{{MC/HistoryLine|java}} | ||
|{{HistoryLine||1.6.1|dev=pre|Added {{ | |{{HistoryLine||1.6.1|dev=pre|Added {{MC/Cmd|playsound|link=none}}.}} | ||
|{{HistoryLine||1.9|dev=15w49a|{{ | |{{HistoryLine||1.9|dev=15w49a|{{MC/Cmd|playsound|link=none}} now accepts tab-completion.}} | ||
|{{HistoryLine|||dev=16w02a|{{ | |{{HistoryLine|||dev=16w02a|{{MC/Cmd|playsound|link=none}} now requires a ''source'' parameter, specifying what is the sound's category for volume purposes.}} | ||
|{{HistoryLine||1.20.5|dev=24w09a|Can now be used without specifying the player (assuming {{ | |{{HistoryLine||1.20.5|dev=24w09a|Can now be used without specifying the player (assuming {{MC/Cd|@s}}) and without specifying the mixer (assuming {{MC/Cd|master}}).}} | ||
|{{HistoryLine||1.21.6|dev=Pre-Release 3|Added new category {{ | |{{HistoryLine||1.21.6|dev=Pre-Release 3|Added new category {{MC/Cd|ui}}.}} | ||
}} | }} | ||
=== ''Bedrock Edition'' === | === ''Bedrock Edition'' === | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|pocket}} | |{{MC/HistoryLine|pocket}} | ||
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{ | |{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{MC/Cmd|playsound|link=none}}.}} | ||
}} | }} | ||
== See also == | == See also == | ||
* {{ | * {{MC/Cmd|stopsound}} — Stops a sound. | ||
== External links == | == External links == | ||
| Line 100: | Line 100: | ||
== Navigation == | == Navigation == | ||
{{Navbox commands}} | {{MC/Navbox commands}} | ||
de:Befehl/playsound | |||
es:Comandos/playsound | |||
ja:コマンド/playsound | |||
pt:Comandos/playsound | |||
ru:Команды консоли/playsound | |||
uk:Команди консолі/playsound | |||
zh:命令/playsound | |||
Latest revision as of 20:12, 9 April 2026
Template:Infobox command Plays a specified sound to a player, in a location, and in a specific volume and pitch.
Syntax
- Java Edition
playsound <sound> [<source>] [<targets>] [<pos>] [<volume>] [<pitch>] [<minVolume>]
- Bedrock Edition
playsound <sound: string> [player: target] [position: x y z] [volume: float] [pitch: float] [minimumVolume: float]
Arguments
Template:El: <sound>: resource_location
Template:El: sound: string: basic_string
- Specifies the sound to play.
- in Template:Editions, {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|string}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} Should be a sound definition defined in sound_definitions.json (for example,
mob.pig.say). - in Template:Editions, {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}} Should be a Sound Event defined in sounds.json (for example,
entity.pig.ambient). - A sound event may be affiliated with multiple sounds, and the sound that is actually produced is chosen at random from them, modified by their "weight", just as the game normally would. For example, the
entity.pig.ambientsound event plays one of several pig sounds at random, because the event has multiple sounds associated with it. - Resource packs may add their own events to sounds.json; the command successfully plays these. File names are not used by this command; it strictly uses the events defined in sounds.json (which may not even be similar to the original file names and paths), and thus a resource pack adding new sound files must define events for them (this is not necessary when replacing old sounds already defined in events).
- REDIRECT Template:Edition
Template:Rcat: <source>
- Specifies the music category and options the sound falls under. Must be
master,music,record,weather,block,hostile,neutral,player,ambient,voice, orui. If omitted,masteris used.
Template:El: <targets>: entity
Template:El: player: target: CommandSelector<Player>
- Specifies the player(s) for whom the sound is going to be played. If not specified, defaults to the player who executes the command.
- {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|entity}}{{#vardefine:be-arg|entity}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Template:El: <pos>: vec3
Template:El: position: x y z: CommandPositionFloat
- Specifies the position to play the sounds from.
- {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|vec3}}{{#vardefine:be-arg|vec3}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Template:El: <volume>: float
Template:El: volume: float: float
- Specifies the distance that the sound can be heard. If not specified, defaults to 1. For values less than 1, the volume diminishes. For values greater than 1, the sound does not actually grow louder, but its audible range (a 16-block radius at 1) is multiplied by volume. There is always a gradual falloff to silence based on distance from the center of the sphere. For values equal to or less than 0, no player can hear the sound.
- {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|float}}{{#vardefine:be-arg|float}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Template:El: <pitch>: float
Template:El: pitch: float: float
- Specifies the pitch and speed of the sound. If not specified, defaults to 1.
- {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|float}}{{#vardefine:be-arg|float}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
- in Template:Editions, values less than 0.5 are equivalent to 0.5. Values lower than 1 lower the pitch and increase the duration; values greater than 1 raise the pitch and reduce the duration. The pitch value is a multiplier applied to the frequency, so if a value from 0.5 to 1 is doubled, the pitch goes an octave higher. (See Template:Slink for converting other intervals to pitch values, but be aware that 1 isn't F♯ for all sound effects.)
- in Template:Editions, only values between 0 and 256 work. Values above 256 are equivalent to the default value; values less than 0 default to 1, while values equal to 0 makes the sound inaudible. The value of the pitch is also the value for the speed multiplier, ex. if you set the pitch to 2 then the sound will play at double the pitch and double the speed.
- Notice that in Minecraft:Bedrock Edition, if you try to set a pitch value to a sound, then the speed of playing sound will be changed in turn. And the speed multiplier is just the value of this argument.
Template:El: <minVolume>: float
Template:El: minimumVolume: float: float
- Specifies the volume for targets outside the sound's normal audible sphere. If a target is outside the normal sphere, the sound is instead centered some short distance (two blocks away) from the target, and this argument determines its volume. If not greater than 0, targets outside the normal audible sphere cannot hear the sound.
- If not specified, defaults to 0.0.
- {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|float}}{{#vardefine:be-arg|float}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table
Output
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|0}}{{#vardefine:output3-{{#var:output-table-lines}}|0}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|je}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|the number of players who can hear the sound}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|be}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|the number of targeted players}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}
Examples
- To play the creeper hissing sound 3 blocks behind the nearest player:
/Minecraft:execute as @p at @s run playsound entity.creeper.primed hostile @s ^ ^ ^-3 1 0.5Template:Only/Minecraft:execute as @p at @s run playsound note.creeper @s ^ ^ ^-3 1 0.5Template:Only
History
Java Edition
Bedrock Edition
See also
- REDIRECT Template:Command
Template:Redr — Stops a sound.
External links
de:Befehl/playsound es:Comandos/playsound ja:コマンド/playsound pt:Comandos/playsound ru:Команды консоли/playsound uk:Команди консолі/playsound zh:命令/playsound