Entity: make getNetworkTypeId non-static (#6037)

This was static to permit ItemFactory to register spawn eggs for all known entity types in early PM4. However, nowadays we provide a callback to the spawn egg instead, and spawn eggs must be manually implemented, so this is no longer needed.

In addition, having this static forces everyone to make a new entity class for every unique type of entity, which isn't ideal.
This commit is contained in:
Doge 2023-09-06 17:26:32 +03:00 committed by GitHub
parent 4dc9d696d0
commit ed61a68013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 20 additions and 20 deletions

View File

@ -1473,7 +1473,7 @@ abstract class Entity{
return $this->hasSpawned; return $this->hasSpawned;
} }
abstract public static function getNetworkTypeId() : string; abstract public function getNetworkTypeId() : string;
/** /**
* Called by spawnTo() to send whatever packets needed to spawn the entity to the client. * Called by spawnTo() to send whatever packets needed to spawn the entity to the client.
@ -1482,7 +1482,7 @@ abstract class Entity{
$player->getNetworkSession()->sendDataPacket(AddActorPacket::create( $player->getNetworkSession()->sendDataPacket(AddActorPacket::create(
$this->getId(), //TODO: actor unique ID $this->getId(), //TODO: actor unique ID
$this->getId(), $this->getId(),
static::getNetworkTypeId(), $this->getNetworkTypeId(),
$this->location->asVector3(), $this->location->asVector3(),
$this->getMotion(), $this->getMotion(),
$this->location->pitch, $this->location->pitch,

View File

@ -98,7 +98,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
private const TAG_SKIN_GEOMETRY_NAME = "GeometryName"; //TAG_String private const TAG_SKIN_GEOMETRY_NAME = "GeometryName"; //TAG_String
private const TAG_SKIN_GEOMETRY_DATA = "GeometryData"; //TAG_ByteArray private const TAG_SKIN_GEOMETRY_DATA = "GeometryData"; //TAG_ByteArray
public static function getNetworkTypeId() : string{ return EntityIds::PLAYER; } public function getNetworkTypeId() : string{ return EntityIds::PLAYER; }
protected PlayerInventory $inventory; protected PlayerInventory $inventory;
protected PlayerOffHandInventory $offHandInventory; protected PlayerOffHandInventory $offHandInventory;

View File

@ -37,7 +37,7 @@ use const M_PI;
class Squid extends WaterAnimal{ class Squid extends WaterAnimal{
public static function getNetworkTypeId() : string{ return EntityIds::SQUID; } public function getNetworkTypeId() : string{ return EntityIds::SQUID; }
public ?Vector3 $swimDirection = null; public ?Vector3 $swimDirection = null;
public float $swimSpeed = 0.1; public float $swimSpeed = 0.1;

View File

@ -38,7 +38,7 @@ class Villager extends Living implements Ageable{
private const TAG_PROFESSION = "Profession"; //TAG_Int private const TAG_PROFESSION = "Profession"; //TAG_Int
public static function getNetworkTypeId() : string{ return EntityIds::VILLAGER; } public function getNetworkTypeId() : string{ return EntityIds::VILLAGER; }
private bool $baby = false; private bool $baby = false;
private int $profession = self::PROFESSION_FARMER; private int $profession = self::PROFESSION_FARMER;

View File

@ -29,7 +29,7 @@ use function mt_rand;
class Zombie extends Living{ class Zombie extends Living{
public static function getNetworkTypeId() : string{ return EntityIds::ZOMBIE; } public function getNetworkTypeId() : string{ return EntityIds::ZOMBIE; }
protected function getInitialSizeInfo() : EntitySizeInfo{ protected function getInitialSizeInfo() : EntitySizeInfo{
return new EntitySizeInfo(1.8, 0.6); //TODO: eye height ?? return new EntitySizeInfo(1.8, 0.6); //TODO: eye height ??

View File

@ -37,7 +37,7 @@ use function sqrt;
class ExperienceOrb extends Entity{ class ExperienceOrb extends Entity{
public static function getNetworkTypeId() : string{ return EntityIds::XP_ORB; } public function getNetworkTypeId() : string{ return EntityIds::XP_ORB; }
public const TAG_VALUE_PC = "Value"; //short public const TAG_VALUE_PC = "Value"; //short
public const TAG_VALUE_PE = "experience value"; //int (WTF?) public const TAG_VALUE_PE = "experience value"; //int (WTF?)

View File

@ -55,7 +55,7 @@ class FallingBlock extends Entity{
private const TAG_TILE = "Tile"; //TAG_Byte private const TAG_TILE = "Tile"; //TAG_Byte
private const TAG_DATA = "Data"; //TAG_Byte private const TAG_DATA = "Data"; //TAG_Byte
public static function getNetworkTypeId() : string{ return EntityIds::FALLING_BLOCK; } public function getNetworkTypeId() : string{ return EntityIds::FALLING_BLOCK; }
protected Block $block; protected Block $block;

View File

@ -52,7 +52,7 @@ class ItemEntity extends Entity{
private const TAG_THROWER = "Thrower"; //TAG_String private const TAG_THROWER = "Thrower"; //TAG_String
public const TAG_ITEM = "Item"; //TAG_Compound public const TAG_ITEM = "Item"; //TAG_Compound
public static function getNetworkTypeId() : string{ return EntityIds::ITEM; } public function getNetworkTypeId() : string{ return EntityIds::ITEM; }
public const MERGE_CHECK_PERIOD = 2; //0.1 seconds public const MERGE_CHECK_PERIOD = 2; //0.1 seconds
public const DEFAULT_DESPAWN_DELAY = 6000; //5 minutes public const DEFAULT_DESPAWN_DELAY = 6000; //5 minutes

View File

@ -48,7 +48,7 @@ class Painting extends Entity{
public const TAG_DIRECTION_BE = "Direction"; //TAG_Byte public const TAG_DIRECTION_BE = "Direction"; //TAG_Byte
public const TAG_MOTIVE = "Motive"; //TAG_String public const TAG_MOTIVE = "Motive"; //TAG_String
public static function getNetworkTypeId() : string{ return EntityIds::PAINTING; } public function getNetworkTypeId() : string{ return EntityIds::PAINTING; }
public const DATA_TO_FACING = [ public const DATA_TO_FACING = [
0 => Facing::SOUTH, 0 => Facing::SOUTH,

View File

@ -41,7 +41,7 @@ class PrimedTNT extends Entity implements Explosive{
private const TAG_FUSE = "Fuse"; //TAG_Short private const TAG_FUSE = "Fuse"; //TAG_Short
public static function getNetworkTypeId() : string{ return EntityIds::TNT; } public function getNetworkTypeId() : string{ return EntityIds::TNT; }
protected int $fuse; protected int $fuse;
protected bool $worksUnderwater = false; protected bool $worksUnderwater = false;

View File

@ -46,7 +46,7 @@ use function sqrt;
class Arrow extends Projectile{ class Arrow extends Projectile{
public static function getNetworkTypeId() : string{ return EntityIds::ARROW; } public function getNetworkTypeId() : string{ return EntityIds::ARROW; }
public const PICKUP_NONE = 0; public const PICKUP_NONE = 0;
public const PICKUP_ANY = 1; public const PICKUP_ANY = 1;

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\world\particle\ItemBreakParticle; use pocketmine\world\particle\ItemBreakParticle;
class Egg extends Throwable{ class Egg extends Throwable{
public static function getNetworkTypeId() : string{ return EntityIds::EGG; } public function getNetworkTypeId() : string{ return EntityIds::EGG; }
//TODO: spawn chickens on collision //TODO: spawn chickens on collision

View File

@ -30,7 +30,7 @@ use pocketmine\world\particle\EndermanTeleportParticle;
use pocketmine\world\sound\EndermanTeleportSound; use pocketmine\world\sound\EndermanTeleportSound;
class EnderPearl extends Throwable{ class EnderPearl extends Throwable{
public static function getNetworkTypeId() : string{ return EntityIds::ENDER_PEARL; } public function getNetworkTypeId() : string{ return EntityIds::ENDER_PEARL; }
protected function onHit(ProjectileHitEvent $event) : void{ protected function onHit(ProjectileHitEvent $event) : void{
$owner = $this->getOwningEntity(); $owner = $this->getOwningEntity();

View File

@ -30,7 +30,7 @@ use pocketmine\world\sound\PotionSplashSound;
use function mt_rand; use function mt_rand;
class ExperienceBottle extends Throwable{ class ExperienceBottle extends Throwable{
public static function getNetworkTypeId() : string{ return EntityIds::XP_BOTTLE; } public function getNetworkTypeId() : string{ return EntityIds::XP_BOTTLE; }
protected function getInitialGravity() : float{ return 0.07; } protected function getInitialGravity() : float{ return 0.07; }

View File

@ -28,7 +28,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\world\particle\SnowballPoofParticle; use pocketmine\world\particle\SnowballPoofParticle;
class Snowball extends Throwable{ class Snowball extends Throwable{
public static function getNetworkTypeId() : string{ return EntityIds::SNOWBALL; } public function getNetworkTypeId() : string{ return EntityIds::SNOWBALL; }
protected function onHit(ProjectileHitEvent $event) : void{ protected function onHit(ProjectileHitEvent $event) : void{
for($i = 0; $i < 6; ++$i){ for($i = 0; $i < 6; ++$i){

View File

@ -52,7 +52,7 @@ class SplashPotion extends Throwable{
public const TAG_POTION_ID = "PotionId"; //TAG_Short public const TAG_POTION_ID = "PotionId"; //TAG_Short
public static function getNetworkTypeId() : string{ return EntityIds::SPLASH_POTION; } public function getNetworkTypeId() : string{ return EntityIds::SPLASH_POTION; }
protected bool $linger = false; protected bool $linger = false;
protected PotionType $potionType; protected PotionType $potionType;

View File

@ -44,7 +44,7 @@ class EntityLandSound implements Sound{
LevelSoundEvent::LAND, LevelSoundEvent::LAND,
$pos, $pos,
TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->blockLandedOn->getStateId()), TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->blockLandedOn->getStateId()),
$this->entity::getNetworkTypeId(), $this->entity->getNetworkTypeId(),
false, //TODO: does isBaby have any relevance here? false, //TODO: does isBaby have any relevance here?
false false
)]; )];

View File

@ -40,7 +40,7 @@ class EntityLongFallSound implements Sound{
LevelSoundEvent::FALL_BIG, LevelSoundEvent::FALL_BIG,
$pos, $pos,
-1, -1,
$this->entity::getNetworkTypeId(), $this->entity->getNetworkTypeId(),
false, //TODO: is isBaby relevant here? false, //TODO: is isBaby relevant here?
false false
)]; )];

View File

@ -39,7 +39,7 @@ class EntityShortFallSound implements Sound{
LevelSoundEvent::FALL_SMALL, LevelSoundEvent::FALL_SMALL,
$pos, $pos,
-1, -1,
$this->entity::getNetworkTypeId(), $this->entity->getNetworkTypeId(),
false, //TODO: does isBaby have any relevance here? false, //TODO: does isBaby have any relevance here?
false false
)]; )];