mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
Entity: add abstract getNetworkTypeId(), remove NETWORK_ID constant
this now requires that subclasses supply a proper NETWORK_ID.
This commit is contained in:
parent
67666db827
commit
c30dd9f1b6
@ -80,8 +80,6 @@ abstract class Entity{
|
|||||||
|
|
||||||
public const MOTION_THRESHOLD = 0.00001;
|
public const MOTION_THRESHOLD = 0.00001;
|
||||||
|
|
||||||
public const NETWORK_ID = -1;
|
|
||||||
|
|
||||||
/** @var Player[] */
|
/** @var Player[] */
|
||||||
protected $hasSpawned = [];
|
protected $hasSpawned = [];
|
||||||
|
|
||||||
@ -1506,13 +1504,15 @@ abstract class Entity{
|
|||||||
return $this->hasSpawned;
|
return $this->hasSpawned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract public static function getNetworkTypeId() : int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
protected function sendSpawnPacket(Player $player) : void{
|
protected function sendSpawnPacket(Player $player) : void{
|
||||||
$pk = new AddActorPacket();
|
$pk = new AddActorPacket();
|
||||||
$pk->entityRuntimeId = $this->getId();
|
$pk->entityRuntimeId = $this->getId();
|
||||||
$pk->type = LegacyEntityIdToStringIdMap::getInstance()->legacyToString(static::NETWORK_ID);
|
$pk->type = LegacyEntityIdToStringIdMap::getInstance()->legacyToString(static::getNetworkTypeId());
|
||||||
$pk->position = $this->location->asVector3();
|
$pk->position = $this->location->asVector3();
|
||||||
$pk->motion = $this->getMotion();
|
$pk->motion = $this->getMotion();
|
||||||
$pk->yaw = $this->location->yaw;
|
$pk->yaw = $this->location->yaw;
|
||||||
|
@ -66,6 +66,10 @@ use function strlen;
|
|||||||
|
|
||||||
class Human extends Living implements ProjectileSource, InventoryHolder{
|
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 ...
|
||||||
|
}
|
||||||
|
|
||||||
/** @var PlayerInventory */
|
/** @var PlayerInventory */
|
||||||
protected $inventory;
|
protected $inventory;
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ use function sqrt;
|
|||||||
use const M_PI;
|
use const M_PI;
|
||||||
|
|
||||||
class Squid extends WaterAnimal{
|
class Squid extends WaterAnimal{
|
||||||
public const NETWORK_ID = EntityLegacyIds::SQUID;
|
|
||||||
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::SQUID; }
|
||||||
|
|
||||||
public $width = 0.95;
|
public $width = 0.95;
|
||||||
public $height = 0.95;
|
public $height = 0.95;
|
||||||
|
@ -35,7 +35,7 @@ class Villager extends Living implements Ageable{
|
|||||||
public const PROFESSION_BLACKSMITH = 3;
|
public const PROFESSION_BLACKSMITH = 3;
|
||||||
public const PROFESSION_BUTCHER = 4;
|
public const PROFESSION_BUTCHER = 4;
|
||||||
|
|
||||||
public const NETWORK_ID = EntityLegacyIds::VILLAGER;
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::VILLAGER; }
|
||||||
|
|
||||||
public $width = 0.6;
|
public $width = 0.6;
|
||||||
public $height = 1.8;
|
public $height = 1.8;
|
||||||
|
@ -28,7 +28,8 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
|||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class Zombie extends Living{
|
class Zombie extends Living{
|
||||||
public const NETWORK_ID = EntityLegacyIds::ZOMBIE;
|
|
||||||
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::ZOMBIE; }
|
||||||
|
|
||||||
public $width = 0.6;
|
public $width = 0.6;
|
||||||
public $height = 1.8;
|
public $height = 1.8;
|
||||||
|
@ -31,10 +31,12 @@ use pocketmine\nbt\tag\ShortTag;
|
|||||||
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
||||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
|
use function realpath;
|
||||||
use function sqrt;
|
use function sqrt;
|
||||||
|
|
||||||
class ExperienceOrb extends Entity{
|
class ExperienceOrb extends Entity{
|
||||||
public const NETWORK_ID = EntityLegacyIds::XP_ORB;
|
|
||||||
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::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?)
|
||||||
|
@ -38,7 +38,8 @@ use function abs;
|
|||||||
use function get_class;
|
use function get_class;
|
||||||
|
|
||||||
class FallingBlock extends Entity{
|
class FallingBlock extends Entity{
|
||||||
public const NETWORK_ID = EntityLegacyIds::FALLING_BLOCK;
|
|
||||||
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::FALLING_BLOCK; }
|
||||||
|
|
||||||
public $width = 0.98;
|
public $width = 0.98;
|
||||||
public $height = 0.98;
|
public $height = 0.98;
|
||||||
|
@ -37,7 +37,8 @@ use function get_class;
|
|||||||
use function max;
|
use function max;
|
||||||
|
|
||||||
class ItemEntity extends Entity{
|
class ItemEntity extends Entity{
|
||||||
public const NETWORK_ID = EntityLegacyIds::ITEM;
|
|
||||||
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::ITEM; }
|
||||||
|
|
||||||
public const DEFAULT_DESPAWN_DELAY = 6000; //5 minutes
|
public const DEFAULT_DESPAWN_DELAY = 6000; //5 minutes
|
||||||
public const NEVER_DESPAWN = -1;
|
public const NEVER_DESPAWN = -1;
|
||||||
|
@ -40,7 +40,7 @@ use pocketmine\world\World;
|
|||||||
use function ceil;
|
use function ceil;
|
||||||
|
|
||||||
class Painting extends Entity{
|
class Painting extends Entity{
|
||||||
public const NETWORK_ID = EntityLegacyIds::PAINTING;
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::PAINTING; }
|
||||||
|
|
||||||
private const DATA_TO_FACING = [
|
private const DATA_TO_FACING = [
|
||||||
0 => Facing::SOUTH,
|
0 => Facing::SOUTH,
|
||||||
|
@ -36,7 +36,8 @@ use pocketmine\world\Position;
|
|||||||
use pocketmine\world\sound\IgniteSound;
|
use pocketmine\world\sound\IgniteSound;
|
||||||
|
|
||||||
class PrimedTNT extends Entity implements Explosive{
|
class PrimedTNT extends Entity implements Explosive{
|
||||||
public const NETWORK_ID = EntityLegacyIds::TNT;
|
|
||||||
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::TNT; }
|
||||||
|
|
||||||
public $width = 0.98;
|
public $width = 0.98;
|
||||||
public $height = 0.98;
|
public $height = 0.98;
|
||||||
|
@ -40,7 +40,8 @@ use function mt_rand;
|
|||||||
use function sqrt;
|
use function sqrt;
|
||||||
|
|
||||||
class Arrow extends Projectile{
|
class Arrow extends Projectile{
|
||||||
public const NETWORK_ID = EntityLegacyIds::ARROW;
|
|
||||||
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::ARROW; }
|
||||||
|
|
||||||
public const PICKUP_NONE = 0;
|
public const PICKUP_NONE = 0;
|
||||||
public const PICKUP_ANY = 1;
|
public const PICKUP_ANY = 1;
|
||||||
|
@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
|||||||
use pocketmine\world\particle\ItemBreakParticle;
|
use pocketmine\world\particle\ItemBreakParticle;
|
||||||
|
|
||||||
class Egg extends Throwable{
|
class Egg extends Throwable{
|
||||||
public const NETWORK_ID = EntityLegacyIds::EGG;
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::EGG; }
|
||||||
|
|
||||||
//TODO: spawn chickens on collision
|
//TODO: spawn chickens on collision
|
||||||
|
|
||||||
|
@ -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 const NETWORK_ID = EntityLegacyIds::ENDER_PEARL;
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::ENDER_PEARL; }
|
||||||
|
|
||||||
protected function onHit(ProjectileHitEvent $event) : void{
|
protected function onHit(ProjectileHitEvent $event) : void{
|
||||||
$owner = $this->getOwningEntity();
|
$owner = $this->getOwningEntity();
|
||||||
|
@ -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 const NETWORK_ID = EntityLegacyIds::XP_BOTTLE;
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::XP_BOTTLE; }
|
||||||
|
|
||||||
protected $gravity = 0.07;
|
protected $gravity = 0.07;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
|||||||
use pocketmine\world\particle\SnowballPoofParticle;
|
use pocketmine\world\particle\SnowballPoofParticle;
|
||||||
|
|
||||||
class Snowball extends Throwable{
|
class Snowball extends Throwable{
|
||||||
public const NETWORK_ID = EntityLegacyIds::SNOWBALL;
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::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){
|
||||||
|
@ -45,7 +45,7 @@ use function sqrt;
|
|||||||
|
|
||||||
class SplashPotion extends Throwable{
|
class SplashPotion extends Throwable{
|
||||||
|
|
||||||
public const NETWORK_ID = EntityLegacyIds::SPLASH_POTION;
|
public static function getNetworkTypeId() : int{ return EntityLegacyIds::SPLASH_POTION; }
|
||||||
|
|
||||||
protected $gravity = 0.05;
|
protected $gravity = 0.05;
|
||||||
protected $drag = 0.01;
|
protected $drag = 0.01;
|
||||||
|
@ -252,8 +252,8 @@ class ItemFactory{
|
|||||||
|
|
||||||
foreach(EntityFactory::getInstance()->getKnownTypes() as $className){
|
foreach(EntityFactory::getInstance()->getKnownTypes() as $className){
|
||||||
/** @var Living|string $className */
|
/** @var Living|string $className */
|
||||||
if(is_a($className, Living::class, true) and $className::NETWORK_ID !== -1){
|
if(is_a($className, Living::class, true) and $className::getNetworkTypeId() !== -1){
|
||||||
$this->register(new SpawnEgg(ItemIds::SPAWN_EGG, $className::NETWORK_ID, "Spawn Egg", $className));
|
$this->register(new SpawnEgg(ItemIds::SPAWN_EGG, $className::getNetworkTypeId(), "Spawn Egg", $className));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class EntityLandSound implements Sound{
|
|||||||
LevelSoundEventPacket::SOUND_LAND,
|
LevelSoundEventPacket::SOUND_LAND,
|
||||||
$pos,
|
$pos,
|
||||||
$this->blockLandedOn->getRuntimeId(),
|
$this->blockLandedOn->getRuntimeId(),
|
||||||
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::NETWORK_ID) //TODO: bad hack, stuff depends on players having a -1 network ID :(
|
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :(
|
||||||
//TODO: does isBaby have any relevance here?
|
//TODO: does isBaby have any relevance here?
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class EntityLongFallSound implements Sound{
|
|||||||
LevelSoundEventPacket::SOUND_FALL_BIG,
|
LevelSoundEventPacket::SOUND_FALL_BIG,
|
||||||
$pos,
|
$pos,
|
||||||
-1,
|
-1,
|
||||||
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::NETWORK_ID) //TODO: bad hack, stuff depends on players having a -1 network ID :(
|
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :(
|
||||||
//TODO: is isBaby relevant here?
|
//TODO: is isBaby relevant here?
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class EntityShortFallSound implements Sound{
|
|||||||
LevelSoundEventPacket::SOUND_FALL_SMALL,
|
LevelSoundEventPacket::SOUND_FALL_SMALL,
|
||||||
$pos,
|
$pos,
|
||||||
-1,
|
-1,
|
||||||
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::NETWORK_ID) //TODO: bad hack, stuff depends on players having a -1 network ID :(
|
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :(
|
||||||
//TODO: does isBaby have any relevance here?
|
//TODO: does isBaby have any relevance here?
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: ../../../src/entity/projectile/Projectile.php
|
path: ../../../src/entity/projectile/Projectile.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^If condition is always false\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: ../../../src/item/ItemFactory.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Strict comparison using \\!\\=\\= between \\-1 and \\-1 will always evaluate to false\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: ../../../src/item/ItemFactory.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^If condition is always false\\.$#"
|
message: "#^If condition is always false\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user