From dd98e4aaed3731f0d23447d52825b9100826523f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 14 Nov 2023 12:47:33 +0000 Subject: [PATCH] block: clean up unnecessary getter usages with the assistance of a custom phpstan rule this inconsistent mess has been bothering me for a long time --- src/block/Bamboo.php | 2 +- src/block/Barrel.php | 8 ++++---- src/block/BaseBigDripleaf.php | 10 +++++----- src/block/Bed.php | 2 +- src/block/ChiseledBookshelf.php | 2 +- src/block/ChorusFlower.php | 4 ++-- src/block/ChorusPlant.php | 2 +- src/block/Farmland.php | 2 +- src/block/Fire.php | 2 +- src/block/FloorCoralFan.php | 2 +- src/block/Jukebox.php | 6 +++--- src/block/NetherVines.php | 4 ++-- src/block/PinkPetals.php | 8 ++++---- src/block/RedMushroom.php | 2 +- src/block/SmallDripleaf.php | 4 ++-- src/block/Stair.php | 4 ++-- src/block/inventory/AnimatedBlockInventoryTrait.php | 8 ++++---- src/block/tile/Chest.php | 2 +- 18 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/block/Bamboo.php b/src/block/Bamboo.php index 5df71f696..9f605bca6 100644 --- a/src/block/Bamboo.php +++ b/src/block/Bamboo.php @@ -173,7 +173,7 @@ class Bamboo extends Transparent{ $newHeight = $height + $growAmount; $stemBlock = (clone $this)->setReady(false)->setLeafSize(self::NO_LEAVES); - if($newHeight >= 4 && !$stemBlock->isThick()){ //don't change it to false if height is less, because it might have been chopped + if($newHeight >= 4 && !$stemBlock->thick){ //don't change it to false if height is less, because it might have been chopped $stemBlock = $stemBlock->setThick(true); } $smallLeavesBlock = (clone $stemBlock)->setLeafSize(self::SMALL_LEAVES); diff --git a/src/block/Barrel.php b/src/block/Barrel.php index 1dce2376b..0f0499ab9 100644 --- a/src/block/Barrel.php +++ b/src/block/Barrel.php @@ -55,12 +55,12 @@ class Barrel extends Opaque{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ - if(abs($player->getPosition()->getX() - $this->position->getX()) < 2 && abs($player->getPosition()->getZ() - $this->position->getZ()) < 2){ - $y = $player->getEyePos()->getY(); + if(abs($player->getPosition()->x - $this->position->x) < 2 && abs($player->getPosition()->z - $this->position->z) < 2){ + $y = $player->getEyePos()->y; - if($y - $this->position->getY() > 2){ + if($y - $this->position->y > 2){ $this->facing = Facing::UP; - }elseif($this->position->getY() - $y > 0){ + }elseif($this->position->y - $y > 0){ $this->facing = Facing::DOWN; }else{ $this->facing = Facing::opposite($player->getHorizontalFacing()); diff --git a/src/block/BaseBigDripleaf.php b/src/block/BaseBigDripleaf.php index b2547447c..f0ff59cf0 100644 --- a/src/block/BaseBigDripleaf.php +++ b/src/block/BaseBigDripleaf.php @@ -65,8 +65,8 @@ abstract class BaseBigDripleaf extends Transparent{ $this->facing = Facing::opposite($player->getHorizontalFacing()); } if($block instanceof BaseBigDripleaf){ - $this->facing = $block->getFacing(); - $tx->addBlock($block->getPosition(), VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($this->facing)); + $this->facing = $block->facing; + $tx->addBlock($block->position, VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($this->facing)); } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -98,7 +98,7 @@ abstract class BaseBigDripleaf extends Transparent{ if($head === null){ return false; } - $pos = $head->getPosition(); + $pos = $head->position; $up = $pos->up(); $world = $pos->getWorld(); if( @@ -110,8 +110,8 @@ abstract class BaseBigDripleaf extends Transparent{ $tx = new BlockTransaction($world); - $tx->addBlock($pos, VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($head->getFacing())); - $tx->addBlock($up, VanillaBlocks::BIG_DRIPLEAF_HEAD()->setFacing($head->getFacing())); + $tx->addBlock($pos, VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($head->facing)); + $tx->addBlock($up, VanillaBlocks::BIG_DRIPLEAF_HEAD()->setFacing($head->facing)); $ev = new StructureGrowEvent($head, $tx, $player); $ev->call(); diff --git a/src/block/Bed.php b/src/block/Bed.php index d4dca17d6..8efbdfe01 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -145,7 +145,7 @@ class Bed extends Transparent{ $b = ($this->isHeadPart() ? $this : $other); - if($b->isOccupied()){ + if($b->occupied){ $player->sendMessage(KnownTranslationFactory::tile_bed_occupied()->prefix(TextFormat::GRAY)); return true; diff --git a/src/block/ChiseledBookshelf.php b/src/block/ChiseledBookshelf.php index 021ed58e9..89340a8f3 100644 --- a/src/block/ChiseledBookshelf.php +++ b/src/block/ChiseledBookshelf.php @@ -97,7 +97,7 @@ class ChiseledBookshelf extends Opaque{ return false; } - $x = Facing::axis($face) === Axis::X ? $clickVector->getZ() : $clickVector->getX(); + $x = Facing::axis($face) === Axis::X ? $clickVector->z : $clickVector->x; $slot = ChiseledBookshelfSlot::fromBlockFaceCoordinates( Facing::isPositive(Facing::rotateY($face, true)) ? 1 - $x : $x, $clickVector->y diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index 2dcf4bb70..cc3c606d9 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -54,7 +54,7 @@ final class ChorusFlower extends Flowable{ } private function canBeSupportedAt(Block $block) : bool{ - $position = $block->getPosition(); + $position = $block->position; $world = $position->getWorld(); $down = $world->getBlock($position->down()); @@ -152,7 +152,7 @@ final class ChorusFlower extends Flowable{ if($tx === null){ $tx = new BlockTransaction($this->position->getWorld()); } - $tx->addBlock($this->position->getSide($facing), (clone $this)->setAge(min(self::MAX_AGE, $this->getAge() + $ageChange))); + $tx->addBlock($this->position->getSide($facing), (clone $this)->setAge(min(self::MAX_AGE, $this->age + $ageChange))); return $tx; } diff --git a/src/block/ChorusPlant.php b/src/block/ChorusPlant.php index e3cc8de9d..9013f6825 100644 --- a/src/block/ChorusPlant.php +++ b/src/block/ChorusPlant.php @@ -51,7 +51,7 @@ final class ChorusPlant extends Flowable{ } private function canBeSupportedAt(Block $block) : bool{ - $position = $block->getPosition(); + $position = $block->position; $world = $position->getWorld(); $down = $world->getBlock($position->down()); diff --git a/src/block/Farmland.php b/src/block/Farmland.php index c2694dd83..a17a220f0 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -152,7 +152,7 @@ class Farmland extends Transparent{ $ev = new EntityTrampleFarmlandEvent($entity, $this); $ev->call(); if(!$ev->isCancelled()){ - $this->getPosition()->getWorld()->setBlock($this->getPosition(), VanillaBlocks::DIRT()); + $this->position->getWorld()->setBlock($this->position, VanillaBlocks::DIRT()); } } return null; diff --git a/src/block/Fire.php b/src/block/Fire.php index 5487c34ed..35a7a696c 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -140,7 +140,7 @@ class Fire extends BaseFire{ $block->onIncinerate(); $world = $this->position->getWorld(); - if($world->getBlock($block->getPosition())->isSameState($block)){ + if($world->getBlock($block->position)->isSameState($block)){ $spreadedFire = false; if(mt_rand(0, $this->age + 9) < 5){ //TODO: check rain $fire = clone $this; diff --git a/src/block/FloorCoralFan.php b/src/block/FloorCoralFan.php index 81ea88186..5b74d08af 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -58,7 +58,7 @@ final class FloorCoralFan extends BaseCoral{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $playerBlockPos = $player->getPosition()->floor(); - $directionVector = $blockReplace->getPosition()->subtractVector($playerBlockPos)->normalize(); + $directionVector = $blockReplace->position->subtractVector($playerBlockPos)->normalize(); $angle = rad2deg(atan2($directionVector->getZ(), $directionVector->getX())); if($angle <= 45 || 315 <= $angle || (135 <= $angle && $angle <= 225)){ diff --git a/src/block/Jukebox.php b/src/block/Jukebox.php index 20c3cab61..a61dd06db 100644 --- a/src/block/Jukebox.php +++ b/src/block/Jukebox.php @@ -61,7 +61,7 @@ class Jukebox extends Opaque{ public function ejectRecord() : void{ if($this->record !== null){ - $this->getPosition()->getWorld()->dropItem($this->getPosition()->add(0.5, 1, 0.5), $this->record); + $this->position->getWorld()->dropItem($this->position->add(0.5, 1, 0.5), $this->record); $this->record = null; $this->stopSound(); } @@ -76,12 +76,12 @@ class Jukebox extends Opaque{ public function startSound() : void{ if($this->record !== null){ - $this->getPosition()->getWorld()->addSound($this->getPosition(), new RecordSound($this->record->getRecordType())); + $this->position->getWorld()->addSound($this->position, new RecordSound($this->record->getRecordType())); } } public function stopSound() : void{ - $this->getPosition()->getWorld()->addSound($this->getPosition(), new RecordStopSound()); + $this->position->getWorld()->addSound($this->position, new RecordStopSound()); } public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/NetherVines.php b/src/block/NetherVines.php index eb459a0f1..e8729c00f 100644 --- a/src/block/NetherVines.php +++ b/src/block/NetherVines.php @@ -108,8 +108,8 @@ class NetherVines extends Flowable{ private function grow(?Player $player, int $growthAmount = 1) : bool{ $top = $this->seekToTip(); - $age = $top->getAge(); - $pos = $top->getPosition(); + $age = $top->age; + $pos = $top->position; $world = $pos->getWorld(); $changedBlocks = 0; diff --git a/src/block/PinkPetals.php b/src/block/PinkPetals.php index 872798df0..17bc4c50a 100644 --- a/src/block/PinkPetals.php +++ b/src/block/PinkPetals.php @@ -70,13 +70,13 @@ class PinkPetals extends Flowable{ } public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ - return ($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); + return ($blockReplace instanceof PinkPetals && $blockReplace->count < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT){ - $this->count = $blockReplace->getCount() + 1; - $this->facing = $blockReplace->getFacing(); + if($blockReplace instanceof PinkPetals && $blockReplace->count < self::MAX_COUNT){ + $this->count = $blockReplace->count + 1; + $this->facing = $blockReplace->facing; }elseif($player !== null){ $this->facing = Facing::opposite($player->getHorizontalFacing()); } diff --git a/src/block/RedMushroom.php b/src/block/RedMushroom.php index 553957fe6..81ab940f5 100644 --- a/src/block/RedMushroom.php +++ b/src/block/RedMushroom.php @@ -43,7 +43,7 @@ class RedMushroom extends Flowable{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); - $position = $this->getPosition(); + $position = $this->position; $lightLevel = $position->getWorld()->getFullLightAt($position->x, $position->y, $position->z); $downId = $down->getTypeId(); //TODO: nylium support diff --git a/src/block/SmallDripleaf.php b/src/block/SmallDripleaf.php index ad23608bf..d192e43db 100644 --- a/src/block/SmallDripleaf.php +++ b/src/block/SmallDripleaf.php @@ -83,7 +83,7 @@ class SmallDripleaf extends Transparent{ $this->facing = Facing::opposite($player->getHorizontalFacing()); } - $tx->addBlock($block->getPosition(), VanillaBlocks::SMALL_DRIPLEAF() + $tx->addBlock($block->position, VanillaBlocks::SMALL_DRIPLEAF() ->setFacing($this->facing) ->setTop(true) ); @@ -117,7 +117,7 @@ class SmallDripleaf extends Transparent{ $height = mt_rand(2, 5); $grown = 0; for($i = 0; $i < $height; $i++){ - $pos = $bottomBlock->getSide(Facing::UP, $i)->getPosition(); + $pos = $bottomBlock->getSide(Facing::UP, $i)->position; if(!$this->canGrowTo($pos)){ break; } diff --git a/src/block/Stair.php b/src/block/Stair.php index 1acaac962..d66a9ce5c 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -106,8 +106,8 @@ class Stair extends Transparent{ public function getSupportType(int $facing) : SupportType{ if( - $facing === Facing::UP && $this->isUpsideDown() || - $facing === Facing::DOWN && !$this->isUpsideDown() || + $facing === Facing::UP && $this->upsideDown || + $facing === Facing::DOWN && !$this->upsideDown || ($facing === $this->facing && $this->shape !== StairShape::OUTER_LEFT && $this->shape !== StairShape::OUTER_RIGHT) || ($facing === Facing::rotate($this->facing, Axis::Y, false) && $this->shape === StairShape::INNER_LEFT) || ($facing === Facing::rotate($this->facing, Axis::Y, true) && $this->shape === StairShape::INNER_RIGHT) diff --git a/src/block/inventory/AnimatedBlockInventoryTrait.php b/src/block/inventory/AnimatedBlockInventoryTrait.php index a9965190c..8720c985b 100644 --- a/src/block/inventory/AnimatedBlockInventoryTrait.php +++ b/src/block/inventory/AnimatedBlockInventoryTrait.php @@ -47,20 +47,20 @@ trait AnimatedBlockInventoryTrait{ public function onOpen(Player $who) : void{ parent::onOpen($who); - if($this->getHolder()->isValid() && $this->getViewerCount() === 1){ + if($this->holder->isValid() && $this->getViewerCount() === 1){ //TODO: this crap really shouldn't be managed by the inventory $this->animateBlock(true); - $this->getHolder()->getWorld()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound()); + $this->holder->getWorld()->addSound($this->holder->add(0.5, 0.5, 0.5), $this->getOpenSound()); } } abstract protected function animateBlock(bool $isOpen) : void; public function onClose(Player $who) : void{ - if($this->getHolder()->isValid() && $this->getViewerCount() === 1){ + if($this->holder->isValid() && $this->getViewerCount() === 1){ //TODO: this crap really shouldn't be managed by the inventory $this->animateBlock(false); - $this->getHolder()->getWorld()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound()); + $this->holder->getWorld()->addSound($this->holder->add(0.5, 0.5, 0.5), $this->getCloseSound()); } parent::onClose($who); } diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index 46d97191b..4f97eed23 100644 --- a/src/block/tile/Chest.php +++ b/src/block/tile/Chest.php @@ -139,7 +139,7 @@ class Chest extends Spawnable implements Container, Nameable{ if($pair->doubleInventory !== null){ $this->doubleInventory = $pair->doubleInventory; }else{ - if(($pair->getPosition()->x + ($pair->getPosition()->z << 15)) > ($this->position->x + ($this->position->z << 15))){ //Order them correctly + if(($pair->position->x + ($pair->position->z << 15)) > ($this->position->x + ($this->position->z << 15))){ //Order them correctly $this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($pair->inventory, $this->inventory); }else{ $this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($this->inventory, $pair->inventory);