From 99a0c2a18846bd7f8055ab81552456d10cd5c383 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 21 Jun 2018 19:58:28 +0100 Subject: [PATCH] Block: Make recalculation of BB non-dependent on block position This now computes BBs relative to 0,0,0 and then offsets them as appropriate. This requires less boilerplate code and also furthers the goal of separating block types from instances. --- src/pocketmine/block/Anvil.php | 18 +--- src/pocketmine/block/Bed.php | 9 +- src/pocketmine/block/Block.php | 15 ++- src/pocketmine/block/Cactus.php | 11 +-- src/pocketmine/block/Cake.php | 13 ++- src/pocketmine/block/Carpet.php | 10 +- src/pocketmine/block/Chest.php | 9 +- src/pocketmine/block/CobblestoneWall.php | 12 +-- src/pocketmine/block/Door.php | 118 +++-------------------- src/pocketmine/block/EndPortalFrame.php | 12 +-- src/pocketmine/block/EndRod.php | 36 +++---- src/pocketmine/block/Farmland.php | 10 +- src/pocketmine/block/Fence.php | 48 ++++----- src/pocketmine/block/FenceGate.php | 25 +++-- src/pocketmine/block/FlowerPot.php | 10 +- src/pocketmine/block/GrassPath.php | 9 +- src/pocketmine/block/Ladder.php | 12 +-- src/pocketmine/block/Skull.php | 10 +- src/pocketmine/block/Slab.php | 18 +--- src/pocketmine/block/SoulSand.php | 10 +- src/pocketmine/block/Stair.php | 18 +--- src/pocketmine/block/Thin.php | 48 ++++----- src/pocketmine/block/Trapdoor.php | 54 ++--------- src/pocketmine/block/Vine.php | 10 +- src/pocketmine/block/WaterLily.php | 11 +-- 25 files changed, 149 insertions(+), 407 deletions(-) diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index d4b09eae6..8729925ab 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -76,23 +76,9 @@ class Anvil extends Fallable{ $inset = 0.125; if($this->meta & 0x01){ //east/west - return new AxisAlignedBB( - $this->x, - $this->y, - $this->z + $inset, - $this->x + 1, - $this->y + 1, - $this->z + 1 - $inset - ); + return new AxisAlignedBB(0, 0, $inset, 1, 1, 1 - $inset); }else{ - return new AxisAlignedBB( - $this->x + $inset, - $this->y, - $this->z, - $this->x + 1 - $inset, - $this->y + 1, - $this->z + 1 - ); + return new AxisAlignedBB($inset, 0, 0, 1 - $inset, 1, 1); } } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index 8a3131616..b4024b238 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -55,14 +55,7 @@ class Bed extends Transparent{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - return new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 0.5625, - $this->z + 1 - ); + return new AxisAlignedBB(0, 0, 0, 1, 0.5625, 1); } public function isHeadPart() : bool{ diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 42d77663b..74e1dd05f 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -657,6 +657,9 @@ class Block extends Position implements BlockIds, Metadatable{ public function getCollisionBoxes() : array{ if($this->collisionBoxes === null){ $this->collisionBoxes = $this->recalculateCollisionBoxes(); + foreach($this->collisionBoxes as $bb){ + $bb->offset($this->x, $this->y, $this->z); + } } return $this->collisionBoxes; @@ -679,6 +682,9 @@ class Block extends Position implements BlockIds, Metadatable{ public function getBoundingBox() : ?AxisAlignedBB{ if($this->boundingBox === null){ $this->boundingBox = $this->recalculateBoundingBox(); + if($this->boundingBox !== null){ + $this->boundingBox->offset($this->x, $this->y, $this->z); + } } return $this->boundingBox; } @@ -687,14 +693,7 @@ class Block extends Position implements BlockIds, Metadatable{ * @return AxisAlignedBB|null */ protected function recalculateBoundingBox() : ?AxisAlignedBB{ - return new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + return new AxisAlignedBB(0, 0, 0, 1, 1, 1); } /** diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 02118d898..bd980f588 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -54,15 +54,8 @@ class Cactus extends Transparent{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - - return new AxisAlignedBB( - $this->x + 0.0625, - $this->y + 0.0625, - $this->z + 0.0625, - $this->x + 0.9375, - $this->y + 0.9375, - $this->z + 0.9375 - ); + static $shrinkSize = 0.0625; + return new AxisAlignedBB($shrinkSize, $shrinkSize, $shrinkSize, 1 - $shrinkSize, 1 - $shrinkSize, 1 - $shrinkSize); } public function onEntityCollide(Entity $entity) : void{ diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index f67fa4e7d..d4c46d520 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -48,16 +48,15 @@ class Cake extends Transparent implements FoodSource{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $f = $this->getDamage() * 0.125; //1 slice width return new AxisAlignedBB( - $this->x + 0.0625 + $f, - $this->y, - $this->z + 0.0625, - $this->x + 1 - 0.0625, - $this->y + 0.5, - $this->z + 1 - 0.0625 + 0.0625 + $f, + 0, + 0.0625, + 1 - 0.0625, + 0.5, + 1 - 0.0625 ); } diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index 3631248f3..6c0189a50 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -50,15 +50,7 @@ class Carpet extends Flowable{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - - return new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 0.0625, - $this->z + 1 - ); + return new AxisAlignedBB(0, 0, 0, 1, 0.0625, 1); } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index b11809ef2..a0b8d1a61 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -52,14 +52,7 @@ class Chest extends Transparent{ protected function recalculateBoundingBox() : ?AxisAlignedBB{ //these are slightly bigger than in PC - return new AxisAlignedBB( - $this->x + 0.025, - $this->y, - $this->z + 0.025, - $this->x + 0.975, - $this->y + 0.95, - $this->z + 0.975 - ); + return new AxisAlignedBB(0.025, 0, 0.025, 0.975, 0.95, 0.975); } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ diff --git a/src/pocketmine/block/CobblestoneWall.php b/src/pocketmine/block/CobblestoneWall.php index 1e9e611ee..34bd9a8b1 100644 --- a/src/pocketmine/block/CobblestoneWall.php +++ b/src/pocketmine/block/CobblestoneWall.php @@ -78,12 +78,12 @@ class CobblestoneWall extends Transparent{ } return new AxisAlignedBB( - $this->x + ($west ? 0 : $inset), - $this->y, - $this->z + ($north ? 0 : $inset), - $this->x + 1 - ($east ? 0 : $inset), - $this->y + 1.5, - $this->z + 1 - ($south ? 0 : $inset) + ($west ? 0 : $inset), + 0, + ($north ? 0 : $inset), + 1 - ($east ? 0 : $inset), + 1.5, + 1 - ($south ? 0 : $inset) ); } diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index a23df95f0..3b4f54af7 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -54,18 +54,10 @@ abstract class Door extends Transparent{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $f = 0.1875; $damage = $this->getFullDamage(); - $bb = new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 2, - $this->z + 1 - ); + $bb = new AxisAlignedBB(0, 0, 0, 1, 2, 1); $j = $damage & 0x03; $isOpen = (($damage & 0x04) > 0); @@ -74,126 +66,42 @@ abstract class Door extends Transparent{ if($j === 0){ if($isOpen){ if(!$isRight){ - $bb->setBounds( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + $f - ); + $bb->setBounds(0, 0, 0, 1, 1, $f); }else{ - $bb->setBounds( - $this->x, - $this->y, - $this->z + 1 - $f, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); } }else{ - $bb->setBounds( - $this->x, - $this->y, - $this->z, - $this->x + $f, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(0, 0, 0, $f, 1, 1); } }elseif($j === 1){ if($isOpen){ if(!$isRight){ - $bb->setBounds( - $this->x + 1 - $f, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); }else{ - $bb->setBounds( - $this->x, - $this->y, - $this->z, - $this->x + $f, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(0, 0, 0, $f, 1, 1); } }else{ - $bb->setBounds( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + $f - ); + $bb->setBounds(0, 0, 0, 1, 1, $f); } }elseif($j === 2){ if($isOpen){ if(!$isRight){ - $bb->setBounds( - $this->x, - $this->y, - $this->z + 1 - $f, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); }else{ - $bb->setBounds( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + $f - ); + $bb->setBounds(0, 0, 0, 1, 1, $f); } }else{ - $bb->setBounds( - $this->x + 1 - $f, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); } }elseif($j === 3){ if($isOpen){ if(!$isRight){ - $bb->setBounds( - $this->x, - $this->y, - $this->z, - $this->x + $f, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(0, 0, 0, $f, 1, 1); }else{ - $bb->setBounds( - $this->x + 1 - $f, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); } }else{ - $bb->setBounds( - $this->x, - $this->y, - $this->z + 1 - $f, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); } } diff --git a/src/pocketmine/block/EndPortalFrame.php b/src/pocketmine/block/EndPortalFrame.php index 5ecf29556..1e51399b6 100644 --- a/src/pocketmine/block/EndPortalFrame.php +++ b/src/pocketmine/block/EndPortalFrame.php @@ -57,12 +57,12 @@ class EndPortalFrame extends Solid{ protected function recalculateBoundingBox() : ?AxisAlignedBB{ return new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + (($this->getDamage() & 0x04) > 0 ? 1 : 0.8125), - $this->z + 1 + 0, + 0, + 0, + 1, + (($this->getDamage() & 0x04) > 0 ? 1 : 0.8125), + 1 ); } } diff --git a/src/pocketmine/block/EndRod.php b/src/pocketmine/block/EndRod.php index 91251ab75..da64cc568 100644 --- a/src/pocketmine/block/EndRod.php +++ b/src/pocketmine/block/EndRod.php @@ -68,30 +68,30 @@ class EndRod extends Flowable{ switch($m){ case 0x00: //up/down return new AxisAlignedBB( - $this->x + $width, - $this->y, - $this->z + $width, - $this->x + 1 - $width, - $this->y + 1, - $this->z + 1 - $width + $width, + 0, + $width, + 1 - $width, + 1, + 1 - $width ); case 0x02: //north/south return new AxisAlignedBB( - $this->x, - $this->y + $width, - $this->z + $width, - $this->x + 1, - $this->y + 1 - $width, - $this->z + 1 - $width + 0, + $width, + $width, + 1, + 1 - $width, + 1 - $width ); case 0x04: //east/west return new AxisAlignedBB( - $this->x + $width, - $this->y + $width, - $this->z, - $this->x + 1 - $width, - $this->y + 1 - $width, - $this->z + 1 + $width, + $width, + 0, + 1 - $width, + 1 - $width, + 1 ); } diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 1da290a60..9c473a512 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -48,16 +48,8 @@ class Farmland extends Transparent{ return BlockToolType::TYPE_SHOVEL; } - protected function recalculateBoundingBox() : ?AxisAlignedBB{ - return new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, //TODO: this should be 0.9375, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109) - $this->z + 1 - ); + return new AxisAlignedBB(0, 0, 0, 1, 1, 1); //TODO: y max should be 0.9375, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109) } public function onNearbyBlockChange() : void{ diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index 1e579c1eb..aa9cdd00f 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -40,12 +40,12 @@ abstract class Fence extends Transparent{ $width = 0.5 - $this->getThickness() / 2; return new AxisAlignedBB( - $this->x + ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), - $this->y, - $this->z + ($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width), - $this->x + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width), - $this->y + 1.5, - $this->z + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width) + ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), + 0, + ($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width), + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width), + 1.5, + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width) ); } @@ -61,12 +61,12 @@ abstract class Fence extends Transparent{ if($connectWest or $connectEast){ //X axis (west/east) $bbs[] = new AxisAlignedBB( - $this->x + ($connectWest ? 0 : $inset), - $this->y, - $this->z + $inset, - $this->x + 1 - ($connectEast ? 0 : $inset), - $this->y + 1.5, - $this->z + 1 - $inset + ($connectWest ? 0 : $inset), + 0, + $inset, + 1 - ($connectEast ? 0 : $inset), + 1.5, + 1 - $inset ); } @@ -76,12 +76,12 @@ abstract class Fence extends Transparent{ if($connectNorth or $connectSouth){ //Z axis (north/south) $bbs[] = new AxisAlignedBB( - $this->x + $inset, - $this->y, - $this->z + ($connectNorth ? 0 : $inset), - $this->x + 1 - $inset, - $this->y + 1.5, - $this->z + 1 - ($connectSouth ? 0 : $inset) + $inset, + 0, + ($connectNorth ? 0 : $inset), + 1 - $inset, + 1.5, + 1 - ($connectSouth ? 0 : $inset) ); } @@ -89,12 +89,12 @@ abstract class Fence extends Transparent{ //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( - $this->x + $inset, - $this->y, - $this->z + $inset, - $this->x + 1 - $inset, - $this->y + 1.5, - $this->z + 1 - $inset + $inset, + 0, + $inset, + 1 - $inset, + 1.5, + 1 - $inset ) ]; } diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 8f08a10c9..1d7a93b9c 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -41,7 +41,6 @@ class FenceGate extends Transparent{ protected function recalculateBoundingBox() : ?AxisAlignedBB{ - if(($this->getDamage() & 0x04) > 0){ return null; } @@ -49,21 +48,21 @@ class FenceGate extends Transparent{ $i = ($this->getDamage() & 0x03); if($i === 2 or $i === 0){ return new AxisAlignedBB( - $this->x, - $this->y, - $this->z + 0.375, - $this->x + 1, - $this->y + 1.5, - $this->z + 0.625 + 0, + 0, + 0.375, + 1, + 1.5, + 0.625 ); }else{ return new AxisAlignedBB( - $this->x + 0.375, - $this->y, - $this->z, - $this->x + 0.625, - $this->y + 1.5, - $this->z + 1 + 0.375, + 0, + 0, + 0.625, + 1.5, + 1 ); } } diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index cc5d3b9ed..3f92b7cc0 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -47,14 +47,8 @@ class FlowerPot extends Flowable{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - return new AxisAlignedBB( - $this->x + 0.3125, - $this->y, - $this->z + 0.3125, - $this->x + 0.6875, - $this->y + 0.375, - $this->z + 0.6875 - ); + static $f = 0.3125; + return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.375, 1 - $f); } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ diff --git a/src/pocketmine/block/GrassPath.php b/src/pocketmine/block/GrassPath.php index 712f3e547..e58c40224 100644 --- a/src/pocketmine/block/GrassPath.php +++ b/src/pocketmine/block/GrassPath.php @@ -45,14 +45,7 @@ class GrassPath extends Transparent{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - return new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, //TODO: this should be 0.9375, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109) - $this->z + 1 - ); + return new AxisAlignedBB(0, 0, 0, 1, 1, 1); //TODO: y max should be 0.9375, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109) } public function getHardness() : float{ diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index 062b972d5..49729cac2 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -79,12 +79,12 @@ class Ladder extends Transparent{ } return new AxisAlignedBB( - $this->x + $minX, - $this->y, - $this->z + $minZ, - $this->x + $maxX, - $this->y + 1, - $this->z + $maxZ + $minX, + 0, + $minZ, + $maxX, + 1, + $maxZ ); } diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 9e4c6c425..dc74b96eb 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -49,14 +49,8 @@ class Skull extends Flowable{ protected function recalculateBoundingBox() : ?AxisAlignedBB{ //TODO: different bounds depending on attached face (meta) - return new AxisAlignedBB( - $this->x + 0.25, - $this->y, - $this->z + 0.25, - $this->x + 0.75, - $this->y + 0.5, - $this->z + 0.75 - ); + static $f = 0.25; + return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.5, 1 - $f); } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 8444479b6..319d03998 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -107,23 +107,9 @@ abstract class Slab extends Transparent{ protected function recalculateBoundingBox() : ?AxisAlignedBB{ if(($this->meta & 0x08) > 0){ - return new AxisAlignedBB( - $this->x, - $this->y + 0.5, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + return new AxisAlignedBB(0, 0.5, 0, 1, 1, 1); }else{ - return new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 0.5, - $this->z + 1 - ); + return new AxisAlignedBB(0, 0, 0, 1, 0.5, 1); } } } diff --git a/src/pocketmine/block/SoulSand.php b/src/pocketmine/block/SoulSand.php index dbe6deadc..5e402678e 100644 --- a/src/pocketmine/block/SoulSand.php +++ b/src/pocketmine/block/SoulSand.php @@ -46,14 +46,6 @@ class SoulSand extends Solid{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - - return new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1 - 0.125, - $this->z + 1 - ); + return new AxisAlignedBB(0, 0, 0, 1, 1 - 0.125, 1); } } diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index e45e25482..27e66a24e 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -37,14 +37,7 @@ abstract class Stair extends Transparent{ $maxYSlab = $minYSlab + 0.5; $bbs = [ - new AxisAlignedBB( - $this->x, - $this->y + $minYSlab, - $this->z, - $this->x + 1, - $this->y + $maxYSlab, - $this->z + 1 - ) + new AxisAlignedBB(0, $minYSlab, 0, 1, $maxYSlab, 1) ]; $minY = ($this->meta & 0x04) === 0 ? 0.5 : 0; @@ -70,14 +63,7 @@ abstract class Stair extends Transparent{ break; } - $bbs[] = new AxisAlignedBB( - $this->x + $minX, - $this->y + $minY, - $this->z + $minZ, - $this->x + $maxX, - $this->y + $maxY, - $this->z + $maxZ - ); + $bbs[] = new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ); return $bbs; } diff --git a/src/pocketmine/block/Thin.php b/src/pocketmine/block/Thin.php index 108e8728d..fb6b5f91c 100644 --- a/src/pocketmine/block/Thin.php +++ b/src/pocketmine/block/Thin.php @@ -32,12 +32,12 @@ abstract class Thin extends Transparent{ $width = 0.5 - 0.125 / 2; return new AxisAlignedBB( - $this->x + ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), - $this->y, - $this->z + ($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width), - $this->x + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width), - $this->y + 1, - $this->z + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width) + ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), + 0, + ($this->canConnect($this->getSide(Vector3::SIDE_NORTH)) ? 0 : $width), + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_EAST)) ? 0 : $width), + 1, + 1 - ($this->canConnect($this->getSide(Vector3::SIDE_SOUTH)) ? 0 : $width) ); } @@ -53,12 +53,12 @@ abstract class Thin extends Transparent{ if($connectWest or $connectEast){ //X axis (west/east) $bbs[] = new AxisAlignedBB( - $this->x + ($connectWest ? 0 : $inset), - $this->y, - $this->z + $inset, - $this->x + 1 - ($connectEast ? 0 : $inset), - $this->y + 1, - $this->z + 1 - $inset + ($connectWest ? 0 : $inset), + 0, + $inset, + 1 - ($connectEast ? 0 : $inset), + 1, + 1 - $inset ); } @@ -68,12 +68,12 @@ abstract class Thin extends Transparent{ if($connectNorth or $connectSouth){ //Z axis (north/south) $bbs[] = new AxisAlignedBB( - $this->x + $inset, - $this->y, - $this->z + ($connectNorth ? 0 : $inset), - $this->x + 1 - $inset, - $this->y + 1, - $this->z + 1 - ($connectSouth ? 0 : $inset) + $inset, + 0, + ($connectNorth ? 0 : $inset), + 1 - $inset, + 1, + 1 - ($connectSouth ? 0 : $inset) ); } @@ -81,12 +81,12 @@ abstract class Thin extends Transparent{ //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( - $this->x + $inset, - $this->y, - $this->z + $inset, - $this->x + 1 - $inset, - $this->y + 1, - $this->z + 1 - $inset + $inset, + 0, + $inset, + 1 - $inset, + 1, + 1 - $inset ) ]; } diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 25c747cbd..1dfde7d44 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -59,64 +59,22 @@ class Trapdoor extends Transparent{ $f = 0.1875; if(($damage & self::MASK_UPPER) > 0){ - $bb = new AxisAlignedBB( - $this->x, - $this->y + 1 - $f, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb = new AxisAlignedBB(0, 1 - $f, 0, 1, 1, 1); }else{ - $bb = new AxisAlignedBB( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + $f, - $this->z + 1 - ); + $bb = new AxisAlignedBB(0, 0, 0, 1, $f, 1); } if(($damage & self::MASK_OPENED) > 0){ if(($damage & 0x03) === self::MASK_SIDE_NORTH){ - $bb->setBounds( - $this->x, - $this->y, - $this->z + 1 - $f, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); }elseif(($damage & 0x03) === self::MASK_SIDE_SOUTH){ - $bb->setBounds( - $this->x, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + $f - ); + $bb->setBounds(0, 0, 0, 1, 1, $f); } if(($damage & 0x03) === self::MASK_SIDE_WEST){ - $bb->setBounds( - $this->x + 1 - $f, - $this->y, - $this->z, - $this->x + 1, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); } if(($damage & 0x03) === self::MASK_SIDE_EAST){ - $bb->setBounds( - $this->x, - $this->y, - $this->z, - $this->x + $f, - $this->y + 1, - $this->z + 1 - ); + $bb->setBounds(0, 0, 0, $f, 1, 1); } } diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index f589d7d21..f9c27a65e 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -70,7 +70,6 @@ class Vine extends Flowable{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $minX = 1; $minY = 1; $minZ = 1; @@ -121,14 +120,7 @@ class Vine extends Flowable{ $maxZ = 1; } - return new AxisAlignedBB( - $this->x + $minX, - $this->y + $minY, - $this->z + $minZ, - $this->x + $maxX, - $this->y + $maxY, - $this->z + $maxZ - ); + return new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ); } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ diff --git a/src/pocketmine/block/WaterLily.php b/src/pocketmine/block/WaterLily.php index 5327857d5..78eb3cd33 100644 --- a/src/pocketmine/block/WaterLily.php +++ b/src/pocketmine/block/WaterLily.php @@ -45,17 +45,10 @@ class WaterLily extends Flowable{ } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - return new AxisAlignedBB( - $this->x + 0.0625, - $this->y, - $this->z + 0.0625, - $this->x + 0.9375, - $this->y + 0.015625, - $this->z + 0.9375 - ); + static $f = 0.0625; + return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.015625, 1 - $f); } - public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ if($blockClicked instanceof Water){ $up = $blockClicked->getSide(Vector3::SIDE_UP);