forked from NetherGamesMC/PocketMine-MP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
16 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1627,18 +1627,13 @@ public function getCollisionBlocks(AxisAlignedBB $bb, bool $targetFirst = false) | |
|
||
$collides = []; | ||
|
||
$collisionInfo = $this->blockStateRegistry->collisionInfo; | ||
if($targetFirst){ | ||
for($z = $minZ; $z <= $maxZ; ++$z){ | ||
for($x = $minX; $x <= $maxX; ++$x){ | ||
for($y = $minY; $y <= $maxY; ++$y){ | ||
$stateCollisionInfo = $this->getBlockCollisionInfo($x, $y, $z, $collisionInfo); | ||
if(match($stateCollisionInfo){ | ||
RuntimeBlockStateRegistry::COLLISION_CUBE => true, | ||
RuntimeBlockStateRegistry::COLLISION_NONE => false, | ||
default => $this->getBlockAt($x, $y, $z)->collidesWithBB($bb) | ||
}){ | ||
return [$this->getBlockAt($x, $y, $z)]; | ||
$block = $this->getBlockAt($x, $y, $z); | ||
if($block->collidesWithBB($bb)){ | ||
return [$block]; | ||
} | ||
} | ||
} | ||
|
@@ -1647,13 +1642,9 @@ public function getCollisionBlocks(AxisAlignedBB $bb, bool $targetFirst = false) | |
for($z = $minZ; $z <= $maxZ; ++$z){ | ||
for($x = $minX; $x <= $maxX; ++$x){ | ||
for($y = $minY; $y <= $maxY; ++$y){ | ||
$stateCollisionInfo = $this->getBlockCollisionInfo($x, $y, $z, $collisionInfo); | ||
if(match($stateCollisionInfo){ | ||
RuntimeBlockStateRegistry::COLLISION_CUBE => true, | ||
RuntimeBlockStateRegistry::COLLISION_NONE => false, | ||
default => $this->getBlockAt($x, $y, $z)->collidesWithBB($bb) | ||
}){ | ||
$collides[] = $this->getBlockAt($x, $y, $z); | ||
$block = $this->getBlockAt($x, $y, $z); | ||
if($block->collidesWithBB($bb)){ | ||
$collides[] = $block; | ||
} | ||
} | ||
} | ||
|
@@ -1696,31 +1687,15 @@ private function getBlockCollisionInfo(int $x, int $y, int $z, array $collisionI | |
* @return AxisAlignedBB[] | ||
* @phpstan-return list<AxisAlignedBB> | ||
*/ | ||
private function getBlockCollisionBoxesForCell(int $x, int $y, int $z, array $collisionInfo) : array{ | ||
$stateCollisionInfo = $this->getBlockCollisionInfo($x, $y, $z, $collisionInfo); | ||
$boxes = match($stateCollisionInfo){ | ||
RuntimeBlockStateRegistry::COLLISION_NONE => [], | ||
RuntimeBlockStateRegistry::COLLISION_CUBE => [AxisAlignedBB::one()->offset($x, $y, $z)], | ||
default => $this->getBlockAt($x, $y, $z)->getCollisionBoxes() | ||
}; | ||
|
||
//overlapping AABBs can't make any difference if this is a cube, so we can save some CPU cycles in this common case | ||
if($stateCollisionInfo !== RuntimeBlockStateRegistry::COLLISION_CUBE){ | ||
$cellBB = null; | ||
foreach(Facing::OFFSET as [$dx, $dy, $dz]){ | ||
$offsetX = $x + $dx; | ||
$offsetY = $y + $dy; | ||
$offsetZ = $z + $dz; | ||
$stateCollisionInfo = $this->getBlockCollisionInfo($offsetX, $offsetY, $offsetZ, $collisionInfo); | ||
if($stateCollisionInfo === RuntimeBlockStateRegistry::COLLISION_MAY_OVERFLOW){ | ||
//avoid allocating this unless it's needed | ||
$cellBB ??= AxisAlignedBB::one()->offset($x, $y, $z); | ||
$extraBoxes = $this->getBlockAt($offsetX, $offsetY, $offsetZ)->getCollisionBoxes(); | ||
foreach($extraBoxes as $extraBox){ | ||
if($extraBox->intersectsWith($cellBB)){ | ||
$boxes[] = $extraBox; | ||
} | ||
} | ||
private function getBlockCollisionBoxesForCell(int $x, int $y, int $z) : array{ | ||
Check failure on line 1690 in src/world/World.php
|
||
$block = $this->getBlockAt($x, $y, $z); | ||
$boxes = $block->getCollisionBoxes(); | ||
$cellBB = AxisAlignedBB::one()->offset($x, $y, $z); | ||
foreach(Facing::OFFSET as [$dx, $dy, $dz]){ | ||
$extraBoxes = $this->getBlockAt($x + $dx, $y + $dy, $z + $dz)->getCollisionBoxes(); | ||
foreach($extraBoxes as $extraBox){ | ||
if($extraBox->intersectsWith($cellBB)){ | ||
$boxes[] = $extraBox; | ||
} | ||
} | ||
} | ||
|
@@ -1750,7 +1725,7 @@ public function getBlockCollisionBoxes(AxisAlignedBB $bb) : array{ | |
for($y = $minY; $y <= $maxY; ++$y){ | ||
$relativeBlockHash = World::chunkBlockHash($x, $y, $z); | ||
|
||
$boxes = $this->blockCollisionBoxCache[$chunkPosHash][$relativeBlockHash] ??= $this->getBlockCollisionBoxesForCell($x, $y, $z, $collisionInfo); | ||
$boxes = $this->blockCollisionBoxCache[$chunkPosHash][$relativeBlockHash] ??= $this->getBlockCollisionBoxesForCell($x, $y, $z); | ||
|
||
foreach($boxes as $blockBB){ | ||
if($blockBB->intersectsWith($bb)){ | ||
|