Search in sources :

Example 1 with SoundType

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

the class ItemToolbox method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (player.isSneaking()) {
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        if (!block.isReplaceable(world, pos))
            pos = pos.offset(side);
        if (stack.stackSize != 0 && player.canPlayerEdit(pos, side, stack) && world.canBlockBePlaced(IEContent.blockMetalDecoration2, pos, false, side, null, stack)) {
            IBlockState toolbox = IEContent.blockMetalDecoration2.getStateFromMeta(BlockTypes_MetalDecoration2.TOOLBOX.getMeta());
            if (world.setBlockState(pos, toolbox, 3)) {
                IEContent.blockMetalDecoration2.onIEBlockPlacedBy(world, pos, toolbox, side, hitX, hitY, hitZ, player, stack);
                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);
                --stack.stackSize;
            }
            return EnumActionResult.SUCCESS;
        } else
            return EnumActionResult.FAIL;
    }
    return super.onItemUse(stack, player, world, pos, hand, side, hitX, hitY, hitZ);
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block)

Example 2 with SoundType

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

the class ItemCoresample method onItemUse.

@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (player.isSneaking()) {
        IBlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        if (!block.isReplaceable(world, pos))
            pos = pos.offset(side);
        if (stack.stackSize != 0 && player.canPlayerEdit(pos, side, stack) && world.canBlockBePlaced(IEContent.blockStoneDevice, pos, false, side, null, stack)) {
            IBlockState toolbox = IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.CORESAMPLE.getMeta());
            if (world.setBlockState(pos, toolbox, 3)) {
                IEContent.blockStoneDevice.onIEBlockPlacedBy(world, pos, toolbox, side, hitX, hitY, hitZ, player, stack);
                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);
                --stack.stackSize;
            }
            return EnumActionResult.SUCCESS;
        } else
            return EnumActionResult.FAIL;
    }
    return super.onItemUse(stack, player, world, pos, hand, side, hitX, hitY, hitZ);
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block)

Example 3 with SoundType

use of net.minecraft.block.SoundType in project minecolonies by Minecolonies.

the class EntityAIWorkLumberjack method plantSapling.

/**
     * Plant a sapling at said location.
     *
     * @param location the location to plant the sapling at
     * @return true if a sapling was planted
     */
private boolean plantSapling(@NotNull final BlockPos location) {
    final Block worldBlock = world.getBlockState(location).getBlock();
    if (worldBlock != Blocks.AIR && !(worldBlock instanceof BlockSapling)) {
        return false;
    }
    final int saplingSlot = findSaplingSlot();
    if (saplingSlot != -1) {
        final ItemStack stack = getInventory().getStackInSlot(saplingSlot);
        final Block block = ((ItemBlock) stack.getItem()).getBlock();
        worker.setHeldItem(saplingSlot);
        placeSaplings(saplingSlot, stack, block);
        final SoundType soundType = block.getSoundType(world.getBlockState(location), world, location, worker);
        world.playSound(null, this.worker.getPosition(), soundType.getPlaceSound(), SoundCategory.BLOCKS, soundType.getVolume(), soundType.getPitch());
        worker.swingArm(worker.getActiveHand());
        this.getOwnBuilding().getColony().incrementStatistic("saplings");
    }
    if (job.tree.getStumpLocations().isEmpty() || timeWaited >= MAX_WAITING_TIME) {
        timeWaited = 0;
        setDelay(TIMEOUT_DELAY);
        return true;
    }
    timeWaited++;
    return false;
}
Also used : SoundType(net.minecraft.block.SoundType) BlockSapling(net.minecraft.block.BlockSapling) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 4 with SoundType

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

the class SoundHelper method playPlaceSoundForBlock.

public static void playPlaceSoundForBlock(World world, BlockPos pos) {
    IBlockState state = WorldPlugin.getBlockState(world, pos);
    Block block = state.getBlock();
    SoundType soundType = block.getSoundType(state, world, pos, null);
    playSound(world, null, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F);
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block)

Example 5 with SoundType

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

the class TileEntityCrop method setCrossCrop.

@Override
public boolean setCrossCrop(boolean status) {
    // If remote, change was failure.
    if (this.isRemote()) {
        return false;
    }
    // If we have a plant, change was a failure.
    if (this.hasSeed()) {
        return false;
    }
    // If the new state does not differ, change was a failure.
    if (this.crossCrop == status) {
        return false;
    }
    // Otherwise perform change.
    this.crossCrop = status;
    SoundType type = Blocks.PLANKS.getSoundType(null, null, null, null);
    worldObj.playSound(null, (double) ((float) xCoord() + 0.5F), (double) ((float) yCoord() + 0.5F), (double) ((float) zCoord() + 0.5F), type.getPlaceSound(), SoundCategory.BLOCKS, (type.getVolume() + 1.0F) / 2.0F, type.getPitch() * 0.8F);
    this.markForUpdate();
    // Operation was a success!
    return true;
}
Also used : SoundType(net.minecraft.block.SoundType)

Aggregations

SoundType (net.minecraft.block.SoundType)12 IBlockState (net.minecraft.block.state.IBlockState)7 Block (net.minecraft.block.Block)6 ItemBlock (net.minecraft.item.ItemBlock)4 ItemStack (net.minecraft.item.ItemStack)4 ResourceLocation (net.minecraft.util.ResourceLocation)2 SoundEvent (net.minecraft.util.SoundEvent)2 BlockPos (net.minecraft.util.math.BlockPos)2 TileEntityCrop (com.infinityraider.agricraft.tiles.TileEntityCrop)1 BlockSapling (net.minecraft.block.BlockSapling)1 ISound (net.minecraft.client.audio.ISound)1 PositionedSound (net.minecraft.client.audio.PositionedSound)1 EnumFacing (net.minecraft.util.EnumFacing)1 World (net.minecraft.world.World)1 PlaySoundEvent (net.minecraftforge.client.event.sound.PlaySoundEvent)1 BlockSnapshot (net.minecraftforge.common.util.BlockSnapshot)1 BlockEvent (net.minecraftforge.event.world.BlockEvent)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 IItemHandler (net.minecraftforge.items.IItemHandler)1