Search in sources :

Example 1 with Mode

use of io.xol.chunkstories.api.sound.SoundSource.Mode in project chunkstories by Hugobros3.

the class PacketSoundSource method process.

@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
    String soundName = in.readUTF();
    long UUID = in.readLong();
    boolean hasPosition = in.readBoolean();
    Vector3dc position = null;
    if (hasPosition) {
        position = new Vector3d(in.readFloat(), in.readFloat(), in.readFloat());
    }
    // boolean loop = in.readBoolean();
    // boolean isAmbient = in.readBoolean();
    // boolean buffered = in.readBoolean();
    byte modeByte = in.readByte();
    Mode mode = Mode.values()[modeByte];
    boolean stopped = in.readBoolean();
    float pitch = in.readFloat();
    float gain = in.readFloat();
    float attenuationStart = in.readFloat();
    float attenuationEnd = in.readFloat();
    if (!(processor instanceof ClientPacketsProcessor))
        return;
    ClientPacketsProcessor cpe = (ClientPacketsProcessor) processor;
    SoundSource soundSource = cpe.getContext().getSoundManager().getSoundSourceByUUID(UUID);
    // ALSoundSource soundSource = (ALSoundSource) Client.getInstance().getSoundManager().getSoundSourceByUUID(UUID);
    if (soundSource == null && stopped)
        return;
    if (soundSource == null) {
        soundSource = cpe.getContext().getSoundManager().replicateServerSoundSource(soundName, mode, position, pitch, gain, attenuationStart, attenuationEnd, UUID);
        return;
    }
    if (stopped) {
        soundSource.stop();
        return;
    }
    // Update the soundSource with all we can
    soundSource.setPosition(position);
    soundSource.setPitch(pitch);
    soundSource.setGain(gain);
    soundSource.setAttenuationStart(attenuationStart);
    soundSource.setAttenuationEnd(attenuationEnd);
}
Also used : Vector3dc(org.joml.Vector3dc) SoundSource(io.xol.chunkstories.api.sound.SoundSource) ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) Vector3d(org.joml.Vector3d) Mode(io.xol.chunkstories.api.sound.SoundSource.Mode)

Aggregations

ClientPacketsProcessor (io.xol.chunkstories.api.client.net.ClientPacketsProcessor)1 SoundSource (io.xol.chunkstories.api.sound.SoundSource)1 Mode (io.xol.chunkstories.api.sound.SoundSource.Mode)1 Vector3d (org.joml.Vector3d)1 Vector3dc (org.joml.Vector3dc)1