
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).

πHow it works:
1. Every few ticks, each player's nearby entities are scanned
2. Entities are filtered down to ones that are safe to touch: no players,
no bosses, no villagers/traders, no leashed/ridden/inventoried mobs, and
(by default) no custom-named entities.
3. For each remaining candidate, we check whether *any* player can see it
('fov.js' for the view-cone test, `raycast.js` for the 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), 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`).
5. On a second timer, every culled record is checked against current
player visibility. 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
β
βΌ
/summon

πCommands (optional):
All of these require operator permission and cheats enabled:
| Command | Effect |
|---|---|
| `/cull:on` | Enable the system |
| `/cull:off` | Disable it and immediately restore everything currently culled |
| `/cull:debug` | Toggle chat messages on every cull/restore |
| `/cull:stats` | Show how many entities are currently culled |
| `/cull:distance <blocks>` | Set scan/restore range (8-128) |
| `/cull:fov <degrees>` | Set the view-cone angle (30-180) |
| `/cull:reload` | Reset all settings to defaults |
| `/cull:help` | List these commands in-game |

This was inspired by tr7zw's Entity Culling mod <3.

