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

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

Introduction

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

Prototype

public BlockPos getPos() 

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();
    if (event.getWorld().getBlockState(pos).getBlock() != Blocks.NOTEBLOCK)
        return;//w  w w.  ja v a2s  .c om

    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();

    EnumFacing[] facings = new EnumFacing[] { EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST,
            EnumFacing.WEST };//from   www.  j  av a2s. c o m

    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);
        }
    }
}