Blackboard System
The Blackboard system provides a shared memory architecture for NPCs to store and access information about their environment, events, and interactions. It acts as a central knowledge base that sensors can query to make decisions.
Overview
Section titled “Overview”The Blackboard class (com.hypixel.hytale.server.npc.blackboard.Blackboard) is a resource attached to the EntityStore that manages different types of views into game state. Each view type provides specialized access to different kinds of information.
Blackboard Views
Section titled “Blackboard Views”The blackboard uses a view-based architecture where different view types provide access to specific categories of information:
AttitudeView
Section titled “AttitudeView”Located at com.hypixel.hytale.server.npc.blackboard.view.attitude.AttitudeView
Manages NPC attitudes and relationships toward entities and items:
AttitudeMap- Maps entities to attitude valuesItemAttitudeMap- Maps items to attitude values- Faction relationships
- Hostility tracking
BlockTypeView
Section titled “BlockTypeView”Located at com.hypixel.hytale.server.npc.blackboard.view.blocktype.BlockTypeView
Provides information about blocks in the world:
- Block type queries
- Block state information
- Material properties
- Managed by
BlockTypeViewManager
BlockEventView
Section titled “BlockEventView”Located at com.hypixel.hytale.server.npc.blackboard.view.event.block.BlockEventView
Tracks block-related events that NPCs observe:
onEntityDamageBlock()- When an entity damages a blockonEntityBreakBlock()- When an entity breaks a block- Event memory and history
EntityEventView
Section titled “EntityEventView”Located at com.hypixel.hytale.server.npc.blackboard.view.event.entity.EntityEventView
Tracks entity-related events:
- Entity spawn events
- Entity death events
- Entity state changes
- Combat events
ResourceView
Section titled “ResourceView”Located at com.hypixel.hytale.server.npc.blackboard.view.resource.ResourceView
Manages resource information:
- Resource locations
- Resource availability
- Managed by
ResourceViewManager
InteractionView
Section titled “InteractionView”Located at com.hypixel.hytale.server.npc.blackboard.view.interaction.InteractionView
Tracks NPC interactions:
- Player interactions
- NPC-to-NPC interactions
- Interaction history
View Managers
Section titled “View Managers”Each view type has an associated manager that controls view lifecycle and access:
IBlackboardViewManager Interface
Section titled “IBlackboardViewManager Interface”Base interface for all view managers with methods:
get(Ref, Blackboard, ComponentAccessor)- Get view for an entityget(chunkX, chunkZ, Blackboard)- Get view for a chunkget(index, Blackboard)- Get view by indexgetIfExists(index)- Check if view existsforEachView(Consumer)- Iterate over all viewscleanup()- Clean up unused viewsclear()- Clear all viewsonWorldRemoved()- Handle world removal
SingletonBlackboardViewManager
Section titled “SingletonBlackboardViewManager”Used for global views that apply to the entire world:
new SingletonBlackboardViewManager<BlockEventView>(new BlockEventView(world))Used by:
- BlockEventView
- EntityEventView
- AttitudeView
- InteractionView
Per-Entity/Per-Chunk Managers
Section titled “Per-Entity/Per-Chunk Managers”Other managers provide per-entity or per-chunk views:
BlockTypeViewManager- Per-chunk block informationResourceViewManager- Resource tracking
Accessing the Blackboard
Section titled “Accessing the Blackboard”Getting the Blackboard Resource
Section titled “Getting the Blackboard Resource”ResourceType<EntityStore, Blackboard> blackboardType = Blackboard.getResourceType();Blackboard blackboard = store.getResource(blackboardType);Querying Views
Section titled “Querying Views”Get a view for a specific entity:
AttitudeView attitudeView = blackboard.getView( AttitudeView.class, entityRef, componentAccessor);Get a view for a chunk:
BlockTypeView blockTypeView = blackboard.getView( BlockTypeView.class, chunkX, chunkZ);Get a view by index:
ResourceView resourceView = blackboard.getView( ResourceView.class, index);Iterating Over Views
Section titled “Iterating Over Views”blackboard.forEachView(AttitudeView.class, view -> { // Process each attitude view});Blackboard Lifecycle
Section titled “Blackboard Lifecycle”Initialization
Section titled “Initialization”The blackboard is initialized when a world is loaded:
blackboard.init(world);This registers all view types and their managers.
Event Handling
Section titled “Event Handling”The blackboard receives events and propagates them to appropriate views:
// Block damage eventblackboard.onEntityDamageBlock(entityRef, damageBlockEvent);
// Block break eventblackboard.onEntityBreakBlock(entityRef, breakBlockEvent);Cleanup
Section titled “Cleanup”Views are cleaned up periodically:
blackboard.cleanupViews(); // Cleanup unused viewsblackboard.clear(); // Clear all viewsblackboard.onWorldRemoved(); // World shutdownIntegration with Sensors
Section titled “Integration with Sensors”Sensors use the blackboard to access world state information. The blackboard provides the data that sensors need to evaluate their conditions.
For example, a sensor checking if an entity is hostile might:
- Get the AttitudeView from the blackboard
- Query the attitude toward the target entity
- Return whether the attitude indicates hostility
View Access Patterns
Section titled “View Access Patterns”Spatial Queries
Section titled “Spatial Queries”Views can be accessed by spatial location (chunk coordinates) for efficient spatial queries:
// Get block information for a specific chunkBlockTypeView view = blackboard.getView(BlockTypeView.class, chunkX, chunkZ);Entity-Based Queries
Section titled “Entity-Based Queries”Views can be accessed per-entity for entity-specific information:
// Get attitude information for a specific NPCAttitudeView view = blackboard.getView(AttitudeView.class, npcRef, accessor);Global Queries
Section titled “Global Queries”Some views are singletons that provide world-wide information:
// Get global interaction viewInteractionView view = blackboard.getView(InteractionView.class, npcRef, accessor);Thread Safety
Section titled “Thread Safety”The blackboard uses ConcurrentHashMap for thread-safe view management, allowing concurrent access from multiple systems.
Related Systems
Section titled “Related Systems”- Sensors - Use blackboard for decision-making
- Decision Makers - Evaluate conditions using blackboard data
- Event System - Feeds events into the blackboard