It hasn’t been a good year to be a cop in New York City, but at 12:30 Sunday morning at the gang-plagued Edenwald Houses in the Bronx, bad became infinitely worse.

Nearly-seven-year NYPD veteran Brian Mulkeen, 33, was shot to death — apparently with his own gun — in a struggle with an armed ex-con gangbanger and parolee who had been fleeing anti-crime officers.

It was the third time city cops have come under fire in recent weeks. An officer was slightly wounded on Staten Island late last month — and while there were no police injuries during a similar incident in Brooklyn a week earlier, that’s not because the shooter wasn’t trying.

All three perps died when officers returned fire — in context, perfectly reasonable outcomes — but while the circumstances of each incident differed, they reflected the increasingly open antagonism cops face on the streets every day.

Mulkeen’s death speaks for itself.

The Staten Island incident involved a suspect in a domestic violence complaint who opened up on officers with an illegal gun before being killed in the return fire. Then onlookers loudly did their best to escalate the incident — wishing the cops on the scene dead, among other ugly things.

Such police-civilian confrontations are common in the city. They range from simple verbal baiting of officers to dumping of water and even milk on them, to the deadly encounters on Staten Island and in Brooklyn. And, early Sunday, to the tragedy in the Bronx.

It’s hard to imagine how heavily all this weighs on the minds of individual officers as they report for duty.

Will someone with a gun and lethal intentions be standing in the next jeering crowd gathered in response to legitimate police action? This happened early in the de Blasio administration, when crowds chanting for “dead cops” wracked the city following the death of Eric Garner — and two cops were assassinated in their patrol car.

How long before high tension, social volatility and just pure bad luck combine to create an otherwise avoidable tragedy?

How many cops on the beat fear ending up as a scapegoat — as did Daniel Pantaleo, fired in the Garner case — and hesitate for a fatal split-second in responding to a lethal challenge?

Was that a factor in the Bronx early Sunday?

It doesn’t help that many cops believe, quite reasonably, they’ve been abandoned by the de Blasio administration — and by New York’s political culture itself.

City Hall has been growing increasingly antagonistic to legitimate law enforcement in recent years, fretting about Rikers Island and “over-policing” in the schools while showing little more than rhetorical interest when cops have buckets of water dumped on them — or are shot at.

This trend was underscored dramatically by Albany’s symbolic but consequential virtual abolition of cash bail during this year’s legislative session.

And by One Police Plaza’s slow but accelerating drift away from quality-of-life policing — the results of which are clearly visible on city streets and in the subways.

And then there is the bitterness over Pantaleo’s firing; officers feel — with substantial justification — that City Hall and police brass ignored both case law and longstanding custom giving officers the benefit of the doubt in ambiguous situations.

Deep-sixing those protections, so the reasoning goes, leads to cultural timidity as cops — fearful of firing or worse — begin to back away from aggressive criminal behavior. (And it doesn’t help that the Albany Legislature is considering doing away with the protections altogether.)

There seems little doubt New Yorkers inclined to fight cops have found encouragement in all this. They may be criminals, but many are clever enough to understand that the NYPD no longer stands rock-solid behind its officers.

That could be why people are throwing water on them — to say nothing of shooting at them.

Or, as in the Bronx early Sunday, killing them.

The NYPD is a rare and precious public resource and never is that more obvious than when an officer dies in service to the city.

Now will come the necessary words, and the requisite ceremonies, to mark the passing of yet another young hero. But how flat all that must sound to cops growing increasingly inured to empty rhetoric, and ever more suspicious of their leaders’ motives.

Still, that’s for the future.

Right now, it’s enough to bow one’s head in honor of one man’s singular sacrifice.

God bless you, Brian Mulkeen.

Bob McManus is a contributing editor at City Journal.