Search in sources :

Example 16 with SoundType

use of net.minecraft.block.SoundType in project ImmersiveEngineering by BluSunrize.

the class ItemBlockIEBase method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    IBlockState iblockstate = world.getBlockState(pos);
    Block block = iblockstate.getBlock();
    if (!block.isReplaceable(world, pos))
        pos = pos.offset(side);
    if (stack.stackSize > 0 && player.canPlayerEdit(pos, side, stack) && canBlockBePlaced(world, pos, side, stack)) {
        int i = this.getMetadata(stack.getMetadata());
        IBlockState iblockstate1 = this.block.onBlockPlaced(world, pos, side, hitX, hitY, hitZ, i, player);
        if (placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, iblockstate1)) {
            SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
            world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            if (!player.capabilities.isCreativeMode)
                --stack.stackSize;
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.FAIL;
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock)

Example 17 with SoundType

use of net.minecraft.block.SoundType in project Railcraft by Railcraft.

the class RCSoundHandler method onPlaySound.

//TODO: test, catch PlaySoundAtEntityEvent?
@SubscribeEvent
public void onPlaySound(PlaySoundEvent event) {
    ISound soundEvent = event.getSound();
    ResourceLocation soundResource = soundEvent.getSoundLocation();
    if (SoundHelper.matchesSoundResource(soundResource, "null")) {
        event.setResultSound(null);
    } else if (SoundHelper.matchesSoundResource(soundResource, "override")) {
        World world = Railcraft.getProxy().getClientWorld();
        if (world != null) {
            float x = soundEvent.getXPosF();
            float y = soundEvent.getYPosF();
            float z = soundEvent.getZPosF();
            BlockPos pos = new BlockPos(x, y, z);
            String soundPath = soundEvent.getSoundLocation().getResourcePath();
            SoundType blockSound = SoundRegistry.getBlockSound(world, pos);
            if (blockSound == null) {
                if (soundPath.contains("place")) {
                    //Play sound later to adjust for the block not being there yet.
                    event.getManager().playDelayedSound(event.getSound(), 3);
                } else if (soundPath.contains("step")) {
                    blockSound = SoundRegistry.getBlockSound(world, pos.down());
                }
            }
            if (blockSound != null) {
                SoundEvent newSound = SoundHelper.matchSoundEvent(soundResource, blockSound);
                ObfuscationReflectionHelper.setPrivateValue(PositionedSound.class, (PositionedSound) soundEvent, newSound.getSoundName(), 3);
            } else {
                event.setResultSound(null);
            }
        }
    }
}
Also used : SoundType(net.minecraft.block.SoundType) ISound(net.minecraft.client.audio.ISound) PlaySoundEvent(net.minecraftforge.client.event.sound.PlaySoundEvent) SoundEvent(net.minecraft.util.SoundEvent) PositionedSound(net.minecraft.client.audio.PositionedSound) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 18 with SoundType

use of net.minecraft.block.SoundType in project Railcraft by Railcraft.

the class SoundHelper method playBlockSound.

//TODO: test
public static void playBlockSound(World world, BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch, IBlockState state) {
    if (world != null && sound != null) {
        ResourceLocation soundPath = ReflectionHelper.getPrivateValue(SoundEvent.class, sound, 1);
        if (matchesSoundResource(soundPath, "override")) {
            SoundType blockSound = SoundRegistry.getBlockSound(state, world, pos);
            if (blockSound != null) {
                SoundEvent newSound = matchSoundEvent(soundPath, blockSound);
                playSound(world, null, pos, newSound, category, volume, pitch * blockSound.getPitch());
            }
        }
        playSound(world, null, pos, sound, category, volume, pitch);
    }
}
Also used : SoundType(net.minecraft.block.SoundType) SoundEvent(net.minecraft.util.SoundEvent) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 19 with SoundType

use of net.minecraft.block.SoundType in project RecurrentComplex by Ivorforce.

the class ItemBlockGenericSpace method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = playerIn.getHeldItem(hand);
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();
    if (// Only this was changed
    !block.isReplaceable(worldIn, pos) || block == getBlock()) {
        pos = pos.offset(facing);
    }
    if (stack.getCount() != 0 && playerIn.canPlayerEdit(pos, facing, stack) && worldIn.mayPlace(this.block, pos, false, facing, null)) {
        int i = this.getMetadata(stack.getMetadata());
        IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, playerIn, EnumHand.MAIN_HAND);
        if (placeBlockAt(stack, playerIn, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1)) {
            SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, playerIn);
            worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            stack.shrink(1);
        }
        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack)

Example 20 with SoundType

use of net.minecraft.block.SoundType in project Traverse by ProfessorProspector.

the class ItemTraverseWoodDoor method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (facing != EnumFacing.UP)
        return EnumActionResult.FAIL;
    IBlockState state = world.getBlockState(pos);
    ItemStack held = player.getHeldItem(hand);
    if (!state.getBlock().isReplaceable(world, pos)) {
        pos = pos.offset(facing);
        state = world.getBlockState(pos);
    }
    if (player.canPlayerEdit(pos, facing, held) && block.canPlaceBlockAt(world, pos)) {
        EnumFacing enumfacing = EnumFacing.fromAngle((double) player.rotationYaw);
        int offsetX = enumfacing.getFrontOffsetX();
        int offsetZ = enumfacing.getFrontOffsetZ();
        boolean isRightHinge = offsetX < 0 && hitZ < 0.5F || offsetX > 0 && hitZ > 0.5F || offsetZ < 0 && hitX > 0.5F || offsetZ > 0 && hitX < 0.5F;
        placeDoor(world, pos, enumfacing, block, isRightHinge);
        SoundType soundtype = state.getBlock().getSoundType(state, world, pos, player);
        world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
        held.shrink(1);
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.FAIL;
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SoundType (net.minecraft.block.SoundType)27 IBlockState (net.minecraft.block.state.IBlockState)21 Block (net.minecraft.block.Block)17 ItemStack (net.minecraft.item.ItemStack)15 ItemBlock (net.minecraft.item.ItemBlock)8 EnumFacing (net.minecraft.util.EnumFacing)6 Entity (net.minecraft.entity.Entity)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)4 BlockPos (net.minecraft.util.math.BlockPos)4 TileEntityCrop (com.infinityraider.agricraft.tiles.TileEntityCrop)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SoundEvent (net.minecraft.util.SoundEvent)2 BlockSapling (net.minecraft.block.BlockSapling)1 BlockSlab (net.minecraft.block.BlockSlab)1 EnumBlockHalf (net.minecraft.block.BlockSlab.EnumBlockHalf)1 IProperty (net.minecraft.block.properties.IProperty)1 ISound (net.minecraft.client.audio.ISound)1 PositionedSound (net.minecraft.client.audio.PositionedSound)1 World (net.minecraft.world.World)1