This library provides an extensible AI system for mobs in PocketMine-MP using the clousclouds\mobai namespace. It allows developers to easily integrate AI behaviors such as movement, attacking, and interaction with the game world. The library is designed for flexibility, enabling custom AI logic for various entities.
- AI Interface (
AiInterface): Defines core AI methods (think,move,interact,attack,defend). - Base AI Implementation (
Ai): Implements default AI behaviors such as random movement, player detection, and attack logic. - Customizable Mob AI (
MobAI): Extendable class for specific mob behaviors. - No World Generators: Focus solely on entity AI logic without world manipulation.
- MIT License: Open-source and free to use.
- PocketMine-MP: API version 5.
- PHP: 8.1 or higher.
- Composer: To manage the dependency and autoloading.
- Install via Composer:
composer require clousclouds/mobai
- Ensure that Composer's autoloader is included in your project:
require 'vendor/autoload.php';
To create an AI for your mob:
- Inherit from the MobAI class:
use clousclouds\mobai\MobAI;
use pocketmine\entity\Entity;
class CustomMobAI extends MobAI {
public function think(): void {
parent::think(); // Use the base logic
// Add custom behavior here
}
public function move(): void {
parent::move(); // Use the base movement logic
// Add custom movement logic here
}
}- Assign AI to a Mob:
In your project, assign the AI to the mob when spawning or initializing:
$mob = new YourMobClass($position); // Replace with your mob entity
$ai = new CustomMobAI($mob);
$mob->setAI($ai);You can easily extend or override existing AI methods like think(), move(), or attack() in your custom AI class to implement specific behaviors.
For example, adding custom attack logic:
public function attack(): void {
if ($this->target && $this->isInRange($this->target)) {
$this->performAttack($this->target);
// Custom logic after attack
$this->celebrateAttack(); // Example of custom logic
}
}
protected function celebrateAttack(): void {
// Custom behavior after a successful attack
}This project is licensed under the (LICENSE)[MIT LICENSE]