use of pl.asie.charset.api.audio.AudioPacket in project Charset by CharsetMC.
the class PacketAudioData method readData.
@Override
public void readData(INetHandler handler, PacketBuffer buf) {
id = buf.readInt();
packet = new AudioPacket();
packet.readData(buf);
}
use of pl.asie.charset.api.audio.AudioPacket in project Charset by CharsetMC.
the class CharsetAudioNoteblock method onNoteEvent.
@SubscribeEvent(priority = EventPriority.LOW)
public void onNoteEvent(NoteBlockEvent.Play event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
int param = event.getVanillaNoteId();
SoundEvent sound = getSound(event.getWorld(), event.getPos(), event.getInstrument().ordinal());
float pitch = (float) Math.pow(2.0D, (double) (param - 12) / 12.0D);
if (!world.isRemote) {
TileEntity note = world.getTileEntity(pos);
if (note != null && note.hasCapability(Capabilities.AUDIO_SOURCE, null)) {
AudioDataGameSound dataSound = new AudioDataGameSound(SoundEvent.REGISTRY.getNameForObject(sound).toString(), pitch);
AudioPacket packet = new AudioPacket(dataSound, getSoundVolume(world, pos));
for (EnumFacing facing : EnumFacing.VALUES) {
TileEntity tile = event.getWorld().getTileEntity(pos.offset(facing));
if (tile != null && tile.hasCapability(Capabilities.AUDIO_RECEIVER, facing.getOpposite())) {
tile.getCapability(Capabilities.AUDIO_RECEIVER, facing.getOpposite()).receive(packet);
}
}
if (packet.getSinkCount() > 0) {
event.setCanceled(true);
packet.send();
return;
}
}
if (!compatibilityMode) {
if (event.getState().getBlock() == Blocks.NOTEBLOCK) {
event.setCanceled(true);
world.playSound(null, pos, sound, SoundCategory.BLOCKS, getSoundVolume(world, pos), pitch);
packet.sendToAllAround(new PacketNoteParticle(note, param), note, 32);
}
}
}
}
Aggregations