From d38c17835d0cc0771d2ddc7f37ef0b0afdda6994 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 20 Jun 2020 13:43:31 +0100 Subject: [PATCH] Properly switch to string entity IDs --- src/entity/Entity.php | 5 +- src/entity/Human.php | 5 +- src/entity/Squid.php | 4 +- src/entity/Villager.php | 4 +- src/entity/Zombie.php | 4 +- src/entity/object/ExperienceOrb.php | 4 +- src/entity/object/FallingBlock.php | 4 +- src/entity/object/ItemEntity.php | 4 +- src/entity/object/Painting.php | 4 +- src/entity/object/PrimedTNT.php | 4 +- src/entity/projectile/Arrow.php | 4 +- src/entity/projectile/Egg.php | 4 +- src/entity/projectile/EnderPearl.php | 4 +- src/entity/projectile/ExperienceBottle.php | 4 +- src/entity/projectile/Snowball.php | 4 +- src/entity/projectile/SplashPotion.php | 4 +- .../mcpe/protocol/types/entity/EntityIds.php | 144 ++++++++++++++++++ src/world/sound/EntityLandSound.php | 4 +- src/world/sound/EntityLongFallSound.php | 4 +- src/world/sound/EntityShortFallSound.php | 4 +- 20 files changed, 179 insertions(+), 43 deletions(-) create mode 100644 src/network/mcpe/protocol/types/entity/EntityIds.php diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 0ec443ebe..0c367a28c 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -28,7 +28,6 @@ namespace pocketmine\entity; use pocketmine\block\Block; use pocketmine\block\Water; -use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap; use pocketmine\entity\animation\Animation; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDespawnEvent; @@ -1475,7 +1474,7 @@ abstract class Entity{ return $this->hasSpawned; } - abstract public static function getNetworkTypeId() : int; + abstract public static function getNetworkTypeId() : string; /** * Called by spawnTo() to send whatever packets needed to spawn the entity to the client. @@ -1483,7 +1482,7 @@ abstract class Entity{ protected function sendSpawnPacket(Player $player) : void{ $pk = new AddActorPacket(); $pk->entityRuntimeId = $this->getId(); - $pk->type = LegacyEntityIdToStringIdMap::getInstance()->legacyToString(static::getNetworkTypeId()); + $pk->type = static::getNetworkTypeId(); $pk->position = $this->location->asVector3(); $pk->motion = $this->getMotion(); $pk->yaw = $this->location->yaw; diff --git a/src/entity/Human.php b/src/entity/Human.php index 04c5a38e4..676b105ab 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -48,6 +48,7 @@ use pocketmine\network\mcpe\protocol\AddPlayerPacket; use pocketmine\network\mcpe\protocol\MovePlayerPacket; use pocketmine\network\mcpe\protocol\PlayerListPacket; use pocketmine\network\mcpe\protocol\PlayerSkinPacket; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; use pocketmine\network\mcpe\protocol\types\entity\StringMetadataProperty; use pocketmine\network\mcpe\protocol\types\PlayerListEntry; @@ -63,9 +64,7 @@ use function random_int; class Human extends Living implements ProjectileSource, InventoryHolder{ - public static function getNetworkTypeId() : int{ - return -1; //TODO: ideally we shouldn't have to specify this at all here ... - } + public static function getNetworkTypeId() : string{ return EntityIds::PLAYER; } /** @var PlayerInventory */ protected $inventory; diff --git a/src/entity/Squid.php b/src/entity/Squid.php index 209f63a8b..b39913bfa 100644 --- a/src/entity/Squid.php +++ b/src/entity/Squid.php @@ -29,7 +29,7 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\VanillaItems; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use function atan2; use function mt_rand; use function sqrt; @@ -37,7 +37,7 @@ use const M_PI; class Squid extends WaterAnimal{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::SQUID; } + public static function getNetworkTypeId() : string{ return EntityIds::SQUID; } public $width = 0.95; public $height = 0.95; diff --git a/src/entity/Villager.php b/src/entity/Villager.php index bdc0e33ae..f4329ade6 100644 --- a/src/entity/Villager.php +++ b/src/entity/Villager.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\entity; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; @@ -36,7 +36,7 @@ class Villager extends Living implements Ageable{ public const PROFESSION_BLACKSMITH = 3; public const PROFESSION_BUTCHER = 4; - public static function getNetworkTypeId() : int{ return EntityLegacyIds::VILLAGER; } + public static function getNetworkTypeId() : string{ return EntityIds::VILLAGER; } public $width = 0.6; public $height = 1.8; diff --git a/src/entity/Zombie.php b/src/entity/Zombie.php index 307d9d574..91a43b11c 100644 --- a/src/entity/Zombie.php +++ b/src/entity/Zombie.php @@ -24,12 +24,12 @@ declare(strict_types=1); namespace pocketmine\entity; use pocketmine\item\VanillaItems; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use function mt_rand; class Zombie extends Living{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::ZOMBIE; } + public static function getNetworkTypeId() : string{ return EntityIds::ZOMBIE; } public $width = 0.6; public $height = 1.8; diff --git a/src/entity/object/ExperienceOrb.php b/src/entity/object/ExperienceOrb.php index a58ba1034..6594369b8 100644 --- a/src/entity/object/ExperienceOrb.php +++ b/src/entity/object/ExperienceOrb.php @@ -28,7 +28,7 @@ use pocketmine\entity\Human; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ShortTag; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; use pocketmine\player\Player; @@ -36,7 +36,7 @@ use function sqrt; class ExperienceOrb extends Entity{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::XP_ORB; } + public static 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 a3d78e785..0ad553ae9 100644 --- a/src/entity/object/FallingBlock.php +++ b/src/entity/object/FallingBlock.php @@ -33,14 +33,14 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; use function abs; class FallingBlock extends Entity{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::FALLING_BLOCK; } + public static function getNetworkTypeId() : string{ return EntityIds::FALLING_BLOCK; } public $width = 0.98; public $height = 0.98; diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 3c835c0f4..23c32c688 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -32,13 +32,13 @@ use pocketmine\item\Item; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\convert\TypeConverter; use pocketmine\network\mcpe\protocol\AddItemActorPacket; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\player\Player; use function max; class ItemEntity extends Entity{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::ITEM; } + public static function getNetworkTypeId() : string{ return EntityIds::ITEM; } public const DEFAULT_DESPAWN_DELAY = 6000; //5 minutes public const NEVER_DESPAWN = -1; diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index 9282199f1..8aa53f6aa 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -33,14 +33,14 @@ use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\AddPaintingPacket; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\player\Player; use pocketmine\world\particle\DestroyBlockParticle; use pocketmine\world\World; use function ceil; class Painting extends Entity{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::PAINTING; } + public static 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 1a22d030b..76244509c 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -28,7 +28,7 @@ use pocketmine\entity\Explosive; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\ExplosionPrimeEvent; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; @@ -38,7 +38,7 @@ use pocketmine\world\sound\IgniteSound; class PrimedTNT extends Entity implements Explosive{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::TNT; } + public static function getNetworkTypeId() : string{ return EntityIds::TNT; } public $width = 0.98; public $height = 0.98; diff --git a/src/entity/projectile/Arrow.php b/src/entity/projectile/Arrow.php index d94679747..a5961dc2c 100644 --- a/src/entity/projectile/Arrow.php +++ b/src/entity/projectile/Arrow.php @@ -32,7 +32,7 @@ use pocketmine\event\inventory\InventoryPickupArrowEvent; use pocketmine\item\VanillaItems; use pocketmine\math\RayTraceResult; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags; use pocketmine\player\Player; @@ -42,7 +42,7 @@ use function sqrt; class Arrow extends Projectile{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::ARROW; } + public static 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 a2ccbb41a..c12af4731 100644 --- a/src/entity/projectile/Egg.php +++ b/src/entity/projectile/Egg.php @@ -25,11 +25,11 @@ namespace pocketmine\entity\projectile; use pocketmine\event\entity\ProjectileHitEvent; use pocketmine\item\VanillaItems; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\world\particle\ItemBreakParticle; class Egg extends Throwable{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::EGG; } + public static 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 378952521..2714ab81d 100644 --- a/src/entity/projectile/EnderPearl.php +++ b/src/entity/projectile/EnderPearl.php @@ -25,12 +25,12 @@ namespace pocketmine\entity\projectile; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\ProjectileHitEvent; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\world\particle\EndermanTeleportParticle; use pocketmine\world\sound\EndermanTeleportSound; class EnderPearl extends Throwable{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::ENDER_PEARL; } + public static 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 0c787a04e..e6c026af3 100644 --- a/src/entity/projectile/ExperienceBottle.php +++ b/src/entity/projectile/ExperienceBottle.php @@ -24,13 +24,13 @@ declare(strict_types=1); namespace pocketmine\entity\projectile; use pocketmine\event\entity\ProjectileHitEvent; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\world\particle\PotionSplashParticle; use pocketmine\world\sound\PotionSplashSound; use function mt_rand; class ExperienceBottle extends Throwable{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::XP_BOTTLE; } + public static function getNetworkTypeId() : string{ return EntityIds::XP_BOTTLE; } protected $gravity = 0.07; diff --git a/src/entity/projectile/Snowball.php b/src/entity/projectile/Snowball.php index b758505b6..54c18b6e3 100644 --- a/src/entity/projectile/Snowball.php +++ b/src/entity/projectile/Snowball.php @@ -24,11 +24,11 @@ declare(strict_types=1); namespace pocketmine\entity\projectile; use pocketmine\event\entity\ProjectileHitEvent; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\world\particle\SnowballPoofParticle; class Snowball extends Throwable{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::SNOWBALL; } + public static 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 a6f2cf0b4..f4f0c1443 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -34,7 +34,7 @@ use pocketmine\event\entity\ProjectileHitEntityEvent; use pocketmine\event\entity\ProjectileHitEvent; use pocketmine\item\Potion; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds; +use pocketmine\network\mcpe\protocol\types\entity\EntityIds; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags; use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties; @@ -46,7 +46,7 @@ use function sqrt; class SplashPotion extends Throwable{ - public static function getNetworkTypeId() : int{ return EntityLegacyIds::SPLASH_POTION; } + public static function getNetworkTypeId() : string{ return EntityIds::SPLASH_POTION; } protected $gravity = 0.05; protected $drag = 0.01; diff --git a/src/network/mcpe/protocol/types/entity/EntityIds.php b/src/network/mcpe/protocol/types/entity/EntityIds.php new file mode 100644 index 000000000..22bd83490 --- /dev/null +++ b/src/network/mcpe/protocol/types/entity/EntityIds.php @@ -0,0 +1,144 @@ +blockLandedOn->getRuntimeId(), - $this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :( + $this->entity::getNetworkTypeId() //TODO: does isBaby have any relevance here? ); } diff --git a/src/world/sound/EntityLongFallSound.php b/src/world/sound/EntityLongFallSound.php index 896cc8f0b..93378e218 100644 --- a/src/world/sound/EntityLongFallSound.php +++ b/src/world/sound/EntityLongFallSound.php @@ -23,11 +23,9 @@ declare(strict_types=1); namespace pocketmine\world\sound; -use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap; use pocketmine\entity\Entity; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; -use pocketmine\player\Player; /** * Played when an entity hits ground after falling a long distance (damage). @@ -47,7 +45,7 @@ class EntityLongFallSound implements Sound{ LevelSoundEventPacket::SOUND_FALL_BIG, $pos, -1, - $this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :( + $this->entity::getNetworkTypeId() //TODO: is isBaby relevant here? ); } diff --git a/src/world/sound/EntityShortFallSound.php b/src/world/sound/EntityShortFallSound.php index ff1f1bbb1..d1f096ce2 100644 --- a/src/world/sound/EntityShortFallSound.php +++ b/src/world/sound/EntityShortFallSound.php @@ -23,11 +23,9 @@ declare(strict_types=1); namespace pocketmine\world\sound; -use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap; use pocketmine\entity\Entity; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; -use pocketmine\player\Player; /** * Played when an entity hits the ground after falling a short distance. @@ -46,7 +44,7 @@ class EntityShortFallSound implements Sound{ LevelSoundEventPacket::SOUND_FALL_SMALL, $pos, -1, - $this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :( + $this->entity::getNetworkTypeId() //TODO: does isBaby have any relevance here? ); }