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; } }
@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; } }
public static void playSoundPlaceBlock(World world, BlockPos pos, Block block) { if (block == null) { return; } SoundType type = block.getSoundType(block.getDefaultState(), world, pos, null); if (type != null && type.getPlaceSound() != null) { UtilSound.playSound(world, pos, type.getPlaceSound(), SoundCategory.BLOCKS); } }
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 playSoundPlaceBlock(EntityPlayer player, BlockPos pos, Block block) { if (player == null) { return; } BlockPos here = (pos == null) ? player.getPosition() : pos; if (block == null) { return; } SoundType type = block.getSoundType(block.getDefaultState(), player.getEntityWorld(), here, player); if (type != null && type.getPlaceSound() != null) { UtilSound.playSound(player, here, type.getPlaceSound()); } }
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 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 ); }
@Override public boolean prepareBlock(@Nonnull IFarmer farm, @Nonnull BlockPos pos, @Nonnull IBlockState state) { final ItemStack seed = farm.getSeedTypeInSuppliesFor(pos); final EntityPlayerMP player = farm.getFakePlayer(); final World world = farm.getWorld(); if (canPlant(seed) && isValidPlantingSpot(world, pos) && player.canPlayerEdit(pos, EnumFacing.UP, seed) && world.mayPlace(Blocks.CHORUS_FLOWER, pos, false, EnumFacing.UP, (Entity) null)) { IBlockState iblockstate1 = Blocks.CHORUS_FLOWER.getDefaultState().withProperty(BlockChorusFlower.AGE, 0); IBlockState oldState = world.getBlockState(pos); if (placeBlockAt(seed, player, world, pos, iblockstate1)) { if (Prep.isValid(farm.takeSeedFromSupplies(pos))) { 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); return true; } else { world.setBlockState(pos, oldState, 3); } } } return 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(@Nonnull ItemStack stack, @Nonnull World worldIn, @Nonnull BlockPos pos) { IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab && singleSlab != doubleSlab) { BlockSlab.EnumBlockHalf blockslab$enumblockhalf = iblockstate.getValue(BlockSlab.HALF); IBlockState iblockstate1 = this.doubleSlab.getDefaultState(); IBlockState paintSource = singleSlab.getPaintSource(iblockstate, worldIn, pos); IBlockState paintSource1 = PaintUtil.getSourceBlock(stack); final AxisAlignedBB collisionBoundingBox = iblockstate1.getCollisionBoundingBox(worldIn, pos); if ((collisionBoundingBox == null || worldIn.checkNoEntityCollision(collisionBoundingBox)) && worldIn.setBlockState(pos, iblockstate1, 3)) { if (blockslab$enumblockhalf == BlockSlab.EnumBlockHalf.BOTTOM) { doubleSlab.setPaintSource(iblockstate1, worldIn, pos, paintSource); doubleSlab.setPaintSource2(iblockstate1, worldIn, pos, paintSource1); } else { doubleSlab.setPaintSource(iblockstate1, worldIn, pos, paintSource1); doubleSlab.setPaintSource2(iblockstate1, worldIn, pos, paintSource); } worldIn.playSound(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, this.doubleSlab.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (this.doubleSlab.getSoundType().getVolume() + 1.0F) / 2.0F, this.doubleSlab.getSoundType().getPitch() * 0.8F, true); 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; }
@SubscribeEvent public void leftClick(PlayerInteractEvent.LeftClickBlock event) { if(event.getEntityPlayer().getHeldItemMainhand().isEmpty()) { IBlockState state = event.getWorld().getBlockState(event.getPos()); Block block = state.getBlock(); if(block instanceof BlockDoor && state.getMaterial() == Material.WOOD) event.getWorld().playSound(null, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ(), block.getSoundType().getPlaceSound(), SoundCategory.PLAYERS, 1F, 1F); } }
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); }
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){ ItemStack stack = player.getHeldItem(hand); if(StackUtil.isValid(stack) && player.canPlayerEdit(pos.offset(facing), facing, stack)){ IBlockState state = world.getBlockState(pos); if(state.getBlock() == this.block){ BlockSlabs theBlock = (BlockSlabs)this.block; if((facing == EnumFacing.UP && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM) || (facing == EnumFacing.DOWN && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP)){ 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 EnumActionResult.SUCCESS; } } return this.tryPlace(player, stack, hand, world, pos.offset(facing)) ? EnumActionResult.SUCCESS : super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ); } else{ return EnumActionResult.FAIL; } }
@Override public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException { BlockPos pos = data.readBlockPos(); VisualFXType visualFX = VisualFXType.values()[data.readByte()]; SoundFXType soundFX = SoundFXType.values()[data.readByte()]; World world = player.world; IBlockState blockState = NBTUtil.readBlockState(data.readCompoundTag()); Block block = blockState.getBlock(); if (visualFX == VisualFXType.BLOCK_BREAK) { Minecraft.getMinecraft().effectRenderer.addBlockDestroyEffects(pos, blockState); } if (soundFX != SoundFXType.NONE) { SoundType soundType = block.getSoundType(blockState, world, pos, null); if (soundFX == SoundFXType.BLOCK_BREAK) { world.playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundType.getBreakSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false); } else if (soundFX == SoundFXType.BLOCK_PLACE) { world.playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false); } } } }