Mob groups
Mob groups gather nearby mobs of one entity type into herds that Stope keeps current as mobs
move, load, and die, each with a center, an optional leader, and a count of recent losses.
Use them when mobs should act together, for example through reaction bindings, and
MobControl alone when each mob acts on its own.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
GroupDefinition |
Describes one kind of mob group: its entity types, radius, size, leader, filter, and bindings. | Experimental | 1.2.0 | both | any |
LeaderChoice |
How a mob group picks its leader. | Experimental | 1.2.0 | both | any |
MobGroup |
Read-only view of one live mob group. | Experimental | 1.2.0 | server | server |
MobGroupChangedCallback |
Fired when a mob joins or leaves a mob group. | Experimental | 1.2.0 | server | server |
MobGroups |
Entry point for mob groups: define kinds of group, and Stope keeps live groups current. | Experimental | 1.2.0 | server | server |
Quick start
Section titled “Quick start”In your mod’s common initializer, with cow in the last lines standing for any cow on the
server:
// Defined again at every server start, so each world gets the same groups.ServerStartedCallback.EVENT.register(server -> MobGroups.define(id("herds"), List.of( GroupDefinition.builder(id("cows")) .type(EntityType.COW) .leader(LeaderChoice.OLDEST) .build())));
// Later, on the server thread, a cow's herd and its leader:MobGroup herd = MobGroups.groupOf(cow);Mob leader = herd == null ? null : herd.leader();MobGroups
Section titled “MobGroups”Experimental · Since 1.2.0 · Side: server · Thread: server
Define a mod’s kinds of group from a DataReloaders handler, so they follow its data files.
With LOGGER, the mod’s SLF4J logger:
DataReloaders.registerFiles(id("herds"), "herd_bindings", "mymod/herd_bindings", files -> { GroupDefinition.Builder cows = GroupDefinition.builder(id("cows")) .type(EntityType.COW).tag(id("cattle")) .radius(16).maxSize(12).leader(LeaderChoice.OLDEST).refreshInterval(20) .filter(mob -> !mob.isLeashed()); for (DataFile file : files) { try (Reader reader = file.openReader()) { JsonObject binding = JsonParser.parseReader(reader).getAsJsonObject(); cows.binding(ReactionBinding.parse(binding, "mymod")); } catch (IOException | RuntimeException e) { // A broken file loses only its own binding; the herd keeps every other one. LOGGER.warn("Skipped herd binding {}: {}", file.location(), e.getMessage()); } } MobGroups.define(id("herds"), List.of(cows.build()));});Ordering and timing
Section titled “Ordering and timing”- Every mob of an entity type a definition covers, grouped or not, checks its membership
once every
GroupDefinition#refreshIntervalticks, offset by its entity ID, so the members of a group check on different ticks. - A mob leaves its group when the group’s center is farther than
GroupDefinition#radius. - A mob leaves its group when it fails the definition’s
GroupDefinition#filter. - A mob joins the largest nearby group of its definition and entity type that has room and is at least as large as its own group, so neighboring groups drain into one. With no such group, it starts a group of its own.
- The check of the group’s first member (the one that joined earliest) also recomputes the
group’s center (the mean of member positions) and its leader. Standing behaviors and the
threat_seentrigger are checked on this schedule (the group schedule).
Edge cases
Section titled “Edge cases”- One member far from the others pulls the mean toward itself.
- When a group splits, either side may keep the old
MobGroupobject. - After
MobGroups#definedissolves an owner’s groups, every member regroups at its own next check, so the new groups form within one refresh interval.
See also
Section titled “See also”- Mob control: orders for single mobs.
- Reactions (Java) and the reaction binding format: what a group’s members do when a trigger fires.
- Saved data and reloaders:
the reload handlers that call
MobGroups#define. - Herd animals that flee from players: a guide that builds a fleeing herd step by step.