mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-22 11:24:02 +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
|
* @return Block
|
||||||
*/
|
*/
|
||||||
public function getSide(int $side, int $step = 1){
|
public function getSide(int $side, int $step = 1){
|
||||||
if($this->position->isValid()){
|
$position = $this->position;
|
||||||
return $this->position->getWorld()->getBlock($this->position->getSide($side, $step));
|
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");
|
throw new \LogicException("Block does not have a valid world");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user