use of pl.asie.charset.api.audio.AudioSink in project Charset by CharsetMC.
the class AudioUtils method send.
public static void send(int id, AudioPacket audio) {
if (audio.getVolume() <= 0.0f) {
return;
}
PacketAudioData packet = new PacketAudioData(id, audio);
Map<WorldServer, Set<AudioSink>> worlds = new HashMap<>();
for (AudioSink sink : audio.getSinks()) {
if (sink.getVolume() <= 0.0f || sink.getDistance() <= 0.0f) {
continue;
}
if (worlds.containsKey(sink.getWorld())) {
worlds.get(sink.getWorld()).add(sink);
} else {
HashSet<AudioSink> sinkLocal = new HashSet<>();
sinkLocal.add(sink);
worlds.put((WorldServer) sink.getWorld(), sinkLocal);
}
}
for (WorldServer world : worlds.keySet()) {
for (EntityPlayerMP player : world.getMinecraftServer().getPlayerList().getPlayers()) {
if (player.world.provider.getDimension() == world.provider.getDimension()) {
for (AudioSink sink : worlds.get(world)) {
BlockPos pos = new BlockPos(sink.getPos());
if (world.getPlayerChunkMap().isPlayerWatchingChunk(player, pos.getX() >> 4, pos.getZ() >> 4)) {
CharsetLib.packet.sendTo(packet, player);
break;
}
}
}
}
}
}
use of pl.asie.charset.api.audio.AudioSink in project Charset by CharsetMC.
the class PacketAudioData method apply.
@Override
public void apply(INetHandler handler) {
AudioData audioData = packet.getData();
if (audioData instanceof IDataGameSound) {
IDataGameSound sound = (IDataGameSound) audioData;
playSoundNote(packet, sound);
return;
}
if (!(audioData instanceof IAudioDataPCM) || ((IAudioDataPCM) audioData).getSampleSize() != 1) {
// Nope!
return;
}
IAudioDataPCM pcmPacket = (IAudioDataPCM) audioData;
byte[] data = pcmPacket.getSamplePCMData();
if (pcmPacket.isSampleSigned()) {
byte[] data2 = new byte[data.length];
for (int i = 0; i < data.length; i++) {
data2[i] = (byte) (data[i] ^ 0x80);
}
data = data2;
}
IAudioStream stream = AudioStreamManagerClient.INSTANCE.get(id);
if (stream == null) {
stream = new AudioStreamOpenAL(false, false, 8);
AudioStreamManagerClient.INSTANCE.put(id, stream);
}
stream.setSampleRate(pcmPacket.getSampleRate());
stream.push(data);
for (AudioSink sink : packet.getSinks()) {
try {
stream.play((float) sink.getPos().x, (float) sink.getPos().y, (float) sink.getPos().z, sink.getDistance(), sink.getVolume() * packet.getVolume());
} catch (Exception e) {
}
}
}
Aggregations