mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Entity: extract getBlocksIntersected() from getBlocksAroundWithEntityInsideActions()
This commit is contained in:
parent
207f7ec309
commit
62afa2f28d
@ -1219,32 +1219,41 @@ abstract class Entity{
|
||||
$this->onGround = ($wantedY != $dy and $wantedY < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Yields all the blocks whose full-cube areas are intersected by the entity's AABB.
|
||||
*
|
||||
* @phpstan-return \Generator<int, Block, void, void>
|
||||
*/
|
||||
protected function getBlocksIntersected(float $inset) : \Generator{
|
||||
$minX = (int) floor($this->boundingBox->minX + $inset);
|
||||
$minY = (int) floor($this->boundingBox->minY + $inset);
|
||||
$minZ = (int) floor($this->boundingBox->minZ + $inset);
|
||||
$maxX = (int) floor($this->boundingBox->maxX - $inset);
|
||||
$maxY = (int) floor($this->boundingBox->maxY - $inset);
|
||||
$maxZ = (int) floor($this->boundingBox->maxZ - $inset);
|
||||
|
||||
$world = $this->getWorld();
|
||||
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
yield $world->getBlockAt($x, $y, $z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Block[]
|
||||
*/
|
||||
protected function getBlocksAroundWithEntityInsideActions() : array{
|
||||
if($this->blocksAround === null){
|
||||
$inset = 0.001; //Offset against floating-point errors
|
||||
|
||||
$minX = (int) floor($this->boundingBox->minX + $inset);
|
||||
$minY = (int) floor($this->boundingBox->minY + $inset);
|
||||
$minZ = (int) floor($this->boundingBox->minZ + $inset);
|
||||
$maxX = (int) floor($this->boundingBox->maxX - $inset);
|
||||
$maxY = (int) floor($this->boundingBox->maxY - $inset);
|
||||
$maxZ = (int) floor($this->boundingBox->maxZ - $inset);
|
||||
|
||||
$this->blocksAround = [];
|
||||
|
||||
$world = $this->getWorld();
|
||||
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$block = $world->getBlockAt($x, $y, $z);
|
||||
if($block->hasEntityCollision()){
|
||||
$this->blocksAround[] = $block;
|
||||
}
|
||||
}
|
||||
$inset = 0.001; //Offset against floating-point errors
|
||||
foreach($this->getBlocksIntersected($inset) as $block){
|
||||
if($block->hasEntityCollision()){
|
||||
$this->blocksAround[] = $block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user