diff --git a/src/entity/Entity.php b/src/entity/Entity.php index c3340db50..4d4442c63 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -184,6 +184,8 @@ abstract class Entity{ /** @var TimingsHandler */ protected $timings; + protected bool $networkPropertiesDirty = false; + /** @var string */ protected $nameTag = ""; /** @var bool */ @@ -269,6 +271,7 @@ abstract class Entity{ public function setNameTag(string $name) : void{ $this->nameTag = $name; + $this->networkPropertiesDirty = true; } public function setNameTagVisible(bool $value = true) : void{ @@ -277,6 +280,7 @@ abstract class Entity{ public function setNameTagAlwaysVisible(bool $value = true) : void{ $this->alwaysShowNameTag = $value; + $this->networkPropertiesDirty = true; } public function getScoreTag() : ?string{ @@ -285,6 +289,7 @@ abstract class Entity{ public function setScoreTag(string $score) : void{ $this->scoreTag = $score; + $this->networkPropertiesDirty = true; } public function getScale() : float{ @@ -300,6 +305,7 @@ abstract class Entity{ $this->scale = $value; $this->recalculateBoundingBox(); + $this->networkPropertiesDirty = true; } public function getBoundingBox() : AxisAlignedBB{ @@ -325,6 +331,7 @@ abstract class Entity{ public function setImmobile(bool $value = true) : void{ $this->immobile = $value; + $this->networkPropertiesDirty = true; } public function isInvisible() : bool{ @@ -333,6 +340,7 @@ abstract class Entity{ public function setInvisible(bool $value = true) : void{ $this->invisible = $value; + $this->networkPropertiesDirty = true; } public function isSilent() : bool{ @@ -341,6 +349,7 @@ abstract class Entity{ public function setSilent(bool $value = true) : void{ $this->silent = $value; + $this->networkPropertiesDirty = true; } /** @@ -355,6 +364,7 @@ abstract class Entity{ */ public function setCanClimb(bool $value = true) : void{ $this->canClimb = $value; + $this->networkPropertiesDirty = true; } /** @@ -369,6 +379,7 @@ abstract class Entity{ */ public function setCanClimbWalls(bool $value = true) : void{ $this->canClimbWalls = $value; + $this->networkPropertiesDirty = true; } /** @@ -398,6 +409,7 @@ abstract class Entity{ }else{ $this->ownerId = $owner->getId(); } + $this->networkPropertiesDirty = true; } /** @@ -428,6 +440,7 @@ abstract class Entity{ }else{ $this->targetId = $target->getId(); } + $this->networkPropertiesDirty = true; } /** @@ -635,6 +648,7 @@ abstract class Entity{ if($ticks > $this->getFireTicks()){ $this->setFireTicks($ticks); } + $this->networkPropertiesDirty = true; } public function getFireTicks() : int{ @@ -1580,7 +1594,10 @@ abstract class Entity{ * @phpstan-return array */ final protected function getDirtyNetworkData() : array{ - $this->syncNetworkData($this->networkProperties); + if($this->networkPropertiesDirty){ + $this->syncNetworkData($this->networkProperties); + $this->networkPropertiesDirty = false; + } return $this->networkProperties->getDirty(); } @@ -1589,7 +1606,10 @@ abstract class Entity{ * @phpstan-return array */ final protected function getAllNetworkData() : array{ - $this->syncNetworkData($this->networkProperties); + if($this->networkPropertiesDirty){ + $this->syncNetworkData($this->networkProperties); + $this->networkPropertiesDirty = false; + } return $this->networkProperties->getAll(); } diff --git a/src/entity/Living.php b/src/entity/Living.php index 6bedafacf..e11b2e5a1 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -123,6 +123,8 @@ abstract class Living extends Entity{ parent::initEntity($nbt); $this->effectManager = new EffectManager($this); + $this->effectManager->getEffectAddHooks()->add(function() : void{ $this->networkPropertiesDirty = true; }); + $this->effectManager->getEffectRemoveHooks()->add(function() : void{ $this->networkPropertiesDirty = true; }); $this->armorInventory = new ArmorInventory($this); //TODO: load/save armor inventory contents @@ -208,6 +210,7 @@ abstract class Living extends Entity{ public function setSneaking(bool $value = true) : void{ $this->sneaking = $value; + $this->networkPropertiesDirty = true; } public function isSprinting() : bool{ @@ -217,6 +220,7 @@ abstract class Living extends Entity{ public function setSprinting(bool $value = true) : void{ if($value !== $this->isSprinting()){ $this->sprinting = $value; + $this->networkPropertiesDirty = true; $moveSpeed = $this->getMovementSpeed(); $this->setMovementSpeed($value ? ($moveSpeed * 1.3) : ($moveSpeed / 1.3)); $this->moveSpeedAttr->markSynchronized(false); //TODO: reevaluate this hack @@ -643,6 +647,7 @@ abstract class Living extends Entity{ */ public function setBreathing(bool $value = true) : void{ $this->breathing = $value; + $this->networkPropertiesDirty = true; } /** @@ -658,6 +663,7 @@ abstract class Living extends Entity{ */ public function setAirSupplyTicks(int $ticks) : void{ $this->breathTicks = $ticks; + $this->networkPropertiesDirty = true; } /** @@ -672,6 +678,7 @@ abstract class Living extends Entity{ */ public function setMaxAirSupplyTicks(int $ticks) : void{ $this->maxBreathTicks = $ticks; + $this->networkPropertiesDirty = true; } /** diff --git a/src/entity/Villager.php b/src/entity/Villager.php index ac749735d..d43e4faf9 100644 --- a/src/entity/Villager.php +++ b/src/entity/Villager.php @@ -76,6 +76,7 @@ class Villager extends Living implements Ageable{ */ public function setProfession(int $profession) : void{ $this->profession = $profession; //TODO: validation + $this->networkPropertiesDirty = true; } public function getProfession() : int{ diff --git a/src/entity/object/ExperienceOrb.php b/src/entity/object/ExperienceOrb.php index 260d4f8b2..c3f0b6382 100644 --- a/src/entity/object/ExperienceOrb.php +++ b/src/entity/object/ExperienceOrb.php @@ -137,6 +137,7 @@ class ExperienceOrb extends Entity{ throw new \InvalidArgumentException("XP amount must be greater than 0, got $amount"); } $this->xpValue = $amount; + $this->networkPropertiesDirty = true; } public function hasTargetPlayer() : bool{ diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index d6e728d9d..184a30285 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -62,11 +62,15 @@ class PrimedTNT extends Entity implements Explosive{ throw new \InvalidArgumentException("Fuse must be in the range 0-32767"); } $this->fuse = $fuse; + $this->networkPropertiesDirty = true; } public function worksUnderwater() : bool{ return $this->worksUnderwater; } - public function setWorksUnderwater(bool $worksUnderwater) : void{ $this->worksUnderwater = $worksUnderwater; } + public function setWorksUnderwater(bool $worksUnderwater) : void{ + $this->worksUnderwater = $worksUnderwater; + $this->networkPropertiesDirty = true; + } public function attack(EntityDamageEvent $source) : void{ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ diff --git a/src/entity/projectile/Arrow.php b/src/entity/projectile/Arrow.php index fc163472e..d296b4092 100644 --- a/src/entity/projectile/Arrow.php +++ b/src/entity/projectile/Arrow.php @@ -96,6 +96,7 @@ class Arrow extends Projectile{ public function setCritical(bool $value = true) : void{ $this->critical = $value; + $this->networkPropertiesDirty = true; } public function getResultDamage() : int{ diff --git a/src/entity/projectile/SplashPotion.php b/src/entity/projectile/SplashPotion.php index a800ee555..7fea391af 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -150,6 +150,7 @@ class SplashPotion extends Throwable{ public function setPotionId(int $id) : void{ $this->potionId = $id; //TODO: validation + $this->networkPropertiesDirty = true; } /** @@ -164,6 +165,7 @@ class SplashPotion extends Throwable{ */ public function setLinger(bool $value = true) : void{ $this->linger = $value; + $this->networkPropertiesDirty = true; } /** diff --git a/src/player/Player.php b/src/player/Player.php index e36976345..ed8a706f4 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -594,6 +594,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ public function setUsingItem(bool $value) : void{ $this->startAction = $value ? $this->server->getTick() : -1; + $this->networkPropertiesDirty = true; } /** @@ -956,6 +957,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ } $this->sleeping = $pos; + $this->networkPropertiesDirty = true; $this->setSpawn($pos); @@ -974,6 +976,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ (new PlayerBedLeaveEvent($this, $b))->call(); $this->sleeping = null; + $this->networkPropertiesDirty = true; $this->getWorld()->setSleepTicks(0);