From ed61a68013749647820c47a8e8ac22f89bbdbae7 Mon Sep 17 00:00:00 2001 From: Doge Date: Wed, 6 Sep 2023 17:26:32 +0300 Subject: [PATCH] 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. --- src/entity/Entity.php | 4 ++-- src/entity/Human.php | 2 +- src/entity/Squid.php | 2 +- src/entity/Villager.php | 2 +- src/entity/Zombie.php | 2 +- src/entity/object/ExperienceOrb.php | 2 +- src/entity/object/FallingBlock.php | 2 +- src/entity/object/ItemEntity.php | 2 +- src/entity/object/Painting.php | 2 +- src/entity/object/PrimedTNT.php | 2 +- src/entity/projectile/Arrow.php | 2 +- src/entity/projectile/Egg.php | 2 +- src/entity/projectile/EnderPearl.php | 2 +- src/entity/projectile/ExperienceBottle.php | 2 +- src/entity/projectile/Snowball.php | 2 +- src/entity/projectile/SplashPotion.php | 2 +- src/world/sound/EntityLandSound.php | 2 +- src/world/sound/EntityLongFallSound.php | 2 +- src/world/sound/EntityShortFallSound.php | 2 +- 19 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 8a406924e..d663f5f5c 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1473,7 +1473,7 @@ abstract class Entity{ 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. @@ -1482,7 +1482,7 @@ abstract class Entity{ $player->getNetworkSession()->sendDataPacket(AddActorPacket::create( $this->getId(), //TODO: actor unique ID $this->getId(), - static::getNetworkTypeId(), + $this->getNetworkTypeId(), $this->location->asVector3(), $this->getMotion(), $this->location->pitch, diff --git a/src/entity/Human.php b/src/entity/Human.php index f2c4c7a74..006bf6df8 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -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_DATA = "GeometryData"; //TAG_ByteArray - public static function getNetworkTypeId() : string{ return EntityIds::PLAYER; } + public function getNetworkTypeId() : string{ return EntityIds::PLAYER; } protected PlayerInventory $inventory; protected PlayerOffHandInventory $offHandInventory; diff --git a/src/entity/Squid.php b/src/entity/Squid.php index 75c50061b..bc47925f3 100644 --- a/src/entity/Squid.php +++ b/src/entity/Squid.php @@ -37,7 +37,7 @@ use const M_PI; class Squid extends WaterAnimal{ - public static function getNetworkTypeId() : string{ return EntityIds::SQUID; } + public function getNetworkTypeId() : string{ return EntityIds::SQUID; } public ?Vector3 $swimDirection = null; public float $swimSpeed = 0.1; diff --git a/src/entity/Villager.php b/src/entity/Villager.php index 376401a5d..caca9a148 100644 --- a/src/entity/Villager.php +++ b/src/entity/Villager.php @@ -38,7 +38,7 @@ class Villager extends Living implements Ageable{ 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 int $profession = self::PROFESSION_FARMER; diff --git a/src/entity/Zombie.php b/src/entity/Zombie.php index 18fc2207e..16ca4c0b0 100644 --- a/src/entity/Zombie.php +++ b/src/entity/Zombie.php @@ -29,7 +29,7 @@ use function mt_rand; class Zombie extends Living{ - public static function getNetworkTypeId() : string{ return EntityIds::ZOMBIE; } + public function getNetworkTypeId() : string{ return EntityIds::ZOMBIE; } protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(1.8, 0.6); //TODO: eye height ?? diff --git a/src/entity/object/ExperienceOrb.php b/src/entity/object/ExperienceOrb.php index 5120da3e1..b72fda748 100644 --- a/src/entity/object/ExperienceOrb.php +++ b/src/entity/object/ExperienceOrb.php @@ -37,7 +37,7 @@ use function sqrt; 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_PE = "experience value"; //int (WTF?) diff --git a/src/entity/object/FallingBlock.php b/src/entity/object/FallingBlock.php index 9d8af8934..f1cc37332 100644 --- a/src/entity/object/FallingBlock.php +++ b/src/entity/object/FallingBlock.php @@ -55,7 +55,7 @@ class FallingBlock extends Entity{ private const TAG_TILE = "Tile"; //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; diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 90eeece67..43c495b6d 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -52,7 +52,7 @@ class ItemEntity extends Entity{ private const TAG_THROWER = "Thrower"; //TAG_String 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 DEFAULT_DESPAWN_DELAY = 6000; //5 minutes diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index f6449883c..5b5217e62 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -48,7 +48,7 @@ class Painting extends Entity{ public const TAG_DIRECTION_BE = "Direction"; //TAG_Byte 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 = [ 0 => Facing::SOUTH, diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index ec621adfb..d08b9f1bb 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -41,7 +41,7 @@ class PrimedTNT extends Entity implements Explosive{ 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 bool $worksUnderwater = false; diff --git a/src/entity/projectile/Arrow.php b/src/entity/projectile/Arrow.php index 5a288ba72..81cd07663 100644 --- a/src/entity/projectile/Arrow.php +++ b/src/entity/projectile/Arrow.php @@ -46,7 +46,7 @@ use function sqrt; 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_ANY = 1; diff --git a/src/entity/projectile/Egg.php b/src/entity/projectile/Egg.php index 9c3826714..1b2807f5f 100644 --- a/src/entity/projectile/Egg.php +++ b/src/entity/projectile/Egg.php @@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\world\particle\ItemBreakParticle; class Egg extends Throwable{ - public static function getNetworkTypeId() : string{ return EntityIds::EGG; } + public function getNetworkTypeId() : string{ return EntityIds::EGG; } //TODO: spawn chickens on collision diff --git a/src/entity/projectile/EnderPearl.php b/src/entity/projectile/EnderPearl.php index 1f92ee8d9..3b69c5326 100644 --- a/src/entity/projectile/EnderPearl.php +++ b/src/entity/projectile/EnderPearl.php @@ -30,7 +30,7 @@ use pocketmine\world\particle\EndermanTeleportParticle; use pocketmine\world\sound\EndermanTeleportSound; 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{ $owner = $this->getOwningEntity(); diff --git a/src/entity/projectile/ExperienceBottle.php b/src/entity/projectile/ExperienceBottle.php index ea8447a74..b30346880 100644 --- a/src/entity/projectile/ExperienceBottle.php +++ b/src/entity/projectile/ExperienceBottle.php @@ -30,7 +30,7 @@ use pocketmine\world\sound\PotionSplashSound; use function mt_rand; 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; } diff --git a/src/entity/projectile/Snowball.php b/src/entity/projectile/Snowball.php index cf9d7c689..11801d151 100644 --- a/src/entity/projectile/Snowball.php +++ b/src/entity/projectile/Snowball.php @@ -28,7 +28,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\world\particle\SnowballPoofParticle; 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{ for($i = 0; $i < 6; ++$i){ diff --git a/src/entity/projectile/SplashPotion.php b/src/entity/projectile/SplashPotion.php index 17e4d8af7..764a594f8 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -52,7 +52,7 @@ class SplashPotion extends Throwable{ 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 PotionType $potionType; diff --git a/src/world/sound/EntityLandSound.php b/src/world/sound/EntityLandSound.php index 998c5ed02..60ed6c84a 100644 --- a/src/world/sound/EntityLandSound.php +++ b/src/world/sound/EntityLandSound.php @@ -44,7 +44,7 @@ class EntityLandSound implements Sound{ LevelSoundEvent::LAND, $pos, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->blockLandedOn->getStateId()), - $this->entity::getNetworkTypeId(), + $this->entity->getNetworkTypeId(), false, //TODO: does isBaby have any relevance here? false )]; diff --git a/src/world/sound/EntityLongFallSound.php b/src/world/sound/EntityLongFallSound.php index e0dabe3a5..30c4425b1 100644 --- a/src/world/sound/EntityLongFallSound.php +++ b/src/world/sound/EntityLongFallSound.php @@ -40,7 +40,7 @@ class EntityLongFallSound implements Sound{ LevelSoundEvent::FALL_BIG, $pos, -1, - $this->entity::getNetworkTypeId(), + $this->entity->getNetworkTypeId(), false, //TODO: is isBaby relevant here? false )]; diff --git a/src/world/sound/EntityShortFallSound.php b/src/world/sound/EntityShortFallSound.php index 8955c3552..3ea39b3fe 100644 --- a/src/world/sound/EntityShortFallSound.php +++ b/src/world/sound/EntityShortFallSound.php @@ -39,7 +39,7 @@ class EntityShortFallSound implements Sound{ LevelSoundEvent::FALL_SMALL, $pos, -1, - $this->entity::getNetworkTypeId(), + $this->entity->getNetworkTypeId(), false, //TODO: does isBaby have any relevance here? false )];