-
Notifications
You must be signed in to change notification settings - Fork 54
Custom Entities
Before you can register an entity, you need to create a class extending Entity
that uses your custom identifier. This is required for pocketmine to know the type of entity to spawn.
use pocketmine\entity\Entity;
class ExampleEntity extends Entity {
// ...
public static function getNetworkTypeId(): string {
return "customies:example_entity";
}
// ...
}
Registering a custom entity is as simple as registering a normal entity. All you need to do is use the CustomiesEntityFactory
class to register the entity and use the same identifier from the previous step.
use customiesdevs\customies\entity\CustomiesEntityFactory;
// ...
public function onEnable(): void {
CustomiesEntityFactory::getInstance()->registerEntity(ExampleEntity::class, "customies:example_entity");
}
// ...
If you want to provide your own creation function, you can provide a
Closure(World $world, CompoundTag $nbt): Entity
as the 3rd argument.
Creating a custom entity is identical to how you would do it normally with any other entity, and the same applies for spawning it.
$entity = new ExampleEntity(...);
$entity->spawnToAll();
For support with the Customies API, you can join our Discord.
Copyright © 2022 CustomiesDevs/Customies