Block: Avoid useless Vector3 allocations in getHorizontalSides and getAllSides

This commit is contained in:
Dylan K. Taylor 2023-10-20 17:28:19 +01:00
parent eb935ca80f
commit 1f461977d4
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -768,8 +768,14 @@ class Block{
*/
public function getHorizontalSides() : \Generator{
$world = $this->position->getWorld();
foreach($this->position->sidesAroundAxis(Axis::Y) as $vector3){
yield $world->getBlock($vector3);
foreach(Facing::HORIZONTAL as $facing){
[$dx, $dy, $dz] = Facing::OFFSET[$facing];
//TODO: yield Facing as the key?
yield $world->getBlockAt(
$this->position->x + $dx,
$this->position->y + $dy,
$this->position->z + $dz
);
}
}
@ -781,8 +787,13 @@ class Block{
*/
public function getAllSides() : \Generator{
$world = $this->position->getWorld();
foreach($this->position->sides() as $vector3){
yield $world->getBlock($vector3);
foreach(Facing::OFFSET as [$dx, $dy, $dz]){
//TODO: yield Facing as the key?
yield $world->getBlockAt(
$this->position->x + $dx,
$this->position->y + $dy,
$this->position->z + $dz
);
}
}