mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
ÂBlock: use Facing::OFFSET in getSide()
instead of the comically inefficient getBlock() + throwaway Position->getSide() This improved the function's performance by 2.3x.
This commit is contained in:
parent
ccd2cdd324
commit
6a3ec70c72
@ -747,8 +747,14 @@ class Block{
|
||||
* @return Block
|
||||
*/
|
||||
public function getSide(int $side, int $step = 1){
|
||||
if($this->position->isValid()){
|
||||
return $this->position->getWorld()->getBlock($this->position->getSide($side, $step));
|
||||
$position = $this->position;
|
||||
if($position->isValid()){
|
||||
[$dx, $dy, $dz] = Facing::OFFSET[$side] ?? throw new \InvalidArgumentException("Unknown side $side");
|
||||
return $position->getWorld()->getBlockAt(
|
||||
$position->x + ($dx * $step),
|
||||
$position->y + ($dy * $step),
|
||||
$position->z + ($dz * $step)
|
||||
);
|
||||
}
|
||||
|
||||
throw new \LogicException("Block does not have a valid world");
|
||||
|
Loading…
x
Reference in New Issue
Block a user