--- title: NPC AI type: docs weight: 3 --- The NPC AI system provides intelligent decision-making through blackboards, decision makers, sensors, and instructions. **Packages:** - `com.hypixel.hytale.server.npc.blackboard` - `com.hypixel.hytale.server.npc.decisionmaker` - `com.hypixel.hytale.server.npc.sensorinfo` - `com.hypixel.hytale.server.npc.instructions` ## Blackboard System The Blackboard is a shared memory space where NPC components communicate through key-value pairs. ### Blackboard Class ```java public class Blackboard { private Map, Object> data; // Store value public void set(BlackboardKey key, T value); // Retrieve value public T get(BlackboardKey key); public T getOrDefault(BlackboardKey key, T defaultValue); // Check existence public boolean has(BlackboardKey key); // Remove value public void remove(BlackboardKey key); // Clear all public void clear(); } ``` ### BlackboardKey Type-safe keys for blackboard access: ```java // Predefined keys public class BlackboardKeys { public static final BlackboardKey TARGET = new BlackboardKey<>("target", Entity.class); public static final BlackboardKey HOME_POSITION = new BlackboardKey<>("home_position", Vector3d.class); public static final BlackboardKey ALERT_LEVEL = new BlackboardKey<>("alert_level", Float.class); public static final BlackboardKey IN_COMBAT = new BlackboardKey<>("in_combat", Boolean.class); } // Custom keys BlackboardKey CUSTOM_KEY = new BlackboardKey<>("custom_data", String.class); ``` ### Using the Blackboard ```java NPCEntity npc = // get NPC Blackboard bb = npc.getBlackboard(); // Set target bb.set(BlackboardKeys.TARGET, targetEntity); // Get home position Vector3d home = bb.getOrDefault(BlackboardKeys.HOME_POSITION, npc.getPosition()); // Check combat status if (bb.getOrDefault(BlackboardKeys.IN_COMBAT, false)) { // Handle combat } ``` ## Decision Maker System The Decision Maker evaluates options and selects the best action for the NPC to take. ### DecisionMaker Interface ```java public interface DecisionMaker { // Evaluate and select best option Option evaluate(NPCEntity npc, Blackboard blackboard); // Get all available options List