### Build a Behavior Source: https://github.com/kanelucky/mobmind/blob/master/README.md Construct a BehaviorImpl using BehaviorImpl.builder(). Specify an executor for the action, an evaluator for activation conditions, priority, and period. The example shows an idle behavior. ```java BehaviorImpl.builder() .executor(Executors.idle(20, 60)) .evaluator(entity -> true) .priority(1) .period(20) .build() ``` -------------------------------- ### Define Custom Memory Types Source: https://github.com/kanelucky/mobmind/blob/master/README.md Create custom MemoryType instances for storing entity-specific state. The example defines AGGRO_TARGET for storing an Entity. ```java // Custom types public static final MemoryType AGGRO_TARGET = new MemoryType<>("myplugin:aggro_target"); ``` -------------------------------- ### Sensor Factory Methods in Java Source: https://context7.com/kanelucky/mobmind/llms.txt Demonstrates how to use factory methods to create sensor instances for detecting entities like players. Allows customization of detection range and update period. ```java import org.kanelucky.mobmind.api.entity.ai.sensor.Sensors; // Find nearest player within range Sensors.nearestPlayer(); // Default: range 16, period 20 ticks Sensors.nearestPlayer(24.0, 0.0, 10); // range, minRange, period // Find nearest player holding a breeding item Sensors.nearestFeedingPlayer(); // Default: range 8, period 20 ticks Sensors.nearestFeedingPlayer(12.0, 15); // range, period ``` ```java // Usage in BehaviorGroup BehaviorGroup.builder() .sensor(Sensors.nearestPlayer(16.0, 0.0, 20)) .sensor(Sensors.nearestFeedingPlayer(8.0, 20)) // ... behaviors that use NEAREST_PLAYER and NEAREST_FEEDING_PLAYER memories .build(); ``` -------------------------------- ### Movement Controllers in Java Source: https://context7.com/kanelucky/mobmind/llms.txt Shows how to integrate movement controllers like 'walk' and 'look' into a BehaviorGroup for entity navigation and head rotation. ```java import org.kanelucky.mobmind.api.entity.ai.controller.Controllers; // Walk controller - handles ground pathfinding to MOVE_TARGET Controllers.walk(); // Look controller - rotates entity head toward LOOK_TARGET Controllers.look(); ``` ```java // Usage - always add both for typical ground mobs BehaviorGroup.builder() .sensor(Sensors.nearestPlayer()) .behavior(/* ... */) .controller(Controllers.walk()) // Ground movement .controller(Controllers.look()) // Head rotation .build(); ``` -------------------------------- ### Configure MobMind Controllers Source: https://context7.com/kanelucky/mobmind/llms.txt Sets up walk and look controllers within the MobMind framework. Ensure necessary dependencies are met before building. ```java .build() ), 1, 40 // priority, period ) ) .controller(Controllers.walk()) .controller(Controllers.look()) .build(); } } ``` -------------------------------- ### Create Behaviors with BehaviorImpl.builder() Source: https://context7.com/kanelucky/mobmind/llms.txt Constructs complex AI behaviors by defining executors, evaluators, priority, weight, and evaluation periods. ```java import org.kanelucky.mobmind.api.entity.ai.behavior.BehaviorImpl; import org.kanelucky.mobmind.api.entity.ai.evaluator.Evaluators; import org.kanelucky.mobmind.api.entity.ai.executor.Executors; // Simple idle behavior BehaviorImpl idleBehavior = BehaviorImpl.builder() .executor(Executors.idle(20, 60)) // Stand still for 20-60 ticks .evaluator(entity -> true) // Always available .priority(1) // Low priority .weight(1) // Selection weight for weighted random .period(1) // Evaluate every tick .build(); // Panic behavior triggered by damage BehaviorImpl panicBehavior = BehaviorImpl.builder() .executor(Executors.panic(0.15, 0.1, 8)) // speed, normalSpeed, range .evaluator(Evaluators.panic()) // True when PANIC_TICKS > 0 .priority(4) // High priority - interrupts other behaviors .period(1) .build(); // Look at nearby player occasionally BehaviorImpl lookAtPlayerBehavior = BehaviorImpl.builder() .executor(Executors.lookAtEntity(MemoryTypes.NEAREST_PLAYER, 60)) .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; if (e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.NEAREST_PLAYER) == null) return false; return Math.random() < 0.05; // 5% chance per evaluation }) .priority(2) .period(10) // Evaluate every 10 ticks .build(); ``` -------------------------------- ### Initialize MobMind Core Source: https://context7.com/kanelucky/mobmind/llms.txt Initialize MobMind once at server startup before spawning any entities by registering the core implementation and calling init(). ```java import org.kanelucky.mobmind.api.MobMind; import org.kanelucky.mobmind.core.CoreInitializer; public class MyServer { public static void main(String[] args) { MinecraftServer minecraftServer = MinecraftServer.init(); // Initialize MobMind - must be called before spawning any entities MobMind.INSTANCE.register(new CoreInitializer()); MobMind.INSTANCE.init(); // Continue with server setup... minecraftServer.start("0.0.0.0", 25565); } } ``` -------------------------------- ### Weighted Random Behavior Selection in Java Source: https://context7.com/kanelucky/mobmind/llms.txt Demonstrates creating a weighted random behavior that selects between multiple sub-behaviors based on assigned weights, useful for varied AI actions. ```java import org.kanelucky.mobmind.api.entity.ai.behavior.Behavior; import org.kanelucky.mobmind.api.entity.ai.behavior.BehaviorImpl; import org.kanelucky.mobmind.api.entity.ai.behavior.Behaviors; import java.util.Set; // Weighted random between idle and roaming Behaviors.weighted( Set.of( BehaviorImpl.builder() .executor(Executors.idle(20, 60)) .evaluator(entity -> true) .priority(1) .weight(1) // 1 part idle .period(1) .build(), BehaviorImpl.builder() .executor(Executors.roam(0.1, 0.1, 10, 20, true, 100, true, 10)) .evaluator(entity -> true) .priority(1) .weight(3) // 3 parts roam (75% chance) .period(1) .build() ), 1, // Group priority 40 // Re-evaluation period ); ``` -------------------------------- ### Register CoreInitializer at Startup Source: https://github.com/kanelucky/mobmind/blob/master/core/README.md Register the CoreInitializer with MobMind at server startup to initialize all implementations. ```java MobMind.INSTANCE.register(new CoreInitializer()); MobMind.INSTANCE.init(); ``` -------------------------------- ### MemoryTypes and Custom Memory Definition in Java Source: https://context7.com/kanelucky/mobmind/llms.txt Illustrates the use of built-in memory types for storing entity state and how to define custom memory types with specific data types and keys. ```java import org.kanelucky.mobmind.api.entity.ai.memory.MemoryType; import org.kanelucky.mobmind.api.entity.ai.memory.MemoryTypes; import net.minestom.server.coordinate.Point; import net.minestom.server.entity.Entity; // Built-in memory types MemoryTypes.NEAREST_PLAYER; // Player - nearest detected player MemoryTypes.NEAREST_FEEDING_PLAYER; // Player - nearest player holding food MemoryTypes.MOVE_TARGET; // Point - pathfinding destination MemoryTypes.LOOK_TARGET; // Point - where to look MemoryTypes.ATTACK_TARGET; // LivingEntity - current attack target MemoryTypes.PANIC_TICKS; // Integer - ticks remaining in panic MemoryTypes.IS_IN_LOVE; // Boolean - breeding mode active MemoryTypes.LAST_IN_LOVE_TIME; // Long - timestamp of last love mode ``` ```java // Define custom memory types public static final MemoryType AGGRO_TARGET = new MemoryType<>("myplugin:aggro_target"); public static final MemoryType HOME_POSITION = new MemoryType<>("myplugin:home_position"); public static final MemoryType ATTACK_COUNT = new MemoryType<>("myplugin:attack_count"); ``` ```java // Reading and writing memory @Override public boolean damage(@NotNull Damage damage) { boolean result = super.damage(damage); if (result) { // Set panic state on damage getBehaviorGroup().getMemoryStorage().set(MemoryTypes.PANIC_TICKS, 100); } return result; } ``` ```java // Check memory in evaluator .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; Integer panicTicks = e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.PANIC_TICKS); return panicTicks != null && panicTicks > 0; }) ``` -------------------------------- ### Implement a Custom Sensor Source: https://github.com/kanelucky/mobmind/blob/master/README.md Create a custom sensor by implementing the Sensor interface. Override getPeriod() to set the sensing frequency and sense() to implement the sensing logic, writing results to memory. ```java public class MyCustomSensor implements Sensor { @Override public int getPeriod() { return 10; } @Override public void sense(EntityCreature entity) { if (!(entity instanceof IntelligentEntity e)) return; e.getBehaviorGroup().getMemoryStorage().set(MyMemoryTypes.NEAREST_ENEMY, ...); } } ``` -------------------------------- ### Configure Weighted Idle/Roam Behavior Source: https://context7.com/kanelucky/mobmind/llms.txt Sets up a weighted fallback behavior for entities, allowing them to either idle or roam with different probabilities. The 'roam' behavior has a higher weight, making it more likely to be chosen. ```java Behaviors.weighted( Set.of( BehaviorImpl.builder() .executor(Executors.idle(40, 80)) .evaluator(entity -> true) .priority(1).weight(1).period(1) .build(), BehaviorImpl.builder() .executor(Executors.roam(0.08, 0.08, 6, 20, true, 100, true, 10)) .evaluator(entity -> true) .priority(1).weight(2).period(1) .build() ), 1, 40 ) ``` -------------------------------- ### Configure Projectile Shooting Executor Source: https://github.com/kanelucky/mobmind/blob/master/README.md Use Executors.shootProjectile to define how an entity targets and fires projectiles at a specific memory target. ```java Executors.shootProjectile( MemoryTypes.NEAREST_PLAYER, 0.1, 0.1, // speed, normalSpeed 256.0, // maxShootRangeSq 60, 20, // cooldown, attackDelay false, // clearDataWhenLose shooter -> new EntityProjectile(shooter, EntityType.SNOWBALL) ) ``` -------------------------------- ### BehaviorImpl Builder Source: https://context7.com/kanelucky/mobmind/llms.txt Defines how to construct a new AI behavior using the BehaviorImpl builder pattern, specifying executors, evaluators, priority, and timing. ```APIDOC ## BehaviorImpl.builder() ### Description Creates individual behaviors with an executor (what to do), evaluator (when to activate), priority, weight, and period configuration. ### Request Body - **executor** (Executor) - Required - The action to perform when the behavior is active. - **evaluator** (Evaluator) - Required - The condition that determines if the behavior can activate. - **priority** (int) - Optional - The priority level of the behavior (higher values interrupt lower ones). - **weight** (int) - Optional - Selection weight for weighted random selection. - **period** (int) - Optional - The evaluation frequency in ticks. ``` -------------------------------- ### Use Built-in Sensors Source: https://github.com/kanelucky/mobmind/blob/master/README.md Utilize pre-defined sensors like nearestPlayer() and nearestFeedingPlayer() to scan the environment. Custom ranges and periods can be specified. ```java Sensors.nearestPlayer() // range 16, period 20 Sensors.nearestPlayer(24.0, 0.0, 10) // custom range and period Sensors.nearestFeedingPlayer() // range 8, period 20 ``` -------------------------------- ### Implement Breedable Entities in Java Source: https://github.com/kanelucky/mobmind/blob/master/README.md Implement the Breedable, Feedable, and Offspring interfaces to enable breeding mechanics for custom entities. ```java public class MySheep extends IntelligentEntity implements Breedable, Feedable, Offspring { private boolean baby = false; private int breedCooldown = 0; @Override public boolean isBaby() { return baby; } @Override public void setBaby(boolean baby) { this.baby = baby; } @Override public int getBreedCooldown() { return breedCooldown; } @Override public void setBreedCooldown(int cooldown) { this.breedCooldown = cooldown; } @Override public boolean isBreedingItem(ItemStack item) { return item.material() == Material.WHEAT; } @Override public EntityCreature createOffspring() { MySheep baby = new MySheep(); baby.setBaby(true); return baby; } } ``` -------------------------------- ### Build BehaviorGroup with Behaviors and Sensors Source: https://context7.com/kanelucky/mobmind/llms.txt Use the BehaviorGroup builder to add sensors for environment scanning and behaviors with defined priorities and periods. Includes movement controllers. ```java import org.kanelucky.mobmind.api.entity.ai.behavior.BehaviorImpl; import org.kanelucky.mobmind.api.entity.ai.behaviorgroup.BehaviorGroup; import org.kanelucky.mobmind.api.entity.ai.controller.Controllers; import org.kanelucky.mobmind.api.entity.ai.executor.Executors; import org.kanelucky.mobmind.api.entity.ai.memory.MemoryTypes; import org.kanelucky.mobmind.api.entity.ai.sensor.Sensors; BehaviorGroup behaviorGroup = BehaviorGroup.builder() // Add sensors to scan the environment .sensor(Sensors.nearestPlayer(16.0, 0.0, 20)) .sensor(Sensors.nearestFeedingPlayer(8.0, 20)) // High priority: attack nearby players .behavior( BehaviorImpl.builder() .executor(Executors.meleeAttack(MemoryTypes.NEAREST_PLAYER)) .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; return e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.NEAREST_PLAYER) != null; }) .priority(3) .period(1) .build() ) // Low priority: wander around .behavior( BehaviorImpl.builder() .executor(Executors.roam()) .evaluator(entity -> true) .priority(1) .period(1) .build() ) // Add movement controllers .controller(Controllers.walk()) .controller(Controllers.look()) .build(); ``` -------------------------------- ### Executors Factory Methods Source: https://context7.com/kanelucky/mobmind/llms.txt Provides a list of built-in factory methods for common AI actions including movement, combat, and special behaviors. ```APIDOC ## Executors Factory Methods ### Description The Executors class provides factory methods for all built-in behavior executors including movement, combat, and special actions. ### Available Methods - **idle(min, max)**: Stand still for a random duration. - **roam(...)**: Complex roaming behavior with speed, range, and avoidance settings. - **wander(radius)**: Move to a random position within a radius. - **lookAround(min, max)**: Look in a random direction. - **followEntity(memory, speed, normalSpeed, maxRangeSq, minRangeSq)**: Follow a target entity. - **meleeAttack(...)**: Perform a melee attack on a target. - **shootProjectile(...)**: Shoot a projectile at a target. - **flee(...)**: Flee from an attack target. ``` -------------------------------- ### Add MobMind Dependencies to build.gradle.kts Source: https://github.com/kanelucky/mobmind/blob/master/README.md Add JitPack repository and MobMind API and core dependencies to your project's build.gradle.kts file. ```kotlin repositories { maven("https://jitpack.io") } dependencies { implementation("com.github.Kanelucky.MobMind:api:0.1.1") implementation("com.github.Kanelucky.MobMind:core:0.1.1") } ``` -------------------------------- ### Utilize Executors Factory Methods Source: https://context7.com/kanelucky/mobmind/llms.txt Provides built-in logic for movement, combat, and special actions to be used within behavior builders. ```java import org.kanelucky.mobmind.api.entity.ai.executor.Executors; import org.kanelucky.mobmind.api.entity.ai.memory.MemoryTypes; // Movement executors Executors.idle(20, 60); // Stand still for 20-60 ticks Executors.roam(0.1, 0.1, 10, 20, true, 100, true, 10); // speed, normalSpeed, maxRange, frequency, calNextImmediately, runningTime, avoidWater, maxRetry Executors.wander(10.0); // Move to random position within radius Executors.lookAround(20, 60); // Look in random direction for 20-60 ticks Executors.followEntity(MemoryTypes.NEAREST_PLAYER, 0.125, 0.1, 256.0, 2.0); // memory, speed, normalSpeed, maxRangeSq, minRangeSq Executors.moveToTarget(MemoryTypes.MOVE_TARGET, 0.2, 0.1, 256.0, 0.0); // memory, speed, normalSpeed, maxRangeSq, minRangeSq // Combat executors Executors.meleeAttack(MemoryTypes.NEAREST_PLAYER, 0.1, 0.1, 256.0, 2.5, 20, false); // memory, speed, normalSpeed, maxSenseRangeSq, attackRangeSq, cooldown, clearOnLose Executors.beamAttack(MemoryTypes.NEAREST_PLAYER, 256.0, 40, 20, false); // memory, maxRangeSq, cooldownTicks, attackDelay, clearOnLose Executors.shootProjectile(MemoryTypes.NEAREST_PLAYER, 0.1, 0.1, 256.0, 40, 20, false, shooter -> new EntityProjectile(shooter, EntityType.SNOWBALL)); // memory, speed, normalSpeed, maxShootRangeSq, cooldown, attackDelay, clearOnLose, supplier Executors.flee(MemoryTypes.ATTACK_TARGET, 0.15, 0.1, 64.0, 256.0, 10); // memory, fleeSpeed, normalSpeed, minFleeRangeSq, maxFleeRangeSq, recalcInterval // Special executors Executors.panic(0.15, 0.1, 8); // panicSpeed, normalSpeed, range Executors.jump(80, 10, 0.6, 0.5); // interval, delay, power, variance Executors.eatGrass(40, callback); // duration, callback Executors.breeding(60, 0.3, 0.1); // duration, speed, normalSpeed ``` -------------------------------- ### Implement Breeding Interfaces in IntelligentEntity Source: https://context7.com/kanelucky/mobmind/llms.txt A complete implementation of a sheep entity that supports breeding, feeding with wheat, and aging mechanics. ```java import org.kanelucky.mobmind.api.entity.IntelligentEntity; import org.kanelucky.mobmind.api.entity.ai.Breedable; import org.kanelucky.mobmind.api.entity.ai.Feedable; import org.kanelucky.mobmind.api.entity.ai.Offspring; import net.minestom.server.entity.EntityCreature; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; public class BreedableSheep extends IntelligentEntity implements Breedable, Feedable, Offspring { private boolean baby = false; private int breedCooldown = 0; private int ageTicks = 0; public BreedableSheep() { super(EntityType.SHEEP); this.behaviorGroup = buildBehaviorGroup(); this.behaviorGroup.setEntity(this); } // Breedable interface @Override public boolean isBaby() { return baby; } @Override public void setBaby(boolean baby) { this.baby = baby; } @Override public int getBreedCooldown() { return breedCooldown; } @Override public void setBreedCooldown(int cooldown) { this.breedCooldown = cooldown; } // Feedable interface - define what food triggers love mode @Override public boolean isBreedingItem(ItemStack item) { return item.material() == Material.WHEAT; } // Offspring interface - create baby entity @Override public EntityCreature createOffspring() { BreedableSheep baby = new BreedableSheep(); baby.setBaby(true); return baby; } @Override public void update(long time) { super.update(time); // Age up babies if (isBaby()) { ageTicks++; if (ageTicks >= 24000) { // 20 minutes setBaby(false); ageTicks = 0; } } if (breedCooldown > 0) breedCooldown--; } private BehaviorGroup buildBehaviorGroup() { return BehaviorGroup.builder() .sensor(Sensors.nearestFeedingPlayer()) .behavior( BehaviorImpl.builder() .executor(Executors.breeding(60, 0.3, 0.1)) .evaluator(Evaluators.inLove()) .priority(3) .period(1) .build() ) .behavior( BehaviorImpl.builder() .executor(Executors.followEntity( MemoryTypes.NEAREST_FEEDING_PLAYER, 0.125, 0.1, 256.0, 2.0)) .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; return e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.NEAREST_FEEDING_PLAYER) != null; }) .priority(2) .period(1) .build() ) .controller(Controllers.walk()) .controller(Controllers.look()) .build(); } } ``` -------------------------------- ### Spawn AggressiveZombie Entity Source: https://context7.com/kanelucky/mobmind/llms.txt Demonstrates how to create an instance of an AggressiveZombie entity and spawn it into a Minestom world at a specific coordinate. ```java AggressiveZombie zombie = new AggressiveZombie(); zombie.setInstance(instanceContainer, new Pos(100, 64, 100)); ``` -------------------------------- ### Create Custom IntelligentEntity Source: https://context7.com/kanelucky/mobmind/llms.txt Extend IntelligentEntity to create custom mobs with configurable attributes. Ensure to set the behavior group and entity reference. ```java import net.kyori.adventure.key.Key; import net.minestom.server.entity.EntityType; import org.kanelucky.mobmind.api.entity.IntelligentEntity; import org.kanelucky.mobmind.api.entity.ai.behaviorgroup.BehaviorGroup; public class MyCustomMob extends IntelligentEntity { private final BehaviorGroup behaviorGroup; public MyCustomMob() { super(EntityType.ZOMBIE); this.behaviorGroup = buildBehaviorGroup(); this.behaviorGroup.setEntity(this); } @Override public Key getMobKey() { return Key.key("myplugin", "custom_mob"); } @Override public BehaviorGroup getBehaviorGroup() { return behaviorGroup; } // Override base attributes @Override protected double getBaseHealth() { return 30.0; } @Override protected double getBaseAttack() { return 5.0; } @Override protected double getBaseMoveSpeed() { return 0.12; } private BehaviorGroup buildBehaviorGroup() { return BehaviorGroup.builder() .controller(Controllers.walk()) .controller(Controllers.look()) .build(); } } ``` -------------------------------- ### Behaviors.weighted() Source: https://context7.com/kanelucky/mobmind/llms.txt The `Behaviors.weighted()` method creates a weighted random selection behavior, allowing multiple sub-behaviors to be chosen based on their assigned weights. ```APIDOC ## Behaviors.weighted() Creates a weighted random selection behavior that picks between multiple sub-behaviors of equal priority based on their weights. ### Usage Example This example demonstrates a weighted random selection between an idle behavior and a roaming behavior. ```java Behaviors.weighted( Set.of( BehaviorImpl.builder() .executor(Executors.idle(20, 60)) .evaluator(entity -> true) .priority(1) .weight(1) // 1 part idle .period(1) .build(), BehaviorImpl.builder() .executor(Executors.roam(0.1, 0.1, 10, 20, true, 100, true, 10)) .evaluator(entity -> true) .priority(1) .weight(3) // 3 parts roam (75% chance) .period(1) .build() ), 1, // Group priority 40 // Re-evaluation period ); ``` ``` -------------------------------- ### Add MobMind API Dependency Source: https://github.com/kanelucky/mobmind/blob/master/api/README.md Include this dependency in your project's build file to use the MobMind API. ```kotlin implementation("com.github.Kanelucky.MobMind:api:0.1.1") ``` -------------------------------- ### Spawn Multiple BreedableSheep Entities Source: https://context7.com/kanelucky/mobmind/llms.txt Shows how to spawn multiple BreedableSheep entities within a Minestom world instance. Each sheep is spawned at a random position within a specified area. ```java for (int i = 0; i < 5; i++) { BreedableSheep sheep = new BreedableSheep(); sheep.setInstance(instanceContainer, new Pos( Math.random() * 50, 64, Math.random() * 50 )); } ``` -------------------------------- ### Sensors Factory Methods Source: https://context7.com/kanelucky/mobmind/llms.txt Sensors are used to scan the environment periodically and write detected data to entity memory. This section details how to find nearby players, including those holding breeding items. ```APIDOC ## Sensors Factory Methods Sensors scan the environment periodically and write detected data to entity memory for use by behaviors. ### Finding Nearest Player - `Sensors.nearestPlayer()`: Finds the nearest player within the default range (16) and period (20 ticks). - `Sensors.nearestPlayer(double range, double minRange, int period)`: Finds the nearest player within a specified range and minimum range, with a given scan period. ### Finding Nearest Feeding Player - `Sensors.nearestFeedingPlayer()`: Finds the nearest player holding a breeding item within the default range (8) and period (20 ticks). - `Sensors.nearestFeedingPlayer(double range, int period)`: Finds the nearest player holding a breeding item within a specified range and scan period. ### Usage Example in BehaviorGroup ```java BehaviorGroup.builder() .sensor(Sensors.nearestPlayer(16.0, 0.0, 20)) .sensor(Sensors.nearestFeedingPlayer(8.0, 20)) // ... behaviors that use NEAREST_PLAYER and NEAREST_FEEDING_PLAYER memories .build(); ``` ``` -------------------------------- ### Create a Custom Intelligent Entity Source: https://github.com/kanelucky/mobmind/blob/master/README.md Extend IntelligentEntity to create a custom entity with a behavior group. Override getMobKey, getBehaviorGroup, getBaseHealth, getBaseAttack, and getBaseMoveSpeed. The damage method can be overridden to modify behavior on taking damage. ```java public class MyZombie extends IntelligentEntity { private final BehaviorGroup behaviorGroup; public MyZombie() { super(EntityType.ZOMBIE); this.behaviorGroup = buildBehaviorGroup(); this.behaviorGroup.setEntity(this); } @Override public Key getMobKey() { return Key.key("myplugin", "my_zombie"); } @Override public BehaviorGroup getBehaviorGroup() { return behaviorGroup; } @Override protected double getBaseHealth() { return 20.0; } @Override protected double getBaseAttack() { return 3.0; } @Override protected double getBaseMoveSpeed() { return 0.1; } @Override public boolean damage(@NotNull Damage damage) { boolean result = super.damage(damage); if (result) { getBehaviorGroup().getMemoryStorage().set(MemoryTypes.PANIC_TICKS, 100); } return result; } private BehaviorGroup buildBehaviorGroup() { return BehaviorGroup.builder() .sensor(Sensors.nearestPlayer()) .behavior( BehaviorImpl.builder() .executor(Executors.meleeAttack(MemoryTypes.NEAREST_PLAYER)) .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; return e.getBehaviorGroup().getMemoryStorage().get(MemoryTypes.NEAREST_PLAYER) != null; }) .priority(2) .period(1) .build() ) .behavior( BehaviorImpl.builder() .executor(Executors.roam()) .evaluator(entity -> true) .priority(1) .period(1) .build() ) .controller(Controllers.walk()) .controller(Controllers.look()) .build(); } } ``` -------------------------------- ### Controllers Source: https://context7.com/kanelucky/mobmind/llms.txt Movement controllers manage the entity's actual movement based on targets set in memory by behaviors. This includes walking and looking controllers. ```APIDOC ## Controllers Movement controllers handle the actual entity movement based on memory targets set by behaviors. ### Walk Controller - `Controllers.walk()`: Handles ground pathfinding to the `MOVE_TARGET` memory. ### Look Controller - `Controllers.look()`: Rotates the entity's head towards the `LOOK_TARGET` memory. ### Usage Example It is typical to add both walk and look controllers for ground-based mobs. ```java BehaviorGroup.builder() .sensor(Sensors.nearestPlayer()) .behavior(/* ... */) .controller(Controllers.walk()) // Ground movement .controller(Controllers.look()) // Head rotation .build(); ``` ``` -------------------------------- ### Add MobMind Core Dependency Source: https://github.com/kanelucky/mobmind/blob/master/core/README.md Include this dependency in your project to use the MobMind Core module. ```kotlin implementation("com.github.Kanelucky.MobMind:core:0.1.1") ``` -------------------------------- ### MemoryTypes and Custom Memory Source: https://context7.com/kanelucky/mobmind/llms.txt MemoryTypes provide type-safe key-value storage for entity state, which can be read and written by sensors and executors. This section covers built-in types and how to define custom ones. ```APIDOC ## MemoryTypes and Custom Memory Type-safe key-value storage for entity state, read and written by sensors and executors. ### Built-in Memory Types - `MemoryTypes.NEAREST_PLAYER`: Stores the nearest detected player. - `MemoryTypes.NEAREST_FEEDING_PLAYER`: Stores the nearest player holding food. - `MemoryTypes.MOVE_TARGET`: Stores the pathfinding destination point. - `MemoryTypes.LOOK_TARGET`: Stores the point the entity should look at. - `MemoryTypes.ATTACK_TARGET`: Stores the current living entity target for attacks. - `MemoryTypes.PANIC_TICKS`: Stores the remaining ticks for panic state. - `MemoryTypes.IS_IN_LOVE`: Stores a boolean indicating if the entity is in breeding mode. - `MemoryTypes.LAST_IN_LOVE_TIME`: Stores the timestamp of the last time the entity entered love mode. ### Defining Custom Memory Types Custom memory types can be defined using `MemoryType`. ```java // Example custom memory types public static final MemoryType AGGRO_TARGET = new MemoryType<>("myplugin:aggro_target"); public static final MemoryType HOME_POSITION = new MemoryType<>("myplugin:home_position"); public static final MemoryType ATTACK_COUNT = new MemoryType<>("myplugin:attack_count"); ``` ### Reading and Writing Memory Memory can be accessed and modified through the `MemoryStorage`. ```java // Example: Setting panic state on damage @Override public boolean damage(@NotNull Damage damage) { boolean result = super.damage(damage); if (result) { getBehaviorGroup().getMemoryStorage().set(MemoryTypes.PANIC_TICKS, 100); } return result; } // Example: Checking memory in an evaluator .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; Integer panicTicks = e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.PANIC_TICKS); return panicTicks != null && panicTicks > 0; }) ``` ``` -------------------------------- ### Define Weighted Random Behaviors in Java Source: https://github.com/kanelucky/mobmind/blob/master/README.md Use Behaviors.weighted to define a set of behaviors with specific weights, priorities, and execution periods. ```java Behaviors.weighted( Set.of( BehaviorImpl.builder() .executor(Executors.idle(20, 60)) .evaluator(entity -> true) .priority(1).weight(1).period(1).build(), BehaviorImpl.builder() .executor(Executors.roam()) .evaluator(entity -> true) .priority(1).weight(3).period(1).build() // 3x more likely to roam ), 1, // priority 40 // period ) ``` -------------------------------- ### RangedGuardian Entity Implementation Source: https://context7.com/kanelucky/mobmind/llms.txt Defines a RangedGuardian entity extending IntelligentEntity, configuring its health, attack, movement speed, and behavior group. Requires MobMind API dependencies. ```java import net.kyori.adventure.key.Key; import net.minestom.server.entity.EntityProjectile; import net.minestom.server.entity.EntityType; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; import org.kanelucky.mobmind.api.entity.IntelligentEntity; import org.kanelucky.mobmind.api.entity.ai.behavior.Behavior; import org.kanelucky.mobmind.api.entity.ai.behavior.BehaviorImpl; import org.kanelucky.mobmind.api.entity.ai.behavior.Behaviors; import org.kanelucky.mobmind.api.entity.ai.behaviorgroup.BehaviorGroup; import org.kanelucky.mobmind.api.entity.ai.controller.Controllers; import org.kanelucky.mobmind.api.entity.ai.executor.Executors; import org.kanelucky.mobmind.api.entity.ai.memory.MemoryTypes; import org.kanelucky.mobmind.api.entity.ai.sensor.Sensors; import java.util.Set; public class RangedGuardian extends IntelligentEntity { private final BehaviorGroup behaviorGroup; public RangedGuardian() { super(EntityType.BLAZE); this.behaviorGroup = buildBehaviorGroup(); this.behaviorGroup.setEntity(this); } @Override public Key getMobKey() { return Key.key("myplugin", "ranged_guardian"); } @Override public BehaviorGroup getBehaviorGroup() { return behaviorGroup; } @Override protected double getBaseHealth() { return 60.0; } @Override protected double getBaseAttack() { return 8.0; } @Override protected double getBaseMoveSpeed() { return 0.12; } private BehaviorGroup buildBehaviorGroup() { return BehaviorGroup.builder() .sensor(Sensors.nearestPlayer(24.0, 0.0, 20)) // Guardian-style beam attack (highest priority combat) .behavior( BehaviorImpl.builder() .executor(Executors.beamAttack( MemoryTypes.NEAREST_PLAYER, 576.0, // maxRangeSq (24 blocks) 40, // cooldown ticks 20, // attack delay false)) // clearDataWhenLose .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; return e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.NEAREST_PLAYER) != null; }) .priority(3) .period(1) .build() ) // Projectile attack with custom snowball .behavior( BehaviorImpl.builder() .executor(Executors.shootProjectile( MemoryTypes.NEAREST_PLAYER, 0.1, 0.1, // speed, normalSpeed 576.0, // maxShootRangeSq 60, // cooldown 20, // attackDelay false, // clearDataWhenLose shooter -> { EntityProjectile projectile = new EntityProjectile(shooter, EntityType.SNOWBALL); var meta = (net.minestom.server.entity.metadata .item.SnowballMeta) projectile.getEntityMeta(); meta.setItem(ItemStack.of(Material.SNOWBALL)); return projectile; })) .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; return e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.NEAREST_PLAYER) != null; }) .priority(2) .period(1) .build() ) // Periodic jumping behavior .behavior( BehaviorImpl.builder() .executor(Executors.jump( 80, // interval between jumps 10, // delay before jump 0.8, // jump power 0.4)) // power variance ``` -------------------------------- ### Implement an Aggressive Zombie Entity Source: https://context7.com/kanelucky/mobmind/llms.txt Defines a custom zombie entity with a behavior group that manages sensors, melee attacks, following, and idle roaming. Requires the IntelligentEntity base class and associated MobMind API components. ```java import net.kyori.adventure.key.Key; import net.minestom.server.entity.EntityType; import net.minestom.server.entity.damage.Damage; import org.jetbrains.annotations.NotNull; import org.kanelucky.mobmind.api.entity.IntelligentEntity; import org.kanelucky.mobmind.api.entity.ai.behavior.BehaviorImpl; import org.kanelucky.mobmind.api.entity.ai.behavior.Behaviors; import org.kanelucky.mobmind.api.entity.ai.behaviorgroup.BehaviorGroup; import org.kanelucky.mobmind.api.entity.ai.controller.Controllers; import org.kanelucky.mobmind.api.entity.ai.executor.Executors; import org.kanelucky.mobmind.api.entity.ai.memory.MemoryTypes; import org.kanelucky.mobmind.api.entity.ai.sensor.Sensors; import java.util.Set; public class AggressiveZombie extends IntelligentEntity { private final BehaviorGroup behaviorGroup; public AggressiveZombie() { super(EntityType.ZOMBIE); this.behaviorGroup = buildBehaviorGroup(); this.behaviorGroup.setEntity(this); } @Override public Key getMobKey() { return Key.key("myplugin", "aggressive_zombie"); } @Override public BehaviorGroup getBehaviorGroup() { return behaviorGroup; } @Override protected double getBaseHealth() { return 20.0; } @Override protected double getBaseAttack() { return 3.0; } @Override protected double getBaseMoveSpeed() { return 0.1; } @Override public boolean damage(@NotNull Damage damage) { boolean result = super.damage(damage); if (result) { getBehaviorGroup().getMemoryStorage().set(MemoryTypes.PANIC_TICKS, 60); } return result; } private BehaviorGroup buildBehaviorGroup() { return BehaviorGroup.builder() // Sensor: detect players within 16 blocks .sensor(Sensors.nearestPlayer(16.0, 0.0, 20)) // Priority 3: Melee attack when close to player .behavior( BehaviorImpl.builder() .executor(Executors.meleeAttack( MemoryTypes.NEAREST_PLAYER, 0.1, 0.1, // speed, normalSpeed 1024.0, // maxSenseRangeSq (32 blocks) 2.5, // attackRangeSq 30, // attack cooldown ticks false)) // don't clear on lose target .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; return e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.NEAREST_PLAYER) != null; }) .priority(3) .period(1) .build() ) // Priority 2: Follow player when detected .behavior( BehaviorImpl.builder() .executor(Executors.followEntity( MemoryTypes.NEAREST_PLAYER, 0.15, 0.1, // speed, normalSpeed 256.0, 2.0)) // maxRangeSq, minRangeSq .evaluator(entity -> { if (!(entity instanceof IntelligentEntity e)) return false; return e.getBehaviorGroup().getMemoryStorage() .get(MemoryTypes.NEAREST_PLAYER) != null; }) .priority(2) .period(1) .build() ) // Priority 1: Weighted random idle/roam when no target .behavior( Behaviors.weighted( Set.of( BehaviorImpl.builder() .executor(Executors.idle(20, 60)) .evaluator(entity -> true) .priority(1).weight(1).period(1) .build(), BehaviorImpl.builder() .executor(Executors.roam(0.08, 0.08, 8, 20, true, 100, false, 10)) .evaluator(entity -> true) .priority(1).weight(3).period(1) ``` -------------------------------- ### Evaluators Factory Methods Source: https://context7.com/kanelucky/mobmind/llms.txt Defines conditions for behavior activation using built-in evaluators or custom lambda expressions. ```APIDOC ## Evaluators Factory Methods ### Description Evaluators determine when behaviors should activate based on entity state and conditions. ### Built-in Evaluators - **Evaluators.panic()**: True when PANIC_TICKS > 0. - **Evaluators.inLove()**: True when entity is in love and not a baby. - **Evaluators.probability(numerator, denominator)**: Returns true based on a probability chance. ``` -------------------------------- ### Define Evaluators for Behavior Activation Source: https://context7.com/kanelucky/mobmind/llms.txt Determines when a behavior should run using built-in factory methods or custom lambda expressions. ```java import org.kanelucky.mobmind.api.entity.ai.evaluator.Evaluators; import org.kanelucky.mobmind.api.entity.ai.memory.MemoryTypes; // Built-in evaluators Evaluators.panic(); // True when PANIC_TICKS > 0 in memory Evaluators.inLove(); // True when IS_IN_LOVE and not baby, no cooldown Evaluators.probability(1, 200); // 1/200 = 0.5% chance per evaluation // Lambda evaluators for custom conditions BehaviorImpl.builder() .executor(Executors.meleeAttack(MemoryTypes.NEAREST_PLAYER)) .evaluator(entity -> { // Custom evaluation logic if (!(entity instanceof IntelligentEntity e)) return false; Player nearestPlayer = e.getBehaviorGroup() .getMemoryStorage() .get(MemoryTypes.NEAREST_PLAYER); return nearestPlayer != null && nearestPlayer.getHealth() > 0; }) .priority(2) .period(1) .build(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.