Skip to content

[Feat] Zone flag to clear and prevent mobs from existing in a zone #79

@derrickmehaffy

Description

@derrickmehaffy

Scope

  1. A new zone flag mob_clear (or mob_purge) that ensures a zone is always free of mobs
  2. When enabled, all existing mobs inside the zone boundaries should be immediately removed
  3. Any mob that enters or spawns inside the zone should be automatically killed/removed
  4. Should work alongside existing mob_spawning flag — mob_spawning: false prevents new spawns but does NOT remove mobs that wander in from outside; mob_clear actively removes all mobs continuously
  5. Should apply to hostile, passive, and neutral mobs (controlled by the master toggle)
  6. Should NOT affect players
  7. Should optionally have sub-flags for granular control: mob_clear_hostile, mob_clear_passive, mob_clear_neutral as children of mob_clear (matching the existing spawning flag hierarchy)
  8. Should be a periodic check (e.g., every few seconds) rather than per-tick to avoid performance impact

Implementation Details

  1. New zone flag constants in ZoneFlags.java:

    • mob_clear — master toggle, parent flag
    • mob_clear_hostile — clear hostile mobs (child)
    • mob_clear_passive — clear passive mobs (child)
    • mob_clear_neutral — clear neutral mobs (child)
  2. Default values:

    • SafeZone: mob_clear: true (all sub-flags true) — safe zones should be mob-free
    • WarZone: mob_clear: false (all sub-flags false) — war zones keep mobs for danger
  3. Suggested implementation approach:

    • Periodic task (every 5-10 seconds) iterates zones with mob_clear enabled
    • For each zone, query entities in the zone's chunk range
    • Check each entity against NPCGroup (hostile/passive/neutral) and the sub-flags
    • Remove matching entities via entity.remove() or equivalent server API
    • Could reuse the existing SpawnSuppressionController chunk iteration pattern
  4. Parent-child hierarchy in ZoneFlags.getParentFlag():

    case MOB_CLEAR_HOSTILE, MOB_CLEAR_PASSIVE, MOB_CLEAR_NEUTRAL -> MOB_CLEAR;
  5. UI category: Add to existing "Spawning" category or create a new "Mob Control" category

Risks and Alternatives

  1. Performance risk: Iterating all entities in zone chunks every few seconds could be expensive with many zones. Mitigate by only processing zones that have mob_clear enabled, and by using chunk-based spatial indexing (already exists for claims).
  2. Edge case: Mobs on zone boundaries may flicker in and out. Use a small buffer or only check mobs fully inside the region.
  3. Alternative — combine with mob_spawning: Instead of a new flag, enhance mob_spawning: false to also remove existing mobs. However, this changes existing behavior where mob_spawning only prevents new spawns, which some servers may rely on (e.g., keeping existing farm animals but preventing new wild spawns).
  4. Mixin dependency: May require mixin support to intercept mob movement into zones, or could use a simpler polling approach that doesn't need mixins.
  5. Named/tamed mobs: Consider whether tamed or named mobs should be exempt from clearing. Could add a config option mob_clear_exempt_tamed: true.

References and Media

Existing related flags in ZoneFlags.java:

  • mob_spawning (master toggle) with children hostile_mob_spawning, passive_mob_spawning, neutral_mob_spawning
  • npc_spawning (mixin-dependent)
  • The spawning flags prevent NEW spawns but don't remove mobs that walk in from outside the zone

Similar concept in other games:

  • Minecraft WorldGuard mob-spawning + deny-spawn flags with entity removal
  • Factions plugins with "safe zone mob clearing" features

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions