Decision Makers
The Decision Maker system provides condition evaluation and state-based logic for NPCs. It allows NPCs to make intelligent decisions based on their current state and environment.
Overview
Section titled “Overview”Decision makers are located in the com.hypixel.hytale.server.npc.decisionmaker package and provide two main approaches to decision-making:
- Condition-based evaluation - Using the core conditions system
- State evaluation - Using state evaluators for complex state machines
Core Conditions
Section titled “Core Conditions”Located at com.hypixel.hytale.server.npc.decisionmaker.core.conditions
Condition Interface
Section titled “Condition Interface”The base Condition interface provides:
boolean evaluate(Ref<EntityStore> ref, Role role, ComponentAccessor<EntityStore> accessor);Conditions are registered with a codec system for serialization:
Condition.CODEC.register("ConditionName", ConditionClass.class, ConditionClass.CODEC);Base Conditions
Section titled “Base Conditions”Located at com.hypixel.hytale.server.npc.decisionmaker.core.conditions.base
These provide fundamental condition types that can be composed together:
Logical Operators
Section titled “Logical Operators”- AND Condition - All child conditions must be true
- OR Condition - At least one child condition must be true
- NOT Condition - Inverts the result of a child condition
Comparison Conditions
Section titled “Comparison Conditions”- Value comparisons (equals, greater than, less than, etc.)
- Numeric range checks
- String matching
Compound Conditions
Section titled “Compound Conditions”Conditions can be nested and combined to create complex decision trees:
AND( condition1, OR( condition2, condition3 ), NOT(condition4))State Evaluator
Section titled “State Evaluator”Located at com.hypixel.hytale.server.npc.decisionmaker.stateevaluator
State evaluators provide a higher-level abstraction for managing NPC state machines. They evaluate conditions to determine state transitions.
Key Concepts
Section titled “Key Concepts”State Evaluation: Determines which state an NPC should be in based on current conditions
State Transitions: Managed through the StateTransitionController system
Priority: States can have priorities to determine which state takes precedence when multiple conditions are met
Integration with Instructions
Section titled “Integration with Instructions”Decision makers work closely with the instruction system:
- Sensors query conditions to determine if they match
- Instructions execute when their sensor conditions evaluate to true
- State changes trigger new instruction evaluations
Condition Types
Section titled “Condition Types”Common condition types available in the system:
Entity Conditions
Section titled “Entity Conditions”- Entity distance checks
- Line of sight checks
- Entity type matching
- Entity state checks
Combat Conditions
Section titled “Combat Conditions”- Health thresholds
- Damage received
- Combat state (in combat, fleeing, etc.)
- Target availability
World Conditions
Section titled “World Conditions”- Time of day
- Weather conditions
- Biome checks
- Block presence
Timer Conditions
Section titled “Timer Conditions”- Elapsed time checks
- Cooldown completion
- Scheduled events
Flock Conditions
Section titled “Flock Conditions”- Flock size (
FlockSizeCondition) - Flock state
- Flock membership
Custom Conditions
Section titled “Custom Conditions”Plugins can register custom conditions:
Condition.CODEC.register("CustomCondition", CustomCondition.class, CustomCondition.CODEC);State Support
Section titled “State Support”The StateSupport class (part of Role) manages NPC state:
Located at com.hypixel.hytale.server.npc.role.support.StateSupport
Provides:
- Current state tracking
- State transition handling
- State history
- State-specific data
Decision Making Flow
Section titled “Decision Making Flow”- Evaluation: Conditions are evaluated each tick or on specific events
- Matching: The first instruction with matching sensor conditions is selected
- Execution: The selected instruction’s actions are executed
- State Update: State changes may trigger new evaluations
State Machines
Section titled “State Machines”NPCs can have complex state machines defined through:
State Transition Controller
Section titled “State Transition Controller”Located at com.hypixel.hytale.server.npc.statetransition.StateTransitionController
Manages transitions between states:
- Entry conditions: Conditions that must be met to enter a state
- Exit conditions: Conditions that cause leaving a state
- Transition priorities: Which transitions take precedence
- State duration: Minimum/maximum time in a state
Builder Pattern
Section titled “Builder Pattern”State transitions are configured using builders:
Located at com.hypixel.hytale.server.npc.statetransition.builders
Provides a fluent API for defining state machines in asset files.
Role States
Section titled “Role States”The RoleStateChange interface defines lifecycle callbacks:
void stateChanged(Ref<EntityStore> ref, Role role, ComponentAccessor<EntityStore> accessor);void roleChanged(Ref<EntityStore> ref, Role role, ComponentAccessor<EntityStore> accessor);Components implementing this interface are notified when:
- NPC state changes
- NPC role changes
Examples
Section titled “Examples”Simple Condition Check
Section titled “Simple Condition Check”// Check if target is within rangeDistanceCondition condition = new DistanceCondition(10.0);boolean inRange = condition.evaluate(ref, role, accessor);Complex Condition
Section titled “Complex Condition”// Attack if: (enemy nearby AND health > 50%) OR (being attacked)AND( OR( AND( EnemyNearbyCondition(), HealthAboveCondition(0.5) ), BeingAttackedCondition() ), NOT(FleeingCondition()))State Machine
Section titled “State Machine”// Passive -> Alert -> Combat -> FleeingStates: Passive: default state, wander behavior Alert: enemy detected, prepare for combat Combat: actively fighting Fleeing: health low, retreat
Transitions: Passive -> Alert: enemy within detection range Alert -> Combat: enemy within attack range Combat -> Fleeing: health < 20% Fleeing -> Passive: safe for 10 seconds * -> Passive: no threats for 30 secondsBest Practices
Section titled “Best Practices”- Keep conditions simple: Complex logic should be broken into smaller, reusable conditions
- Use priorities: Ensure critical states (like fleeing) have higher priority
- Avoid rapid state changes: Add cooldowns or minimum durations to prevent flickering
- Cache expensive checks: Use the blackboard to cache computation results
- Test edge cases: Ensure conditions handle edge cases like null entities
Performance Considerations
Section titled “Performance Considerations”- Conditions are evaluated frequently, keep them lightweight
- Use early exits in AND conditions
- Cache condition results when appropriate
- Avoid expensive world queries in conditions
- Use spatial indexing for distance checks
Related Systems
Section titled “Related Systems”- Instructions - Execute based on condition results
- Blackboard - Provides data for condition evaluation
- Roles - Define state machines and behaviors
- Sensors - Use conditions to match