diff --git a/src/pocketmine/block/CobblestoneWall.php b/src/pocketmine/block/CobblestoneWall.php index 4e5b7ff3e..3d8c7bdc0 100644 --- a/src/pocketmine/block/CobblestoneWall.php +++ b/src/pocketmine/block/CobblestoneWall.php @@ -27,7 +27,7 @@ use pocketmine\item\Tool; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; -class CobblestoneWall extends Transparent{ +class CobblestoneWall extends Fence{ const NONE_MOSSY_WALL = 0; const MOSSY_WALL = 1; @@ -37,10 +37,6 @@ class CobblestoneWall extends Transparent{ $this->meta = $meta; } - public function isSolid() : bool{ - return false; - } - public function getToolType() : int{ return Tool::TYPE_PICKAXE; } @@ -57,38 +53,8 @@ class CobblestoneWall extends Transparent{ return "Cobblestone Wall"; } - protected function recalculateBoundingBox() : ?AxisAlignedBB{ - - $north = $this->canConnect($this->getSide(Vector3::SIDE_NORTH)); - $south = $this->canConnect($this->getSide(Vector3::SIDE_SOUTH)); - $west = $this->canConnect($this->getSide(Vector3::SIDE_WEST)); - $east = $this->canConnect($this->getSide(Vector3::SIDE_EAST)); - - $n = $north ? 0 : 0.25; - $s = $south ? 1 : 0.75; - $w = $west ? 0 : 0.25; - $e = $east ? 1 : 0.75; - - if($north and $south and !$west and !$east){ - $w = 0.3125; - $e = 0.6875; - }elseif(!$north and !$south and $west and $east){ - $n = 0.3125; - $s = 0.6875; - } - - return new AxisAlignedBB( - $this->x + $w, - $this->y, - $this->z + $n, - $this->x + $e, - $this->y + 1.5, - $this->z + $s - ); - } - - public function canConnect(Block $block){ - return ($block->getId() !== self::COBBLESTONE_WALL and $block->getId() !== self::FENCE_GATE) ? $block->isSolid() and !$block->isTransparent() : true; + public function getThickness() : float{ + return 0.5; } } diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index 2166854b7..6ee70e5d0 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -32,8 +32,12 @@ abstract class Fence extends Transparent{ $this->meta = $meta; } + public function getThickness() : float{ + return 0.25; + } + protected function recalculateBoundingBox() : ?AxisAlignedBB{ - $width = 0.375; + $width = 0.5 - $this->getThickness() / 2; return new AxisAlignedBB( $this->x + ($this->canConnect($this->getSide(Vector3::SIDE_WEST)) ? 0 : $width), @@ -45,6 +49,80 @@ abstract class Fence extends Transparent{ ); } + protected function recalculateCollisionBoxes() : array{ + $inset = 0.5 - $this->getThickness() / 2; + + $bbs = [ + new AxisAlignedBB( //centre post AABB + $this->x + $inset, + $this->y, + $this->z + $inset, + $this->x + 1 - $inset, + $this->y + 1.5, + $this->z + 1 - $inset + ) + ]; + + if($this->canConnect($this->getSide(Vector3::SIDE_WEST))){ + //western side connected part from start X to post (negative X) + // + // -# + // + $bbs[] = new AxisAlignedBB( + $this->x, + $this->y, + $this->z + $inset, + $this->x + $inset, //don't overlap with centre post + $this->y + 1.5, + $this->z + 1 - $inset + ); + } + if($this->canConnect($this->getSide(Vector3::SIDE_EAST))){ + //eastern side connected part from post to end X (positive X) + // + // #- + // + $bbs[] = new AxisAlignedBB( + $this->x + 1 - $inset, + $this->y, + $this->z + $inset, + $this->x + 1, + $this->y + 1.5, + $this->z + 1 - $inset + ); + } + if($this->canConnect($this->getSide(Vector3::SIDE_NORTH))){ + //northern side connected part from start Z to post (negative Z) + // | + // # + // + $bbs[] = new AxisAlignedBB( + $this->x + $inset, + $this->y, + $this->z, + $this->x + 1 - $inset, + $this->y + 1.5, + $this->z + $inset + ); + } + if($this->canConnect($this->getSide(Vector3::SIDE_SOUTH))){ + //southern side connected part from post to end Z (positive Z) + // + // # + // | + $bbs[] = new AxisAlignedBB( + $this->x + $inset, + $this->y, + $this->z + 1 - $inset, + $this->x + 1 - $inset, + $this->y + 1.5, + $this->z + 1 + ); + } + + return $bbs; + } + public function canConnect(Block $block){ return $block instanceof static or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent()); }