Eliminate repeated calls to Position->getWorld()

as well as improving readability, it also improves performance in some areas.
This commit is contained in:
Dylan K. Taylor
2022-07-20 20:44:05 +01:00
parent 24e72ec109
commit 2940547026
39 changed files with 185 additions and 134 deletions

View File

@ -90,6 +90,7 @@ class SweetBerryBush extends Flowable{
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$world = $this->position->getWorld();
if($this->age < self::STAGE_MATURE && $item instanceof Fertilizer){
$block = clone $this;
$block->age++;
@ -98,13 +99,13 @@ class SweetBerryBush extends Flowable{
$ev->call();
if(!$ev->isCancelled()){
$this->position->getWorld()->setBlock($this->position, $ev->getNewState());
$world->setBlock($this->position, $ev->getNewState());
$item->pop();
}
}elseif(($dropAmount = $this->getBerryDropAmount()) > 0){
$this->position->getWorld()->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES));
$this->position->getWorld()->dropItem($this->position, $this->asItem()->setCount($dropAmount));
$world->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES));
$world->dropItem($this->position, $this->asItem()->setCount($dropAmount));
}
return true;