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