Make it so mobs can't hit certain mobs? (friendly fire)

Started by BMAgamer on

Topic category: Help with Minecraft modding (Java Edition)

Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Make it so mobs can't hit certain mobs? (friendly fire)

So i'm making a mod, where there are these turret things, but sometimes they shoot each other. They are not hostile to each other, but if they are trying to shoot a mob, and another turret is right in front of it, the projectile will hit that turret. How can I make it so there is no friendly fire between these mobs.

Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Maybe you can make them…
Sat, 03/23/2024 - 03:19

Maybe you can make them immune to the damage that their projectile deal in the behavior page.

Joined Jan 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Get something like this in…
Sun, 01/26/2025 - 15:19

Get something like this in your Behavior Pack's "entities" file:

"minecraft:damage_sensor": {
{
"on_damage": {
"filters": {
"test": "is_family",
"subject": "other",
"value": "turret"
}
},
"cause": "all",
"deals_damage" : false
},
]
},

This will make it so that your mob won't register any damage from mobs of the "turret" family. They won't take any damage, and they won't play the hurt sound and turn red, but only from mobs that have that family.

If you were to change "turret" into, for example, "monster", that would mean your mob won't register any damage from mobs of the "monster" family; which encompasses every single hostile mob in the game.

"turret" should be replaced with whatever unique family is listed under "minecraft:type_family". If there isn't a family in there that only your turret has, you can easily add one.

You can also expand the "minecraft:damage_sensor" component to cover multiple damage sources. Here's the one I'm running:

"minecraft:damage_sensor": {
"triggers": [
{
"on_damage": {
"filters": {
"all_of": [
{
"test": "is_family",
"subject": "other",
"operator": "!=",
"value": "noctern"
},
{
"test": "is_block",
"subject": "block",
"operator": "!=",
"value": "minecraft:sweet_berry_bush"
}
]
},
"event":
"lol"
},
"cause": "all",
"deals_damage" : true,
"damage_modifier": -999999999
},
{
"on_damage": {
"filters": {
"test": "is_family",
"subject": "other",
"value": "noctern"
},
"event":
"lol"
},
"cause": "all",
"deals_damage" : false
},
{
"cause": "projectile",
"deals_damage" : false
},
{
"cause": "fall",
"deals_damage" : false
},
{
"cause": "freezing",
"deals_damage" : false
},
{
"on_damage": {
"filters": {
"test": "is_block",
"subject": "block",
"value": "minecraft:sweet_berry_bush"
}
},
"cause": "all",
"deals_damage": false
}
]
},

The above will not register damage from projectiles, falls, powder snow, berry bushes, and mobs of the "noctern" family.

It will however, register damage from all other sources (it'll play the sound and turn red). But that damage will be reduced by 999999999.

In other words my mob's functionally immortal.

There's documentation for every component online if your search up it's name. The links for learn.microsoft.com and wiki.bedrock.dev are my preferred sources.

Also download the bedrock sample pack and take a look through the vanilla "entities" files in the behavior pack. The Creaking's file is what taught me that it was possible to put multiple sources under the "minecraft:damage_sensor" component, I think it's the only vanilla mob that makes use of that fact.

Anyways, good luck!