From 85c6eb50031db1964ff0981e0968610b93d3ef50 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 12 May 2019 16:22:41 +0100 Subject: [PATCH] Fence: cleanup some BB handling --- src/pocketmine/block/Fence.php | 53 ++++++++++++++-------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index caad4df8e..31ec5e9bf 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -50,14 +50,14 @@ abstract class Fence extends Transparent{ protected function recalculateBoundingBox() : ?AxisAlignedBB{ $width = 0.5 - $this->getThickness() / 2; - return new AxisAlignedBB( - (isset($this->connections[Facing::WEST]) ? 0 : $width), - 0, - (isset($this->connections[Facing::NORTH]) ? 0 : $width), - 1 - (isset($this->connections[Facing::EAST]) ? 0 : $width), - 1.5, - 1 - (isset($this->connections[Facing::WEST]) ? 0 : $width) - ); + $bb = AxisAlignedBB::one() + ->extend(Facing::UP, 0.5); + foreach(Facing::HORIZONTAL as $facing){ + if(!isset($this->connections[$facing])){ + $bb->trim($facing, $width); + } + } + return $bb; } protected function recalculateCollisionBoxes() : array{ @@ -71,14 +71,11 @@ abstract class Fence extends Transparent{ if($connectWest or $connectEast){ //X axis (west/east) - $bbs[] = new AxisAlignedBB( - ($connectWest ? 0 : $inset), - 0, - $inset, - 1 - ($connectEast ? 0 : $inset), - 1.5, - 1 - $inset - ); + $bbs[] = AxisAlignedBB::one() + ->squash(Facing::AXIS_Z, $inset) + ->extend(Facing::UP, 0.5) + ->trim(Facing::WEST, $connectWest ? 0 : $inset) + ->trim(Facing::EAST, $connectEast ? 0 : $inset); } $connectNorth = isset($this->connections[Facing::NORTH]); @@ -86,27 +83,19 @@ abstract class Fence extends Transparent{ if($connectNorth or $connectSouth){ //Z axis (north/south) - $bbs[] = new AxisAlignedBB( - $inset, - 0, - ($connectNorth ? 0 : $inset), - 1 - $inset, - 1.5, - 1 - ($connectSouth ? 0 : $inset) - ); + $bbs[] = AxisAlignedBB::one() + ->squash(Facing::AXIS_X, $inset) + ->extend(Facing::UP, 0.5) + ->trim(Facing::NORTH, $connectNorth ? 0 : $inset) + ->trim(Facing::SOUTH, $connectSouth ? 0 : $inset); } if(empty($bbs)){ //centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made) return [ - new AxisAlignedBB( - $inset, - 0, - $inset, - 1 - $inset, - 1.5, - 1 - $inset - ) + AxisAlignedBB::one() + ->extend(Facing::UP, 0.5) + ->contract($inset, 0, $inset) ]; }