Search in sources :

Example 26 with SoundType

use of net.minecraft.block.SoundType in project MorePlanets by SteveKunG.

the class ItemBlockFlower method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    ItemStack itemStack = player.getHeldItem(hand);
    if (!block.isReplaceable(world, pos)) {
        pos = pos.offset(facing);
    }
    if (!itemStack.isEmpty() && player.canPlayerEdit(pos, facing, itemStack) && world.mayPlace(this.block, pos, false, facing, (Entity) null)) {
        int i = this.getMetadata(itemStack.getMetadata());
        IBlockState iblockstate1 = this.block.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player, hand);
        if (this.placeBlockAt(itemStack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1)) {
            SoundType sound = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
            world.playSound(player, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1.0F) / 2.0F, sound.getPitch() * 0.8F);
            itemStack.shrink(1);
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.PASS;
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : SoundType(net.minecraft.block.SoundType) Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack)

Example 27 with SoundType

use of net.minecraft.block.SoundType in project Almura by AlmuraDev.

the class SlabItemImpl method onItemUse.

@Override
public EnumActionResult onItemUse(final EntityPlayer player, final World world, final BlockPos pos, final EnumHand hand, final EnumFacing facing, final float hitX, final float hitY, final float hitZ) {
    this.checkAndDelegate();
    final ItemStack item = player.getHeldItem(hand);
    if (item.isEmpty() || !player.canPlayerEdit(pos.offset(facing), facing, item)) {
        return EnumActionResult.FAIL;
    }
    final IBlockState state = world.getBlockState(pos);
    if (state.getBlock() == this.singleBlock.get().getBlock()) {
        final BlockSlab.EnumBlockHalf half = state.getValue(BlockSlab.HALF);
        if (facing == EnumFacing.UP && half == BlockSlab.EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && half == BlockSlab.EnumBlockHalf.TOP) {
            final IBlockState doubleState = this.doubleBlock.get();
            final AxisAlignedBB aabb = doubleState.getCollisionBoundingBox(world, pos);
            if (aabb != Block.NULL_AABB && world.checkNoEntityCollision(aabb.offset(pos)) && world.setBlockState(pos, doubleState, 11)) {
                final SoundType sounds = this.doubleBlock.get().getBlock().getSoundType(doubleState, world, pos, player);
                world.playSound(player, pos, sounds.getPlaceSound(), SoundCategory.BLOCKS, (sounds.getVolume() + 1.0F) / 2.0F, sounds.getPitch() * 0.8F);
                item.shrink(1);
                if (player instanceof EntityPlayerMP) {
                    CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, item);
                }
            }
            return EnumActionResult.SUCCESS;
        }
    }
    return this.tryPlaceSingle(world, player, hand, item, pos, facing, hitX, hitY, hitZ);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) BlockSlab(net.minecraft.block.BlockSlab) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) 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