EntityAI is an advanced Bukkit/Spigot library for creating sophisticated, dynamic mob behaviors in Minecraft. This system empowers developers to craft intelligent entity interactions with a flexible, priority-based AI management approach.
- Dynamic AI behavior management
- Customizable behavior priority system
- Precise entity navigation
- Intelligent behavior switching
- Extensible design for custom AI behaviors
- Download the latest EntityAI library JAR
- Add to your plugin's build path
- Import required classes
public class ZombieAIPlugin extends JavaPlugin {
private EntityAI entityAI;
@Override
public void onEnable() {
// Initialize EntityAI with your plugin instance
entityAI = new EntityAI(this);
}
public void spawnEnhancedZombie(Location spawnLocation) {
// Spawn a zombie with advanced AI
Zombie zombie = (Zombie) spawnLocation.getWorld().spawnEntity(spawnLocation, EntityType.ZOMBIE);
// Create AI manager for the zombie
AIManager zombieAI = entityAI.createAIForEntity(zombie);
// Add multiple behaviors with different priorities
zombieAI.addBehavior(new HuntingBehavior(zombie, Player.class, 15.0));
zombieAI.addBehavior(new TerritorialBehavior(zombie, spawnLocation, 20.0));
}
}public class ScaredBehavior extends AIBehavior {
private final double fearRadius;
private final Class<? extends LivingEntity> threatType;
public ScaredBehavior(Mob entity, Class<? extends LivingEntity> threatType, double fearRadius) {
super(entity, 0.9); // High priority
this.threatType = threatType;
this.fearRadius = fearRadius;
}
@Override
public boolean canRun() {
// Only run if a threat is nearby
return entity.getNearbyEntities(fearRadius, fearRadius, fearRadius)
.stream().anyMatch(threatType::isInstance);
}
@Override
public void start() {
isActive = true;
Bukkit.getLogger().info("Entering scared state!");
}
@Override
public void update() {
if (!isActive) return;
// Find the nearest threat
LivingEntity nearestThreat = EntityUtils.findNearestEntity(
entity,
entity.getNearbyEntities(fearRadius, fearRadius, fearRadius)
.stream()
.filter(threatType::isInstance)
.map(e -> (LivingEntity) e)
.collect(Collectors.toList()),
fearRadius
);
if (nearestThreat != null) {
// Run away from the threat
Location fleeDirection = entity.getLocation().subtract(nearestThreat.getLocation());
entity.teleport(entity.getLocation().add(fleeDirection.toVector().normalize().multiply(5)));
}
}
@Override
public void stop() {
isActive = false;
Bukkit.getLogger().info("Exiting scared state!");
}
}public class MobAIController {
public void setupAdvancedMobAI(World world) {
// Create a specific location for spawning and territory
Location spawnLocation = new Location(world, 100, 64, 100);
Location villageCenter = new Location(world, 100, 64, 100);
// Spawn a complex mob with multiple behaviors
Mob guardEntity = (Mob) world.spawnEntity(spawnLocation, EntityType.IRON_GOLEM);
AIManager guardAI = EntityAI.getInstance().createAIForEntity(guardEntity);
// Territorial behavior with high priority
guardAI.addBehavior(new TerritorialBehavior(
guardEntity,
villageCenter,
50.0 // Large patrol radius
));
// Hunting behavior to protect against hostile mobs
guardAI.addBehavior(new HuntingBehavior(
guardEntity,
Monster.class, // Target all monster types
30.0 // Search radius
));
// Custom scared behavior as a fallback
guardAI.addBehavior(new ScaredBehavior(
guardEntity,
Creeper.class, // Specific threat type
10.0 // Fear radius
));
}
}@Override
public void onDisable() {
// Stop all AI processing and clean up resources
EntityAI.getInstance().disable();
}- Always create AI behaviors with appropriate priority levels
- Use
canRun()to add complex activation conditions - Minimize computational complexity in
update()methods - Test behaviors thoroughly in different scenarios
- Implement custom
AIBehaviorsubclasses - Fine-tune behavior priorities
- Create complex interaction rules
- Leverage
AdvancedNavigatorfor precise movement