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.
This commit is contained in:
Dylan K. Taylor 2018-03-25 13:15:10 +01:00
parent 924334a776
commit c0c684b12e
3 changed files with 22 additions and 31 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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);