mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
World: extract getBlockCollisionBoxes() from getCollisionBoxes()
closes #6104 This function has been a footgun for anyone using it, since it also returns entity AABBs by default. In all core use cases, this functionality was disabled, and we were paying a needless (admittedly micro) performance penalty for passing the extra useless argument and useless condition check.
This commit is contained in:
parent
48dcf0e32c
commit
c7a358a56f
@ -842,7 +842,7 @@ abstract class Entity{
|
||||
|
||||
protected function checkObstruction(float $x, float $y, float $z) : bool{
|
||||
$world = $this->getWorld();
|
||||
if(count($world->getCollisionBoxes($this, $this->getBoundingBox(), false)) === 0){
|
||||
if(count($world->getBlockCollisionBoxes($this->boundingBox)) === 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1144,7 +1144,7 @@ abstract class Entity{
|
||||
|
||||
assert(abs($dx) <= 20 && abs($dy) <= 20 && abs($dz) <= 20, "Movement distance is excessive: dx=$dx, dy=$dy, dz=$dz");
|
||||
|
||||
$list = $this->getWorld()->getCollisionBoxes($this, $moveBB->addCoord($dx, $dy, $dz), false);
|
||||
$list = $this->getWorld()->getBlockCollisionBoxes($moveBB->addCoord($dx, $dy, $dz));
|
||||
|
||||
foreach($list as $bb){
|
||||
$dy = $bb->calculateYOffset($moveBB, $dy);
|
||||
@ -1176,7 +1176,7 @@ abstract class Entity{
|
||||
|
||||
$stepBB = clone $this->boundingBox;
|
||||
|
||||
$list = $this->getWorld()->getCollisionBoxes($this, $stepBB->addCoord($dx, $dy, $dz), false);
|
||||
$list = $this->getWorld()->getBlockCollisionBoxes($stepBB->addCoord($dx, $dy, $dz));
|
||||
foreach($list as $bb){
|
||||
$dy = $bb->calculateYOffset($stepBB, $dy);
|
||||
}
|
||||
|
@ -1526,7 +1526,7 @@ class World implements ChunkManager{
|
||||
*
|
||||
* @return AxisAlignedBB[]
|
||||
*/
|
||||
private function getCollisionBoxesForCell(int $x, int $y, int $z) : array{
|
||||
private function getBlockCollisionBoxesForCell(int $x, int $y, int $z) : array{
|
||||
$block = $this->getBlockAt($x, $y, $z);
|
||||
$boxes = $block->getCollisionBoxes();
|
||||
|
||||
@ -1547,7 +1547,7 @@ class World implements ChunkManager{
|
||||
* @return AxisAlignedBB[]
|
||||
* @phpstan-return list<AxisAlignedBB>
|
||||
*/
|
||||
public function getCollisionBoxes(Entity $entity, AxisAlignedBB $bb, bool $entities = true) : array{
|
||||
public function getBlockCollisionBoxes(AxisAlignedBB $bb) : array{
|
||||
$minX = (int) floor($bb->minX);
|
||||
$minY = (int) floor($bb->minY);
|
||||
$minZ = (int) floor($bb->minZ);
|
||||
@ -1563,7 +1563,7 @@ class World implements ChunkManager{
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$relativeBlockHash = World::chunkBlockHash($x, $y, $z);
|
||||
|
||||
$boxes = $this->blockCollisionBoxCache[$chunkPosHash][$relativeBlockHash] ??= $this->getCollisionBoxesForCell($x, $y, $z);
|
||||
$boxes = $this->blockCollisionBoxCache[$chunkPosHash][$relativeBlockHash] ??= $this->getBlockCollisionBoxesForCell($x, $y, $z);
|
||||
|
||||
foreach($boxes as $blockBB){
|
||||
if($blockBB->intersectsWith($bb)){
|
||||
@ -1574,6 +1574,19 @@ class World implements ChunkManager{
|
||||
}
|
||||
}
|
||||
|
||||
return $collides;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link World::getBlockCollisionBoxes()} instead (alongside {@link World::getCollidingEntities()}
|
||||
* if entity collision boxes are also required).
|
||||
*
|
||||
* @return AxisAlignedBB[]
|
||||
* @phpstan-return list<AxisAlignedBB>
|
||||
*/
|
||||
public function getCollisionBoxes(Entity $entity, AxisAlignedBB $bb, bool $entities = true) : array{
|
||||
$collides = $this->getBlockCollisionBoxes($bb);
|
||||
|
||||
if($entities){
|
||||
foreach($this->getCollidingEntities($bb->expandedCopy(0.25, 0.25, 0.25), $entity) as $ent){
|
||||
$collides[] = clone $ent->boundingBox;
|
||||
|
Loading…
x
Reference in New Issue
Block a user