mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Entity: make networkProperties private
this reduces the temptation to use it in high-level code, as well as making syncNetworkData() more useful (now it can export to many data collections, which means we can start to think about having a property cache per network session, which is more flexible)
This commit is contained in:
parent
1aa92bd6a8
commit
6257f717b1
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
|
||||
abstract class Animal extends Living implements Ageable{
|
||||
@ -33,8 +34,8 @@ abstract class Animal extends Living implements Ageable{
|
||||
return $this->baby;
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::BABY, $this->baby);
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::BABY, $this->baby);
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ abstract class Entity{
|
||||
protected $id;
|
||||
|
||||
/** @var EntityMetadataCollection */
|
||||
protected $networkProperties;
|
||||
private $networkProperties;
|
||||
|
||||
/** @var Chunk|null */
|
||||
public $chunk;
|
||||
@ -1650,30 +1650,30 @@ abstract class Entity{
|
||||
* @return MetadataProperty[]
|
||||
*/
|
||||
final protected function getSyncedNetworkData(bool $dirtyOnly) : array{
|
||||
$this->syncNetworkData();
|
||||
$this->syncNetworkData($this->networkProperties);
|
||||
|
||||
return $dirtyOnly ? $this->networkProperties->getDirty() : $this->networkProperties->getAll();
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
$this->networkProperties->setByte(EntityMetadataProperties::ALWAYS_SHOW_NAMETAG, $this->alwaysShowNameTag ? 1 : 0);
|
||||
$this->networkProperties->setFloat(EntityMetadataProperties::BOUNDING_BOX_HEIGHT, $this->height);
|
||||
$this->networkProperties->setFloat(EntityMetadataProperties::BOUNDING_BOX_WIDTH, $this->width);
|
||||
$this->networkProperties->setFloat(EntityMetadataProperties::SCALE, $this->scale);
|
||||
$this->networkProperties->setLong(EntityMetadataProperties::LEAD_HOLDER_EID, -1);
|
||||
$this->networkProperties->setLong(EntityMetadataProperties::OWNER_EID, $this->ownerId ?? -1);
|
||||
$this->networkProperties->setLong(EntityMetadataProperties::TARGET_EID, $this->targetId ?? 0);
|
||||
$this->networkProperties->setString(EntityMetadataProperties::NAMETAG, $this->nameTag);
|
||||
$this->networkProperties->setString(EntityMetadataProperties::SCORE_TAG, $this->scoreTag);
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
$properties->setByte(EntityMetadataProperties::ALWAYS_SHOW_NAMETAG, $this->alwaysShowNameTag ? 1 : 0);
|
||||
$properties->setFloat(EntityMetadataProperties::BOUNDING_BOX_HEIGHT, $this->height);
|
||||
$properties->setFloat(EntityMetadataProperties::BOUNDING_BOX_WIDTH, $this->width);
|
||||
$properties->setFloat(EntityMetadataProperties::SCALE, $this->scale);
|
||||
$properties->setLong(EntityMetadataProperties::LEAD_HOLDER_EID, -1);
|
||||
$properties->setLong(EntityMetadataProperties::OWNER_EID, $this->ownerId ?? -1);
|
||||
$properties->setLong(EntityMetadataProperties::TARGET_EID, $this->targetId ?? 0);
|
||||
$properties->setString(EntityMetadataProperties::NAMETAG, $this->nameTag);
|
||||
$properties->setString(EntityMetadataProperties::SCORE_TAG, $this->scoreTag);
|
||||
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::AFFECTED_BY_GRAVITY, true);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::CAN_CLIMB, $this->canClimb);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::CAN_SHOW_NAMETAG, $this->nameTagVisible);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::HAS_COLLISION, true);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::IMMOBILE, $this->immobile);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::INVISIBLE, $this->invisible);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::ONFIRE, $this->isOnFire());
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::WALLCLIMBING, $this->canClimbWalls);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::AFFECTED_BY_GRAVITY, true);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::CAN_CLIMB, $this->canClimb);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::CAN_SHOW_NAMETAG, $this->nameTagVisible);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::HAS_COLLISION, true);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::IMMOBILE, $this->immobile);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::INVISIBLE, $this->invisible);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::ONFIRE, $this->isOnFire());
|
||||
$properties->setGenericFlag(EntityMetadataFlags::WALLCLIMBING, $this->canClimbWalls);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,6 +49,7 @@ use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\FloatTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\nbt\tag\ShortTag;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
use pocketmine\player\Player;
|
||||
@ -766,17 +767,17 @@ abstract class Living extends Entity{
|
||||
$player->getNetworkSession()->onMobArmorChange($this);
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
|
||||
$this->networkProperties->setByte(EntityMetadataProperties::POTION_AMBIENT, $this->effectManager->hasOnlyAmbientEffects() ? 1 : 0);
|
||||
$this->networkProperties->setInt(EntityMetadataProperties::POTION_COLOR, Binary::signInt($this->effectManager->getBubbleColor()->toARGB()));
|
||||
$this->networkProperties->setShort(EntityMetadataProperties::AIR, $this->breathTicks);
|
||||
$this->networkProperties->setShort(EntityMetadataProperties::MAX_AIR, $this->maxBreathTicks);
|
||||
$properties->setByte(EntityMetadataProperties::POTION_AMBIENT, $this->effectManager->hasOnlyAmbientEffects() ? 1 : 0);
|
||||
$properties->setInt(EntityMetadataProperties::POTION_COLOR, Binary::signInt($this->effectManager->getBubbleColor()->toARGB()));
|
||||
$properties->setShort(EntityMetadataProperties::AIR, $this->breathTicks);
|
||||
$properties->setShort(EntityMetadataProperties::MAX_AIR, $this->maxBreathTicks);
|
||||
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::BREATHING, $this->breathing);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::SNEAKING, $this->sneaking);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::SPRINTING, $this->sprinting);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::BREATHING, $this->breathing);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::SNEAKING, $this->sneaking);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::SPRINTING, $this->sprinting);
|
||||
}
|
||||
|
||||
protected function onDispose() : void{
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
|
||||
@ -84,10 +85,10 @@ class Villager extends Living implements Ageable{
|
||||
return $this->baby;
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::BABY, $this->baby);
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::BABY, $this->baby);
|
||||
|
||||
$this->networkProperties->setInt(EntityMetadataProperties::VARIANT, $this->profession);
|
||||
$properties->setInt(EntityMetadataProperties::VARIANT, $this->profession);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
|
||||
abstract class WaterAnimal extends Living implements Ageable{
|
||||
@ -43,8 +44,8 @@ abstract class WaterAnimal extends Living implements Ageable{
|
||||
$this->attack($ev);
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::BABY, $this->baby);
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::BABY, $this->baby);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ 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\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
use pocketmine\player\Player;
|
||||
use function sqrt;
|
||||
@ -220,9 +221,9 @@ class ExperienceOrb extends Entity{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
|
||||
$this->networkProperties->setInt(EntityMetadataProperties::EXPERIENCE_VALUE, $this->xpValue);
|
||||
$properties->setInt(EntityMetadataProperties::EXPERIENCE_VALUE, $this->xpValue);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ 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\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
use function abs;
|
||||
use function get_class;
|
||||
@ -140,9 +141,9 @@ class FallingBlock extends Entity{
|
||||
return $nbt;
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
|
||||
$this->networkProperties->setInt(EntityMetadataProperties::VARIANT, $this->block->getRuntimeId());
|
||||
$properties->setInt(EntityMetadataProperties::VARIANT, $this->block->getRuntimeId());
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ 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\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
use pocketmine\world\Explosion;
|
||||
@ -108,10 +109,10 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
}
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::IGNITED, true);
|
||||
$this->networkProperties->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::IGNITED, true);
|
||||
$properties->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ 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\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\sound\ArrowHitSound;
|
||||
@ -193,9 +194,9 @@ class Arrow extends Projectile{
|
||||
$this->flagForDespawn();
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::CRITICAL, $this->critical);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::CRITICAL, $this->critical);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ 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\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
use pocketmine\world\particle\PotionSplashParticle;
|
||||
@ -172,10 +173,10 @@ class SplashPotion extends Throwable{
|
||||
return Potion::getPotionEffectsById($this->getPotionId());
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
|
||||
$this->networkProperties->setShort(EntityMetadataProperties::POTION_AUX_VALUE, $this->potionId);
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::LINGER, $this->linger);
|
||||
$properties->setShort(EntityMetadataProperties::POTION_AUX_VALUE, $this->potionId);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::LINGER, $this->linger);
|
||||
}
|
||||
}
|
||||
|
@ -86,6 +86,7 @@ use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\network\mcpe\NetworkSession;
|
||||
use pocketmine\network\mcpe\protocol\AnimatePacket;
|
||||
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\PlayerMetadataFlags;
|
||||
@ -2181,13 +2182,13 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
||||
parent::attack($source);
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::ACTION, $this->startAction > -1);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::ACTION, $this->startAction > -1);
|
||||
|
||||
$this->networkProperties->setPlayerFlag(PlayerMetadataFlags::SLEEP, $this->sleeping !== null);
|
||||
$this->networkProperties->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, $this->sleeping ?? new Vector3(0, 0, 0));
|
||||
$properties->setPlayerFlag(PlayerMetadataFlags::SLEEP, $this->sleeping !== null);
|
||||
$properties->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, $this->sleeping ?? new Vector3(0, 0, 0));
|
||||
}
|
||||
|
||||
public function broadcastAnimation(Animation $animation, ?array $targets = null) : void{
|
||||
|
Loading…
x
Reference in New Issue
Block a user