Example usage for net.minecraftforge.event.world NoteBlockEvent.Play getWorld

List of usage examples for net.minecraftforge.event.world NoteBlockEvent.Play getWorld

Introduction

In this page you can find the example usage for net.minecraftforge.event.world NoteBlockEvent.Play getWorld.

Prototype

public IWorld getWorld() 

Source Link

Usage

From source file:vazkii.quark.misc.feature.NoteBlocksMobSounds.java

License:Creative Commons License

@SubscribeEvent
public void noteBlockPlayed(NoteBlockEvent.Play event) {
    BlockPos pos = event.getPos();//from   w  w w.j  a v  a2  s.  co  m
    if (event.getWorld().getBlockState(pos).getBlock() != Blocks.NOTEBLOCK)
        return;

    int type = getSkullType(event.getWorld(), pos);
    if (type != -1 && type != 3) {
        event.setCanceled(true);

        SoundEvent sound = null;
        switch (type) {
        case 0:
            sound = SoundEvents.ENTITY_SKELETON_AMBIENT;
            break;
        case 1:
            sound = SoundEvents.ENTITY_WITHER_SKELETON_AMBIENT;
            break;
        case 2:
            sound = SoundEvents.ENTITY_ZOMBIE_AMBIENT;
            break;
        case 4:
            sound = SoundEvents.ENTITY_CREEPER_PRIMED;
            break;
        case 5:
            sound = SoundEvents.ENTITY_ENDERDRAGON_AMBIENT;
            break;
        }

        if (sound != null) {
            float pitch = (float) Math.pow(2.0, (event.getVanillaNoteId() - 12) / 12.0);
            event.getWorld().playSound(null, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, sound,
                    SoundCategory.BLOCKS, 1F, pitch);
        }
    }
}

From source file:vazkii.quark.tweaks.feature.NoteBlocksMobSounds.java

License:Creative Commons License

@SubscribeEvent
public void noteBlockPlayed(NoteBlockEvent.Play event) {
    BlockPos pos = event.getPos();/*from   ww w  .java 2  s. co m*/

    EnumFacing[] facings = new EnumFacing[] { EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST,
            EnumFacing.WEST };

    TileEntity tile = null;
    boolean can = false;
    for (EnumFacing face : facings) {
        BlockPos apos = pos.offset(face);
        tile = event.getWorld().getTileEntity(apos);
        if (tile != null && tile instanceof TileEntitySkull) {
            IBlockState state = event.getWorld().getBlockState(apos);
            if (state.getValue(BlockSkull.FACING) == face) {
                can = true;
                break;
            }
        }
    }

    if (can) {
        int type = ((TileEntitySkull) tile).getSkullType();
        if (type != 3) {
            event.setCanceled(true);

            SoundEvent sound = null;
            switch (type) {
            case 0:
            case 1:
                sound = SoundEvents.ENTITY_SKELETON_AMBIENT;
                break;
            case 2:
                sound = SoundEvents.ENTITY_ZOMBIE_AMBIENT;
                break;
            case 4:
                sound = SoundEvents.ENTITY_CREEPER_PRIMED;
                break;
            case 5:
                sound = SoundEvents.ENTITY_ENDERDRAGON_AMBIENT;
                break;
            }

            if (sound != null)
                event.getWorld().playSound(null, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, sound,
                        SoundCategory.BLOCKS, 1F, 1F);
        }
    }
}