From 27798c69eef9bfe549989c395bb34dfb4acc675a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 29 Sep 2017 15:27:14 +0100 Subject: [PATCH] fix collision detection not detecting fence & fence-gate, fixed nether-brick fence gate AABB, close #1299 --- src/pocketmine/block/Fence.php | 3 +-- src/pocketmine/block/NetherBrickFence.php | 19 ++++++++++++++--- src/pocketmine/level/Level.php | 26 ++++++++++++----------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index 771ce24e5..cf7512605 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -85,11 +85,10 @@ class Fence extends Transparent{ } public function canConnect(Block $block){ - return ($block instanceof Fence or $block instanceof FenceGate) ? true : $block->isSolid() and !$block->isTransparent(); + return $block instanceof Fence or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent()); } public function getFuelTime() : int{ return 300; } - } diff --git a/src/pocketmine/block/NetherBrickFence.php b/src/pocketmine/block/NetherBrickFence.php index 974e653d9..59a87c9d4 100644 --- a/src/pocketmine/block/NetherBrickFence.php +++ b/src/pocketmine/block/NetherBrickFence.php @@ -25,6 +25,8 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; +use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Vector3; class NetherBrickFence extends Transparent{ @@ -46,8 +48,21 @@ class NetherBrickFence extends Transparent{ return "Nether Brick Fence"; } + protected function recalculateBoundingBox(){ + $width = 0.375; + + 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) + ); + } + public function canConnect(Block $block){ - return ($block instanceof NetherBrickFence) or ($block->isSolid() and !$block->isTransparent()); + return $block instanceof NetherBrickFence or $block instanceof FenceGate or ($block->isSolid() and !$block->isTransparent()); } public function getDrops(Item $item) : array{ @@ -57,6 +72,4 @@ class NetherBrickFence extends Transparent{ return []; } - - //TODO: fix bounding boxes } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 561de400b..f2c189e3c 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1094,12 +1094,13 @@ class Level implements ChunkManager, Metadatable{ * @return Block[] */ public function getCollisionBlocks(AxisAlignedBB $bb, bool $targetFirst = false) : array{ - $minX = Math::floorFloat($bb->minX); - $minY = Math::floorFloat($bb->minY); - $minZ = Math::floorFloat($bb->minZ); - $maxX = Math::ceilFloat($bb->maxX); - $maxY = Math::ceilFloat($bb->maxY); - $maxZ = Math::ceilFloat($bb->maxZ); + $bbPlusOne = $bb->grow(1, 1, 1); + $minX = Math::floorFloat($bbPlusOne->minX); + $minY = Math::floorFloat($bbPlusOne->minY); + $minZ = Math::floorFloat($bbPlusOne->minZ); + $maxX = Math::ceilFloat($bbPlusOne->maxX); + $maxY = Math::ceilFloat($bbPlusOne->maxY); + $maxZ = Math::ceilFloat($bbPlusOne->maxZ); $collides = []; @@ -1157,12 +1158,13 @@ class Level implements ChunkManager, Metadatable{ * @return AxisAlignedBB[] */ public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb, bool $entities = true) : array{ - $minX = Math::floorFloat($bb->minX); - $minY = Math::floorFloat($bb->minY); - $minZ = Math::floorFloat($bb->minZ); - $maxX = Math::ceilFloat($bb->maxX); - $maxY = Math::ceilFloat($bb->maxY); - $maxZ = Math::ceilFloat($bb->maxZ); + $bbPlusOne = $bb->grow(1, 1, 1); + $minX = Math::floorFloat($bbPlusOne->minX); + $minY = Math::floorFloat($bbPlusOne->minY); + $minZ = Math::floorFloat($bbPlusOne->minZ); + $maxX = Math::ceilFloat($bbPlusOne->maxX); + $maxY = Math::ceilFloat($bbPlusOne->maxY); + $maxZ = Math::ceilFloat($bbPlusOne->maxZ); $collides = [];