diff --git a/composer.lock b/composer.lock index 72dd12b7a..5ea2d220a 100644 --- a/composer.lock +++ b/composer.lock @@ -187,12 +187,12 @@ "source": { "type": "git", "url": "https://github.com/pmmp/Math.git", - "reference": "115700a493fc38fe8886739c20c4303eeb1cd182" + "reference": "93a430a089da009b44b710cca0c4fd4c2f06e702" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/Math/zipball/115700a493fc38fe8886739c20c4303eeb1cd182", - "reference": "115700a493fc38fe8886739c20c4303eeb1cd182", + "url": "https://api.github.com/repos/pmmp/Math/zipball/93a430a089da009b44b710cca0c4fd4c2f06e702", + "reference": "93a430a089da009b44b710cca0c4fd4c2f06e702", "shasum": "" }, "require": { @@ -218,7 +218,7 @@ "source": "https://github.com/pmmp/Math/tree/master", "issues": "https://github.com/pmmp/Math/issues" }, - "time": "2018-09-23T17:50:23+00:00" + "time": "2018-11-23T19:38:18+00:00" }, { "name": "pocketmine/nbt", diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index d3212e03b..065c8b8ac 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -76,11 +76,8 @@ class Anvil extends Fallable{ public function recalculateBoundingBox() : ?AxisAlignedBB{ $inset = 0.125; - if(Facing::axis($this->facing) === Facing::AXIS_X){ - return new AxisAlignedBB(0, 0, $inset, 1, 1, 1 - $inset); - }else{ - return new AxisAlignedBB($inset, 0, 0, 1 - $inset, 1, 1); - } + $bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1); + return $bb->squash(Facing::axis(Facing::rotate($this->facing, Facing::AXIS_Y, false)), $inset); } public function onActivate(Item $item, Player $player = null) : bool{ diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index f306cccc8..15523b53c 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -74,36 +74,12 @@ class CocoaBlock extends Transparent{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - static $logDistance = 1 / 16; + $bb = new AxisAlignedBB(0, (7 - $this->age * 2) / 16, 0, 1, 0.75, 1); - $widthInset = (6 - $this->age) / 16; - $faceDistance = (5 + $this->age * 2) / 16; - - $minY = (7 - $this->age * 2) / 16; - - if(Facing::isPositive($this->facing)){ - $minFacing = $logDistance; - $maxFacing = $faceDistance; - }else{ - $minFacing = 1 - $faceDistance; - $maxFacing = 1 - $logDistance; - } - - if(Facing::axis($this->facing) === Facing::AXIS_Z){ - $minX = $widthInset; - $maxX = 1 - $widthInset; - - $minZ = $minFacing; - $maxZ = $maxFacing; - }else{ - $minX = $minFacing; - $maxX = $maxFacing; - - $minZ = $widthInset; - $maxZ = 1 - $widthInset; - } - - return new AxisAlignedBB($minX, $minY, $minZ, $maxX, 0.75, $maxZ); + return $bb + ->squash(Facing::axis(Facing::rotate($this->facing, Facing::AXIS_Y, true)), (6 - $this->age) / 16) //sides + ->trim(Facing::opposite($this->facing), 1 / 16) //gap between log and pod + ->trim($this->facing, (11 - $this->age * 2) / 16); //outward face } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index a99638ef3..5aea3c1ec 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -91,54 +91,10 @@ abstract class Door extends Transparent{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $f = 0.1875; $this->updateStateFromOtherHalf(); $bb = new AxisAlignedBB(0, 0, 0, 1, 2, 1); - - if($this->facing === Facing::EAST){ - if($this->open){ - if(!$this->hingeRight){ - $bb->setBounds(0, 0, 0, 1, 1, $f); - }else{ - $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); - } - }else{ - $bb->setBounds(0, 0, 0, $f, 1, 1); - } - }elseif($this->facing === Facing::SOUTH){ - if($this->open){ - if(!$this->hingeRight){ - $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); - }else{ - $bb->setBounds(0, 0, 0, $f, 1, 1); - } - }else{ - $bb->setBounds(0, 0, 0, 1, 1, $f); - } - }elseif($this->facing === Facing::WEST){ - if($this->open){ - if(!$this->hingeRight){ - $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); - }else{ - $bb->setBounds(0, 0, 0, 1, 1, $f); - } - }else{ - $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); - } - }elseif($this->facing === Facing::NORTH){ - if($this->open){ - if(!$this->hingeRight){ - $bb->setBounds(0, 0, 0, $f, 1, 1); - }else{ - $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); - } - }else{ - $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); - } - } - - return $bb; + return $bb->trim($this->open ? Facing::rotate($this->facing, Facing::AXIS_Y, !$this->hingeRight) : $this->facing, 13 / 16); } public function onNearbyBlockChange() : void{ diff --git a/src/pocketmine/block/EndRod.php b/src/pocketmine/block/EndRod.php index c639fc495..d4caf3bc4 100644 --- a/src/pocketmine/block/EndRod.php +++ b/src/pocketmine/block/EndRod.php @@ -81,40 +81,15 @@ class EndRod extends Flowable{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $m = Facing::axis($this->facing); - $width = 0.375; + $myAxis = Facing::axis($this->facing); - switch($m){ - case Facing::AXIS_Y: - return new AxisAlignedBB( - $width, - 0, - $width, - 1 - $width, - 1, - 1 - $width - ); - case Facing::AXIS_Z: - return new AxisAlignedBB( - $width, - $width, - 0, - 1 - $width, - 1 - $width, - 1 - ); - - case Facing::AXIS_X: - return new AxisAlignedBB( - 0, - $width, - $width, - 1, - 1 - $width, - 1 - $width - ); + $bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1); + foreach([Facing::AXIS_Y, Facing::AXIS_Z, Facing::AXIS_X] as $axis){ + if($axis === $myAxis){ + continue; + } + $bb->squash($axis, 6 / 16); } - - return null; + return $bb; } } diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index cd8878a45..6da249915 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -64,25 +64,8 @@ class FenceGate extends Transparent{ return null; } - if(Facing::axis($this->facing) === Facing::AXIS_Z){ - return new AxisAlignedBB( - 0, - 0, - 0.375, - 1, - 1.5, - 0.625 - ); - }else{ - return new AxisAlignedBB( - 0.375, - 0, - 0, - 0.625, - 1.5, - 1 - ); - } + $bb = new AxisAlignedBB(0, 0, 0, 1, 1.5, 1); + return $bb->squash(Facing::axis($this->facing), 6 / 16); } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index b309fa18a..f6f2218b0 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -79,29 +79,8 @@ class Ladder extends Transparent{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $f = 0.1875; - - $minX = $minZ = 0; - $maxX = $maxZ = 1; - - if($this->facing === Facing::NORTH){ - $minZ = 1 - $f; - }elseif($this->facing === Facing::SOUTH){ - $maxZ = $f; - }elseif($this->facing === Facing::WEST){ - $minX = 1 - $f; - }elseif($this->facing === Facing::EAST){ - $maxX = $f; - } - - return new AxisAlignedBB( - $minX, - 0, - $minZ, - $maxX, - 1, - $maxZ - ); + $bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1); + return $bb->trim($this->facing, 13 / 16); } diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index dcdaf1ac0..cdf4019ca 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -59,17 +59,17 @@ abstract class Stair extends Transparent{ $minY = $this->upsideDown ? 0 : 0.5; $topStep = new AxisAlignedBB(0, $minY, 0, 1, $minY + 0.5, 1); - self::setBoundsForFacing($topStep, $this->facing); + $topStep->trim(Facing::opposite($this->facing), 0.5); /** @var Stair $corner */ if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){ - self::setBoundsForFacing($topStep, $backFacing); + $topStep->trim(Facing::opposite($backFacing), 0.5); }elseif(($frontFacing = $this->getPossibleCornerFacing(true)) !== null){ //add an extra cube $extraCube = new AxisAlignedBB(0, $minY, 0, 1, $minY + 0.5, 1); - self::setBoundsForFacing($extraCube, Facing::opposite($this->facing)); - self::setBoundsForFacing($extraCube, $frontFacing); - $bbs[] = $extraCube; + $bbs[] = $extraCube + ->trim($this->facing, 0.5) + ->trim(Facing::opposite($frontFacing), 0.5); } $bbs[] = $topStep; @@ -88,25 +88,6 @@ abstract class Stair extends Transparent{ return null; } - private static function setBoundsForFacing(AxisAlignedBB $bb, int $facing) : void{ - switch($facing){ - case Facing::EAST: - $bb->minX = 0.5; - break; - case Facing::WEST: - $bb->maxX = 0.5; - break; - case Facing::SOUTH: - $bb->minZ = 0.5; - break; - case Facing::NORTH: - $bb->maxZ = 0.5; - break; - default: - throw new \InvalidArgumentException("Facing must be horizontal"); - } - } - public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($player !== null){ $this->facing = Bearing::toFacing($player->getDirection()); diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index b9a5dbdae..42cb728b9 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -73,27 +73,8 @@ class Trapdoor extends Transparent{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $f = 0.1875; - - if($this->top){ - $bb = new AxisAlignedBB(0, 1 - $f, 0, 1, 1, 1); - }else{ - $bb = new AxisAlignedBB(0, 0, 0, 1, $f, 1); - } - - if($this->open){ - if($this->facing === Facing::NORTH){ - $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); - }elseif($this->facing === Facing::SOUTH){ - $bb->setBounds(0, 0, 0, 1, 1, $f); - }elseif($this->facing === Facing::WEST){ - $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); - }elseif($this->facing === Facing::EAST){ - $bb->setBounds(0, 0, 0, $f, 1, 1); - } - } - - return $bb; + $bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1); + return $bb->trim($this->open ? $this->facing : ($this->top ? Facing::DOWN : Facing::UP), 13 / 16); } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{