Skip to content

Writing your own herd rules

Strength In Numbers makes mobs of a kind stick together in herds. What a herd does is set by rules: small JSON files, one per kind of mob. You can change any default, add mobs from other mods, or switch a species off, without writing code.

This guide ships inside Strength In Numbers. Every launch keeps a copy at config/strengthinnumbers/RULES.md.

  1. Open your Minecraft folder’s config/strengthinnumbers/rules/ (on a server, the server’s folder). The mod creates it on first launch, with a disabled example.json.disabled inside.
  2. Create a file ending in .json, for example my_rules.json, and paste one of the examples below into it.
  3. In game, run /reload (needs op), or restart.
  4. Check the log. A broken file is reported by name, for example Herd rule config/strengthinnumbers/rules/my_rules.json is invalid and was skipped: ..., and the other rules keep working.

Which rule wins. Each kind of mob uses one rule. A rule in config/strengthinnumbers/rules/ always wins over data packs and mods for the mobs it names. Among data packs, the pack loaded later wins; within one source, the file whose name sorts later wins. Names sort character by character, with capital letters before lower-case ones (Zebra.json before apple.json), on every system.

Data packs work too: put the same files in data/<your_namespace>/herd_rules/ inside a pack. That is how mods and modpacks ship rules.

{
"entity": "minecraft:sheep",
"herd": { "radius": 16, "max_size": 12, "leader": "none" },
"standing": [ { "do": "cohesion", "strength": 0.5, "distance": 6 } ],
"reactions": [
{ "on": "member_hurt", "do": "huddle", "radius": 12, "cooldown_ticks": 60, "duration_ticks": 30,
"then": { "do": "flee", "duration_ticks": 80 } }
]
}

Read it as: sheep form herds of up to 12 within 16 blocks. Strays drift back (cohesion). When a sheep is hurt, the sheep within 12 blocks of it bunch up (huddle), then run (flee).

Key Required Meaning
entity yes One entity ID ("minecraft:cow"), a tag ("#minecraft:skeletons"), or a list of both.
enabled no false switches these mobs off: they never herd. Default true.
herd no How herds form; see below.
standing no Behaviors that run all the time (while no reaction is running).
reactions no What the herd does when something happens.

Keys that start with _ are comments and are ignored, for example "_note": "my tweak". Any other unknown key makes the rule invalid, so typos show up in the log.

Key Default Allowed Meaning
radius 16 2 to 64 Mobs within this many blocks of a herd’s center can join it.
max_size 12 2 to 64 A herd never grows past this; extra mobs start another herd.
leader none none, oldest, largest Who leads. follow_leader needs a leader. Adults are chosen first. A leader that dies or leaves is replaced.

A herd holds one kind of mob. A rule naming several kinds (cows and mooshrooms) makes separate herds for each.

Animals people keep are left alone, so farms are not disrupted: leashed, name-tagged, tamed (an owned horse, donkey, mule, or llama; a tamed wolf or cat), saddled, carrying a player in any seat, a llama in a caravan, and animals bred by a player. Babies bred by a player get the entity tag strengthinnumbers.domestic. Remove it with /tag @e[...] remove strengthinnumbers.domestic to make one wild.

On Peaceful, no reaction makes a herd member target a player. (Vanilla behavior stays: a hit llama may still spit back.)

Each entry in standing is { "do": <behavior>, <parameters> }. Standing behaviors run on the herd’s schedule (once a second by default) whenever no reaction is running.

Behavior What members do Parameters (default, allowed)
cohesion Each idle member farther than distance from the herd center walks back, with chance strength per check, to a point inside distance. A member that cannot get back (a fence in the way) rests 10 seconds before trying again. Members chasing a target are not idle. strength (0.5, 0 to 1), distance (6, 1 to 32), speed (1.0, 0.3 to 2)
follow_leader Members farther than distance from the leader walk to it. Needs "leader": "oldest" or "largest". distance (6, 2 to 32), speed (1.0, 0.3 to 2)

Each entry in reactions is { "on": <trigger>, "do": <reaction>, ... }: when the trigger fires, the chosen members run the reaction. A trigger’s source is the entity that caused it (the attacker, the killer, the target, or the threat).

Trigger Fires when Source Trigger keys (default, allowed)
member_hurt A herd member takes damage. Falls, drowning, and other damage with no attacker have no source. The attacker none
member_killed A herd member dies. The killer, if any none
target_acquired A herd member picks a new attack target on its own. The target none
threat_seen A member can see a mob matching threat within range. Checked on the herd’s schedule, one member looking at a time. The nearest such mob threat (required: ID, #tag, or list), range (16, 1 to 64)
losses The herd lost at least fraction of its members within window_ticks. The last killer, if any fraction (0.5, 0.01 to 1), window_ticks (200, 1 to 72000)

Hits and target changes that a reaction causes never fire another trigger, so one hit causes at most one reaction per rule entry, and alarms never chain from herd to herd.

Times are in ticks: 20 ticks are one second. Speeds multiply the mob’s normal walking speed.

Reaction What the chosen members do Parameters (default, allowed)
flee Each runs from the source on its own: a scatter. With "direction": "random", short runs every which way instead of away from the source. duration_ticks (100, 1 to 1200), speed (the species’ panic speed, 0.1 to 4), direction (away, or random)
avoid Each keeps at least distance from the source. Does nothing without a source. duration_ticks (100, 1 to 1200), distance (8, 1 to 32), speed (1.2, 0.1 to 3)
defend Adults attack the source. Neutral mobs get angry; goats ram. Babies stay out of it. When it ends, they keep the target unless release is true, which makes them let go. duration_ticks (200, 1 to 2400), release (false)
join_attack All attack the source (what the member that fired the trigger attacked or targeted). release as for defend. duration_ticks (200, 1 to 2400), release (false)
stampede The whole herd runs one shared direction away from the source, keeping its shape. duration_ticks (100, 1 to 1200), distance (24, 4 to 64), speed (1.6, 0.5 to 3)
huddle Adults close into a ring around the herd center, about spacing apart; babies go to the middle. Holds the ring hold_ticks once everyone is in place, then ends (duration_ticks at most), so a then follows promptly. duration_ticks (40, 1 to 600), spacing (1.5, 0.5 to 4), speed (1.1, 0.3 to 3), hold_ticks (0, 0 to 200)
flap Each, with chance chance, leaps about height blocks into the air away from the source, then comes down (chickens flutter), each at its own moment within spread_ticks. Combine it with flee in a second entry. chance (0.35, 0 to 1), height (1.5, 0.5 to 4), push (0.25, 0 to 1), spread_ticks (20, 0 to 100)
freeze Each stops and faces the source. duration_ticks (20, 1 to 200)
flank Each attacks the target; those far from it first walk to spots distance from it, spread across arc degrees, so the pack arrives from several sides. duration_ticks (100, 1 to 600), arc (180, 0 to 360), distance (3, 1 to 8), speed (1.0, 0.5 to 2)
hold_range Archers hold still and hold fire while any herd mob stands in their line of fire. width widens the line. duration_ticks (200, 1 to 1200), width (0.5, 0 to 2)
regroup Survivors fall back to a rally point distance past the herd center, away from the killer, and wait there duration_ticks from each one’s arrival, then attack again. The walk is limited to duration_ticks too. duration_ticks (60, 1 to 600), distance (8, 0 to 32), spacing (1.5, 0.5 to 4), speed (1.2, 0.5 to 3)

These keys go in a reaction entry next to on and do:

Key Default Meaning
who all all, adults, babies, leader, followers (everyone but the leader), or nearest with count.
count 1 With "who": "nearest": how many of the members nearest the one that fired react.
radius whole herd Only members within this many blocks of the member that fired react (0.5 to 256).
when always Conditions; all must hold. See below.
cooldown_ticks 0 After this entry starts, the herd ignores it for this long (0 to 72000).
then none { "do": ..., <parameters>, "then": ... }: runs with the same members once this reaction ends.

when conditions:

Condition Meaning
herd_size_at_least The herd has at least this many members. The “strength in numbers” switch: a pack of three attacks, two stragglers do not.
herd_size_at_most The herd has at most this many members.
source_type The source is this entity ID, #tag, or one of a list. For example, flee only from players.
chance From 0 to 1: the chance the entry runs each time the trigger fires.

While a reaction from reactions runs, standing behaviors pause, and a new reaction stops them.

Name it by ID. A rule for a mob whose mod is not installed simply matches nothing, so modpacks can ship rules for optional mods.

{
"_note": "Deer from a wildlife mod: herds of up to 8 that stampede when one is hurt.",
"entity": "examplewildlife:deer",
"herd": { "radius": 20, "max_size": 8, "leader": "oldest" },
"standing": [ { "do": "follow_leader", "distance": 8 } ],
"reactions": [
{ "on": "member_hurt", "do": "stampede", "radius": 16, "cooldown_ticks": 60,
"duration_ticks": 100, "distance": 28, "speed": 1.8 }
]
}

A tag covers every mob listed in it. Use one a mod already ships, or make your own in a data pack: data/my_pack/tags/entity_types/grazers.json holding { "values": ["examplewildlife:deer", "examplewildlife:bison"] }. Then name it with #:

{
"entity": "#my_pack:grazers",
"herd": { "radius": 16, "max_size": 10 },
"standing": [ { "do": "cohesion", "strength": 0.5, "distance": 6 } ],
"reactions": [ { "on": "member_hurt", "do": "flee", "radius": 12, "duration_ticks": 80 } ]
}

Each kind of mob in the tag forms its own herds.

config/strengthinnumbers/strengthinnumbers.json has a switch for every reaction under reactions. Set one to false and restart the game (/reload does not reread this file; in single player, the Mod Menu settings screen applies it at once): every rule drops it. A rule entry whose first reaction is off continues with its then.

{
"enabled": true,
"updateInterval": 20,
"debugHerds": false,
"reactions": {
"stampede": false
}
}

"enabled": false at the top switches the whole mod’s herding off. updateInterval is how often, in ticks, each mob checks its herd (1 to 200); higher is cheaper but slower to react.

{
"entity": "minecraft:chicken",
"enabled": false
}

Reactions combine with then, when, and who. Rabbits that spot a fox freeze for a moment, then scatter, but only in groups of at least three; a lone rabbit just runs:

{
"entity": "minecraft:rabbit",
"herd": { "radius": 10, "max_size": 8 },
"standing": [ { "do": "cohesion", "strength": 0.4, "distance": 5 } ],
"reactions": [
{ "on": "threat_seen", "threat": "minecraft:fox", "range": 12, "cooldown_ticks": 200,
"when": { "herd_size_at_least": 3 },
"do": "freeze", "duration_ticks": 15,
"then": { "do": "flee", "duration_ticks": 60 } },
{ "on": "threat_seen", "threat": "minecraft:fox", "range": 12, "cooldown_ticks": 200,
"when": { "herd_size_at_most": 2 },
"do": "flee", "duration_ticks": 60 },
{ "on": "member_hurt", "do": "flee", "duration_ticks": 60 }
]
}
  • Nothing happens. Run /reload after editing. Check that the mob is not domestic (see above) and that your rule is the one that wins (a config-folder rule beats data packs).
  • The log says a rule was skipped. The message names the file and the problem, for example "max_size" must be from 2 to 64, got 100 or unknown reaction strengthinnumbers:stampeed.
  • See what herds do. Set "debugHerds": true in strengthinnumbers.json and restart (or turn it on in the settings screen): the log shows herds forming and every reaction that starts.
  • IDs. do and on take short names (flee, member_hurt) or full IDs (stope:flee). Reactions from other mods need their full ID.

Strength In Numbers refuses to start alongside HerdsPanic, Herd Mentality, Herd Instinct, Herd Hysteria, or Animals herding: they change the same mob behavior and would fight over it. Remove one of them.