Add Position playsound methods

This commit is contained in:
LeoDog896 2021-02-19 18:43:35 -05:00
parent 06abbcb7fb
commit 4daa55d27e

View File

@ -860,6 +860,48 @@ public class Player extends LivingEntity implements CommandSender {
playerConnection.sendPacket(soundEffectPacket);
}
/**
* Plays a sound from the {@link Sound} enum.
*
* @param sound the sound to play
* @param soundCategory the sound category
* @param position the block position to use.
* @param volume the volume of the sound (1 is 100%)
* @param pitch the pitch of the sound, between 0.5 and 2.0
*/
public void playSound(@NotNull Sound sound, @NotNull SoundCategory soundCategory, BlockPosition position, float volume, float pitch) {
SoundEffectPacket soundEffectPacket = new SoundEffectPacket();
soundEffectPacket.soundId = sound.getId();
soundEffectPacket.soundCategory = soundCategory;
soundEffectPacket.x = position.getX();
soundEffectPacket.y = position.getY();
soundEffectPacket.z = position.getZ();
soundEffectPacket.volume = volume;
soundEffectPacket.pitch = pitch;
playerConnection.sendPacket(soundEffectPacket);
}
/**
* Plays a sound from an identifier (represents a custom sound in a resource pack).
*
* @param identifier the identifier of the sound to play
* @param soundCategory the sound category
* @param position the block position to use.
* @param volume the volume of the sound (1 is 100%)
* @param pitch the pitch of the sound, between 0.5 and 2.0
*/
public void playSound(@NotNull String identifier, @NotNull SoundCategory soundCategory, BlockPosition position, float volume, float pitch) {
NamedSoundEffectPacket namedSoundEffectPacket = new NamedSoundEffectPacket();
namedSoundEffectPacket.soundName = identifier;
namedSoundEffectPacket.soundCategory = soundCategory;
namedSoundEffectPacket.x = position.getX();
namedSoundEffectPacket.y = position.getY();
namedSoundEffectPacket.z = position.getZ();
namedSoundEffectPacket.volume = volume;
namedSoundEffectPacket.pitch = pitch;
playerConnection.sendPacket(namedSoundEffectPacket);
}
/**
* Plays a sound from an identifier (represents a custom sound in a resource pack).
*