Documentation

EntityFactory
in package
Uses SingletonTrait

This class manages the creation of entities loaded from disk.

You need to register your entity into this factory if you want to load/save your entity on disk (saving with chunks).

Table of Contents

$creationFuncs  : array<string|int, Closure>
$instance  : self|null
$saveNames  : array<string|int, string>
__construct()  : mixed
getInstance()  : self
getSaveId()  : string
injectSaveId()  : void
register()  : void
Registers an entity type into the index.
reset()  : void
setInstance()  : void
make()  : self
validateCreationFunc()  : void

Properties

$creationFuncs

private array<string|int, Closure> $creationFuncs = []

save ID => creator function

Tags
phpstan-var

array<int|string, \Closure(World, CompoundTag) : Entity>

$saveNames

private array<string|int, string> $saveNames = []
Tags
phpstan-var

array<class-string<Entity>, string>

Methods

__construct()

public __construct() : mixed
Return values
mixed

getInstance()

public static getInstance() : self
Return values
self

getSaveId()

public getSaveId(string $class) : string
Parameters
$class : string
Tags
phpstan-param

class-string<Entity> $class

Return values
string

register()

Registers an entity type into the index.

public register(string $className, Closure $creationFunc, array<string|int, string> $saveNames[, int|null $legacyMcpeSaveId = null ]) : void
Parameters
$className : string

Class that extends Entity

$creationFunc : Closure
$saveNames : array<string|int, string>

An array of save names which this entity might be saved under.

$legacyMcpeSaveId : int|null = null
Tags
phpstan-param

class-string<Entity> $className

phpstan-param

list $saveNames

phpstan-param

\Closure(World $world, CompoundTag $nbt) : Entity $creationFunc

NOTE: The first save name in the $saveNames array will be used when saving the entity to disk.

throws
InvalidArgumentException
Return values
void

setInstance()

public static setInstance(self $instance) : void
Parameters
$instance : self
Return values
void

validateCreationFunc()

private static validateCreationFunc(Closure $creationFunc) : void
Parameters
$creationFunc : Closure
Tags
phpstan-param

\Closure(World, CompoundTag) : Entity $creationFunc

Return values
void

Search results