private boolean placeBlock(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float xOffset, float yOffset, float zOffset) { IBlockState iblockstate = world.getBlockState(pos); Block block = iblockstate.getBlock(); if(!block.isReplaceable(world, pos)) { pos = pos.offset(side); } if(itemstack.isEmpty()) { return false; } else if(!player.canPlayerEdit(pos, side, itemstack)) { return false; } else if(world.mayPlace(Blocks.MOB_SPAWNER, pos, false, side, null)) { int meta = this.getMetadata(itemstack.getMetadata()); IBlockState iblockstate1 = Blocks.MOB_SPAWNER.getStateForPlacement(world, pos, side, xOffset, yOffset, zOffset, meta, player); if (placeBlockAt(itemstack, player, world, pos, side, xOffset, yOffset, zOffset, iblockstate1)) { world.playSound(null, pos, Blocks.MOB_SPAWNER.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (Blocks.MOB_SPAWNER.getSoundType().getVolume() + 1.0F) / 2.0F, Blocks.MOB_SPAWNER.getSoundType().getPitch() * 0.8F); player.renderBrokenItemStack(itemstack); itemstack.shrink(1); for(int i = 0; i < 100; i++) Botania.proxy.sparkleFX(pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 0.45F + 0.2F * (float) Math.random(), 6); } return true; } else { return false; } }
block1 = Blocks.FARMLAND; world.playSound(null, pos, block1.getSoundType().getStepSound(), SoundCategory.BLOCKS, (block1.getSoundType().getVolume() + 1.0F) / 2.0F, block1.getSoundType().getPitch() * 0.8F);
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { // Copy of ItemBlock.onItemUse IBlockState iblockstate = world.getBlockState(pos); Block block = iblockstate.getBlock(); if (!block.isReplaceable(world, pos)) { pos = pos.offset(facing); } ItemStack stack = player.getHeldItem(hand); if (!stack.isEmpty() && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(ModBlocks.buriedPetals, pos, false, facing, null)) { int i = this.getMetadata(stack.getMetadata()); IBlockState iblockstate1 = ModBlocks.buriedPetals.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player); if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1)) { SoundType soundtype = ModBlocks.buriedPetals.getSoundType(); world.playSound(player, 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; } }
event.getEntityPlayer().swingArm(event.getHand()); else { event.getWorld().playSound(null, event.getPos(), block.getSoundType().getBreakSound(), SoundCategory.BLOCKS, block.getSoundType().getVolume() * 0.4F, block.getSoundType().getPitch() + (float) (Math.random() * 0.2 - 0.1));
public static void playStepSound(@Nonnull SoundType snd, @Nonnull World world, @Nonnull BlockPos pos) { SoundHelper.playSound(world, pos, new Sound(snd.getStepSound()), (snd.getVolume() + 1.0F) / 2.0F, snd.getPitch() * 0.8F); }
public static void playPlaceSound(@Nonnull SoundType snd, @Nonnull World world, @Nonnull BlockPos pos) { SoundHelper.playSound(world, pos, new Sound(snd.getPlaceSound()), (snd.getVolume() + 1.0F) / 2.0F, snd.getPitch() * 0.8F); }
public static void playHitSound(@Nonnull SoundType snd, @Nonnull World world, @Nonnull BlockPos pos) { SoundHelper.playSound(world, pos, new Sound(snd.getHitSound()), (snd.getVolume() + 1.0F) / 2.0F, snd.getPitch() * 0.8F); }
public static void playBreakSound(@Nonnull SoundType snd, @Nonnull World world, @Nonnull BlockPos pos) { SoundHelper.playSound(world, pos, new Sound(snd.getBreakSound()), (snd.getVolume() + 1.0F) / 2.0F, snd.getPitch() * 0.8F); }
.playSound( new PositionedSoundRecord( block.getSoundType() .getBreakSound(), SoundCategory.BLOCKS, ( block.getSoundType().getVolume() + 1.0F ) / 2.0F, block.getSoundType() .getPitch() * 0.8F, (float) this.x + 0.5F, (float) this.y + 0.5F, (float) this.z + 0.5F ) );
world.playSound( null, pos, ss.getPlaceSound(), SoundCategory.BLOCKS, ( ss.getVolume() + 1.0F ) / 2.0F, ss.getPitch() * 0.8F ); } );
private void playBlockSound(World world, RayTraceResult hit, IBlockState state) { SoundType sound = state.getBlock().getSoundType(state, world, hit.getBlockPos(), null); if (sound != null) { world.playSound(null, hit.getBlockPos(), sound.getPlaceSound(), SoundCategory.BLOCKS, sound.getVolume() * 0.5F, sound.getPitch() * 0.8F); } }
/** * Plays the sound for the block at the position. * @param block The block * @param world The world * @param pos The block position */ private void playSound(Block block, World world, BlockPos pos) { double x = pos.getX() + 0.5D; double y = pos.getY() + 0.5D; double z = pos.getZ() + 0.5D; SoundType sound = block.getSoundType(); float vol = (sound.getVolume() + 1F) / 2F; float pitch = sound.getPitch() * 0.8F; world.playSound(x, y, z, sound.getPlaceSound(), SoundCategory.BLOCKS, vol, pitch, false); } }
@SuppressWarnings("deprecation") public static void playPlaceSound(World world, BlockPos pos) { Block block = BlockCable.getInstance(); world.playSound((double) ((float) pos.getX() + 0.5F), (double) ((float) pos.getY() + 0.5F), (double) ((float) pos.getZ() + 0.5F), block.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (block.getSoundType().getVolume() + 1.0F) / 2.0F, block.getSoundType().getPitch() * 0.8F, false); }
public static void breakSound( final World world, final BlockPos pos, final int extractedState ) { final IBlockState state = ModUtil.getStateById( extractedState ); final Block block = state.getBlock(); world.playSound( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, DeprecationHelper.getSoundType( block ).getBreakSound(), SoundCategory.BLOCKS, ( DeprecationHelper.getSoundType( block ).getVolume() + 1.0F ) / 16.0F, DeprecationHelper.getSoundType( block ).getPitch() * 0.9F, false ); }
public static void placeSound( final World world, final BlockPos pos, final int stateID ) { final IBlockState state = ModUtil.getStateById( stateID ); final Block block = state.getBlock(); world.playSound( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, DeprecationHelper.getSoundType( block ).getPlaceSound(), SoundCategory.BLOCKS, ( DeprecationHelper.getSoundType( block ).getVolume() + 1.0F ) / 16.0F, DeprecationHelper.getSoundType( block ).getPitch() * 0.9F, false ); }
private boolean tryPlace(EntityPlayer player, ItemStack stack, World world, BlockPos pos) { IBlockState state = world.getBlockState(pos); if (state.getBlock() == this.singleSlab) { AxisAlignedBB collisionBounds = state.getSelectedBoundingBox(world, pos); if (collisionBounds != Block.NULL_AABB && world.checkNoEntityCollision(collisionBounds.offset(pos)) && world.setBlockState(pos, state, 11)) { SoundType soundtype = this.doubleSlab.getSoundType(); world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); stack.shrink(1);; } return true; } return false; } }
private boolean tryPlace(EntityPlayer player, ItemStack stack, EnumHand hand, World world, BlockPos pos){ IBlockState iblockstate = world.getBlockState(pos); if(iblockstate.getBlock() == this.block){ BlockSlabs theBlock = (BlockSlabs)this.block; IBlockState newState = theBlock.fullBlockState; AxisAlignedBB bound = newState.getCollisionBoundingBox(world, pos); if(bound != Block.NULL_AABB && world.checkNoEntityCollision(bound.offset(pos)) && world.setBlockState(pos, newState, 11)){ SoundType soundtype = theBlock.fullBlockState.getBlock().getSoundType(theBlock.fullBlockState, world, pos, player); world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume()+1.0F)/2.0F, soundtype.getPitch()*0.8F); player.setHeldItem(hand, StackUtil.shrink(stack, 1)); } return true; } return false; }
private EnumActionResult placeFlower(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { IBlockState blockState = world.getBlockState(pos); Block block = blockState.getBlock(); if (!block.isReplaceable(world, pos)) { pos = pos.offset(facing); } if (stack.getCount() != 0 && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(ModuleFlowers.flower, pos, false, facing, null)) { int i = getMetadata(stack.getMetadata()); IBlockState stateForPlacement = ModuleFlowers.flower.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player, hand); if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, stateForPlacement)) { SoundType soundType = block.getSoundType(stateForPlacement, world, pos, player); world.playSound(player, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F); stack.shrink(1); } return EnumActionResult.SUCCESS; } return EnumActionResult.FAIL; }
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack heldItem = player.getHeldItem(hand); if (!heldItem.isEmpty() && player != null && ((state.getValue(HALF).equals(EnumBlockHalf.TOP) && facing.equals(EnumFacing.DOWN)) || (state.getValue(HALF).equals(EnumBlockHalf.BOTTOM) && facing.equals(EnumFacing.UP)))){ if (heldItem.getItem() == Item.getItemFromBlock(this)) { worldIn.setBlockState(pos, state.withProperty(HALF, EnumBlockHalf.FULL)); if(!player.capabilities.isCreativeMode) heldItem.shrink(1); SoundType soundtype = this.getSoundType(); worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); return true; } } return super.onBlockActivated(worldIn, pos, state, player, hand, facing, hitX, hitY, hitZ); }
@Override public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { EnumFacing facing = par1IBlockSource.getBlockState().getValue(BlockDispenser.FACING); Axis axis = facing.getAxis(); BlockPos pos = par1IBlockSource.getBlockPos().offset(facing); World world = par1IBlockSource.getWorld(); if(world.isAirBlock(pos) && block.canPlaceBlockAt(world, pos)) { int meta = item.getMetadata(par2ItemStack.getItemDamage()); IBlockState state; if(!(block instanceof BlockPistonBase)) state = block.getStateFromMeta(meta); else state = block.getDefaultState(); LockDirectionHotkey.setBlockRotated(world, state, pos, facing); SoundType soundtype = block.getSoundType(); world.playSound(null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); par2ItemStack.shrink(1); return par2ItemStack; } return super.dispenseStack(par1IBlockSource, par2ItemStack); }