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;
}
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);
}
}
}
}
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);
}
}
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;
}
}
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;
}
Aggregations