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