Merge pull request #137 from allie-signet/1.18-forge
Add volume & pitch to sound card.
This commit is contained in:
@@ -40,6 +40,16 @@ public final class SoundCardItemDevice extends AbstractItemRPCDevice {
|
||||
|
||||
@Callback
|
||||
public void playSound(@Nullable @Parameter("name") final String name) {
|
||||
playSound(name, 1, 1);
|
||||
}
|
||||
|
||||
@Callback
|
||||
public void playSound(@Nullable @Parameter("name") final String name, @Parameter("volume") final float volume) {
|
||||
playSound(name, volume, 1);
|
||||
}
|
||||
|
||||
@Callback
|
||||
public void playSound(@Nullable @Parameter("name") final String name, @Parameter("volume") final float volume, @Parameter("pitch") final float pitch) {
|
||||
if (name == null) throw new IllegalArgumentException();
|
||||
|
||||
location.get().ifPresent(location -> location.tryGetLevel().ifPresent(level -> {
|
||||
@@ -56,7 +66,7 @@ public final class SoundCardItemDevice extends AbstractItemRPCDevice {
|
||||
|
||||
final SoundEvent soundEvent = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(name));
|
||||
if (soundEvent == null) throw new IllegalArgumentException("Sound not found.");
|
||||
level.playSound(null, location.blockPos(), soundEvent, SoundSource.BLOCKS, 1, 1);
|
||||
level.playSound(null, location.blockPos(), soundEvent, SoundSource.BLOCKS, volume, pitch);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ This is a high level device. It must be controlled using the high level device A
|
||||
Device name: `sound`
|
||||
|
||||
### Methods
|
||||
`playSound(name:string)` plays back the sound effect with the specified name.
|
||||
`playSound(name:string[,volume,pitch])` plays back the sound effect with the specified name.
|
||||
- `name` is the name of the effect to play.
|
||||
- `volume` is the volume at which to play the effect, with `1` being the normal volume. Optional, defaulting to `1`.
|
||||
- `pitch` is the volume at which to play the effect, with `1` being the normal pitch. Optional, defaulting to `1`.
|
||||
- Throws if the specified name is invalid.
|
||||
|
||||
`findSound(name:string):table` returns a list of available sound effects matching the given name. Note that the number of results is limited, so overly generic queries will result in truncated results.
|
||||
|
||||
Reference in New Issue
Block a user