Entity Culling MCBE [Achievements Friendly]
A multiplayer/realms friendly addon for MCBE that despawns mobs no player can currently see (out of FOV *and* behind a block) and restores them once a player can see that spot a...
Screenshots
![Entity Culling MCBE [Achievements Friendly] — screenshot 1](https://r2.mcpedl.com/submissions/236096/images/winter-times-120--tetxure-pack_2.png)
![Entity Culling MCBE [Achievements Friendly] — screenshot 2](https://r2.mcpedl.com/submissions/236096/images/winter-times-120--tetxure-pack_3.png)
![Entity Culling MCBE [Achievements Friendly] — screenshot 3](https://media.forgecdn.net/attachments/description/1239291/description_ae1c79ec-34d8-46a1-b62d-af07ce717131.png)
![Entity Culling MCBE [Achievements Friendly] — screenshot 4](https://r2.mcpedl.com/submissions/196531/images/autumn-vibes-110--texture-pack_2.png)
Description
A addon for MCBE that despawns mobs no player can currently see (out of FOV *and* behind a block) and restores them - position, rotation, health, name tag - once a player can see that spot again. This is the same idea as client-side "Entity Culling" mods, reimplemented server-side with the '@minecraft/server' scripting API, since Bedrock add-ons can't hook the renderer directly.
Built against **Minecraft Bedrock 1.26.40**, using '@minecraft/server' v2.9.0 (stable - no experimental/cheats toggles required).
XP clumps (New!)
A separate subsystem from culling ('xpClumps.js'), with its own loop, its own enable flag, and its own stats. It reduces XP orb counts near players without ever destroying or creating XP.
**Why it can't just merge orbs directly.** An orb's XP value isn't readable through the stable script API, so the obvious approach read N orbs, remove them, spawn one worth the total - would be guessing at the amount. ('Dimension.spawnXp()' exists but is pre-release, so it isn't relied on either.) Instead the system only ever *moves* orbs and lets the engine do the rest:
- Orbs within 'instantCollectRadius' (default 0.8 blocks) of a player get nudged into that player, so vanilla's own pickup code awards the exact XP. - Remaining orbs are grouped and moved onto a shared anchor, so Bedrock's native orb-merging combines their values.
**Nothing in 'xpClumps.js' calls 'remove()' on an orb.** The engine is the only thing that ever deletes one - which is what makes XP loss or duplication structurally impossible here rather than just unlikely. If a merge doesn't happen for some reason, the orbs are still sitting there and the next pass retries; the cost is a wasted teleport, not lost XP.
Other design notes:
- **XP orbs are never culled.** 'filters.js' hard-blocks 'minecraft:xp_orb' with no config flag, alongside players. Culling one would save its type and position while silently losing its value. - **Groups are anchor-based, not chained.** Every member must be within 'mergeRadius' of the anchor itself - otherwise a chain of 2-block hops would collapse a 6-block-wide spread into one point. - **The anchor is the orb with the most neighbours**, so it sits near the middle of a cluster and the orbs that move travel less. - **A spatial hash** keeps neighbour lookups local instead of comparing every orb against every other one. - **'maxProcessedPerTick'** (default 20) caps how many orbs move per pass, so a big farm dumping hundreds of orbs at once can't spike a tick - the count still drops quickly, just over several passes. - **A short cooldown** after moving an orb gives the engine time to actually merge it before the next pass looks at it again. - **Merge success is verified, not assumed.** Moved groups are rechecked a few ticks later; a member that no longer exists was absorbed. That's why '/cull:stats' reports merge *attempts* and *successful* merges separately.
| Command | What it does |
|---|---|
| '/cull:xpclumps on' / 'off' | Enable/disable XP clumping |
| '/cull:xpclumps status' | Show current state and the active radii/interval |
'/cull:off' disables culling only - XP clumping keeps running. Likewise '/cull:xpclumps off' leaves culling alone. The tuning values ('mergeRadius', 'scanRadius', 'checkIntervalTicks', 'maxProcessedPerTick', 'minOrbsToMerge', 'mergeCooldownTicks') live in 'config.js' under 'xpClumps' and aren't exposed as commands yet.
How it works:
\1. Every few ticks, each player's nearby entities are scanned ('scanner.js'), out to 'maxDistance' (default 64 blocks). \2. Entities are filtered down to ones that are safe to touch ('filters.js'), following a fixed precedence: protected entities (no players, no XP orbs, no paintings/armor stands/cushions, no bosses, no villagers/traders, no leashed/ridden/inventoried mobs, and by default no custom-named entities) are never cullable, no matter what; then the blacklist; then the whitelist (if you've set one); and finally the hostile/passive/items category toggles. See "Filters & protection" below. \3. For each remaining candidate, we check whether *any* player can see it ('visibility.js', combining a view-cone test and a block-occlusion test). An entity only counts as hidden if nobody can see it - this is deliberately multiplayer-safe. \4. If an entity stays hidden for 'cullDelayTicks' in a row (default 15 ticks, ~0.75s) AND is within 'cullMaxDistance' (default 32 blocks) of the nearest player, its state is captured ('entityState.js') into a small persistent database ('database.js', stored in world dynamic properties) and the real entity is removed ('culling.js'). Hidden entities farther than 'cullMaxDistance' are left alone entirely - see "Playing nicely with vanilla despawning" below. 'cullDelayTicks' is the "recently visible" grace period: it's what stops a quick look-away/ look-back from despawning and immediately re-summoning the same entity, and it's live-tunable with '/cull:grace <ticks>'. While that timer is running the entity is rechecked on *every* scan pass (skipping distance tiering and load throttling), so any moment it becomes visible resets the timer. Because visibility is sampled once per scan pass, the grace period is a *minimum* hidden time in whole passes (with the default 5-tick scan, 15 ticks culls ~15-20 ticks after the entity is first seen hidden), not an exact duration. \5. Every culled record's nearest-player distance is checked on *every* restore pass, for one of three reasons: the moment nobody is within 'cullMaxDistance' of it anymore (while someone is still within 'restoreDistance', default 64 blocks), it's restored immediately, regardless of visibility and regardless of its normal recheck timer - see "Avoiding mob duplication" below for why that one can't afford to wait. Otherwise, while it's still within 'cullMaxDistance', a record whose category is passive (or a legacy pre-category record whose type id is a known farm animal) restores on proximity alone once a player is within 'passiveRestoreRadius' (default 12 blocks) of its saved position - the safety net for the rare case where the visibility test below can't prove it visible (see "Passive proximity rescue" below); each such restore also puts the rescued animal under a re-cull hold that culling.js honors until someone genuinely sees it or everyone is gone from its radius, so the grace period it just skipped can't immediately undo the rescue (see "Restored passives get an anti-recull hold" below). Anything else falls back to the normal timer: current player visibility is checked, and the moment a player could see that spot again, a fresh entity is '/summon'-ed there and the saved state is reapplied ('restore.js'). \6. 'main.js' just wires all of the above together and registers the '/cull:*' commands ('commands.js').
Architecture:
┌─────────────────────┐
│ Player(s) │
└──────────┬──────────┘
│
every 2–5 ticks
│
▼
┌────────────────────────┐
│ Entity Scanner │
│ nearby entities │
└───────────┬────────────┘
│
┌─────────▼──────────┐
│ FOV Check │
│ Is entity inside │
│ player's FOV? │
└───────┬─────┬──────┘
YES NO
│ │
keep it ▼
┌───────────────┐
│ Block Raycast │
│ Is wall in │
│ front of mob? │
└───────┬───────┘
│
┌───────┴────────┐
│ │
NO wall WALL
│ │
keep mob SAVE STATE
│
▼
DESPAWN MOB
│
▼
Culling Database
│
player looks toward area
│
▼
RESTORE ENTITY
│
▼
restore
**Note this architecture is based of an old version of the pack.
**Monster population reservation (v1.17.0) **
Hostile entities that are culled into the persistent database now reserve an estimated monster-population slot. This prevents Bedrock from immediately refilling the slots of hidden hostile mobs and then restoring the hidden mobs on top of those new spawns.
The stable Script API does not expose Bedrock's internal population counter, so this is an approximation:
'effective population = live monsters reserved culled monsters'
Natural 'EntityInitializationCause.Spawned' monster spawns are observed after they appear and are removed only when the estimated local population is already at the configured cap. Born/event/loaded/transformed entities are ignored, and restore spawns are explicitly marked as internal.
Defaults:
- monster cap: 70 - population radius: 128 blocks - herd overflow allowance: 3 - maximum blocked natural spawns per tick: 20 - reservation reconciliation: every 200 ticks
Reservations are rebuilt from the existing culling database on startup, so no additional persistent database is required. '/cull:stats' and '/cull:status' show reservation information.
Config migration:
Saved settings are versioned (config.js's 'CONFIG_VERSION'). On load, an older save is automatically migrated forward - old field names are mapped to their new equivalents and any newly-added settings (like 'protection' and 'filters') are filled in with defaults - then immediately re-saved in the current shape, so migration only ever runs once per world.
Commands:
(These commands are FULLY optional and for debugging purposes only also the culling starts automatically at world startup so you do NOT need to run /cull:on)
All of these are** optional** and require operator permission and cheats enabled:
| Command | Effect |
|---|---|
| '/cull:on' | Enable the system |
| '/cull:off' | Disable it and restore currently culled entities (very large databases finish over the next few passes) |
| '/cull:toggle' | Flip on/off in one command - off also restores, same as '/cull:off' |
| '/cull:debug' | Toggle chat messages on every cull/restore |
| '/cull:xpclumps <on\ | off\ |
| '/cull:stats [reset]' | Show culling statistics (currently culled, lifetime culled/restored by category, raycasts incl. see-through continuation casts vs. skipped, failed captures/restores), or reset the lifetime counters |
| '/cull:status' | Detailed status panel: enabled state, culled/pending counts, active settings, filter counts, and a full database integrity breakdown (records, shards, failed/missing/orphaned shards and seals, duplicate ids, quarantined and dropped-stale records, invalid records, metadata health) |
| '/cull:distance <blocks>' | Set scan/restore range (8-128) |
| '/cull:cullrange <blocks>' | Set how close an entity must be to actually get culled (4-'maxDistance') |
| '/cull:fov <degrees>' | Set the view-cone angle (30-180) |
| '/cull:grace <ticks>' | Set the "recently visible" grace period - how long an entity must stay continuously hidden before it's culled (0-100 ticks, default 15) |
| '/cull:blacklist <add\ | remove\ |
| '/cull:whitelist <add\ | remove\ |
| '/cull:combatevents <anger\ | calm> <add\ |
| '/cull:cleanup' | Clean up the culling database: compact it, reclaim orphaned shards, and drop unrestorable records |
| '/cull:quarantine <list\ | restore\ |
| '/cull:reload' | Reset all settings to defaults |
| '/cull:help' | List these commands in-game |
Custom entities outside the 'minecraft:' namespace are 'unknown'. Use '/cull:category <category> <on|off>' to change these at runtime. The older '/cull:unknown <protect|passive|all>' command remains as a compatibility alias: 'protect' disables the unknown category, while 'passive' and 'all' enable it (use /cull:unkown passive or /cull:unkown all to cull entities from other mods).
`/cull:blacklist'/ '/cull:whitelist' accept either a bare id ('zombie') or a full type id ('minecraft:zombie') - a bare id is assumed to be 'minecraft:<id>'. Example: '/cull:blacklist add armor_stand'.
Settings persist across restarts. Scan/restore timing ('scanIntervalTicks', 'restoreCheckIntervalTicks', 'lowLoadThreshold', 'highLoadThreshold') aren't exposed as commands - edit the defaults in 'config.js' before packaging if you want to change those. 'cullDelayTicks' (the "recently visible" grace period) is the exception - it's live-tunable with '/cull:grace <ticks>'.
inspired by tr7zw's Entity Culling mod <3.
Changelog
v1.18.8 Changelog:
A major improvement to passive mob visibility detection, restoration, and database recovery, addressing several issues that could cause farm animals and other passive mobs to disappear permanently.
Fixed:
Fixed multiple visibility detection issues involving fences, fence gates, and transparent or partially open blocks.
Fixed cases where passive mobs could remain unrestored because normal visibility checks incorrectly considered them obstructed.
Fixed restoration cases where an interrupted or failed entity spawn could result in lost restoration data.
Fixed an issue where interrupted restoration recovery could finalize a record before the restored entity's saved state had been successfully reapplied.
Fixed an issue where failed entity lookups could be mistaken for confirmed missing entities, potentially resulting in duplicate spawns or incorrect record cleanup.
Fixed orphaned spawned entity recovery so that recovery information is properly saved before attempting further cleanup.
Improved Visibility Detection:
Reworked block raycasting to better handle fences, fence gates, and known transparent blocks.
Improved raycasting to continue through supported transparent and partially open blocks instead of immediately treating them as solid obstructions.
Improved multi-point visibility detection to check multiple positions around an entity rather than relying on a single raycast target.
Added adaptive horizontal visibility sampling to improve detection around obstructed entities.
Improved visibility detection consistency between entity culling and restoration.
Improved error handling for visibility checks to reduce false obstruction results when raycasting fails.
Improved Passive Mob Restoration:
Added a passive proximity restoration fallback for passive mobs and recognized legacy livestock records.
Passive mobs can now be restored when a player approaches their saved position, even when normal FOV or raycast visibility checks fail.
Added a configurable passive restoration radius, defaulting to 12 blocks.
Added a restoration-hold system to prevent recently restored passive mobs from being immediately culled again while players remain nearby.
Restoration holds default to 20 blocks and are released when players move outside the configured radius.
Improved hold-tag cleanup so stale restoration holds can be removed even when culling is disabled, no players are online, or affected entities are in another dimension.
Improved Database and Crash Recovery:
Improved database durability checks to ensure an entity's saved record is persisted before removing the original entity.
Failed entity spawns no longer cause their restoration records or population reservations to be prematurely released.
Restoration records are only finalized after the entity has been successfully spawned, identified, and restored.
Improved identity-tag recovery for entities spawned before an interruption.
Improved restoration of saved entity state when recovering previously interrupted operations.
Improved orphaned entity tracking by ensuring recovery markers are marked dirty, flushed, and verified as durable.
Improved handling of uncertain entity lookup results to avoid spawning duplicates when an existing restored entity may still be present.
Improved restoration safeguards when required entity components or state cannot be accessed.
Added Configuration Commands:
Added
/cull:passiverestore \<blocks\>to configure the passive mob proximity restoration radius.Added
/cull:restorehold \<blocks\>to configure the restoration-hold radius.Both settings can be saved and persist across world restarts.
Setting either radius to
0disables its respective feature.Added both commands to
/cull:help.Added both settings to
/cull:status.Added input validation to prevent negative radius values.
Important Notes:
Passive mob culling remains enabled. This update does not globally disable passive entity culling.
Default passive restoration radius: 12 blocks.
Default restoration-hold radius: 20 blocks.
Passive proximity restoration remains subject to the configured restoration-distance limit.
[Dev Note: Hey its been a while since I've added any new feature other than bug fix related feature n stuff matter of fact from v1.17.0 to v1.18.7 has just been bug fixes why? cause I wanted to make this addon more bug free and enjoyable and doing so the the addon is about 80% bug free now of course it doesn't mean there are no bugs anymore there are still some so if you encounter them please leave a comment about them!. Also from v1.19 I'll add obfuscation and many more new features so stay tuned and thank so much for 25k <3 And Sorry for my bad english btw.]