mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
New way to spawn entities/tiles using a global register table, allow overriding default entity/tile classes via classes
This commit is contained in:
@ -40,6 +40,9 @@ abstract class Tile extends Position{
|
||||
|
||||
public static $tileCount = 1;
|
||||
|
||||
/** @var Tile[] */
|
||||
private static $knownTiles = [];
|
||||
|
||||
/** @var Chunk */
|
||||
public $chunk;
|
||||
public $name;
|
||||
@ -58,6 +61,38 @@ abstract class Tile extends Position{
|
||||
/** @var \pocketmine\event\TimingsHandler */
|
||||
public $tickTimer;
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param FullChunk $chunk
|
||||
* @param Compound $nbt
|
||||
* @param $args
|
||||
*
|
||||
* @return Tile
|
||||
*/
|
||||
public static function createTile($type, FullChunk $chunk, Compound $nbt, ...$args){
|
||||
if(isset(self::$knownTiles[$type])){
|
||||
$class = self::$knownTiles[$type];
|
||||
return new $class($chunk, $nbt, ...$args);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $className
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function registerTile($className){
|
||||
$class = new \ReflectionClass($className);
|
||||
if(is_a($className, Tile::class, true) and !$class->isAbstract()){
|
||||
self::$knownTiles[$class->getShortName()] = $className;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __construct(FullChunk $chunk, Compound $nbt){
|
||||
if($chunk === null or $chunk->getProvider() === null){
|
||||
throw new \Exception("Invalid garbage Chunk given to Tile");
|
||||
|
Reference in New Issue
Block a user