Search in sources :

Example 1 with AudioDataGameSound

use of pl.asie.charset.lib.audio.types.AudioDataGameSound in project Charset by CharsetMC.

the class CharsetLib method init.

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
    packet.registerPacket(0x01, PacketAudioData.class);
    packet.registerPacket(0x02, PacketAudioStop.class);
    packet.registerPacket(0x10, PacketNotification.class);
    packet.registerPacket(0x11, PacketPoint.class);
    packet.registerPacket(0x20, PacketCustomBlockDust.class);
    packet.registerPacket(0x30, PacketRequestScroll.class);
    MinecraftForge.EVENT_BUS.register(ShiftScrollHandler.INSTANCE);
    MinecraftForge.EVENT_BUS.register(new DyeableItemWashHandler());
    MinecraftForge.EVENT_BUS.register(new Todokete());
    Capabilities.init();
    DataSerializersCharset.init();
    UtilProxyCommon.proxy.init();
    if (ModCharset.INDEV || enableDebugInfo)
        MinecraftForge.EVENT_BUS.register(new DebugInfoProvider());
    CharsetAPI.INSTANCE.findSimpleInstantiatingRegistry(AudioData.class).register(AudioDataDFPWM.class, AudioDataDFPWM::new);
    CharsetAPI.INSTANCE.findSimpleInstantiatingRegistry(AudioData.class).register(AudioDataGameSound.class, AudioDataGameSound::new);
    CharsetAPI.INSTANCE.findSimpleInstantiatingRegistry(AudioSink.class).register(AudioSinkBlock.class, AudioSinkBlock::new);
    CommandCharset.register(new SubCommandHelp(Side.CLIENT));
    CommandCharset.register(new SubCommandHelp(Side.SERVER));
    CommandCharset.register(new SubCommandHand());
    CommandCharset.register(new SubCommandAt());
}
Also used : AudioSink(pl.asie.charset.api.audio.AudioSink) AudioData(pl.asie.charset.api.audio.AudioData) PacketAudioData(pl.asie.charset.lib.audio.PacketAudioData) AudioSinkBlock(pl.asie.charset.lib.audio.types.AudioSinkBlock) AudioDataDFPWM(pl.asie.charset.lib.audio.types.AudioDataDFPWM) Todokete(pl.asie.charset.lib.misc.Todokete) AudioDataGameSound(pl.asie.charset.lib.audio.types.AudioDataGameSound)

Example 2 with AudioDataGameSound

use of pl.asie.charset.lib.audio.types.AudioDataGameSound 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);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SoundEvent(net.minecraft.util.SoundEvent) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) AudioDataGameSound(pl.asie.charset.lib.audio.types.AudioDataGameSound) AudioPacket(pl.asie.charset.api.audio.AudioPacket) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

AudioDataGameSound (pl.asie.charset.lib.audio.types.AudioDataGameSound)2 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 SoundEvent (net.minecraft.util.SoundEvent)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 AudioData (pl.asie.charset.api.audio.AudioData)1 AudioPacket (pl.asie.charset.api.audio.AudioPacket)1 AudioSink (pl.asie.charset.api.audio.AudioSink)1 PacketAudioData (pl.asie.charset.lib.audio.PacketAudioData)1 AudioDataDFPWM (pl.asie.charset.lib.audio.types.AudioDataDFPWM)1 AudioSinkBlock (pl.asie.charset.lib.audio.types.AudioSinkBlock)1 Todokete (pl.asie.charset.lib.misc.Todokete)1