Yes, there is a way in the 1.8 snapshots.
Using a RedStone clock give all entities that damage the player a huge weakness effect:
/effect @e[mob id] 18 9999 127
Note that @e targets players and thus so that only mobs get a weakness effect you have to put in an ID for the entity type. You will have to have a few command blocks each for each type of hostile entity(One each for zombies, skeletons, endermen, creepers{change gamerule doMobGriefing to false}, zombie pigmen, ghasts and blazes). This prevents them from doing damage to the player. Note also that if you give them a weakness level of more than 127, it has a negative effect, meaning it will give them basically 127 strength.
Another method that can be used in 1.7.x is giving all the players a resistance effect like you did but weaker, and then giving players a strength effect that overpowers the resistance.
Strength:
/effect @a 5 9999 6
Resistance:
/effect @a 11 9999 4
This will give all players resistance 4 and this is enough to make them invincible to mobs. They will still take hits but will not take any damage. Note: I am not actually sure if Strength 6 is enough to overpower Resistance 4. If it isn't, just give a higher strength. If the Resistance is too low, give them a higher resistance and higher strength. Just look for the balance. :)
A few questions:
- Is there a reason you are not making it on Peaceful mode? (I imagine it is so that players don't regenerate health that quickly but you can turn the gamerule naturalRegeneration off)
- Is there a reason, if you don't want to turn it to peaceful, why you want to keep gamerule doMobSpawning on?
- Are you manually spawning the mobs, i.e. with command blocks? If yes you can modify their attributes to not allow them to damage the player.
So yes, there are ways to do it in vanilla Minecraft.
Hope I helped!
You want to use the Riding:
attribute when you spawn it in. This will produce a zombie chicken jockey in full diamond armor, with a diamond sword (the first item):
/summon Zombie ~ ~1 ~ {IsBaby:1,Riding:{id:Chicken},Equipment:[{id:276},{id:310},{id:311},{id:312},{id:313}]}
It's very likely that you just need to add Riding:{id:Chicken}
to what you've currently got in your command block, and adjust the coordinates to fit.
The decimal values for armor and swords (or other weapons, etc) can be substituted to fit whatever need.
Editorial note - reader beware! It is extremely fun to do positively silly things with this and then realize you spent the whole day doing it.
Best Answer
A mob will not try to attack you if you are on the same team as it. For example, you can create a team:
Then add yourself and the zombie to the team:
You could also summon the zombie already on the team: