From c0c684b12e0c5f34170771c9ca941a9b2ea9cdb8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 25 Mar 2018 13:15:10 +0100 Subject: [PATCH] Removed the need for paintings to check for destruction on schedule Since we have a mechanism for triggering things on entities anyway, make use of it to do more than just forcing movement updates. --- src/pocketmine/entity/Entity.php | 5 +++ src/pocketmine/entity/object/Painting.php | 45 ++++++++--------------- src/pocketmine/level/Level.php | 3 +- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 5a37b2c8a..cfec599be 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1375,6 +1375,11 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->level->updateEntities[$this->id] = $this; } + public function onNearbyBlockChange() : void{ + $this->setForceMovementUpdate(); + $this->scheduleUpdate(); + } + /** * Flags the entity as needing a movement update on the next tick. Setting this forces a movement update even if the * entity's motion is zero. Used to trigger movement updates when blocks change near entities. diff --git a/src/pocketmine/entity/object/Painting.php b/src/pocketmine/entity/object/Painting.php index ce4019980..cb0831901 100644 --- a/src/pocketmine/entity/object/Painting.php +++ b/src/pocketmine/entity/object/Painting.php @@ -50,8 +50,6 @@ class Painting extends Entity{ protected $direction = 0; /** @var string */ protected $motive; - /** @var int */ - protected $checkDestroyedTicker = 0; public function __construct(Level $level, CompoundTag $nbt){ $this->motive = $nbt->getString("Motive"); @@ -80,33 +78,6 @@ class Painting extends Entity{ $this->namedtag->setByte("Direction", (int) $this->direction); //Save both for full compatibility } - public function entityBaseTick(int $tickDiff = 1) : bool{ - static $directions = [ - 0 => Vector3::SIDE_SOUTH, - 1 => Vector3::SIDE_WEST, - 2 => Vector3::SIDE_NORTH, - 3 => Vector3::SIDE_EAST - ]; - - $hasUpdate = parent::entityBaseTick($tickDiff); - - if($this->checkDestroyedTicker++ > 10){ - /* - * we don't have a way to only update on local block updates yet! since random chunk ticking always updates - * all the things - * ugly hack, but vanilla uses 100 ticks so on there it looks even worse - */ - $this->checkDestroyedTicker = 0; - $face = $directions[$this->direction]; - if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){ - $this->kill(); - $hasUpdate = true; - } - } - - return $hasUpdate; //doesn't need to be ticked always - } - public function kill(){ parent::kill(); @@ -139,6 +110,22 @@ class Painting extends Entity{ $this->boundingBox->setBB(self::getPaintingBB($this->blockIn->getSide($facing), $facing, $this->getMotive())); } + public function onNearbyBlockChange() : void{ + parent::onNearbyBlockChange(); + + static $directions = [ + 0 => Vector3::SIDE_SOUTH, + 1 => Vector3::SIDE_WEST, + 2 => Vector3::SIDE_NORTH, + 3 => Vector3::SIDE_EAST + ]; + + $face = $directions[$this->direction]; + if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){ + $this->kill(); + } + } + public function hasMovementUpdate() : bool{ return false; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 7646bf87c..7d305e5bd 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1549,8 +1549,7 @@ class Level implements ChunkManager, Metadatable{ $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block)); if(!$ev->isCancelled()){ foreach($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){ - $entity->setForceMovementUpdate(); - $entity->scheduleUpdate(); + $entity->onNearbyBlockChange(); } $ev->getBlock()->onNearbyBlockChange(); $this->scheduleNeighbourBlockUpdates($pos);