PositionCacheSystems
Package: com.hypixel.hytale.server.npc.systems
public class PositionCacheSystemsContainer class for three ECS systems and a static helper method that manage the NPC PositionCache. The position cache pre-computes spatial queries for nearby players, NPCs, items, and spawn markers each tick, providing efficient proximity data to sensors and behavior components.
Static Method
Section titled “Static Method”public static void initialisePositionCache( @Nonnull Role role, @Nullable StateEvaluator stateEvaluator, double flockInfluenceRange)Configures the position cache from the role’s requirements:
- Resets the cache.
- If avoidance is enabled, registers entity and player distance ranges for avoidance.
- If separation is enabled, registers separation distances.
- If flock influence range is positive, registers those distances.
- Registers all instructions (root, interaction, death) with the role support.
- Registers state transitions with the role support.
- Sets up the state evaluator if present.
- Runs external registrations.
- Finalizes configuration.
Inner Systems
Section titled “Inner Systems”PositionCacheSystems.UpdateSystem
Section titled “PositionCacheSystems.UpdateSystem”public static class UpdateSystem extends SteppableTickingSystemThe main position cache update system. Runs after PlayerSpatialSystem and before RoleSystems.PreBehaviourSupportTickSystem.
Each tick (when the update timer fires):
- Checks the NPC’s breathing state from block material.
- Queries the player spatial resource to populate the nearby player list.
- Queries the NPC spatial resource to populate the nearby NPC list.
- Queries the item spatial resource for nearby dropped items.
- Queries the spawn marker/beacon spatial resources.
Supports benchmarking via NPCPlugin.isBenchmarkingSensorSupport().
Parallelism: false (single-threaded).
PositionCacheSystems.RoleActivateSystem
Section titled “PositionCacheSystems.RoleActivateSystem”public static class RoleActivateSystem extends HolderSystem<EntityStore>Initializes the position cache when an NPC entity is added to the store, and resets it when removed. Determines flock influence range from FlockMembership if present.
PositionCacheSystems.OnFlockJoinSystem
Section titled “PositionCacheSystems.OnFlockJoinSystem”public static class OnFlockJoinSystem extends RefChangeSystem<EntityStore, FlockMembership>Re-initializes the position cache when an NPC’s FlockMembership component is added or changed, incorporating the new flock influence range.
Related Types
Section titled “Related Types”- NPCSpatialSystem — NPC spatial index used by UpdateSystem
- RoleSystems — behavior tick that consumes position cache data
- AvoidanceSystem — uses position cache for avoidance/separation