mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 19:02:59 +00:00
Revamp Entity construction
This is a similar refactor to the one I recently did for tiles. - Entity::createEntity() is removed. In its place are Entity::create() (runtime creation, use where you'd use a constructor, accepts a ::class parameter, throws exceptions on unknown entities) and Entity::createFromData() (internal, used to restore entities from chunks, swallows unknown entities and returns null). - Entity::registerEntity() is renamed to Entity::register(). - Added Entity::override() to allow overriding factory classes without touching save IDs. This allows more cleanly extending & overriding entities. This method only allows overriding registered Entity classes with children of that class, which makes code using the factory much more sane and allows to provide safety guarantees which make the code less nasty. - Entity::getKnownEntityTypes() is renamed to Entity::getKnownTypes(). - ProjectileItem::getProjectileEntityType() now returns a ::class constant instead of a stringy ID. - Cleaned up a bunch of nasty code, particularly in Bow.
This commit is contained in:
@ -33,7 +33,6 @@ use pocketmine\level\format\io\LevelData;
|
||||
use pocketmine\level\format\SubChunk;
|
||||
use pocketmine\nbt\LittleEndianNBTStream;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
use function array_values;
|
||||
@ -248,13 +247,6 @@ class LevelDB extends BaseLevelProvider{
|
||||
$entities = $nbt->readMultiple($entityData);
|
||||
}
|
||||
|
||||
/** @var CompoundTag $entityNBT */
|
||||
foreach($entities as $entityNBT){
|
||||
if($entityNBT->hasTag("id", IntTag::class)){
|
||||
$entityNBT->setInt("id", $entityNBT->getInt("id") & 0xff); //remove type flags - TODO: use these instead of removing them)
|
||||
}
|
||||
}
|
||||
|
||||
/** @var CompoundTag[] $tiles */
|
||||
$tiles = [];
|
||||
if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and $tileData !== ""){
|
||||
|
Reference in New Issue
Block a user