From d637370b8346df86a2f5fc349f1bcaeb91a1d7d3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 23 Oct 2023 17:38:04 +0100 Subject: [PATCH] Wipe internal block AABB cache only for specific blocks that need it the vast majority of blocks don't need this cache erasing, so it's costing performance for no good reason. --- src/block/Block.php | 9 +++------ src/block/Door.php | 2 ++ src/block/Fence.php | 2 ++ src/block/Stair.php | 2 ++ src/block/Thin.php | 2 ++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/block/Block.php b/src/block/Block.php index 5d87db879..a1d553b9d 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -346,17 +346,13 @@ class Block{ /** * Called when this block is created, set, or has a neighbouring block update, to re-detect dynamic properties which - * are not saved on the world. - * - * Clears any cached precomputed objects, such as bounding boxes. Remove any outdated precomputed things such as - * AABBs and force recalculation. + * are not saved in the blockstate ID. + * If any such properties are updated, don't forget to clear things like AABB caches if necessary. * * A replacement block may be returned. This is useful if the block type changed due to reading of world data (e.g. * data from a block entity). */ public function readStateFromWorld() : Block{ - $this->collisionBoxes = null; - return $this; } @@ -596,6 +592,7 @@ class Block{ */ final public function position(World $world, int $x, int $y, int $z) : void{ $this->position = new Position($x, $y, $z, $world); + $this->collisionBoxes = null; } /** diff --git a/src/block/Door.php b/src/block/Door.php index c97c5bb1e..82ddaab51 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -51,6 +51,8 @@ class Door extends Transparent{ public function readStateFromWorld() : Block{ parent::readStateFromWorld(); + $this->collisionBoxes = null; + //copy door properties from other half $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); if($other instanceof Door && $other->hasSameTypeId($this)){ diff --git a/src/block/Fence.php b/src/block/Fence.php index 4fa571b67..30caaa4cf 100644 --- a/src/block/Fence.php +++ b/src/block/Fence.php @@ -40,6 +40,8 @@ class Fence extends Transparent{ public function readStateFromWorld() : Block{ parent::readStateFromWorld(); + $this->collisionBoxes = null; + foreach(Facing::HORIZONTAL as $facing){ $block = $this->getSide($facing); if($block instanceof static || $block instanceof FenceGate || $block->getSupportType(Facing::opposite($facing)) === SupportType::FULL){ diff --git a/src/block/Stair.php b/src/block/Stair.php index 25d1da8d9..1acaac962 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -49,6 +49,8 @@ class Stair extends Transparent{ public function readStateFromWorld() : Block{ parent::readStateFromWorld(); + $this->collisionBoxes = null; + $clockwise = Facing::rotateY($this->facing, true); if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){ $this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT : StairShape::OUTER_LEFT; diff --git a/src/block/Thin.php b/src/block/Thin.php index bf82c3e58..dde2d7d84 100644 --- a/src/block/Thin.php +++ b/src/block/Thin.php @@ -39,6 +39,8 @@ class Thin extends Transparent{ public function readStateFromWorld() : Block{ parent::readStateFromWorld(); + $this->collisionBoxes = null; + foreach(Facing::HORIZONTAL as $facing){ $side = $this->getSide($facing); if($side instanceof Thin || $side instanceof Wall || $side->getSupportType(Facing::opposite($facing)) === SupportType::FULL){