From ae564e445dba4124f6539289b266297aa0fda577 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 7 Sep 2023 17:20:52 +0100 Subject: [PATCH] Start migrating EnumTrait enums to PHP 8.1 native enums --- src/block/Anvil.php | 2 +- src/block/Bamboo.php | 2 +- src/block/BaseBanner.php | 2 +- src/block/BaseBigDripleaf.php | 2 +- src/block/BaseCake.php | 2 +- src/block/BaseCoral.php | 8 +- src/block/BaseSign.php | 2 +- src/block/Bed.php | 4 +- src/block/Bell.php | 42 +-- src/block/BigDripleafHead.php | 34 +- src/block/Block.php | 2 +- src/block/BrewingStand.php | 13 +- src/block/Cactus.php | 2 +- src/block/Candle.php | 2 +- src/block/Cauldron.php | 2 +- src/block/CaveVines.php | 4 +- src/block/Chain.php | 2 +- src/block/Chest.php | 2 +- src/block/CocoaBlock.php | 4 +- src/block/CopperStairs.php | 6 - src/block/CoralBlock.php | 6 - src/block/DaylightSensor.php | 2 +- src/block/Dirt.php | 13 +- src/block/Door.php | 2 +- src/block/DragonEgg.php | 2 +- src/block/EnchantingTable.php | 2 +- src/block/EnderChest.php | 2 +- src/block/Fence.php | 4 +- src/block/FenceGate.php | 2 +- src/block/FillableCauldron.php | 2 +- src/block/Fire.php | 2 +- src/block/Flowable.php | 2 +- src/block/Froglight.php | 7 +- src/block/GlowLichen.php | 8 +- src/block/Grass.php | 2 +- src/block/Hopper.php | 6 +- src/block/ItemFrame.php | 2 +- src/block/Ladder.php | 4 +- src/block/Lantern.php | 2 +- src/block/Leaves.php | 23 +- src/block/Lectern.php | 2 +- src/block/Lever.php | 19 +- src/block/Liquid.php | 2 +- src/block/MobHead.php | 7 +- src/block/MonsterSpawner.php | 2 +- src/block/Mycelium.php | 2 +- src/block/NetherPortal.php | 2 +- src/block/NetherVines.php | 2 +- src/block/PressurePlate.php | 4 +- src/block/RedMushroomBlock.php | 11 +- src/block/RedstoneComparator.php | 2 +- src/block/RedstoneRepeater.php | 2 +- src/block/SeaPickle.php | 2 +- src/block/ShulkerBox.php | 2 +- src/block/Slab.php | 35 +- src/block/SmallDripleaf.php | 2 +- src/block/SnowLayer.php | 6 +- src/block/SporeBlossom.php | 2 +- src/block/Stair.php | 31 +- src/block/Stonecutter.php | 2 +- src/block/Thin.php | 4 +- src/block/Torch.php | 2 +- src/block/Trapdoor.php | 2 +- src/block/VanillaBlocks.php | 13 +- src/block/Wall.php | 6 +- src/block/WoodLikeBlockIdHelper.php | 313 +++++++++--------- src/block/tile/MobHead.php | 9 +- src/block/utils/BannerPatternType.php | 92 +++-- src/block/utils/BellAttachmentType.php | 24 +- src/block/utils/BrewingStandSlot.php | 36 +- src/block/utils/CopperOxidation.php | 49 +-- src/block/utils/CopperTrait.php | 9 +- src/block/utils/CoralType.php | 43 +-- src/block/utils/CoralTypeTrait.php | 2 +- src/block/utils/DirtType.php | 22 +- src/block/utils/DripleafState.php | 41 +-- src/block/utils/FroglightType.php | 22 +- src/block/utils/LeavesType.php | 59 ++-- src/block/utils/LeverFacing.php | 47 ++- src/block/utils/MobHeadType.php | 49 ++- src/block/utils/MushroomBlockType.php | 38 +-- src/block/utils/SaplingType.php | 50 ++- src/block/utils/SlabType.php | 22 +- src/block/utils/StairShape.php | 26 +- src/block/utils/SupportType.php | 28 +- src/block/utils/WallConnectionType.php | 20 +- src/block/utils/WoodType.php | 73 ++-- .../CraftingManagerFromDataHelper.php | 8 +- src/crafting/ShapelessRecipeType.php | 24 +- src/data/bedrock/BannerPatternTypeIdMap.php | 86 ++--- src/data/bedrock/MobHeadTypeIdMap.php | 14 +- src/data/bedrock/MushroomBlockTypeIdMap.php | 22 +- src/data/bedrock/NoteInstrumentIdMap.php | 32 +- .../convert/BlockObjectToStateSerializer.php | 75 ++--- .../block/convert/BlockStateReader.php | 24 +- .../convert/BlockStateSerializerHelper.php | 14 +- .../BlockStateToObjectDeserializer.php | 134 ++++---- .../block/convert/BlockStateWriter.php | 53 ++- src/data/runtime/RuntimeDataReader.php | 13 +- .../runtime/RuntimeDataSizeCalculator.php | 2 +- src/data/runtime/RuntimeDataWriter.php | 15 +- src/item/Armor.php | 2 +- src/item/BoatType.php | 51 ++- src/item/Bow.php | 8 +- src/item/Bucket.php | 8 +- src/item/CoralFan.php | 2 - src/item/FireCharge.php | 4 +- src/item/FlintSteel.php | 4 +- src/item/GlassBottle.php | 4 +- src/item/Item.php | 6 +- src/item/ItemUseResult.php | 22 +- src/item/LiquidBucket.php | 6 +- src/item/PaintingItem.php | 6 +- src/item/ProjectileItem.php | 4 +- src/item/SpawnEgg.php | 2 +- src/item/StringToItemParser.php | 65 ++-- src/item/VanillaItems.php | 21 +- src/network/mcpe/NetworkSession.php | 2 +- src/network/mcpe/cache/CraftingDataCache.php | 11 +- src/player/Player.php | 24 +- src/player/UsedChunkStatus.php | 24 +- src/utils/EnumTrait.php | 3 + src/utils/LegacyEnumShimTrait.php | 92 +++++ src/world/World.php | 4 +- src/world/biome/BiomeRegistry.php | 2 +- src/world/biome/ForestBiome.php | 4 +- src/world/biome/TaigaBiome.php | 2 +- src/world/generator/object/TreeFactory.php | 30 +- src/world/generator/object/TreeType.php | 53 ++- src/world/generator/populator/Tree.php | 2 +- src/world/sound/NoteInstrument.php | 48 ++- 131 files changed, 1157 insertions(+), 1349 deletions(-) create mode 100644 src/utils/LegacyEnumShimTrait.php diff --git a/src/block/Anvil.php b/src/block/Anvil.php index de8b6d33c..b4677e075 100644 --- a/src/block/Anvil.php +++ b/src/block/Anvil.php @@ -78,7 +78,7 @@ class Anvil extends Transparent implements Fallable{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/Bamboo.php b/src/block/Bamboo.php index 980f4382d..e4aaa4af7 100644 --- a/src/block/Bamboo.php +++ b/src/block/Bamboo.php @@ -95,7 +95,7 @@ class Bamboo extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } private static function getOffsetSeed(int $x, int $y, int $z) : int{ diff --git a/src/block/BaseBanner.php b/src/block/BaseBanner.php index fdfad3b09..932a09b10 100644 --- a/src/block/BaseBanner.php +++ b/src/block/BaseBanner.php @@ -111,7 +111,7 @@ abstract class BaseBanner extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } private function canBeSupportedBy(Block $block) : bool{ diff --git a/src/block/BaseBigDripleaf.php b/src/block/BaseBigDripleaf.php index dcd81af0a..b2547447c 100644 --- a/src/block/BaseBigDripleaf.php +++ b/src/block/BaseBigDripleaf.php @@ -131,6 +131,6 @@ abstract class BaseBigDripleaf extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/BaseCake.php b/src/block/BaseCake.php index 21fd6336a..4c1d0e4a3 100644 --- a/src/block/BaseCake.php +++ b/src/block/BaseCake.php @@ -36,7 +36,7 @@ use pocketmine\world\BlockTransaction; abstract class BaseCake extends Transparent implements FoodSource{ public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/BaseCoral.php b/src/block/BaseCoral.php index 3a6acd5d1..b9c595a97 100644 --- a/src/block/BaseCoral.php +++ b/src/block/BaseCoral.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\BlockEventHelper; -use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\utils\SupportType; use pocketmine\item\Item; @@ -33,11 +32,6 @@ use function mt_rand; abstract class BaseCoral extends Transparent{ use CoralTypeTrait; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->coralType = CoralType::TUBE(); - parent::__construct($idInfo, $name, $typeInfo); - } - public function onNearbyBlockChange() : void{ if(!$this->dead){ $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200)); @@ -78,6 +72,6 @@ abstract class BaseCoral extends Transparent{ protected function recalculateCollisionBoxes() : array{ return []; } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/BaseSign.php b/src/block/BaseSign.php index d7a22f3b8..1b0ae8938 100644 --- a/src/block/BaseSign.php +++ b/src/block/BaseSign.php @@ -103,7 +103,7 @@ abstract class BaseSign extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } abstract protected function getSupportingFace() : int; diff --git a/src/block/Bed.php b/src/block/Bed.php index 312b21cd1..74543f78e 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -87,7 +87,7 @@ class Bed extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function isHeadPart() : bool{ @@ -209,7 +209,7 @@ class Bed extends Transparent{ } private function canBeSupportedAt(Block $block) : bool{ - return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE; } public function getMaxStackSize() : int{ return 1; } diff --git a/src/block/Bell.php b/src/block/Bell.php index 3f15d6909..e91082a26 100644 --- a/src/block/Bell.php +++ b/src/block/Bell.php @@ -35,19 +35,13 @@ use pocketmine\math\Facing; use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\utils\AssumptionFailedError; use pocketmine\world\BlockTransaction; use pocketmine\world\sound\BellRingSound; final class Bell extends Transparent{ use HorizontalFacingTrait; - private BellAttachmentType $attachmentType; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->attachmentType = BellAttachmentType::FLOOR(); - parent::__construct($idInfo, $name, $typeInfo); - } + private BellAttachmentType $attachmentType = BellAttachmentType::FLOOR; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->bellAttachmentType($this->attachmentType); @@ -55,12 +49,12 @@ final class Bell extends Transparent{ } protected function recalculateCollisionBoxes() : array{ - if($this->attachmentType->equals(BellAttachmentType::FLOOR())){ + if($this->attachmentType === BellAttachmentType::FLOOR){ return [ AxisAlignedBB::one()->squash(Facing::axis($this->facing), 1 / 4)->trim(Facing::UP, 3 / 16) ]; } - if($this->attachmentType->equals(BellAttachmentType::CEILING())){ + if($this->attachmentType === BellAttachmentType::CEILING){ return [ AxisAlignedBB::one()->contract(1 / 4, 0, 1 / 4)->trim(Facing::DOWN, 1 / 4) ]; @@ -72,12 +66,12 @@ final class Bell extends Transparent{ ->trim(Facing::DOWN, 1 / 4); return [ - $this->attachmentType->equals(BellAttachmentType::ONE_WALL()) ? $box->trim($this->facing, 3 / 16) : $box + $this->attachmentType === BellAttachmentType::ONE_WALL ? $box->trim($this->facing, 3 / 16) : $box ]; } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function getAttachmentType() : BellAttachmentType{ return $this->attachmentType; } @@ -89,7 +83,7 @@ final class Bell extends Transparent{ } private function canBeSupportedAt(Block $block, int $face) : bool{ - return !$block->getAdjacentSupportType($face)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType($face) !== SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ @@ -100,15 +94,15 @@ final class Bell extends Transparent{ if($player !== null){ $this->setFacing(Facing::opposite($player->getHorizontalFacing())); } - $this->setAttachmentType(BellAttachmentType::FLOOR()); + $this->setAttachmentType(BellAttachmentType::FLOOR); }elseif($face === Facing::DOWN){ - $this->setAttachmentType(BellAttachmentType::CEILING()); + $this->setAttachmentType(BellAttachmentType::CEILING); }else{ $this->setFacing($face); $this->setAttachmentType( $this->canBeSupportedAt($blockReplace, $face) ? - BellAttachmentType::TWO_WALLS() : - BellAttachmentType::ONE_WALL() + BellAttachmentType::TWO_WALLS : + BellAttachmentType::ONE_WALL ); } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -116,11 +110,10 @@ final class Bell extends Transparent{ public function onNearbyBlockChange() : void{ foreach(match($this->attachmentType){ - BellAttachmentType::CEILING() => [Facing::UP], - BellAttachmentType::FLOOR() => [Facing::DOWN], - BellAttachmentType::ONE_WALL() => [Facing::opposite($this->facing)], - BellAttachmentType::TWO_WALLS() => [$this->facing, Facing::opposite($this->facing)], - default => throw new AssumptionFailedError("All cases of BellAttachmentType must be handled") + BellAttachmentType::CEILING => [Facing::UP], + BellAttachmentType::FLOOR => [Facing::DOWN], + BellAttachmentType::ONE_WALL => [Facing::opposite($this->facing)], + BellAttachmentType::TWO_WALLS => [$this->facing, Facing::opposite($this->facing)] } as $supportBlockDirection){ if(!$this->canBeSupportedAt($this, $supportBlockDirection)){ $this->position->getWorld()->useBreakOn($this->position); @@ -159,10 +152,9 @@ final class Bell extends Transparent{ private function isValidFaceToRing(int $faceHit) : bool{ return match($this->attachmentType){ - BellAttachmentType::CEILING() => true, - BellAttachmentType::FLOOR() => Facing::axis($faceHit) === Facing::axis($this->facing), - BellAttachmentType::ONE_WALL(), BellAttachmentType::TWO_WALLS() => $faceHit === Facing::rotateY($this->facing, false) || $faceHit === Facing::rotateY($this->facing, true), - default => throw new AssumptionFailedError("All cases of BellAttachmentType must be handled") + BellAttachmentType::CEILING => true, + BellAttachmentType::FLOOR => Facing::axis($faceHit) === Facing::axis($this->facing), + BellAttachmentType::ONE_WALL, BellAttachmentType::TWO_WALLS => $faceHit === Facing::rotateY($this->facing, false) || $faceHit === Facing::rotateY($this->facing, true), }; } } diff --git a/src/block/BigDripleafHead.php b/src/block/BigDripleafHead.php index d5bd226ca..d6f057270 100644 --- a/src/block/BigDripleafHead.php +++ b/src/block/BigDripleafHead.php @@ -36,12 +36,7 @@ use pocketmine\world\sound\DripleafTiltUpSound; class BigDripleafHead extends BaseBigDripleaf{ - protected DripleafState $leafState; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->leafState = DripleafState::STABLE(); - parent::__construct($idInfo, $name, $typeInfo); - } + protected DripleafState $leafState = DripleafState::STABLE; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ parent::describeBlockOnlyState($w); @@ -76,20 +71,20 @@ class BigDripleafHead extends BaseBigDripleaf{ private function getLeafTopOffset() : float{ return match($this->leafState){ - DripleafState::STABLE(), DripleafState::UNSTABLE() => 1 / 16, - DripleafState::PARTIAL_TILT() => 3 / 16, + DripleafState::STABLE, DripleafState::UNSTABLE => 1 / 16, + DripleafState::PARTIAL_TILT => 3 / 16, default => 0 }; } public function onEntityInside(Entity $entity) : bool{ - if(!$entity instanceof Projectile && $this->leafState->equals(DripleafState::STABLE())){ + if(!$entity instanceof Projectile && $this->leafState === DripleafState::STABLE){ //the entity must be standing on top of the leaf - do not collapse if the entity is standing underneath $intersection = AxisAlignedBB::one() ->offset($this->position->x, $this->position->y, $this->position->z) ->trim(Facing::DOWN, 1 - $this->getLeafTopOffset()); if($entity->getBoundingBox()->intersectsWith($intersection)){ - $this->setTiltAndScheduleTick(DripleafState::UNSTABLE()); + $this->setTiltAndScheduleTick(DripleafState::UNSTABLE); return false; } } @@ -97,22 +92,21 @@ class BigDripleafHead extends BaseBigDripleaf{ } public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ - if(!$this->leafState->equals(DripleafState::FULL_TILT())){ - $this->setTiltAndScheduleTick(DripleafState::FULL_TILT()); + if($this->leafState !== DripleafState::FULL_TILT){ + $this->setTiltAndScheduleTick(DripleafState::FULL_TILT); $this->position->getWorld()->addSound($this->position, new DripleafTiltDownSound()); } } public function onScheduledUpdate() : void{ - if(!$this->leafState->equals(DripleafState::STABLE())){ - if($this->leafState->equals(DripleafState::FULL_TILT())){ - $this->position->getWorld()->setBlock($this->position, $this->setLeafState(DripleafState::STABLE())); + if($this->leafState !== DripleafState::STABLE){ + if($this->leafState === DripleafState::FULL_TILT){ + $this->position->getWorld()->setBlock($this->position, $this->setLeafState(DripleafState::STABLE)); $this->position->getWorld()->addSound($this->position, new DripleafTiltUpSound()); }else{ - $this->setTiltAndScheduleTick(match($this->leafState->id()){ - DripleafState::UNSTABLE()->id() => DripleafState::PARTIAL_TILT(), - DripleafState::PARTIAL_TILT()->id() => DripleafState::FULL_TILT(), - default => throw new AssumptionFailedError("All types should be covered") + $this->setTiltAndScheduleTick(match($this->leafState){ + DripleafState::UNSTABLE => DripleafState::PARTIAL_TILT, + DripleafState::PARTIAL_TILT => DripleafState::FULL_TILT, }); $this->position->getWorld()->addSound($this->position, new DripleafTiltDownSound()); } @@ -120,7 +114,7 @@ class BigDripleafHead extends BaseBigDripleaf{ } protected function recalculateCollisionBoxes() : array{ - if(!$this->leafState->equals(DripleafState::FULL_TILT())){ + if($this->leafState !== DripleafState::FULL_TILT){ return [ AxisAlignedBB::one() ->trim(Facing::DOWN, 11 / 16) diff --git a/src/block/Block.php b/src/block/Block.php index 9f61982ff..7d01ce7ef 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -877,7 +877,7 @@ class Block{ * blocks placed on the given face can be supported by this block. */ public function getSupportType(int $facing) : SupportType{ - return SupportType::FULL(); + return SupportType::FULL; } protected function getAdjacentSupportType(int $facing) : SupportType{ diff --git a/src/block/BrewingStand.php b/src/block/BrewingStand.php index 497d282d7..c59ea352b 100644 --- a/src/block/BrewingStand.php +++ b/src/block/BrewingStand.php @@ -34,6 +34,7 @@ use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use function array_key_exists; +use function spl_object_id; class BrewingStand extends Transparent{ @@ -61,18 +62,18 @@ class BrewingStand extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function hasSlot(BrewingStandSlot $slot) : bool{ - return array_key_exists($slot->id(), $this->slots); + return array_key_exists(spl_object_id($slot), $this->slots); } public function setSlot(BrewingStandSlot $slot, bool $occupied) : self{ if($occupied){ - $this->slots[$slot->id()] = $slot; + $this->slots[spl_object_id($slot)] = $slot; }else{ - unset($this->slots[$slot->id()]); + unset($this->slots[spl_object_id($slot)]); } return $this; } @@ -89,7 +90,7 @@ class BrewingStand extends Transparent{ public function setSlots(array $slots) : self{ $this->slots = []; foreach($slots as $slot){ - $this->slots[$slot->id()] = $slot; + $this->slots[spl_object_id($slot)] = $slot; } return $this; } @@ -114,7 +115,7 @@ class BrewingStand extends Transparent{ } $changed = false; - foreach(BrewingStandSlot::getAll() as $slot){ + foreach(BrewingStandSlot::cases() as $slot){ $occupied = !$brewing->getInventory()->isSlotEmpty($slot->getSlotNumber()); if($occupied !== $this->hasSlot($slot)){ $this->setSlot($slot, $occupied); diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 0176d17bd..81d94474b 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -69,7 +69,7 @@ class Cactus extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onEntityInside(Entity $entity) : bool{ diff --git a/src/block/Candle.php b/src/block/Candle.php index 7009acef6..afcf5bb45 100644 --- a/src/block/Candle.php +++ b/src/block/Candle.php @@ -91,7 +91,7 @@ class Candle extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } protected function getCandleIfCompatibleType(Block $block) : ?Candle{ diff --git a/src/block/Cauldron.php b/src/block/Cauldron.php index da1a938b2..fd04077b8 100644 --- a/src/block/Cauldron.php +++ b/src/block/Cauldron.php @@ -61,7 +61,7 @@ final class Cauldron extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return $facing === Facing::UP ? SupportType::EDGE() : SupportType::NONE(); + return $facing === Facing::UP ? SupportType::EDGE : SupportType::NONE; } /** diff --git a/src/block/CaveVines.php b/src/block/CaveVines.php index 6ff934881..18e820bfa 100644 --- a/src/block/CaveVines.php +++ b/src/block/CaveVines.php @@ -88,7 +88,7 @@ class CaveVines extends Flowable{ } private function canBeSupportedAt(Block $block) : bool{ - return $block->getAdjacentSupportType(Facing::UP)->equals(SupportType::FULL()) || $block->hasSameTypeId($this); + return $block->getAdjacentSupportType(Facing::UP) === SupportType::FULL || $block->hasSameTypeId($this); } public function onNearbyBlockChange() : void{ @@ -176,6 +176,6 @@ class CaveVines extends Flowable{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Chain.php b/src/block/Chain.php index fa8ffd1e8..e9cc2c9be 100644 --- a/src/block/Chain.php +++ b/src/block/Chain.php @@ -33,7 +33,7 @@ final class Chain extends Transparent{ use PillarRotationTrait; public function getSupportType(int $facing) : SupportType{ - return $this->axis === Axis::Y && Facing::axis($facing) === Axis::Y ? SupportType::CENTER() : SupportType::NONE(); + return $this->axis === Axis::Y && Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } protected function recalculateCollisionBoxes() : array{ diff --git a/src/block/Chest.php b/src/block/Chest.php index 270c696c3..dca21576a 100644 --- a/src/block/Chest.php +++ b/src/block/Chest.php @@ -45,7 +45,7 @@ class Chest extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onPostPlace() : void{ diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index 69f94eaf6..fcd9f4e0f 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -77,11 +77,11 @@ class CocoaBlock extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } private function canAttachTo(Block $block) : bool{ - return $block instanceof Wood && $block->getWoodType()->equals(WoodType::JUNGLE()); + return $block instanceof Wood && $block->getWoodType() === WoodType::JUNGLE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/CopperStairs.php b/src/block/CopperStairs.php index fe52616ce..b16d49ec1 100644 --- a/src/block/CopperStairs.php +++ b/src/block/CopperStairs.php @@ -23,14 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\block\utils\CopperOxidation; use pocketmine\block\utils\CopperTrait; class CopperStairs extends Stair{ use CopperTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->oxidation = CopperOxidation::NONE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/CoralBlock.php b/src/block/CoralBlock.php index 5ce58f413..3e7ca8224 100644 --- a/src/block/CoralBlock.php +++ b/src/block/CoralBlock.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\BlockEventHelper; -use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\item\Item; use function mt_rand; @@ -32,11 +31,6 @@ use function mt_rand; final class CoralBlock extends Opaque{ use CoralTypeTrait; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->coralType = CoralType::TUBE(); - parent::__construct($idInfo, $name, $typeInfo); - } - public function onNearbyBlockChange() : void{ if(!$this->dead){ $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200)); diff --git a/src/block/DaylightSensor.php b/src/block/DaylightSensor.php index e1f78aef5..0c0ec8820 100644 --- a/src/block/DaylightSensor.php +++ b/src/block/DaylightSensor.php @@ -70,7 +70,7 @@ class DaylightSensor extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 539454b41..738577296 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -38,12 +38,7 @@ use pocketmine\world\sound\ItemUseOnBlockSound; use pocketmine\world\sound\WaterSplashSound; class Dirt extends Opaque{ - protected DirtType $dirtType; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->dirtType = DirtType::NORMAL(); - parent::__construct($idInfo, $name, $typeInfo); - } + protected DirtType $dirtType = DirtType::NORMAL; public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->dirtType($this->dirtType); @@ -62,16 +57,16 @@ class Dirt extends Opaque{ if($face === Facing::UP && $item instanceof Hoe){ $item->applyDamage(1); - $newBlock = $this->dirtType->equals(DirtType::NORMAL()) ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT(); + $newBlock = $this->dirtType === DirtType::NORMAL ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT(); $center = $this->position->add(0.5, 0.5, 0.5); $world->addSound($center, new ItemUseOnBlockSound($newBlock)); $world->setBlock($this->position, $newBlock); - if($this->dirtType->equals(DirtType::ROOTED())){ + if($this->dirtType === DirtType::ROOTED){ $world->dropItem($center, VanillaBlocks::HANGING_ROOTS()->asItem()); } return true; - }elseif($this->dirtType->equals(DirtType::ROOTED()) && $item instanceof Fertilizer){ + }elseif($this->dirtType === DirtType::ROOTED && $item instanceof Fertilizer){ $down = $this->getSide(Facing::DOWN); if($down->getTypeId() !== BlockTypeIds::AIR){ return true; diff --git a/src/block/Door.php b/src/block/Door.php index a03427d5a..c97c5bb1e 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -102,7 +102,7 @@ class Door extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onNearbyBlockChange() : void{ diff --git a/src/block/DragonEgg.php b/src/block/DragonEgg.php index 98809152d..d76a91058 100644 --- a/src/block/DragonEgg.php +++ b/src/block/DragonEgg.php @@ -82,6 +82,6 @@ class DragonEgg extends Transparent implements Fallable{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/EnchantingTable.php b/src/block/EnchantingTable.php index f80d52d12..6a6c936b2 100644 --- a/src/block/EnchantingTable.php +++ b/src/block/EnchantingTable.php @@ -41,7 +41,7 @@ class EnchantingTable extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/EnderChest.php b/src/block/EnderChest.php index 26596eac9..9004f7c79 100644 --- a/src/block/EnderChest.php +++ b/src/block/EnderChest.php @@ -49,7 +49,7 @@ class EnderChest extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/Fence.php b/src/block/Fence.php index b57e81ded..4fa571b67 100644 --- a/src/block/Fence.php +++ b/src/block/Fence.php @@ -42,7 +42,7 @@ class Fence extends Transparent{ foreach(Facing::HORIZONTAL as $facing){ $block = $this->getSide($facing); - if($block instanceof static || $block instanceof FenceGate || $block->getSupportType(Facing::opposite($facing))->equals(SupportType::FULL())){ + if($block instanceof static || $block instanceof FenceGate || $block->getSupportType(Facing::opposite($facing)) === SupportType::FULL){ $this->connections[$facing] = true; }else{ unset($this->connections[$facing]); @@ -98,6 +98,6 @@ class Fence extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return Facing::axis($facing) === Axis::Y ? SupportType::CENTER() : SupportType::NONE(); + return Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } } diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index c22edabc4..735456449 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -72,7 +72,7 @@ class FenceGate extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } private function checkInWall() : bool{ diff --git a/src/block/FillableCauldron.php b/src/block/FillableCauldron.php index 84705ea9d..6c9b2940b 100644 --- a/src/block/FillableCauldron.php +++ b/src/block/FillableCauldron.php @@ -64,7 +64,7 @@ abstract class FillableCauldron extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return $facing === Facing::UP ? SupportType::EDGE() : SupportType::NONE(); + return $facing === Facing::UP ? SupportType::EDGE : SupportType::NONE; } protected function withFillLevel(int $fillLevel) : Block{ diff --git a/src/block/Fire.php b/src/block/Fire.php index 11378b82b..fbe765432 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -60,7 +60,7 @@ class Fire extends BaseFire{ } private function canBeSupportedBy(Block $block) : bool{ - return $block->getSupportType(Facing::UP)->equals(SupportType::FULL()); + return $block->getSupportType(Facing::UP) === SupportType::FULL; } public function onNearbyBlockChange() : void{ diff --git a/src/block/Flowable.php b/src/block/Flowable.php index 2b4e8a02b..795fe2756 100644 --- a/src/block/Flowable.php +++ b/src/block/Flowable.php @@ -48,6 +48,6 @@ abstract class Flowable extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Froglight.php b/src/block/Froglight.php index f33fc8261..2c54b830a 100644 --- a/src/block/Froglight.php +++ b/src/block/Froglight.php @@ -28,12 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber; final class Froglight extends SimplePillar{ - private FroglightType $froglightType; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->froglightType = FroglightType::OCHRE(); - parent::__construct($idInfo, $name, $typeInfo); - } + private FroglightType $froglightType = FroglightType::OCHRE; public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->froglightType($this->froglightType); diff --git a/src/block/GlowLichen.php b/src/block/GlowLichen.php index 84dec29ce..de66ccad7 100644 --- a/src/block/GlowLichen.php +++ b/src/block/GlowLichen.php @@ -95,7 +95,7 @@ class GlowLichen extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function canBeReplaced() : bool{ @@ -121,7 +121,7 @@ class GlowLichen extends Transparent{ $changed = false; foreach($this->faces as $face){ - if(!$this->getAdjacentSupportType($face)->equals(SupportType::FULL())){ + if($this->getAdjacentSupportType($face) !== SupportType::FULL){ unset($this->faces[$face]); $changed = true; } @@ -156,7 +156,7 @@ class GlowLichen extends Transparent{ $supportBlock = $world->getBlock($replacePos->getSide($spreadFace)); $supportFace = Facing::opposite($spreadFace); - if(!$supportBlock->getSupportType($supportFace)->equals(SupportType::FULL())){ + if($supportBlock->getSupportType($supportFace) !== SupportType::FULL){ return false; } @@ -268,7 +268,7 @@ class GlowLichen extends Transparent{ private function getAvailableFaces() : array{ $faces = []; foreach(Facing::ALL as $face){ - if(!$this->hasFace($face) && $this->getAdjacentSupportType($face)->equals(SupportType::FULL())){ + if(!$this->hasFace($face) && $this->getAdjacentSupportType($face) === SupportType::FULL){ $faces[$face] = $face; } } diff --git a/src/block/Grass.php b/src/block/Grass.php index 709dc6a9d..db2f8b922 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -69,7 +69,7 @@ class Grass extends Opaque{ $b = $world->getBlockAt($x, $y, $z); if( !($b instanceof Dirt) || - !$b->getDirtType()->equals(DirtType::NORMAL()) || + $b->getDirtType() !== DirtType::NORMAL || $world->getFullLightAt($x, $y + 1, $z) < 4 || $world->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 ){ diff --git a/src/block/Hopper.php b/src/block/Hopper.php index ea000503c..0d823674b 100644 --- a/src/block/Hopper.php +++ b/src/block/Hopper.php @@ -68,9 +68,9 @@ class Hopper extends Transparent{ public function getSupportType(int $facing) : SupportType{ return match($facing){ - Facing::UP => SupportType::FULL(), - Facing::DOWN => $this->facing === Facing::DOWN ? SupportType::CENTER() : SupportType::NONE(), - default => SupportType::NONE() + Facing::UP => SupportType::FULL, + Facing::DOWN => $this->facing === Facing::DOWN ? SupportType::CENTER : SupportType::NONE, + default => SupportType::NONE }; } diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index 21bc5c20a..b5b6093c4 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -164,7 +164,7 @@ class ItemFrame extends Flowable{ } private function canBeSupportedAt(Block $block, int $face) : bool{ - return !$block->getAdjacentSupportType($face)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType($face) !== SupportType::NONE; } public function onNearbyBlockChange() : void{ diff --git a/src/block/Ladder.php b/src/block/Ladder.php index 83adada82..58f133f6e 100644 --- a/src/block/Ladder.php +++ b/src/block/Ladder.php @@ -66,7 +66,7 @@ class Ladder extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ @@ -85,6 +85,6 @@ class Ladder extends Transparent{ } private function canBeSupportedAt(Block $block, int $face) : bool{ - return $block->getAdjacentSupportType($face)->equals(SupportType::FULL()); + return $block->getAdjacentSupportType($face) === SupportType::FULL; } } diff --git a/src/block/Lantern.php b/src/block/Lantern.php index 8ebc8ba2c..e9cbcc3fe 100644 --- a/src/block/Lantern.php +++ b/src/block/Lantern.php @@ -73,7 +73,7 @@ class Lantern extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/Leaves.php b/src/block/Leaves.php index b1839dca6..ac1ffb94a 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -147,23 +147,22 @@ class Leaves extends Transparent{ if(FortuneDropHelper::bonusChanceDivisor($item, 20, 4)){ //Saplings // TODO: according to the wiki, the jungle saplings have a different drop rate $sapling = (match($this->leavesType){ - LeavesType::ACACIA() => VanillaBlocks::ACACIA_SAPLING(), - LeavesType::BIRCH() => VanillaBlocks::BIRCH_SAPLING(), - LeavesType::DARK_OAK() => VanillaBlocks::DARK_OAK_SAPLING(), - LeavesType::JUNGLE() => VanillaBlocks::JUNGLE_SAPLING(), - LeavesType::OAK() => VanillaBlocks::OAK_SAPLING(), - LeavesType::SPRUCE() => VanillaBlocks::SPRUCE_SAPLING(), - LeavesType::MANGROVE(), //TODO: mangrove propagule - LeavesType::AZALEA(), LeavesType::FLOWERING_AZALEA() => null, //TODO: azalea - LeavesType::CHERRY() => null, //TODO: cherry - default => throw new AssumptionFailedError("Unreachable") + LeavesType::ACACIA => VanillaBlocks::ACACIA_SAPLING(), + LeavesType::BIRCH => VanillaBlocks::BIRCH_SAPLING(), + LeavesType::DARK_OAK => VanillaBlocks::DARK_OAK_SAPLING(), + LeavesType::JUNGLE => VanillaBlocks::JUNGLE_SAPLING(), + LeavesType::OAK => VanillaBlocks::OAK_SAPLING(), + LeavesType::SPRUCE => VanillaBlocks::SPRUCE_SAPLING(), + LeavesType::MANGROVE, //TODO: mangrove propagule + LeavesType::AZALEA, LeavesType::FLOWERING_AZALEA => null, //TODO: azalea + LeavesType::CHERRY => null, //TODO: cherry })?->asItem(); if($sapling !== null){ $drops[] = $sapling; } } if( - ($this->leavesType->equals(LeavesType::OAK()) || $this->leavesType->equals(LeavesType::DARK_OAK())) && + ($this->leavesType === LeavesType::OAK || $this->leavesType === LeavesType::DARK_OAK) && FortuneDropHelper::bonusChanceDivisor($item, 200, 20) ){ //Apples $drops[] = VanillaItems::APPLE(); @@ -188,6 +187,6 @@ class Leaves extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Lectern.php b/src/block/Lectern.php index d9f07d22b..03880b3c5 100644 --- a/src/block/Lectern.php +++ b/src/block/Lectern.php @@ -87,7 +87,7 @@ class Lectern extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function isProducingSignal() : bool{ return $this->producingSignal; } diff --git a/src/block/Lever.php b/src/block/Lever.php index e4b8c0811..01aa89245 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -36,14 +36,9 @@ use pocketmine\world\sound\RedstonePowerOffSound; use pocketmine\world\sound\RedstonePowerOnSound; class Lever extends Flowable{ - protected LeverFacing $facing; + protected LeverFacing $facing = LeverFacing::UP_AXIS_X; protected bool $activated = false; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->facing = LeverFacing::UP_AXIS_X(); - parent::__construct($idInfo, $name, $typeInfo); - } - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->leverFacing($this->facing); $w->bool($this->activated); @@ -77,12 +72,12 @@ class Lever extends Flowable{ return $x; }; $this->facing = match($face){ - Facing::DOWN => $selectUpDownPos(LeverFacing::DOWN_AXIS_X(), LeverFacing::DOWN_AXIS_Z()), - Facing::UP => $selectUpDownPos(LeverFacing::UP_AXIS_X(), LeverFacing::UP_AXIS_Z()), - Facing::NORTH => LeverFacing::NORTH(), - Facing::SOUTH => LeverFacing::SOUTH(), - Facing::WEST => LeverFacing::WEST(), - Facing::EAST => LeverFacing::EAST(), + Facing::DOWN => $selectUpDownPos(LeverFacing::DOWN_AXIS_X, LeverFacing::DOWN_AXIS_Z), + Facing::UP => $selectUpDownPos(LeverFacing::UP_AXIS_X, LeverFacing::UP_AXIS_Z), + Facing::NORTH => LeverFacing::NORTH, + Facing::SOUTH => LeverFacing::SOUTH, + Facing::WEST => LeverFacing::WEST, + Facing::EAST => LeverFacing::EAST, default => throw new AssumptionFailedError("Bad facing value"), }; diff --git a/src/block/Liquid.php b/src/block/Liquid.php index e102540ec..2299f7d71 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -97,7 +97,7 @@ abstract class Liquid extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function getDropsForCompatibleTool(Item $item) : array{ diff --git a/src/block/MobHead.php b/src/block/MobHead.php index 96cd1cf34..125bafe8b 100644 --- a/src/block/MobHead.php +++ b/src/block/MobHead.php @@ -39,16 +39,11 @@ class MobHead extends Flowable{ public const MIN_ROTATION = 0; public const MAX_ROTATION = 15; - protected MobHeadType $mobHeadType; + protected MobHeadType $mobHeadType = MobHeadType::SKELETON; protected int $facing = Facing::NORTH; protected int $rotation = self::MIN_ROTATION; //TODO: split this into floor skull and wall skull handling - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->mobHeadType = MobHeadType::SKELETON(); //TODO: this should be a parameter - parent::__construct($idInfo, $name, $typeInfo); - } - public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->mobHeadType($this->mobHeadType); } diff --git a/src/block/MonsterSpawner.php b/src/block/MonsterSpawner.php index 129da3394..5cbe80e0a 100644 --- a/src/block/MonsterSpawner.php +++ b/src/block/MonsterSpawner.php @@ -42,6 +42,6 @@ class MonsterSpawner extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Mycelium.php b/src/block/Mycelium.php index 08b0b3e75..05b63d9bf 100644 --- a/src/block/Mycelium.php +++ b/src/block/Mycelium.php @@ -52,7 +52,7 @@ class Mycelium extends Opaque{ $z = mt_rand($this->position->z - 1, $this->position->z + 1); $world = $this->position->getWorld(); $block = $world->getBlockAt($x, $y, $z); - if($block instanceof Dirt && $block->getDirtType()->equals(DirtType::NORMAL())){ + if($block instanceof Dirt && $block->getDirtType() === DirtType::NORMAL){ if($block->getSide(Facing::UP) instanceof Transparent){ BlockEventHelper::spread($block, VanillaBlocks::MYCELIUM(), $this); } diff --git a/src/block/NetherPortal.php b/src/block/NetherPortal.php index a2524914a..6a45fb7a0 100644 --- a/src/block/NetherPortal.php +++ b/src/block/NetherPortal.php @@ -70,7 +70,7 @@ class NetherPortal extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function getDrops(Item $item) : array{ diff --git a/src/block/NetherVines.php b/src/block/NetherVines.php index c78000fa1..968a9b92e 100644 --- a/src/block/NetherVines.php +++ b/src/block/NetherVines.php @@ -184,6 +184,6 @@ class NetherVines extends Flowable{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/PressurePlate.php b/src/block/PressurePlate.php index d67433a75..ae2a936bb 100644 --- a/src/block/PressurePlate.php +++ b/src/block/PressurePlate.php @@ -60,7 +60,7 @@ abstract class PressurePlate extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ @@ -71,7 +71,7 @@ abstract class PressurePlate extends Transparent{ } private function canBeSupportedAt(Block $block) : bool{ - return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE; } public function onNearbyBlockChange() : void{ diff --git a/src/block/RedMushroomBlock.php b/src/block/RedMushroomBlock.php index ecac38e18..cf368a30a 100644 --- a/src/block/RedMushroomBlock.php +++ b/src/block/RedMushroomBlock.php @@ -29,12 +29,7 @@ use pocketmine\item\Item; use function mt_rand; class RedMushroomBlock extends Opaque{ - protected MushroomBlockType $mushroomBlockType; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->mushroomBlockType = MushroomBlockType::ALL_CAP(); - parent::__construct($idInfo, $name, $typeInfo); - } + protected MushroomBlockType $mushroomBlockType = MushroomBlockType::ALL_CAP; public function describeBlockItemState(RuntimeDataDescriber $w) : void{ //these blocks always drop as all-cap, but may exist in other forms in the inventory (particularly creative), @@ -61,10 +56,10 @@ class RedMushroomBlock extends Opaque{ } public function getSilkTouchDrops(Item $item) : array{ - return [(clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP())->asItem()]; + return [(clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP)->asItem()]; } public function getPickedItem(bool $addUserData = false) : Item{ - return (clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP())->asItem(); + return (clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP)->asItem(); } } diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index 8b436020b..5a22c6bf8 100644 --- a/src/block/RedstoneComparator.php +++ b/src/block/RedstoneComparator.php @@ -108,7 +108,7 @@ class RedstoneComparator extends Flowable{ } private function canBeSupportedAt(Block $block) : bool{ - return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE; } //TODO: redstone functionality diff --git a/src/block/RedstoneRepeater.php b/src/block/RedstoneRepeater.php index 518eeb9e5..848c9aa89 100644 --- a/src/block/RedstoneRepeater.php +++ b/src/block/RedstoneRepeater.php @@ -94,7 +94,7 @@ class RedstoneRepeater extends Flowable{ } private function canBeSupportedAt(Block $block) : bool{ - return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE; } //TODO: redstone functionality diff --git a/src/block/SeaPickle.php b/src/block/SeaPickle.php index 4e667038e..62662f9cf 100644 --- a/src/block/SeaPickle.php +++ b/src/block/SeaPickle.php @@ -78,7 +78,7 @@ class SeaPickle extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ diff --git a/src/block/ShulkerBox.php b/src/block/ShulkerBox.php index 821e022f4..d557401ee 100644 --- a/src/block/ShulkerBox.php +++ b/src/block/ShulkerBox.php @@ -113,6 +113,6 @@ class ShulkerBox extends Opaque{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Slab.php b/src/block/Slab.php index cbf5dce18..bdf2bb5eb 100644 --- a/src/block/Slab.php +++ b/src/block/Slab.php @@ -34,10 +34,9 @@ use pocketmine\player\Player; use pocketmine\world\BlockTransaction; class Slab extends Transparent{ - protected SlabType $slabType; + protected SlabType $slabType = SlabType::BOTTOM; public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->slabType = SlabType::BOTTOM(); parent::__construct($idInfo, $name . " Slab", $typeInfo); } @@ -46,7 +45,7 @@ class Slab extends Transparent{ } public function isTransparent() : bool{ - return !$this->slabType->equals(SlabType::DOUBLE()); + return $this->slabType !== SlabType::DOUBLE; } /** @@ -69,8 +68,8 @@ class Slab extends Transparent{ return true; } - if($blockReplace instanceof Slab && !$blockReplace->slabType->equals(SlabType::DOUBLE()) && $blockReplace->hasSameTypeId($this)){ - if($blockReplace->slabType->equals(SlabType::TOP())){ //Trying to combine with top slab + if($blockReplace instanceof Slab && $blockReplace->slabType !== SlabType::DOUBLE && $blockReplace->hasSameTypeId($this)){ + if($blockReplace->slabType === SlabType::TOP){ //Trying to combine with top slab return $clickVector->y <= 0.5 || (!$isClickedBlock && $face === Facing::UP); }else{ return $clickVector->y >= 0.5 || (!$isClickedBlock && $face === Facing::DOWN); @@ -81,14 +80,14 @@ class Slab extends Transparent{ } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($blockReplace instanceof Slab && !$blockReplace->slabType->equals(SlabType::DOUBLE()) && $blockReplace->hasSameTypeId($this) && ( - ($blockReplace->slabType->equals(SlabType::TOP()) && ($clickVector->y <= 0.5 || $face === Facing::UP)) || - ($blockReplace->slabType->equals(SlabType::BOTTOM()) && ($clickVector->y >= 0.5 || $face === Facing::DOWN)) + if($blockReplace instanceof Slab && $blockReplace->slabType !== SlabType::DOUBLE && $blockReplace->hasSameTypeId($this) && ( + ($blockReplace->slabType === SlabType::TOP && ($clickVector->y <= 0.5 || $face === Facing::UP)) || + ($blockReplace->slabType === SlabType::BOTTOM && ($clickVector->y >= 0.5 || $face === Facing::DOWN)) )){ //Clicked in empty half of existing slab - $this->slabType = SlabType::DOUBLE(); + $this->slabType = SlabType::DOUBLE; }else{ - $this->slabType = (($face !== Facing::UP && $clickVector->y > 0.5) || $face === Facing::DOWN) ? SlabType::TOP() : SlabType::BOTTOM(); + $this->slabType = (($face !== Facing::UP && $clickVector->y > 0.5) || $face === Facing::DOWN) ? SlabType::TOP : SlabType::BOTTOM; } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -98,22 +97,22 @@ class Slab extends Transparent{ * @return AxisAlignedBB[] */ protected function recalculateCollisionBoxes() : array{ - if($this->slabType->equals(SlabType::DOUBLE())){ + if($this->slabType === SlabType::DOUBLE){ return [AxisAlignedBB::one()]; } - return [AxisAlignedBB::one()->trim($this->slabType->equals(SlabType::TOP()) ? Facing::DOWN : Facing::UP, 0.5)]; + return [AxisAlignedBB::one()->trim($this->slabType === SlabType::TOP ? Facing::DOWN : Facing::UP, 0.5)]; } public function getSupportType(int $facing) : SupportType{ - if($this->slabType->equals(SlabType::DOUBLE())){ - return SupportType::FULL(); - }elseif(($facing === Facing::UP && $this->slabType->equals(SlabType::TOP())) || ($facing === Facing::DOWN && $this->slabType->equals(SlabType::BOTTOM()))){ - return SupportType::FULL(); + if($this->slabType === SlabType::DOUBLE){ + return SupportType::FULL; + }elseif(($facing === Facing::UP && $this->slabType === SlabType::TOP) || ($facing === Facing::DOWN && $this->slabType === SlabType::BOTTOM)){ + return SupportType::FULL; } - return SupportType::NONE(); + return SupportType::NONE; } public function getDropsForCompatibleTool(Item $item) : array{ - return [$this->asItem()->setCount($this->slabType->equals(SlabType::DOUBLE()) ? 2 : 1)]; + return [$this->asItem()->setCount($this->slabType === SlabType::DOUBLE ? 2 : 1)]; } } diff --git a/src/block/SmallDripleaf.php b/src/block/SmallDripleaf.php index e08e6f6e9..ad23608bf 100644 --- a/src/block/SmallDripleaf.php +++ b/src/block/SmallDripleaf.php @@ -161,7 +161,7 @@ class SmallDripleaf extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } protected function recalculateCollisionBoxes() : array{ diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index 05fc88421..fd7258d91 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -75,13 +75,13 @@ class SnowLayer extends Flowable implements Fallable{ public function getSupportType(int $facing) : SupportType{ if(!$this->canBeReplaced()){ - return SupportType::FULL(); + return SupportType::FULL; } - return SupportType::NONE(); + return SupportType::NONE; } private function canBeSupportedAt(Block $block) : bool{ - return $block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::FULL()); + return $block->getAdjacentSupportType(Facing::DOWN) === SupportType::FULL; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/SporeBlossom.php b/src/block/SporeBlossom.php index 909932178..dbb4b71fc 100644 --- a/src/block/SporeBlossom.php +++ b/src/block/SporeBlossom.php @@ -33,7 +33,7 @@ use pocketmine\world\BlockTransaction; final class SporeBlossom extends Flowable{ private function canBeSupportedAt(Block $block) : bool{ - return $block->getAdjacentSupportType(Facing::UP)->equals(SupportType::FULL()); + return $block->getAdjacentSupportType(Facing::UP) === SupportType::FULL; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/Stair.php b/src/block/Stair.php index a20746721..25d1da8d9 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -39,12 +39,7 @@ class Stair extends Transparent{ use HorizontalFacingTrait; protected bool $upsideDown = false; - protected StairShape $shape; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->shape = StairShape::STRAIGHT(); - parent::__construct($idInfo, $name, $typeInfo); - } + protected StairShape $shape = StairShape::STRAIGHT; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); @@ -56,11 +51,11 @@ class Stair extends Transparent{ $clockwise = Facing::rotateY($this->facing, true); if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){ - $this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT() : StairShape::OUTER_LEFT(); + $this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT : StairShape::OUTER_LEFT; }elseif(($frontFacing = $this->getPossibleCornerFacing(true)) !== null){ - $this->shape = $frontFacing === $clockwise ? StairShape::INNER_RIGHT() : StairShape::INNER_LEFT(); + $this->shape = $frontFacing === $clockwise ? StairShape::INNER_RIGHT : StairShape::INNER_LEFT; }else{ - $this->shape = StairShape::STRAIGHT(); + $this->shape = StairShape::STRAIGHT; } return $this; @@ -92,14 +87,14 @@ class Stair extends Transparent{ ->trim(Facing::opposite($topStepFace), 0.5) ->trim(Facing::opposite($this->facing), 0.5); - if($this->shape->equals(StairShape::OUTER_LEFT()) || $this->shape->equals(StairShape::OUTER_RIGHT())){ - $topStep->trim(Facing::rotateY($this->facing, $this->shape->equals(StairShape::OUTER_LEFT())), 0.5); - }elseif($this->shape->equals(StairShape::INNER_LEFT()) || $this->shape->equals(StairShape::INNER_RIGHT())){ + if($this->shape === StairShape::OUTER_LEFT || $this->shape === StairShape::OUTER_RIGHT){ + $topStep->trim(Facing::rotateY($this->facing, $this->shape === StairShape::OUTER_LEFT), 0.5); + }elseif($this->shape === StairShape::INNER_LEFT || $this->shape === StairShape::INNER_RIGHT){ //add an extra cube $bbs[] = AxisAlignedBB::one() ->trim(Facing::opposite($topStepFace), 0.5) ->trim($this->facing, 0.5) //avoid overlapping with main step - ->trim(Facing::rotateY($this->facing, $this->shape->equals(StairShape::INNER_LEFT())), 0.5); + ->trim(Facing::rotateY($this->facing, $this->shape === StairShape::INNER_LEFT), 0.5); } $bbs[] = $topStep; @@ -111,13 +106,13 @@ class Stair extends Transparent{ if( $facing === Facing::UP && $this->isUpsideDown() || $facing === Facing::DOWN && !$this->isUpsideDown() || - ($facing === $this->facing && !$this->shape->equals(StairShape::OUTER_LEFT()) && !$this->shape->equals(StairShape::OUTER_RIGHT())) || - ($facing === Facing::rotate($this->facing, Axis::Y, false) && $this->shape->equals(StairShape::INNER_LEFT())) || - ($facing === Facing::rotate($this->facing, Axis::Y, true) && $this->shape->equals(StairShape::INNER_RIGHT())) + ($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) ){ - return SupportType::FULL(); + return SupportType::FULL; } - return SupportType::NONE(); + return SupportType::NONE; } private function getPossibleCornerFacing(bool $oppositeFacing) : ?int{ diff --git a/src/block/Stonecutter.php b/src/block/Stonecutter.php index eb7dc68c2..30c19d25d 100644 --- a/src/block/Stonecutter.php +++ b/src/block/Stonecutter.php @@ -47,6 +47,6 @@ class Stonecutter extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Thin.php b/src/block/Thin.php index 2b89b4bee..bf82c3e58 100644 --- a/src/block/Thin.php +++ b/src/block/Thin.php @@ -41,7 +41,7 @@ class Thin extends Transparent{ foreach(Facing::HORIZONTAL as $facing){ $side = $this->getSide($facing); - if($side instanceof Thin || $side instanceof Wall || $side->getSupportType(Facing::opposite($facing))->equals(SupportType::FULL())){ + if($side instanceof Thin || $side instanceof Wall || $side->getSupportType(Facing::opposite($facing)) === SupportType::FULL){ $this->connections[$facing] = true; }else{ unset($this->connections[$facing]); @@ -90,6 +90,6 @@ class Thin extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Torch.php b/src/block/Torch.php index 66b62bc19..aee4da32a 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -84,6 +84,6 @@ class Torch extends Flowable{ private function canBeSupportedAt(Block $block, int $face) : bool{ return $face === Facing::DOWN ? $block->getAdjacentSupportType($face)->hasCenterSupport() : - $block->getAdjacentSupportType($face)->equals(SupportType::FULL()); + $block->getAdjacentSupportType($face) === SupportType::FULL; } } diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index d12a922df..20b6af2ab 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -70,7 +70,7 @@ class Trapdoor extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index a41c3985b..c6b878d2f 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -68,6 +68,7 @@ use pocketmine\utils\CloningRegistryTrait; use pocketmine\world\sound\AmethystBlockChimeSound; use pocketmine\world\sound\BlockPunchSound; use function mb_strtolower; +use function strtolower; /** * This doc-block is generated automatically, do not modify it manually. @@ -1140,13 +1141,13 @@ final class VanillaBlocks{ }); $saplingTypeInfo = new Info(BreakInfo::instant(), [Tags::POTTABLE_PLANTS]); - foreach(SaplingType::getAll() as $saplingType){ + foreach(SaplingType::cases() as $saplingType){ $name = $saplingType->getDisplayName(); - self::register($saplingType->name() . "_sapling", new Sapling(WoodLikeBlockIdHelper::getSaplingIdentifier($saplingType), $name . " Sapling", $saplingTypeInfo, $saplingType)); + self::register(strtolower($saplingType->name) . "_sapling", new Sapling(WoodLikeBlockIdHelper::getSaplingIdentifier($saplingType), $name . " Sapling", $saplingTypeInfo, $saplingType)); } - foreach(LeavesType::getAll() as $leavesType){ + foreach(LeavesType::cases() as $leavesType){ $name = $leavesType->getDisplayName(); - self::register($leavesType->name() . "_leaves", new Leaves(WoodLikeBlockIdHelper::getLeavesIdentifier($leavesType), $name . " Leaves", $leavesBreakInfo, $leavesType)); + self::register(strtolower($leavesType->name) . "_leaves", new Leaves(WoodLikeBlockIdHelper::getLeavesIdentifier($leavesType), $name . " Leaves", $leavesBreakInfo, $leavesType)); } $sandstoneBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD())); @@ -1262,9 +1263,9 @@ final class VanillaBlocks{ $woodenButtonBreakInfo = new Info(BreakInfo::axe(0.5)); $woodenPressurePlateBreakInfo = new Info(BreakInfo::axe(0.5)); - foreach(WoodType::getAll() as $woodType){ + foreach(WoodType::cases() as $woodType){ $name = $woodType->getDisplayName(); - $idName = fn(string $suffix) => $woodType->name() . "_" . $suffix; + $idName = fn(string $suffix) => strtolower($woodType->name) . "_" . $suffix; self::register($idName(mb_strtolower($woodType->getStandardLogSuffix() ?? "log", 'US-ASCII')), new Wood(WoodLikeBlockIdHelper::getLogIdentifier($woodType), $name . " " . ($woodType->getStandardLogSuffix() ?? "Log"), $logBreakInfo, $woodType)); self::register($idName(mb_strtolower($woodType->getAllSidedLogSuffix() ?? "wood", 'US-ASCII')), new Wood(WoodLikeBlockIdHelper::getAllSidedLogIdentifier($woodType), $name . " " . ($woodType->getAllSidedLogSuffix() ?? "Wood"), $logBreakInfo, $woodType)); diff --git a/src/block/Wall.php b/src/block/Wall.php index 87ee0b1bd..520ced8eb 100644 --- a/src/block/Wall.php +++ b/src/block/Wall.php @@ -101,9 +101,9 @@ class Wall extends Transparent{ foreach(Facing::HORIZONTAL as $facing){ $block = $this->getSide($facing); - if($block instanceof static || $block instanceof FenceGate || $block instanceof Thin || $block->getSupportType(Facing::opposite($facing))->equals(SupportType::FULL())){ + if($block instanceof static || $block instanceof FenceGate || $block instanceof Thin || $block->getSupportType(Facing::opposite($facing)) === SupportType::FULL){ if(!isset($this->connections[$facing])){ - $this->connections[$facing] = WallConnectionType::SHORT(); + $this->connections[$facing] = WallConnectionType::SHORT; $changed++; } }elseif(isset($this->connections[$facing])){ @@ -152,6 +152,6 @@ class Wall extends Transparent{ } public function getSupportType(int $facing) : SupportType{ - return Facing::axis($facing) === Axis::Y ? SupportType::CENTER() : SupportType::NONE(); + return Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } } diff --git a/src/block/WoodLikeBlockIdHelper.php b/src/block/WoodLikeBlockIdHelper.php index f4cddb53b..add1d54c0 100644 --- a/src/block/WoodLikeBlockIdHelper.php +++ b/src/block/WoodLikeBlockIdHelper.php @@ -48,110 +48,103 @@ use pocketmine\utils\AssumptionFailedError; final class WoodLikeBlockIdHelper{ public static function getPlanksIdentifier(WoodType $type) : BID{ - return new BID(match($type->id()){ - WoodType::OAK()->id() => Ids::OAK_PLANKS, - WoodType::SPRUCE()->id() => Ids::SPRUCE_PLANKS, - WoodType::BIRCH()->id() => Ids::BIRCH_PLANKS, - WoodType::JUNGLE()->id() => Ids::JUNGLE_PLANKS, - WoodType::ACACIA()->id() => Ids::ACACIA_PLANKS, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_PLANKS, - WoodType::MANGROVE()->id() => Ids::MANGROVE_PLANKS, - WoodType::CRIMSON()->id() => Ids::CRIMSON_PLANKS, - WoodType::WARPED()->id() => Ids::WARPED_PLANKS, - WoodType::CHERRY()->id() => Ids::CHERRY_PLANKS, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($type){ + WoodType::OAK => Ids::OAK_PLANKS, + WoodType::SPRUCE => Ids::SPRUCE_PLANKS, + WoodType::BIRCH => Ids::BIRCH_PLANKS, + WoodType::JUNGLE => Ids::JUNGLE_PLANKS, + WoodType::ACACIA => Ids::ACACIA_PLANKS, + WoodType::DARK_OAK => Ids::DARK_OAK_PLANKS, + WoodType::MANGROVE => Ids::MANGROVE_PLANKS, + WoodType::CRIMSON => Ids::CRIMSON_PLANKS, + WoodType::WARPED => Ids::WARPED_PLANKS, + WoodType::CHERRY => Ids::CHERRY_PLANKS, }); } public static function getFenceIdentifier(WoodType $type) : BID{ - return new BID(match($type->id()){ - WoodType::OAK()->id() => Ids::OAK_FENCE, - WoodType::SPRUCE()->id() => Ids::SPRUCE_FENCE, - WoodType::BIRCH()->id() => Ids::BIRCH_FENCE, - WoodType::JUNGLE()->id() => Ids::JUNGLE_FENCE, - WoodType::ACACIA()->id() => Ids::ACACIA_FENCE, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_FENCE, - WoodType::MANGROVE()->id() => Ids::MANGROVE_FENCE, - WoodType::CRIMSON()->id() => Ids::CRIMSON_FENCE, - WoodType::WARPED()->id() => Ids::WARPED_FENCE, - WoodType::CHERRY()->id() => Ids::CHERRY_FENCE, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($type){ + WoodType::OAK => Ids::OAK_FENCE, + WoodType::SPRUCE => Ids::SPRUCE_FENCE, + WoodType::BIRCH => Ids::BIRCH_FENCE, + WoodType::JUNGLE => Ids::JUNGLE_FENCE, + WoodType::ACACIA => Ids::ACACIA_FENCE, + WoodType::DARK_OAK => Ids::DARK_OAK_FENCE, + WoodType::MANGROVE => Ids::MANGROVE_FENCE, + WoodType::CRIMSON => Ids::CRIMSON_FENCE, + WoodType::WARPED => Ids::WARPED_FENCE, + WoodType::CHERRY => Ids::CHERRY_FENCE, }); } public static function getSlabIdentifier(WoodType $type) : BID{ - return new BID(match($type->id()){ - WoodType::OAK()->id() => Ids::OAK_SLAB, - WoodType::SPRUCE()->id() => Ids::SPRUCE_SLAB, - WoodType::BIRCH()->id() => Ids::BIRCH_SLAB, - WoodType::JUNGLE()->id() => Ids::JUNGLE_SLAB, - WoodType::ACACIA()->id() => Ids::ACACIA_SLAB, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_SLAB, - WoodType::MANGROVE()->id() => Ids::MANGROVE_SLAB, - WoodType::CRIMSON()->id() => Ids::CRIMSON_SLAB, - WoodType::WARPED()->id() => Ids::WARPED_SLAB, - WoodType::CHERRY()->id() => Ids::CHERRY_SLAB, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($type){ + WoodType::OAK => Ids::OAK_SLAB, + WoodType::SPRUCE => Ids::SPRUCE_SLAB, + WoodType::BIRCH => Ids::BIRCH_SLAB, + WoodType::JUNGLE => Ids::JUNGLE_SLAB, + WoodType::ACACIA => Ids::ACACIA_SLAB, + WoodType::DARK_OAK => Ids::DARK_OAK_SLAB, + WoodType::MANGROVE => Ids::MANGROVE_SLAB, + WoodType::CRIMSON => Ids::CRIMSON_SLAB, + WoodType::WARPED => Ids::WARPED_SLAB, + WoodType::CHERRY => Ids::CHERRY_SLAB, }); } public static function getLogIdentifier(WoodType $treeType) : BID{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_LOG, - WoodType::SPRUCE()->id() => Ids::SPRUCE_LOG, - WoodType::BIRCH()->id() => Ids::BIRCH_LOG, - WoodType::JUNGLE()->id() => Ids::JUNGLE_LOG, - WoodType::ACACIA()->id() => Ids::ACACIA_LOG, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_LOG, - WoodType::MANGROVE()->id() => Ids::MANGROVE_LOG, - WoodType::CRIMSON()->id() => Ids::CRIMSON_STEM, - WoodType::WARPED()->id() => Ids::WARPED_STEM, - WoodType::CHERRY()->id() => Ids::CHERRY_LOG, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_LOG, + WoodType::SPRUCE => Ids::SPRUCE_LOG, + WoodType::BIRCH => Ids::BIRCH_LOG, + WoodType::JUNGLE => Ids::JUNGLE_LOG, + WoodType::ACACIA => Ids::ACACIA_LOG, + WoodType::DARK_OAK => Ids::DARK_OAK_LOG, + WoodType::MANGROVE => Ids::MANGROVE_LOG, + WoodType::CRIMSON => Ids::CRIMSON_STEM, + WoodType::WARPED => Ids::WARPED_STEM, + WoodType::CHERRY => Ids::CHERRY_LOG, }); } public static function getAllSidedLogIdentifier(WoodType $treeType) : BID{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_WOOD, - WoodType::SPRUCE()->id() => Ids::SPRUCE_WOOD, - WoodType::BIRCH()->id() => Ids::BIRCH_WOOD, - WoodType::JUNGLE()->id() => Ids::JUNGLE_WOOD, - WoodType::ACACIA()->id() => Ids::ACACIA_WOOD, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_WOOD, - WoodType::MANGROVE()->id() => Ids::MANGROVE_WOOD, - WoodType::CRIMSON()->id() => Ids::CRIMSON_HYPHAE, - WoodType::WARPED()->id() => Ids::WARPED_HYPHAE, - WoodType::CHERRY()->id() => Ids::CHERRY_WOOD, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_WOOD, + WoodType::SPRUCE => Ids::SPRUCE_WOOD, + WoodType::BIRCH => Ids::BIRCH_WOOD, + WoodType::JUNGLE => Ids::JUNGLE_WOOD, + WoodType::ACACIA => Ids::ACACIA_WOOD, + WoodType::DARK_OAK => Ids::DARK_OAK_WOOD, + WoodType::MANGROVE => Ids::MANGROVE_WOOD, + WoodType::CRIMSON => Ids::CRIMSON_HYPHAE, + WoodType::WARPED => Ids::WARPED_HYPHAE, + WoodType::CHERRY => Ids::CHERRY_WOOD, }); } public static function getLeavesIdentifier(LeavesType $leavesType) : BID{ - return new BID(match($leavesType->id()){ - LeavesType::OAK()->id() => Ids::OAK_LEAVES, - LeavesType::SPRUCE()->id() => Ids::SPRUCE_LEAVES, - LeavesType::BIRCH()->id() => Ids::BIRCH_LEAVES, - LeavesType::JUNGLE()->id() => Ids::JUNGLE_LEAVES, - LeavesType::ACACIA()->id() => Ids::ACACIA_LEAVES, - LeavesType::DARK_OAK()->id() => Ids::DARK_OAK_LEAVES, - LeavesType::MANGROVE()->id() => Ids::MANGROVE_LEAVES, - LeavesType::AZALEA()->id() => Ids::AZALEA_LEAVES, - LeavesType::FLOWERING_AZALEA()->id() => Ids::FLOWERING_AZALEA_LEAVES, - LeavesType::CHERRY()->id() => Ids::CHERRY_LEAVES, - default => throw new AssumptionFailedError("All leaves types should be covered") + return new BID(match($leavesType){ + LeavesType::OAK => Ids::OAK_LEAVES, + LeavesType::SPRUCE => Ids::SPRUCE_LEAVES, + LeavesType::BIRCH => Ids::BIRCH_LEAVES, + LeavesType::JUNGLE => Ids::JUNGLE_LEAVES, + LeavesType::ACACIA => Ids::ACACIA_LEAVES, + LeavesType::DARK_OAK => Ids::DARK_OAK_LEAVES, + LeavesType::MANGROVE => Ids::MANGROVE_LEAVES, + LeavesType::AZALEA => Ids::AZALEA_LEAVES, + LeavesType::FLOWERING_AZALEA => Ids::FLOWERING_AZALEA_LEAVES, + LeavesType::CHERRY => Ids::CHERRY_LEAVES, }); } public static function getSaplingIdentifier(SaplingType $treeType) : BID{ - return new BID(match($treeType->id()){ - SaplingType::OAK()->id() => Ids::OAK_SAPLING, - SaplingType::SPRUCE()->id() => Ids::SPRUCE_SAPLING, - SaplingType::BIRCH()->id() => Ids::BIRCH_SAPLING, - SaplingType::JUNGLE()->id() => Ids::JUNGLE_SAPLING, - SaplingType::ACACIA()->id() => Ids::ACACIA_SAPLING, - SaplingType::DARK_OAK()->id() => Ids::DARK_OAK_SAPLING, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($treeType){ + SaplingType::OAK => Ids::OAK_SAPLING, + SaplingType::SPRUCE => Ids::SPRUCE_SAPLING, + SaplingType::BIRCH => Ids::BIRCH_SAPLING, + SaplingType::JUNGLE => Ids::JUNGLE_SAPLING, + SaplingType::ACACIA => Ids::ACACIA_SAPLING, + SaplingType::DARK_OAK => Ids::DARK_OAK_SAPLING, }); } @@ -160,62 +153,62 @@ final class WoodLikeBlockIdHelper{ * @phpstan-return array{BID, BID, \Closure() : \pocketmine\item\Item} */ public static function getSignInfo(WoodType $treeType) : array{ - switch($treeType->id()){ - case WoodType::OAK()->id(): + switch($treeType){ + case WoodType::OAK: return [ new BID(Ids::OAK_SIGN, TileSign::class), new BID(Ids::OAK_WALL_SIGN, TileSign::class), fn() => VanillaItems::OAK_SIGN() ]; - case WoodType::SPRUCE()->id(): + case WoodType::SPRUCE: return [ new BID(Ids::SPRUCE_SIGN, TileSign::class), new BID(Ids::SPRUCE_WALL_SIGN, TileSign::class), fn() => VanillaItems::SPRUCE_SIGN() ]; - case WoodType::BIRCH()->id(): + case WoodType::BIRCH: return [ new BID(Ids::BIRCH_SIGN, TileSign::class), new BID(Ids::BIRCH_WALL_SIGN, TileSign::class), fn() => VanillaItems::BIRCH_SIGN() ]; - case WoodType::JUNGLE()->id(): + case WoodType::JUNGLE: return [ new BID(Ids::JUNGLE_SIGN, TileSign::class), new BID(Ids::JUNGLE_WALL_SIGN, TileSign::class), fn() => VanillaItems::JUNGLE_SIGN() ]; - case WoodType::ACACIA()->id(): + case WoodType::ACACIA: return [ new BID(Ids::ACACIA_SIGN, TileSign::class), new BID(Ids::ACACIA_WALL_SIGN, TileSign::class), fn() => VanillaItems::ACACIA_SIGN() ]; - case WoodType::DARK_OAK()->id(): + case WoodType::DARK_OAK: return [ new BID(Ids::DARK_OAK_SIGN, TileSign::class), new BID(Ids::DARK_OAK_WALL_SIGN, TileSign::class), fn() => VanillaItems::DARK_OAK_SIGN() ]; - case WoodType::MANGROVE()->id(): + case WoodType::MANGROVE: return [ new BID(Ids::MANGROVE_SIGN, TileSign::class), new BID(Ids::MANGROVE_WALL_SIGN, TileSign::class), fn() => VanillaItems::MANGROVE_SIGN() ]; - case WoodType::CRIMSON()->id(): + case WoodType::CRIMSON: return [ new BID(Ids::CRIMSON_SIGN, TileSign::class), new BID(Ids::CRIMSON_WALL_SIGN, TileSign::class), fn() => VanillaItems::CRIMSON_SIGN() ]; - case WoodType::WARPED()->id(): + case WoodType::WARPED: return [ new BID(Ids::WARPED_SIGN, TileSign::class), new BID(Ids::WARPED_WALL_SIGN, TileSign::class), fn() => VanillaItems::WARPED_SIGN() ]; - case WoodType::CHERRY()->id(): + case WoodType::CHERRY: return [ new BID(Ids::CHERRY_SIGN, TileSign::class), new BID(Ids::CHERRY_WALL_SIGN, TileSign::class), @@ -226,98 +219,92 @@ final class WoodLikeBlockIdHelper{ } public static function getTrapdoorIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_TRAPDOOR, - WoodType::SPRUCE()->id() => Ids::SPRUCE_TRAPDOOR, - WoodType::BIRCH()->id() => Ids::BIRCH_TRAPDOOR, - WoodType::JUNGLE()->id() => Ids::JUNGLE_TRAPDOOR, - WoodType::ACACIA()->id() => Ids::ACACIA_TRAPDOOR, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_TRAPDOOR, - WoodType::MANGROVE()->id() => Ids::MANGROVE_TRAPDOOR, - WoodType::CRIMSON()->id() => Ids::CRIMSON_TRAPDOOR, - WoodType::WARPED()->id() => Ids::WARPED_TRAPDOOR, - WoodType::CHERRY()->id() => Ids::CHERRY_TRAPDOOR, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_TRAPDOOR, + WoodType::SPRUCE => Ids::SPRUCE_TRAPDOOR, + WoodType::BIRCH => Ids::BIRCH_TRAPDOOR, + WoodType::JUNGLE => Ids::JUNGLE_TRAPDOOR, + WoodType::ACACIA => Ids::ACACIA_TRAPDOOR, + WoodType::DARK_OAK => Ids::DARK_OAK_TRAPDOOR, + WoodType::MANGROVE => Ids::MANGROVE_TRAPDOOR, + WoodType::CRIMSON => Ids::CRIMSON_TRAPDOOR, + WoodType::WARPED => Ids::WARPED_TRAPDOOR, + WoodType::CHERRY => Ids::CHERRY_TRAPDOOR, }); } public static function getButtonIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_BUTTON, - WoodType::SPRUCE()->id() => Ids::SPRUCE_BUTTON, - WoodType::BIRCH()->id() => Ids::BIRCH_BUTTON, - WoodType::JUNGLE()->id() => Ids::JUNGLE_BUTTON, - WoodType::ACACIA()->id() => Ids::ACACIA_BUTTON, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_BUTTON, - WoodType::MANGROVE()->id() => Ids::MANGROVE_BUTTON, - WoodType::CRIMSON()->id() => Ids::CRIMSON_BUTTON, - WoodType::WARPED()->id() => Ids::WARPED_BUTTON, - WoodType::CHERRY()->id() => Ids::CHERRY_BUTTON, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_BUTTON, + WoodType::SPRUCE => Ids::SPRUCE_BUTTON, + WoodType::BIRCH => Ids::BIRCH_BUTTON, + WoodType::JUNGLE => Ids::JUNGLE_BUTTON, + WoodType::ACACIA => Ids::ACACIA_BUTTON, + WoodType::DARK_OAK => Ids::DARK_OAK_BUTTON, + WoodType::MANGROVE => Ids::MANGROVE_BUTTON, + WoodType::CRIMSON => Ids::CRIMSON_BUTTON, + WoodType::WARPED => Ids::WARPED_BUTTON, + WoodType::CHERRY => Ids::CHERRY_BUTTON, }); } public static function getPressurePlateIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_PRESSURE_PLATE, - WoodType::SPRUCE()->id() => Ids::SPRUCE_PRESSURE_PLATE, - WoodType::BIRCH()->id() => Ids::BIRCH_PRESSURE_PLATE, - WoodType::JUNGLE()->id() => Ids::JUNGLE_PRESSURE_PLATE, - WoodType::ACACIA()->id() => Ids::ACACIA_PRESSURE_PLATE, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_PRESSURE_PLATE, - WoodType::MANGROVE()->id() => Ids::MANGROVE_PRESSURE_PLATE, - WoodType::CRIMSON()->id() => Ids::CRIMSON_PRESSURE_PLATE, - WoodType::WARPED()->id() => Ids::WARPED_PRESSURE_PLATE, - WoodType::CHERRY()->id() => Ids::CHERRY_PRESSURE_PLATE, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_PRESSURE_PLATE, + WoodType::SPRUCE => Ids::SPRUCE_PRESSURE_PLATE, + WoodType::BIRCH => Ids::BIRCH_PRESSURE_PLATE, + WoodType::JUNGLE => Ids::JUNGLE_PRESSURE_PLATE, + WoodType::ACACIA => Ids::ACACIA_PRESSURE_PLATE, + WoodType::DARK_OAK => Ids::DARK_OAK_PRESSURE_PLATE, + WoodType::MANGROVE => Ids::MANGROVE_PRESSURE_PLATE, + WoodType::CRIMSON => Ids::CRIMSON_PRESSURE_PLATE, + WoodType::WARPED => Ids::WARPED_PRESSURE_PLATE, + WoodType::CHERRY => Ids::CHERRY_PRESSURE_PLATE, }); } public static function getDoorIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_DOOR, - WoodType::SPRUCE()->id() => Ids::SPRUCE_DOOR, - WoodType::BIRCH()->id() => Ids::BIRCH_DOOR, - WoodType::JUNGLE()->id() => Ids::JUNGLE_DOOR, - WoodType::ACACIA()->id() => Ids::ACACIA_DOOR, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_DOOR, - WoodType::MANGROVE()->id() => Ids::MANGROVE_DOOR, - WoodType::CRIMSON()->id() => Ids::CRIMSON_DOOR, - WoodType::WARPED()->id() => Ids::WARPED_DOOR, - WoodType::CHERRY()->id() => Ids::CHERRY_DOOR, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_DOOR, + WoodType::SPRUCE => Ids::SPRUCE_DOOR, + WoodType::BIRCH => Ids::BIRCH_DOOR, + WoodType::JUNGLE => Ids::JUNGLE_DOOR, + WoodType::ACACIA => Ids::ACACIA_DOOR, + WoodType::DARK_OAK => Ids::DARK_OAK_DOOR, + WoodType::MANGROVE => Ids::MANGROVE_DOOR, + WoodType::CRIMSON => Ids::CRIMSON_DOOR, + WoodType::WARPED => Ids::WARPED_DOOR, + WoodType::CHERRY => Ids::CHERRY_DOOR, }); } public static function getFenceGateIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_FENCE_GATE, - WoodType::SPRUCE()->id() => Ids::SPRUCE_FENCE_GATE, - WoodType::BIRCH()->id() => Ids::BIRCH_FENCE_GATE, - WoodType::JUNGLE()->id() => Ids::JUNGLE_FENCE_GATE, - WoodType::ACACIA()->id() => Ids::ACACIA_FENCE_GATE, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_FENCE_GATE, - WoodType::MANGROVE()->id() => Ids::MANGROVE_FENCE_GATE, - WoodType::CRIMSON()->id() => Ids::CRIMSON_FENCE_GATE, - WoodType::WARPED()->id() => Ids::WARPED_FENCE_GATE, - WoodType::CHERRY()->id() => Ids::CHERRY_FENCE_GATE, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_FENCE_GATE, + WoodType::SPRUCE => Ids::SPRUCE_FENCE_GATE, + WoodType::BIRCH => Ids::BIRCH_FENCE_GATE, + WoodType::JUNGLE => Ids::JUNGLE_FENCE_GATE, + WoodType::ACACIA => Ids::ACACIA_FENCE_GATE, + WoodType::DARK_OAK => Ids::DARK_OAK_FENCE_GATE, + WoodType::MANGROVE => Ids::MANGROVE_FENCE_GATE, + WoodType::CRIMSON => Ids::CRIMSON_FENCE_GATE, + WoodType::WARPED => Ids::WARPED_FENCE_GATE, + WoodType::CHERRY => Ids::CHERRY_FENCE_GATE, }); } public static function getStairsIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_STAIRS, - WoodType::SPRUCE()->id() => Ids::SPRUCE_STAIRS, - WoodType::BIRCH()->id() => Ids::BIRCH_STAIRS, - WoodType::JUNGLE()->id() => Ids::JUNGLE_STAIRS, - WoodType::ACACIA()->id() => Ids::ACACIA_STAIRS, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_STAIRS, - WoodType::MANGROVE()->id() => Ids::MANGROVE_STAIRS, - WoodType::CRIMSON()->id() => Ids::CRIMSON_STAIRS, - WoodType::WARPED()->id() => Ids::WARPED_STAIRS, - WoodType::CHERRY()->id() => Ids::CHERRY_STAIRS, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_STAIRS, + WoodType::SPRUCE => Ids::SPRUCE_STAIRS, + WoodType::BIRCH => Ids::BIRCH_STAIRS, + WoodType::JUNGLE => Ids::JUNGLE_STAIRS, + WoodType::ACACIA => Ids::ACACIA_STAIRS, + WoodType::DARK_OAK => Ids::DARK_OAK_STAIRS, + WoodType::MANGROVE => Ids::MANGROVE_STAIRS, + WoodType::CRIMSON => Ids::CRIMSON_STAIRS, + WoodType::WARPED => Ids::WARPED_STAIRS, + WoodType::CHERRY => Ids::CHERRY_STAIRS, }); } } diff --git a/src/block/tile/MobHead.php b/src/block/tile/MobHead.php index 70a199bf6..be7c0ac2b 100644 --- a/src/block/tile/MobHead.php +++ b/src/block/tile/MobHead.php @@ -26,10 +26,8 @@ namespace pocketmine\block\tile; use pocketmine\block\utils\MobHeadType; use pocketmine\data\bedrock\MobHeadTypeIdMap; use pocketmine\data\SavedDataLoadingException; -use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\world\World; /** * @deprecated @@ -42,14 +40,9 @@ class MobHead extends Spawnable{ private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int - private MobHeadType $mobHeadType; + private MobHeadType $mobHeadType = MobHeadType::SKELETON; private int $rotation = 0; - public function __construct(World $world, Vector3 $pos){ - $this->mobHeadType = MobHeadType::SKELETON(); - parent::__construct($world, $pos); - } - public function readSaveData(CompoundTag $nbt) : void{ if(($skullTypeTag = $nbt->getTag(self::TAG_SKULL_TYPE)) instanceof ByteTag){ $mobHeadType = MobHeadTypeIdMap::getInstance()->fromId($skullTypeTag->getValue()); diff --git a/src/block/utils/BannerPatternType.php b/src/block/utils/BannerPatternType.php index 85b064059..083fada1b 100644 --- a/src/block/utils/BannerPatternType.php +++ b/src/block/utils/BannerPatternType.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static BannerPatternType BORDER() * @method static BannerPatternType BRICKS() @@ -70,49 +68,45 @@ use pocketmine\utils\EnumTrait; * @method static BannerPatternType TRIANGLE_BOTTOM() * @method static BannerPatternType TRIANGLE_TOP() */ -final class BannerPatternType{ - use EnumTrait; +enum BannerPatternType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("border"), - new self("bricks"), - new self("circle"), - new self("creeper"), - new self("cross"), - new self("curly_border"), - new self("diagonal_left"), - new self("diagonal_right"), - new self("diagonal_up_left"), - new self("diagonal_up_right"), - new self("flower"), - new self("gradient"), - new self("gradient_up"), - new self("half_horizontal"), - new self("half_horizontal_bottom"), - new self("half_vertical"), - new self("half_vertical_right"), - new self("mojang"), - new self("rhombus"), - new self("skull"), - new self("small_stripes"), - new self("square_bottom_left"), - new self("square_bottom_right"), - new self("square_top_left"), - new self("square_top_right"), - new self("straight_cross"), - new self("stripe_bottom"), - new self("stripe_center"), - new self("stripe_downleft"), - new self("stripe_downright"), - new self("stripe_left"), - new self("stripe_middle"), - new self("stripe_right"), - new self("stripe_top"), - new self("triangle_bottom"), - new self("triangle_top"), - new self("triangles_bottom"), - new self("triangles_top") - ); - } + case BORDER; + case BRICKS; + case CIRCLE; + case CREEPER; + case CROSS; + case CURLY_BORDER; + case DIAGONAL_LEFT; + case DIAGONAL_RIGHT; + case DIAGONAL_UP_LEFT; + case DIAGONAL_UP_RIGHT; + case FLOWER; + case GRADIENT; + case GRADIENT_UP; + case HALF_HORIZONTAL; + case HALF_HORIZONTAL_BOTTOM; + case HALF_VERTICAL; + case HALF_VERTICAL_RIGHT; + case MOJANG; + case RHOMBUS; + case SKULL; + case SMALL_STRIPES; + case SQUARE_BOTTOM_LEFT; + case SQUARE_BOTTOM_RIGHT; + case SQUARE_TOP_LEFT; + case SQUARE_TOP_RIGHT; + case STRAIGHT_CROSS; + case STRIPE_BOTTOM; + case STRIPE_CENTER; + case STRIPE_DOWNLEFT; + case STRIPE_DOWNRIGHT; + case STRIPE_LEFT; + case STRIPE_MIDDLE; + case STRIPE_RIGHT; + case STRIPE_TOP; + case TRIANGLE_BOTTOM; + case TRIANGLE_TOP; + case TRIANGLES_BOTTOM; + case TRIANGLES_TOP; } diff --git a/src/block/utils/BellAttachmentType.php b/src/block/utils/BellAttachmentType.php index 963257031..29b88a2c4 100644 --- a/src/block/utils/BellAttachmentType.php +++ b/src/block/utils/BellAttachmentType.php @@ -23,28 +23,22 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static BellAttachmentType CEILING() * @method static BellAttachmentType FLOOR() * @method static BellAttachmentType ONE_WALL() * @method static BellAttachmentType TWO_WALLS() */ -final class BellAttachmentType{ - use EnumTrait; +enum BellAttachmentType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("ceiling"), - new self("floor"), - new self("one_wall"), - new self("two_walls") - ); - } + case CEILING; + case FLOOR; + case ONE_WALL; + case TWO_WALLS; } diff --git a/src/block/utils/BrewingStandSlot.php b/src/block/utils/BrewingStandSlot.php index faeeaa7c4..21500b1c9 100644 --- a/src/block/utils/BrewingStandSlot.php +++ b/src/block/utils/BrewingStandSlot.php @@ -24,37 +24,31 @@ declare(strict_types=1); namespace pocketmine\block\utils; use pocketmine\block\inventory\BrewingStandInventory; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static BrewingStandSlot EAST() * @method static BrewingStandSlot NORTHWEST() * @method static BrewingStandSlot SOUTHWEST() */ -final class BrewingStandSlot{ - use EnumTrait { - __construct as Enum___construct; - } +enum BrewingStandSlot{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("east", BrewingStandInventory::SLOT_BOTTLE_LEFT), - new self("northwest", BrewingStandInventory::SLOT_BOTTLE_MIDDLE), - new self("southwest", BrewingStandInventory::SLOT_BOTTLE_RIGHT) - ); - } - - private function __construct(string $enumName, private int $slotNumber){ - $this->Enum___construct($enumName); - } + case EAST; + case NORTHWEST; + case SOUTHWEST; /** * Returns the brewing stand inventory slot number associated with this visual slot. */ - public function getSlotNumber() : int{ return $this->slotNumber; } + public function getSlotNumber() : int{ + return match($this){ + self::EAST => BrewingStandInventory::SLOT_BOTTLE_LEFT, + self::NORTHWEST => BrewingStandInventory::SLOT_BOTTLE_MIDDLE, + self::SOUTHWEST => BrewingStandInventory::SLOT_BOTTLE_RIGHT + }; + } } diff --git a/src/block/utils/CopperOxidation.php b/src/block/utils/CopperOxidation.php index 8278819a7..ba9abeaed 100644 --- a/src/block/utils/CopperOxidation.php +++ b/src/block/utils/CopperOxidation.php @@ -23,57 +23,30 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static CopperOxidation EXPOSED() * @method static CopperOxidation NONE() * @method static CopperOxidation OXIDIZED() * @method static CopperOxidation WEATHERED() */ -final class CopperOxidation{ - use EnumTrait { - __construct as Enum___construct; - register as Enum_register; - } +enum CopperOxidation : int{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("none", 0), - new self("exposed", 1), - new self("weathered", 2), - new self("oxidized", 3) - ); - } - - protected static function register(self $member) : void{ - self::Enum_register($member); - self::$levelMap[$member->value] = $member; - } - - /** - * @var self[] - * @phpstan-var array - */ - private static array $levelMap = []; - - private function __construct( - string $name, - private int $value - ){ - $this->Enum___construct($name); - } + case NONE = 0; + case EXPOSED = 1; + case WEATHERED = 2; + case OXIDIZED = 3; public function getPrevious() : ?self{ - return self::$levelMap[$this->value - 1] ?? null; + return self::tryFrom($this->value - 1); } public function getNext() : ?self{ - return self::$levelMap[$this->value + 1] ?? null; + return self::tryFrom($this->value + 1); } } diff --git a/src/block/utils/CopperTrait.php b/src/block/utils/CopperTrait.php index 5fede94dd..f0d708821 100644 --- a/src/block/utils/CopperTrait.php +++ b/src/block/utils/CopperTrait.php @@ -23,8 +23,6 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\block\BlockIdentifier; -use pocketmine\block\BlockTypeInfo; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Axe; use pocketmine\item\Item; @@ -36,14 +34,9 @@ use pocketmine\world\sound\CopperWaxRemoveSound; use pocketmine\world\sound\ScrapeSound; trait CopperTrait{ - private CopperOxidation $oxidation; + private CopperOxidation $oxidation = CopperOxidation::NONE; private bool $waxed = false; - public function __construct(BlockIdentifier $identifier, string $name, BlockTypeInfo $typeInfo){ - $this->oxidation = CopperOxidation::NONE(); - parent::__construct($identifier, $name, $typeInfo); - } - public function describeBlockItemState(RuntimeDataDescriber $w) : void{ $w->copperOxidation($this->oxidation); $w->bool($this->waxed); diff --git a/src/block/utils/CoralType.php b/src/block/utils/CoralType.php index 5a4d88fa9..cba3e8dde 100644 --- a/src/block/utils/CoralType.php +++ b/src/block/utils/CoralType.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static CoralType BRAIN() * @method static CoralType BUBBLE() @@ -37,27 +35,22 @@ use pocketmine\utils\EnumTrait; * @method static CoralType HORN() * @method static CoralType TUBE() */ -final class CoralType{ - use EnumTrait { - __construct as Enum___construct; - } +enum CoralType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("tube", "Tube"), - new self("brain", "Brain"), - new self("bubble", "Bubble"), - new self("fire", "Fire"), - new self("horn", "Horn"), - ); - } + case TUBE; + case BRAIN; + case BUBBLE; + case FIRE; + case HORN; - private function __construct( - string $name, - private string $displayName - ){ - $this->Enum___construct($name); + public function getDisplayName() : string{ + return match($this){ + self::TUBE => "Tube", + self::BRAIN => "Brain", + self::BUBBLE => "Bubble", + self::FIRE => "Fire", + self::HORN => "Horn", + }; } - - public function getDisplayName() : string{ return $this->displayName; } } diff --git a/src/block/utils/CoralTypeTrait.php b/src/block/utils/CoralTypeTrait.php index 5dcd539d4..fcd7dbf24 100644 --- a/src/block/utils/CoralTypeTrait.php +++ b/src/block/utils/CoralTypeTrait.php @@ -27,7 +27,7 @@ use pocketmine\block\Block; use pocketmine\data\runtime\RuntimeDataDescriber; trait CoralTypeTrait{ - protected CoralType $coralType; + protected CoralType $coralType = CoralType::TUBE; protected bool $dead = false; /** @see Block::describeBlockItemState() */ diff --git a/src/block/utils/DirtType.php b/src/block/utils/DirtType.php index 536268676..9bed30d1c 100644 --- a/src/block/utils/DirtType.php +++ b/src/block/utils/DirtType.php @@ -23,26 +23,20 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static DirtType COARSE() * @method static DirtType NORMAL() * @method static DirtType ROOTED() */ -final class DirtType{ - use EnumTrait; +enum DirtType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("normal"), - new self("coarse"), - new self("rooted") - ); - } + case NORMAL; + case COARSE; + case ROOTED; } diff --git a/src/block/utils/DripleafState.php b/src/block/utils/DripleafState.php index 3c2e20a13..4b0cedce7 100644 --- a/src/block/utils/DripleafState.php +++ b/src/block/utils/DripleafState.php @@ -23,43 +23,30 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static DripleafState FULL_TILT() * @method static DripleafState PARTIAL_TILT() * @method static DripleafState STABLE() * @method static DripleafState UNSTABLE() */ -final class DripleafState{ - use EnumTrait { - register as Enum_register; - __construct as Enum___construct; - } +enum DripleafState{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("stable", null), - new self("unstable", 10), - new self("partial_tilt", 10), - new self("full_tilt", 100) - ); - } - - private function __construct( - string $enumName, - private ?int $scheduledUpdateDelayTicks - ){ - $this->Enum___construct($enumName); - } + case STABLE; + case UNSTABLE; + case PARTIAL_TILT; + case FULL_TILT; public function getScheduledUpdateDelayTicks() : ?int{ - return $this->scheduledUpdateDelayTicks; + return match($this){ + self::STABLE => null, + self::UNSTABLE, self::PARTIAL_TILT => 10, + self::FULL_TILT => 100, + }; } - } diff --git a/src/block/utils/FroglightType.php b/src/block/utils/FroglightType.php index f6b9c1d13..ab20d31ac 100644 --- a/src/block/utils/FroglightType.php +++ b/src/block/utils/FroglightType.php @@ -23,26 +23,20 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static FroglightType OCHRE() * @method static FroglightType PEARLESCENT() * @method static FroglightType VERDANT() */ -final class FroglightType{ - use EnumTrait; +enum FroglightType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("ochre"), - new self("pearlescent"), - new self("verdant") - ); - } + case OCHRE; + case PEARLESCENT; + case VERDANT; } diff --git a/src/block/utils/LeavesType.php b/src/block/utils/LeavesType.php index ecb2a1fd9..975551ad6 100644 --- a/src/block/utils/LeavesType.php +++ b/src/block/utils/LeavesType.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static LeavesType ACACIA() * @method static LeavesType AZALEA() @@ -42,35 +40,32 @@ use pocketmine\utils\EnumTrait; * @method static LeavesType OAK() * @method static LeavesType SPRUCE() */ -final class LeavesType{ - use EnumTrait { - register as Enum_register; - __construct as Enum___construct; - } +enum LeavesType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("oak", "Oak"), - new self("spruce", "Spruce"), - new self("birch", "Birch"), - new self("jungle", "Jungle"), - new self("acacia", "Acacia"), - new self("dark_oak", "Dark Oak"), - new self("mangrove", "Mangrove"), - new self("azalea", "Azalea"), - new self("flowering_azalea", "Flowering Azalea"), - new self("cherry", "Cherry") - ); - } - - private function __construct( - string $enumName, - private string $displayName - ){ - $this->Enum___construct($enumName); - } + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + case MANGROVE; + case AZALEA; + case FLOWERING_AZALEA; + case CHERRY; public function getDisplayName() : string{ - return $this->displayName; + return match($this){ + self::OAK => "Oak", + self::SPRUCE => "Spruce", + self::BIRCH => "Birch", + self::JUNGLE => "Jungle", + self::ACACIA => "Acacia", + self::DARK_OAK => "Dark Oak", + self::MANGROVE => "Mangrove", + self::AZALEA => "Azalea", + self::FLOWERING_AZALEA => "Flowering Azalea", + self::CHERRY => "Cherry" + }; } } diff --git a/src/block/utils/LeverFacing.php b/src/block/utils/LeverFacing.php index 99eeb88d3..1af92d6c4 100644 --- a/src/block/utils/LeverFacing.php +++ b/src/block/utils/LeverFacing.php @@ -24,13 +24,11 @@ declare(strict_types=1); namespace pocketmine\block\utils; use pocketmine\math\Facing; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static LeverFacing DOWN_AXIS_X() * @method static LeverFacing DOWN_AXIS_Z() @@ -41,27 +39,26 @@ use pocketmine\utils\EnumTrait; * @method static LeverFacing UP_AXIS_Z() * @method static LeverFacing WEST() */ -final class LeverFacing{ - use EnumTrait { - __construct as Enum___construct; - } +enum LeverFacing{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("up_axis_x", Facing::UP), - new self("up_axis_z", Facing::UP), - new self("down_axis_x", Facing::DOWN), - new self("down_axis_z", Facing::DOWN), - new self("north", Facing::NORTH), - new self("east", Facing::EAST), - new self("south", Facing::SOUTH), - new self("west", Facing::WEST), - ); - } + case UP_AXIS_X; + case UP_AXIS_Z; + case DOWN_AXIS_X; + case DOWN_AXIS_Z; + case NORTH; + case EAST; + case SOUTH; + case WEST; - private function __construct(string $enumName, private int $facing){ - $this->Enum___construct($enumName); + public function getFacing() : int{ + return match($this){ + self::UP_AXIS_X, self::UP_AXIS_Z => Facing::UP, + self::DOWN_AXIS_X, self::DOWN_AXIS_Z => Facing::DOWN, + self::NORTH => Facing::NORTH, + self::EAST => Facing::EAST, + self::SOUTH => Facing::SOUTH, + self::WEST => Facing::WEST, + }; } - - public function getFacing() : int{ return $this->facing; } } diff --git a/src/block/utils/MobHeadType.php b/src/block/utils/MobHeadType.php index 391b66820..af1fe1c4c 100644 --- a/src/block/utils/MobHeadType.php +++ b/src/block/utils/MobHeadType.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static MobHeadType CREEPER() * @method static MobHeadType DRAGON() @@ -39,31 +37,26 @@ use pocketmine\utils\EnumTrait; * @method static MobHeadType WITHER_SKELETON() * @method static MobHeadType ZOMBIE() */ -final class MobHeadType{ - use EnumTrait { - __construct as Enum___construct; - } +enum MobHeadType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new MobHeadType("skeleton", "Skeleton Skull"), - new MobHeadType("wither_skeleton", "Wither Skeleton Skull"), - new MobHeadType("zombie", "Zombie Head"), - new MobHeadType("player", "Player Head"), - new MobHeadType("creeper", "Creeper Head"), - new MobHeadType("dragon", "Dragon Head"), - new MobHeadType("piglin", "Piglin Head") - ); - } - - private function __construct( - string $enumName, - private string $displayName - ){ - $this->Enum___construct($enumName); - } + case SKELETON; + case WITHER_SKELETON; + case ZOMBIE; + case PLAYER; + case CREEPER; + case DRAGON; + case PIGLIN; public function getDisplayName() : string{ - return $this->displayName; + return match($this){ + self::SKELETON => "Skeleton Skull", + self::WITHER_SKELETON => "Wither Skeleton Skull", + self::ZOMBIE => "Zombie Head", + self::PLAYER => "Player Head", + self::CREEPER => "Creeper Head", + self::DRAGON => "Dragon Head", + self::PIGLIN => "Piglin Head" + }; } } diff --git a/src/block/utils/MushroomBlockType.php b/src/block/utils/MushroomBlockType.php index 7f001d13d..6bc499b23 100644 --- a/src/block/utils/MushroomBlockType.php +++ b/src/block/utils/MushroomBlockType.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static MushroomBlockType ALL_CAP() * @method static MushroomBlockType CAP_EAST() @@ -43,22 +41,18 @@ use pocketmine\utils\EnumTrait; * @method static MushroomBlockType CAP_WEST() * @method static MushroomBlockType PORES() */ -final class MushroomBlockType{ - use EnumTrait; +enum MushroomBlockType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("PORES"), - new self("CAP_NORTHWEST"), - new self("CAP_NORTH"), - new self("CAP_NORTHEAST"), - new self("CAP_WEST"), - new self("CAP_MIDDLE"), - new self("CAP_EAST"), - new self("CAP_SOUTHWEST"), - new self("CAP_SOUTH"), - new self("CAP_SOUTHEAST"), - new self("ALL_CAP") - ); - } + case PORES; + case CAP_NORTHWEST; + case CAP_NORTH; + case CAP_NORTHEAST; + case CAP_WEST; + case CAP_MIDDLE; + case CAP_EAST; + case CAP_SOUTHWEST; + case CAP_SOUTH; + case CAP_SOUTHEAST; + case ALL_CAP; } diff --git a/src/block/utils/SaplingType.php b/src/block/utils/SaplingType.php index 516ee1516..9fe87936c 100644 --- a/src/block/utils/SaplingType.php +++ b/src/block/utils/SaplingType.php @@ -23,14 +23,12 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; use pocketmine\world\generator\object\TreeType; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static SaplingType ACACIA() * @method static SaplingType BIRCH() @@ -39,33 +37,29 @@ use pocketmine\world\generator\object\TreeType; * @method static SaplingType OAK() * @method static SaplingType SPRUCE() */ -final class SaplingType{ - use EnumTrait { - __construct as Enum___construct; - } +enum SaplingType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("oak", TreeType::OAK()), - new self("spruce", TreeType::SPRUCE()), - new self("birch", TreeType::BIRCH()), - new self("jungle", TreeType::JUNGLE()), - new self("acacia", TreeType::ACACIA()), - new self("dark_oak", TreeType::DARK_OAK()), - //TODO: cherry - ); - } + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + //TODO: cherry - private function __construct( - string $enumName, - private TreeType $treeType, - ){ - $this->Enum___construct($enumName); + public function getTreeType() : TreeType{ + return match($this){ + self::OAK => TreeType::OAK, + self::SPRUCE => TreeType::SPRUCE, + self::BIRCH => TreeType::BIRCH, + self::JUNGLE => TreeType::JUNGLE, + self::ACACIA => TreeType::ACACIA, + self::DARK_OAK => TreeType::DARK_OAK, + }; } - public function getTreeType() : TreeType{ return $this->treeType; } - public function getDisplayName() : string{ - return $this->treeType->getDisplayName(); + return $this->getTreeType()->getDisplayName(); } } diff --git a/src/block/utils/SlabType.php b/src/block/utils/SlabType.php index 1da1b3e5a..90f3e0953 100644 --- a/src/block/utils/SlabType.php +++ b/src/block/utils/SlabType.php @@ -23,26 +23,20 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static SlabType BOTTOM() * @method static SlabType DOUBLE() * @method static SlabType TOP() */ -final class SlabType{ - use EnumTrait; +enum SlabType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("bottom"), - new self("top"), - new self("double") - ); - } + case BOTTOM; + case TOP; + case DOUBLE; } diff --git a/src/block/utils/StairShape.php b/src/block/utils/StairShape.php index c98aec8fb..b89b9adbb 100644 --- a/src/block/utils/StairShape.php +++ b/src/block/utils/StairShape.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static StairShape INNER_LEFT() * @method static StairShape INNER_RIGHT() @@ -37,16 +35,12 @@ use pocketmine\utils\EnumTrait; * @method static StairShape OUTER_RIGHT() * @method static StairShape STRAIGHT() */ -final class StairShape{ - use EnumTrait; +enum StairShape{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("straight"), - new self("inner_left"), - new self("inner_right"), - new self("outer_left"), - new self("outer_right") - ); - } + case STRAIGHT; + case INNER_LEFT; + case INNER_RIGHT; + case OUTER_LEFT; + case OUTER_RIGHT; } diff --git a/src/block/utils/SupportType.php b/src/block/utils/SupportType.php index b4480bf57..9513d8640 100644 --- a/src/block/utils/SupportType.php +++ b/src/block/utils/SupportType.php @@ -23,36 +23,30 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static SupportType CENTER() * @method static SupportType EDGE() * @method static SupportType FULL() * @method static SupportType NONE() */ -final class SupportType{ - use EnumTrait; +enum SupportType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("full"), - new self("center"), - new self("edge"), - new self("none") - ); - } + case FULL; + case CENTER; + case EDGE; + case NONE; public function hasEdgeSupport() : bool{ - return $this->equals(self::EDGE()) || $this->equals(self::FULL()); + return $this === self::EDGE || $this === self::FULL; } public function hasCenterSupport() : bool{ - return $this->equals(self::CENTER()) || $this->equals(self::FULL()); + return $this === self::CENTER || $this === self::FULL; } } diff --git a/src/block/utils/WallConnectionType.php b/src/block/utils/WallConnectionType.php index 11765ab33..1d4c8d152 100644 --- a/src/block/utils/WallConnectionType.php +++ b/src/block/utils/WallConnectionType.php @@ -23,24 +23,18 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static WallConnectionType SHORT() * @method static WallConnectionType TALL() */ -final class WallConnectionType{ - use EnumTrait; +enum WallConnectionType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("short"), - new self("tall") - ); - } + case SHORT; + case TALL; } diff --git a/src/block/utils/WoodType.php b/src/block/utils/WoodType.php index b9d96561b..f6195b9f9 100644 --- a/src/block/utils/WoodType.php +++ b/src/block/utils/WoodType.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static WoodType ACACIA() * @method static WoodType BIRCH() @@ -42,41 +40,44 @@ use pocketmine\utils\EnumTrait; * @method static WoodType SPRUCE() * @method static WoodType WARPED() */ -final class WoodType{ - use EnumTrait { - __construct as private Enum___construct; +enum WoodType{ + use LegacyEnumShimTrait; + + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + case MANGROVE; + case CRIMSON; + case WARPED; + case CHERRY; + + public function getDisplayName() : string{ + return match($this){ + self::OAK => "Oak", + self::SPRUCE => "Spruce", + self::BIRCH => "Birch", + self::JUNGLE => "Jungle", + self::ACACIA => "Acacia", + self::DARK_OAK => "Dark Oak", + self::MANGROVE => "Mangrove", + self::CRIMSON => "Crimson", + self::WARPED => "Warped", + self::CHERRY => "Cherry", + }; } - protected static function setup() : void{ - self::registerAll( - new self("oak", "Oak", true), - new self("spruce", "Spruce", true), - new self("birch", "Birch", true), - new self("jungle", "Jungle", true), - new self("acacia", "Acacia", true), - new self("dark_oak", "Dark Oak", true), - new self("mangrove", "Mangrove", true), - new self("crimson", "Crimson", false, "Stem", "Hyphae"), - new self("warped", "Warped", false, "Stem", "Hyphae"), - new self("cherry", "Cherry", true), - ); + public function isFlammable() : bool{ + return $this !== self::CRIMSON && $this !== self::WARPED; } - private function __construct( - string $enumName, - private string $displayName, - private bool $flammable, - private ?string $standardLogSuffix = null, - private ?string $allSidedLogSuffix = null, - ){ - $this->Enum___construct($enumName); + public function getStandardLogSuffix() : ?string{ + return $this === self::CRIMSON || $this === self::WARPED ? "Stem" : null; } - public function getDisplayName() : string{ return $this->displayName; } - - public function isFlammable() : bool{ return $this->flammable; } - - public function getStandardLogSuffix() : ?string{ return $this->standardLogSuffix; } - - public function getAllSidedLogSuffix() : ?string{ return $this->allSidedLogSuffix; } + public function getAllSidedLogSuffix() : ?string{ + return $this === self::CRIMSON || $this === self::WARPED ? "Hyphae" : null; + } } diff --git a/src/crafting/CraftingManagerFromDataHelper.php b/src/crafting/CraftingManagerFromDataHelper.php index 812ff83e0..0c861255b 100644 --- a/src/crafting/CraftingManagerFromDataHelper.php +++ b/src/crafting/CraftingManagerFromDataHelper.php @@ -211,10 +211,10 @@ final class CraftingManagerFromDataHelper{ foreach(self::loadJsonArrayOfObjectsFile(Path::join($directoryPath, 'shapeless_crafting.json'), ShapelessRecipeData::class) as $recipe){ $recipeType = match($recipe->block){ - "crafting_table" => ShapelessRecipeType::CRAFTING(), - "stonecutter" => ShapelessRecipeType::STONECUTTER(), - "smithing_table" => ShapelessRecipeType::SMITHING(), - "cartography_table" => ShapelessRecipeType::CARTOGRAPHY(), + "crafting_table" => ShapelessRecipeType::CRAFTING, + "stonecutter" => ShapelessRecipeType::STONECUTTER, + "smithing_table" => ShapelessRecipeType::SMITHING, + "cartography_table" => ShapelessRecipeType::CARTOGRAPHY, default => null }; if($recipeType === null){ diff --git a/src/crafting/ShapelessRecipeType.php b/src/crafting/ShapelessRecipeType.php index b115c22f4..4f4624a4b 100644 --- a/src/crafting/ShapelessRecipeType.php +++ b/src/crafting/ShapelessRecipeType.php @@ -23,28 +23,22 @@ declare(strict_types=1); namespace pocketmine\crafting; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static ShapelessRecipeType CARTOGRAPHY() * @method static ShapelessRecipeType CRAFTING() * @method static ShapelessRecipeType SMITHING() * @method static ShapelessRecipeType STONECUTTER() */ -final class ShapelessRecipeType{ - use EnumTrait; +enum ShapelessRecipeType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("crafting"), - new self("stonecutter"), - new self("smithing"), - new self("cartography") - ); - } + case CRAFTING; + case STONECUTTER; + case SMITHING; + case CARTOGRAPHY; } diff --git a/src/data/bedrock/BannerPatternTypeIdMap.php b/src/data/bedrock/BannerPatternTypeIdMap.php index 293f8ec38..064844e19 100644 --- a/src/data/bedrock/BannerPatternTypeIdMap.php +++ b/src/data/bedrock/BannerPatternTypeIdMap.php @@ -26,6 +26,7 @@ namespace pocketmine\data\bedrock; use pocketmine\block\utils\BannerPatternType; use pocketmine\utils\SingletonTrait; use function array_key_exists; +use function spl_object_id; final class BannerPatternTypeIdMap{ use SingletonTrait; @@ -42,49 +43,49 @@ final class BannerPatternTypeIdMap{ private array $enumToId = []; public function __construct(){ - $this->register("bo", BannerPatternType::BORDER()); - $this->register("bri", BannerPatternType::BRICKS()); - $this->register("mc", BannerPatternType::CIRCLE()); - $this->register("cre", BannerPatternType::CREEPER()); - $this->register("cr", BannerPatternType::CROSS()); - $this->register("cbo", BannerPatternType::CURLY_BORDER()); - $this->register("lud", BannerPatternType::DIAGONAL_LEFT()); - $this->register("rd", BannerPatternType::DIAGONAL_RIGHT()); - $this->register("ld", BannerPatternType::DIAGONAL_UP_LEFT()); - $this->register("rud", BannerPatternType::DIAGONAL_UP_RIGHT()); - $this->register("flo", BannerPatternType::FLOWER()); - $this->register("gra", BannerPatternType::GRADIENT()); - $this->register("gru", BannerPatternType::GRADIENT_UP()); - $this->register("hh", BannerPatternType::HALF_HORIZONTAL()); - $this->register("hhb", BannerPatternType::HALF_HORIZONTAL_BOTTOM()); - $this->register("vh", BannerPatternType::HALF_VERTICAL()); - $this->register("vhr", BannerPatternType::HALF_VERTICAL_RIGHT()); - $this->register("moj", BannerPatternType::MOJANG()); - $this->register("mr", BannerPatternType::RHOMBUS()); - $this->register("sku", BannerPatternType::SKULL()); - $this->register("ss", BannerPatternType::SMALL_STRIPES()); - $this->register("bl", BannerPatternType::SQUARE_BOTTOM_LEFT()); - $this->register("br", BannerPatternType::SQUARE_BOTTOM_RIGHT()); - $this->register("tl", BannerPatternType::SQUARE_TOP_LEFT()); - $this->register("tr", BannerPatternType::SQUARE_TOP_RIGHT()); - $this->register("sc", BannerPatternType::STRAIGHT_CROSS()); - $this->register("bs", BannerPatternType::STRIPE_BOTTOM()); - $this->register("cs", BannerPatternType::STRIPE_CENTER()); - $this->register("dls", BannerPatternType::STRIPE_DOWNLEFT()); - $this->register("drs", BannerPatternType::STRIPE_DOWNRIGHT()); - $this->register("ls", BannerPatternType::STRIPE_LEFT()); - $this->register("ms", BannerPatternType::STRIPE_MIDDLE()); - $this->register("rs", BannerPatternType::STRIPE_RIGHT()); - $this->register("ts", BannerPatternType::STRIPE_TOP()); - $this->register("bt", BannerPatternType::TRIANGLE_BOTTOM()); - $this->register("tt", BannerPatternType::TRIANGLE_TOP()); - $this->register("bts", BannerPatternType::TRIANGLES_BOTTOM()); - $this->register("tts", BannerPatternType::TRIANGLES_TOP()); + $this->register("bo", BannerPatternType::BORDER); + $this->register("bri", BannerPatternType::BRICKS); + $this->register("mc", BannerPatternType::CIRCLE); + $this->register("cre", BannerPatternType::CREEPER); + $this->register("cr", BannerPatternType::CROSS); + $this->register("cbo", BannerPatternType::CURLY_BORDER); + $this->register("lud", BannerPatternType::DIAGONAL_LEFT); + $this->register("rd", BannerPatternType::DIAGONAL_RIGHT); + $this->register("ld", BannerPatternType::DIAGONAL_UP_LEFT); + $this->register("rud", BannerPatternType::DIAGONAL_UP_RIGHT); + $this->register("flo", BannerPatternType::FLOWER); + $this->register("gra", BannerPatternType::GRADIENT); + $this->register("gru", BannerPatternType::GRADIENT_UP); + $this->register("hh", BannerPatternType::HALF_HORIZONTAL); + $this->register("hhb", BannerPatternType::HALF_HORIZONTAL_BOTTOM); + $this->register("vh", BannerPatternType::HALF_VERTICAL); + $this->register("vhr", BannerPatternType::HALF_VERTICAL_RIGHT); + $this->register("moj", BannerPatternType::MOJANG); + $this->register("mr", BannerPatternType::RHOMBUS); + $this->register("sku", BannerPatternType::SKULL); + $this->register("ss", BannerPatternType::SMALL_STRIPES); + $this->register("bl", BannerPatternType::SQUARE_BOTTOM_LEFT); + $this->register("br", BannerPatternType::SQUARE_BOTTOM_RIGHT); + $this->register("tl", BannerPatternType::SQUARE_TOP_LEFT); + $this->register("tr", BannerPatternType::SQUARE_TOP_RIGHT); + $this->register("sc", BannerPatternType::STRAIGHT_CROSS); + $this->register("bs", BannerPatternType::STRIPE_BOTTOM); + $this->register("cs", BannerPatternType::STRIPE_CENTER); + $this->register("dls", BannerPatternType::STRIPE_DOWNLEFT); + $this->register("drs", BannerPatternType::STRIPE_DOWNRIGHT); + $this->register("ls", BannerPatternType::STRIPE_LEFT); + $this->register("ms", BannerPatternType::STRIPE_MIDDLE); + $this->register("rs", BannerPatternType::STRIPE_RIGHT); + $this->register("ts", BannerPatternType::STRIPE_TOP); + $this->register("bt", BannerPatternType::TRIANGLE_BOTTOM); + $this->register("tt", BannerPatternType::TRIANGLE_TOP); + $this->register("bts", BannerPatternType::TRIANGLES_BOTTOM); + $this->register("tts", BannerPatternType::TRIANGLES_TOP); } public function register(string $stringId, BannerPatternType $type) : void{ $this->idToEnum[$stringId] = $type; - $this->enumToId[$type->id()] = $stringId; + $this->enumToId[spl_object_id($type)] = $stringId; } public function fromId(string $id) : ?BannerPatternType{ @@ -92,9 +93,10 @@ final class BannerPatternTypeIdMap{ } public function toId(BannerPatternType $type) : string{ - if(!array_key_exists($type->id(), $this->enumToId)){ - throw new \InvalidArgumentException("Missing mapping for banner pattern type " . $type->name()); + $k = spl_object_id($type); + if(!array_key_exists($k, $this->enumToId)){ + throw new \InvalidArgumentException("Missing mapping for banner pattern type " . $type->name); } - return $this->enumToId[$type->id()]; + return $this->enumToId[$k]; } } diff --git a/src/data/bedrock/MobHeadTypeIdMap.php b/src/data/bedrock/MobHeadTypeIdMap.php index b99b1097b..ec678b192 100644 --- a/src/data/bedrock/MobHeadTypeIdMap.php +++ b/src/data/bedrock/MobHeadTypeIdMap.php @@ -32,12 +32,12 @@ final class MobHeadTypeIdMap{ use IntSaveIdMapTrait; private function __construct(){ - $this->register(0, MobHeadType::SKELETON()); - $this->register(1, MobHeadType::WITHER_SKELETON()); - $this->register(2, MobHeadType::ZOMBIE()); - $this->register(3, MobHeadType::PLAYER()); - $this->register(4, MobHeadType::CREEPER()); - $this->register(5, MobHeadType::DRAGON()); - $this->register(6, MobHeadType::PIGLIN()); + $this->register(0, MobHeadType::SKELETON); + $this->register(1, MobHeadType::WITHER_SKELETON); + $this->register(2, MobHeadType::ZOMBIE); + $this->register(3, MobHeadType::PLAYER); + $this->register(4, MobHeadType::CREEPER); + $this->register(5, MobHeadType::DRAGON); + $this->register(6, MobHeadType::PIGLIN); } } diff --git a/src/data/bedrock/MushroomBlockTypeIdMap.php b/src/data/bedrock/MushroomBlockTypeIdMap.php index 927b52c76..92edef4b2 100644 --- a/src/data/bedrock/MushroomBlockTypeIdMap.php +++ b/src/data/bedrock/MushroomBlockTypeIdMap.php @@ -33,16 +33,16 @@ final class MushroomBlockTypeIdMap{ use IntSaveIdMapTrait; public function __construct(){ - $this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_PORES, MushroomBlockType::PORES()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER, MushroomBlockType::CAP_NORTHWEST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE, MushroomBlockType::CAP_NORTH()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER, MushroomBlockType::CAP_NORTHEAST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE, MushroomBlockType::CAP_WEST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY, MushroomBlockType::CAP_MIDDLE()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE, MushroomBlockType::CAP_EAST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER, MushroomBlockType::CAP_SOUTHWEST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTH_SIDE, MushroomBlockType::CAP_SOUTH()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHEAST_CORNER, MushroomBlockType::CAP_SOUTHEAST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_CAP, MushroomBlockType::ALL_CAP()); + $this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_PORES, MushroomBlockType::PORES); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER, MushroomBlockType::CAP_NORTHWEST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE, MushroomBlockType::CAP_NORTH); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER, MushroomBlockType::CAP_NORTHEAST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE, MushroomBlockType::CAP_WEST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY, MushroomBlockType::CAP_MIDDLE); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE, MushroomBlockType::CAP_EAST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER, MushroomBlockType::CAP_SOUTHWEST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTH_SIDE, MushroomBlockType::CAP_SOUTH); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHEAST_CORNER, MushroomBlockType::CAP_SOUTHEAST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_CAP, MushroomBlockType::ALL_CAP); } } diff --git a/src/data/bedrock/NoteInstrumentIdMap.php b/src/data/bedrock/NoteInstrumentIdMap.php index 22d7e5cb1..e721b881d 100644 --- a/src/data/bedrock/NoteInstrumentIdMap.php +++ b/src/data/bedrock/NoteInstrumentIdMap.php @@ -32,21 +32,21 @@ final class NoteInstrumentIdMap{ use IntSaveIdMapTrait; private function __construct(){ - $this->register(0, NoteInstrument::PIANO()); - $this->register(1, NoteInstrument::BASS_DRUM()); - $this->register(2, NoteInstrument::SNARE()); - $this->register(3, NoteInstrument::CLICKS_AND_STICKS()); - $this->register(4, NoteInstrument::DOUBLE_BASS()); - $this->register(5, NoteInstrument::BELL()); - $this->register(6, NoteInstrument::FLUTE()); - $this->register(7, NoteInstrument::CHIME()); - $this->register(8, NoteInstrument::GUITAR()); - $this->register(9, NoteInstrument::XYLOPHONE()); - $this->register(10, NoteInstrument::IRON_XYLOPHONE()); - $this->register(11, NoteInstrument::COW_BELL()); - $this->register(12, NoteInstrument::DIDGERIDOO()); - $this->register(13, NoteInstrument::BIT()); - $this->register(14, NoteInstrument::BANJO()); - $this->register(15, NoteInstrument::PLING()); + $this->register(0, NoteInstrument::PIANO); + $this->register(1, NoteInstrument::BASS_DRUM); + $this->register(2, NoteInstrument::SNARE); + $this->register(3, NoteInstrument::CLICKS_AND_STICKS); + $this->register(4, NoteInstrument::DOUBLE_BASS); + $this->register(5, NoteInstrument::BELL); + $this->register(6, NoteInstrument::FLUTE); + $this->register(7, NoteInstrument::CHIME); + $this->register(8, NoteInstrument::GUITAR); + $this->register(9, NoteInstrument::XYLOPHONE); + $this->register(10, NoteInstrument::IRON_XYLOPHONE); + $this->register(11, NoteInstrument::COW_BELL); + $this->register(12, NoteInstrument::DIDGERIDOO); + $this->register(13, NoteInstrument::BIT); + $this->register(14, NoteInstrument::BANJO); + $this->register(15, NoteInstrument::PLING); } } diff --git a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php index 6ffc1c55d..28a6864fe 100644 --- a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php @@ -419,13 +419,12 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ private function registerFlatCoralSerializers() : void{ $this->map(Blocks::CORAL(), fn(Coral $block) => Writer::create( - match($coralType = $block->getCoralType()){ - CoralType::BRAIN() => $block->isDead() ? Ids::DEAD_BRAIN_CORAL : Ids::BRAIN_CORAL, - CoralType::BUBBLE() => $block->isDead() ? Ids::DEAD_BUBBLE_CORAL : Ids::BUBBLE_CORAL, - CoralType::FIRE() => $block->isDead() ? Ids::DEAD_FIRE_CORAL : Ids::FIRE_CORAL, - CoralType::HORN() => $block->isDead() ? Ids::DEAD_HORN_CORAL : Ids::HORN_CORAL, - CoralType::TUBE() => $block->isDead() ? Ids::DEAD_TUBE_CORAL : Ids::TUBE_CORAL, - default => throw new AssumptionFailedError("Unhandled coral type " . $coralType->name()) + match($block->getCoralType()){ + CoralType::BRAIN => $block->isDead() ? Ids::DEAD_BRAIN_CORAL : Ids::BRAIN_CORAL, + CoralType::BUBBLE => $block->isDead() ? Ids::DEAD_BUBBLE_CORAL : Ids::BUBBLE_CORAL, + CoralType::FIRE => $block->isDead() ? Ids::DEAD_FIRE_CORAL : Ids::FIRE_CORAL, + CoralType::HORN => $block->isDead() ? Ids::DEAD_HORN_CORAL : Ids::HORN_CORAL, + CoralType::TUBE => $block->isDead() ? Ids::DEAD_TUBE_CORAL : Ids::TUBE_CORAL, } )); } @@ -966,12 +965,11 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ $this->map(Blocks::BIG_DRIPLEAF_HEAD(), function(BigDripleafHead $block) : Writer{ return Writer::create(Ids::BIG_DRIPLEAF) ->writeLegacyHorizontalFacing($block->getFacing()) - ->writeString(StateNames::BIG_DRIPLEAF_TILT, match($block->getLeafState()->id()){ - DripleafState::STABLE()->id() => StringValues::BIG_DRIPLEAF_TILT_NONE, - DripleafState::UNSTABLE()->id() => StringValues::BIG_DRIPLEAF_TILT_UNSTABLE, - DripleafState::PARTIAL_TILT()->id() => StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT, - DripleafState::FULL_TILT()->id() => StringValues::BIG_DRIPLEAF_TILT_FULL_TILT, - default => throw new BlockStateSerializeException("Invalid Dripleaf tilt type " . $block->getLeafState()->name()) + ->writeString(StateNames::BIG_DRIPLEAF_TILT, match($block->getLeafState()){ + DripleafState::STABLE => StringValues::BIG_DRIPLEAF_TILT_NONE, + DripleafState::UNSTABLE => StringValues::BIG_DRIPLEAF_TILT_UNSTABLE, + DripleafState::PARTIAL_TILT => StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT, + DripleafState::FULL_TILT => StringValues::BIG_DRIPLEAF_TILT_FULL_TILT, }) ->writeBool(StateNames::BIG_DRIPLEAF_HEAD, true); }); @@ -995,9 +993,9 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ }); $this->map(Blocks::BREWING_STAND(), function(BrewingStand $block) : Writer{ return Writer::create(Ids::BREWING_STAND) - ->writeBool(StateNames::BREWING_STAND_SLOT_A_BIT, $block->hasSlot(BrewingStandSlot::EAST())) - ->writeBool(StateNames::BREWING_STAND_SLOT_B_BIT, $block->hasSlot(BrewingStandSlot::SOUTHWEST())) - ->writeBool(StateNames::BREWING_STAND_SLOT_C_BIT, $block->hasSlot(BrewingStandSlot::NORTHWEST())); + ->writeBool(StateNames::BREWING_STAND_SLOT_A_BIT, $block->hasSlot(BrewingStandSlot::EAST)) + ->writeBool(StateNames::BREWING_STAND_SLOT_B_BIT, $block->hasSlot(BrewingStandSlot::SOUTHWEST)) + ->writeBool(StateNames::BREWING_STAND_SLOT_C_BIT, $block->hasSlot(BrewingStandSlot::NORTHWEST)); }); $this->map(Blocks::BRICK_SLAB(), fn(Slab $block) => Helper::encodeStoneSlab1($block, StringValues::STONE_SLAB_TYPE_BRICK)); $this->mapStairs(Blocks::BRICK_STAIRS(), Ids::BRICK_STAIRS); @@ -1184,14 +1182,14 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ $this->map(Blocks::DIORITE_WALL(), fn(Wall $block) => Helper::encodeLegacyWall($block, StringValues::WALL_BLOCK_TYPE_DIORITE)); $this->map(Blocks::DIRT(), function(Dirt $block) : Writer{ $dirtType = $block->getDirtType(); - if($dirtType->equals(DirtType::ROOTED())){ + if($dirtType === DirtType::ROOTED){ return new Writer(Ids::DIRT_WITH_ROOTS); } return Writer::create(Ids::DIRT) ->writeString(StateNames::DIRT_TYPE, match($dirtType){ - DirtType::COARSE() => StringValues::DIRT_TYPE_COARSE, - DirtType::NORMAL() => StringValues::DIRT_TYPE_NORMAL, - default => throw new AssumptionFailedError("Unhandled dirt type " . $dirtType->name()) + DirtType::COARSE => StringValues::DIRT_TYPE_COARSE, + DirtType::NORMAL => StringValues::DIRT_TYPE_NORMAL, + //ROOTED was already checked above }); }); $this->map(Blocks::DOUBLE_TALLGRASS(), fn(DoubleTallGrass $block) => Helper::encodeDoublePlant($block, StringValues::DOUBLE_PLANT_TYPE_GRASS, Writer::create(Ids::DOUBLE_PLANT))); @@ -1229,10 +1227,9 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ }); $this->map(Blocks::FROGLIGHT(), function(Froglight $block){ return Writer::create(match($block->getFroglightType()){ - FroglightType::OCHRE() => Ids::OCHRE_FROGLIGHT, - FroglightType::PEARLESCENT() => Ids::PEARLESCENT_FROGLIGHT, - FroglightType::VERDANT() => Ids::VERDANT_FROGLIGHT, - default => throw new AssumptionFailedError("Unhandled froglight type " . $block->getFroglightType()->name()) + FroglightType::OCHRE => Ids::OCHRE_FROGLIGHT, + FroglightType::PEARLESCENT => Ids::PEARLESCENT_FROGLIGHT, + FroglightType::VERDANT => Ids::VERDANT_FROGLIGHT, }) ->writePillarAxis($block->getAxis()); }); @@ -1296,16 +1293,15 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ $this->map(Blocks::LEVER(), function(Lever $block) : Writer{ return Writer::create(Ids::LEVER) ->writeBool(StateNames::OPEN_BIT, $block->isActivated()) - ->writeString(StateNames::LEVER_DIRECTION, match($block->getFacing()->id()){ - LeverFacing::DOWN_AXIS_Z()->id() => StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH, - LeverFacing::DOWN_AXIS_X()->id() => StringValues::LEVER_DIRECTION_DOWN_EAST_WEST, - LeverFacing::UP_AXIS_Z()->id() => StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH, - LeverFacing::UP_AXIS_X()->id() => StringValues::LEVER_DIRECTION_UP_EAST_WEST, - LeverFacing::NORTH()->id() => StringValues::LEVER_DIRECTION_NORTH, - LeverFacing::SOUTH()->id() => StringValues::LEVER_DIRECTION_SOUTH, - LeverFacing::WEST()->id() => StringValues::LEVER_DIRECTION_WEST, - LeverFacing::EAST()->id() => StringValues::LEVER_DIRECTION_EAST, - default => throw new BlockStateSerializeException("Invalid Lever facing " . $block->getFacing()->name()), + ->writeString(StateNames::LEVER_DIRECTION, match($block->getFacing()){ + LeverFacing::DOWN_AXIS_Z => StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH, + LeverFacing::DOWN_AXIS_X => StringValues::LEVER_DIRECTION_DOWN_EAST_WEST, + LeverFacing::UP_AXIS_Z => StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH, + LeverFacing::UP_AXIS_X => StringValues::LEVER_DIRECTION_UP_EAST_WEST, + LeverFacing::NORTH => StringValues::LEVER_DIRECTION_NORTH, + LeverFacing::SOUTH => StringValues::LEVER_DIRECTION_SOUTH, + LeverFacing::WEST => StringValues::LEVER_DIRECTION_WEST, + LeverFacing::EAST => StringValues::LEVER_DIRECTION_EAST, }); }); $this->map(Blocks::LIGHT(), function(Light $block) : Writer{ @@ -1606,13 +1602,12 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{ }); $this->map(Blocks::WALL_CORAL_FAN(), function(WallCoralFan $block) : Writer{ $coralType = $block->getCoralType(); - return Writer::create(match($coralType->id()){ - CoralType::TUBE()->id(), CoralType::BRAIN()->id() => Ids::CORAL_FAN_HANG, - CoralType::BUBBLE()->id(), CoralType::FIRE()->id() => Ids::CORAL_FAN_HANG2, - CoralType::HORN()->id() => Ids::CORAL_FAN_HANG3, - default => throw new BlockStateSerializeException("Invalid Coral type " . $coralType->name()), + return Writer::create(match($coralType){ + CoralType::TUBE, CoralType::BRAIN => Ids::CORAL_FAN_HANG, + CoralType::BUBBLE, CoralType::FIRE => Ids::CORAL_FAN_HANG2, + CoralType::HORN => Ids::CORAL_FAN_HANG3, }) - ->writeBool(StateNames::CORAL_HANG_TYPE_BIT, $coralType->equals(CoralType::BRAIN()) || $coralType->equals(CoralType::FIRE())) + ->writeBool(StateNames::CORAL_HANG_TYPE_BIT, $coralType === CoralType::BRAIN || $coralType === CoralType::FIRE) ->writeBool(StateNames::DEAD_BIT, $block->isDead()) ->writeCoralFacing($block->getFacing()); }); diff --git a/src/data/bedrock/block/convert/BlockStateReader.php b/src/data/bedrock/block/convert/BlockStateReader.php index 09dab0f2c..42022016e 100644 --- a/src/data/bedrock/block/convert/BlockStateReader.php +++ b/src/data/bedrock/block/convert/BlockStateReader.php @@ -293,7 +293,7 @@ final class BlockStateReader{ /** @throws BlockStateDeserializeException */ public function readSlabPosition() : SlabType{ - return $this->readBool(BlockStateNames::TOP_SLOT_BIT) ? SlabType::TOP() : SlabType::BOTTOM(); + return $this->readBool(BlockStateNames::TOP_SLOT_BIT) ? SlabType::TOP : SlabType::BOTTOM; } /** @@ -316,11 +316,11 @@ final class BlockStateReader{ /** @throws BlockStateDeserializeException */ public function readCoralType() : CoralType{ return match($type = $this->readString(BlockStateNames::CORAL_COLOR)){ - StringValues::CORAL_COLOR_BLUE => CoralType::TUBE(), - StringValues::CORAL_COLOR_PINK => CoralType::BRAIN(), - StringValues::CORAL_COLOR_PURPLE => CoralType::BUBBLE(), - StringValues::CORAL_COLOR_RED => CoralType::FIRE(), - StringValues::CORAL_COLOR_YELLOW => CoralType::HORN(), + StringValues::CORAL_COLOR_BLUE => CoralType::TUBE, + StringValues::CORAL_COLOR_PINK => CoralType::BRAIN, + StringValues::CORAL_COLOR_PURPLE => CoralType::BUBBLE, + StringValues::CORAL_COLOR_RED => CoralType::FIRE, + StringValues::CORAL_COLOR_YELLOW => CoralType::HORN, default => throw $this->badValueException(BlockStateNames::CORAL_COLOR, $type), }; } @@ -328,10 +328,10 @@ final class BlockStateReader{ /** @throws BlockStateDeserializeException */ public function readBellAttachmentType() : BellAttachmentType{ return match($type = $this->readString(BlockStateNames::ATTACHMENT)){ - StringValues::ATTACHMENT_HANGING => BellAttachmentType::CEILING(), - StringValues::ATTACHMENT_STANDING => BellAttachmentType::FLOOR(), - StringValues::ATTACHMENT_SIDE => BellAttachmentType::ONE_WALL(), - StringValues::ATTACHMENT_MULTIPLE => BellAttachmentType::TWO_WALLS(), + StringValues::ATTACHMENT_HANGING => BellAttachmentType::CEILING, + StringValues::ATTACHMENT_STANDING => BellAttachmentType::FLOOR, + StringValues::ATTACHMENT_SIDE => BellAttachmentType::ONE_WALL, + StringValues::ATTACHMENT_MULTIPLE => BellAttachmentType::TWO_WALLS, default => throw $this->badValueException(BlockStateNames::ATTACHMENT, $type), }; } @@ -343,8 +343,8 @@ final class BlockStateReader{ //we need to find a better way to auto-generate the constant names when they are reused //for now, using these constants is better than nothing since it still gives static analysability StringValues::WALL_CONNECTION_TYPE_EAST_NONE => null, - StringValues::WALL_CONNECTION_TYPE_EAST_SHORT => WallConnectionType::SHORT(), - StringValues::WALL_CONNECTION_TYPE_EAST_TALL => WallConnectionType::TALL(), + StringValues::WALL_CONNECTION_TYPE_EAST_SHORT => WallConnectionType::SHORT, + StringValues::WALL_CONNECTION_TYPE_EAST_TALL => WallConnectionType::TALL, default => throw $this->badValueException($name, $type), }; } diff --git a/src/data/bedrock/block/convert/BlockStateSerializerHelper.php b/src/data/bedrock/block/convert/BlockStateSerializerHelper.php index 97fa5532f..08bf11c36 100644 --- a/src/data/bedrock/block/convert/BlockStateSerializerHelper.php +++ b/src/data/bedrock/block/convert/BlockStateSerializerHelper.php @@ -54,7 +54,6 @@ use pocketmine\data\bedrock\block\BlockTypeNames as Ids; use pocketmine\data\bedrock\block\convert\BlockStateWriter as Writer; use pocketmine\data\bedrock\MushroomBlockTypeIdMap; use pocketmine\math\Facing; -use pocketmine\utils\AssumptionFailedError; final class BlockStateSerializerHelper{ @@ -101,11 +100,10 @@ final class BlockStateSerializerHelper{ public static function selectCopperId(CopperOxidation $oxidation, string $noneId, string $exposedId, string $weatheredId, string $oxidizedId) : string{ return match($oxidation){ - CopperOxidation::NONE() => $noneId, - CopperOxidation::EXPOSED() => $exposedId, - CopperOxidation::WEATHERED() => $weatheredId, - CopperOxidation::OXIDIZED() => $oxidizedId, - default => throw new AssumptionFailedError("Unhandled copper oxidation " . $oxidation->name()) + CopperOxidation::NONE => $noneId, + CopperOxidation::EXPOSED => $exposedId, + CopperOxidation::WEATHERED => $weatheredId, + CopperOxidation::OXIDIZED => $oxidizedId, }; } @@ -210,10 +208,10 @@ final class BlockStateSerializerHelper{ public static function encodeSlab(Slab $block, string $singleId, string $doubleId) : BlockStateWriter{ $slabType = $block->getSlabType(); - return BlockStateWriter::create($slabType->equals(SlabType::DOUBLE()) ? $doubleId : $singleId) + return BlockStateWriter::create($slabType === SlabType::DOUBLE ? $doubleId : $singleId) //this is (intentionally) also written for double slabs (as zero) to maintain bug parity with MCPE - ->writeBool(BlockStateNames::TOP_SLOT_BIT, $slabType->equals(SlabType::TOP())); + ->writeBool(BlockStateNames::TOP_SLOT_BIT, $slabType === SlabType::TOP); } public static function encodeStairs(Stair $block, BlockStateWriter $out) : BlockStateWriter{ diff --git a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php index f6b8699a9..ff6b27a28 100644 --- a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php @@ -114,7 +114,7 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ $this->map($singleId, fn(Reader $in) : Slab => $getBlock($in)->setSlabType($in->readSlabPosition())); $this->map($doubleId, function(Reader $in) use ($getBlock) : Slab{ $in->ignored(StateNames::TOP_SLOT_BIT); - return $getBlock($in)->setSlabType(SlabType::DOUBLE()); + return $getBlock($in)->setSlabType(SlabType::DOUBLE); }); } @@ -292,20 +292,20 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ private function registerFlatCoralDeserializers() : void{ foreach([ - Ids::BRAIN_CORAL => CoralType::BRAIN(), - Ids::BUBBLE_CORAL => CoralType::BUBBLE(), - Ids::FIRE_CORAL => CoralType::FIRE(), - Ids::HORN_CORAL => CoralType::HORN(), - Ids::TUBE_CORAL => CoralType::TUBE(), + Ids::BRAIN_CORAL => CoralType::BRAIN, + Ids::BUBBLE_CORAL => CoralType::BUBBLE, + Ids::FIRE_CORAL => CoralType::FIRE, + Ids::HORN_CORAL => CoralType::HORN, + Ids::TUBE_CORAL => CoralType::TUBE, ] as $id => $coralType){ $this->mapSimple($id, fn() => Blocks::CORAL()->setCoralType($coralType)->setDead(false)); } foreach([ - Ids::DEAD_BRAIN_CORAL => CoralType::BRAIN(), - Ids::DEAD_BUBBLE_CORAL => CoralType::BUBBLE(), - Ids::DEAD_FIRE_CORAL => CoralType::FIRE(), - Ids::DEAD_HORN_CORAL => CoralType::HORN(), - Ids::DEAD_TUBE_CORAL => CoralType::TUBE(), + Ids::DEAD_BRAIN_CORAL => CoralType::BRAIN, + Ids::DEAD_BUBBLE_CORAL => CoralType::BUBBLE, + Ids::DEAD_FIRE_CORAL => CoralType::FIRE, + Ids::DEAD_HORN_CORAL => CoralType::HORN, + Ids::DEAD_TUBE_CORAL => CoralType::TUBE, ] as $id => $coralType){ $this->mapSimple($id, fn() => Blocks::CORAL()->setCoralType($coralType)->setDead(true)); } @@ -833,10 +833,10 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ return Blocks::BIG_DRIPLEAF_HEAD() ->setFacing($in->readLegacyHorizontalFacing()) ->setLeafState(match($type = $in->readString(StateNames::BIG_DRIPLEAF_TILT)){ - StringValues::BIG_DRIPLEAF_TILT_NONE => DripleafState::STABLE(), - StringValues::BIG_DRIPLEAF_TILT_UNSTABLE => DripleafState::UNSTABLE(), - StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT => DripleafState::PARTIAL_TILT(), - StringValues::BIG_DRIPLEAF_TILT_FULL_TILT => DripleafState::FULL_TILT(), + StringValues::BIG_DRIPLEAF_TILT_NONE => DripleafState::STABLE, + StringValues::BIG_DRIPLEAF_TILT_UNSTABLE => DripleafState::UNSTABLE, + StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT => DripleafState::PARTIAL_TILT, + StringValues::BIG_DRIPLEAF_TILT_FULL_TILT => DripleafState::FULL_TILT, default => throw $in->badValueException(StateNames::BIG_DRIPLEAF_TILT, $type), }); }else{ @@ -858,9 +858,9 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ }); $this->map(Ids::BREWING_STAND, function(Reader $in) : Block{ return Blocks::BREWING_STAND() - ->setSlot(BrewingStandSlot::EAST(), $in->readBool(StateNames::BREWING_STAND_SLOT_A_BIT)) - ->setSlot(BrewingStandSlot::SOUTHWEST(), $in->readBool(StateNames::BREWING_STAND_SLOT_B_BIT)) - ->setSlot(BrewingStandSlot::NORTHWEST(), $in->readBool(StateNames::BREWING_STAND_SLOT_C_BIT)); + ->setSlot(BrewingStandSlot::EAST, $in->readBool(StateNames::BREWING_STAND_SLOT_A_BIT)) + ->setSlot(BrewingStandSlot::SOUTHWEST, $in->readBool(StateNames::BREWING_STAND_SLOT_B_BIT)) + ->setSlot(BrewingStandSlot::NORTHWEST, $in->readBool(StateNames::BREWING_STAND_SLOT_C_BIT)); }); $this->mapStairs(Ids::BRICK_STAIRS, fn() => Blocks::BRICK_STAIRS()); $this->map(Ids::BROWN_MUSHROOM_BLOCK, fn(Reader $in) => Helper::decodeMushroomBlock(Blocks::BROWN_MUSHROOM_BLOCK(), $in)); @@ -939,10 +939,10 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ return Blocks::CONCRETE_POWDER() ->setColor($in->readColor()); }); - $this->map(Ids::COPPER_BLOCK, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::NONE())); - $this->map(Ids::CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE())); - $this->mapSlab(Ids::CUT_COPPER_SLAB, Ids::DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE())); - $this->mapStairs(Ids::CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE())); + $this->map(Ids::COPPER_BLOCK, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::NONE)); + $this->map(Ids::CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); + $this->mapSlab(Ids::CUT_COPPER_SLAB, Ids::DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); + $this->mapStairs(Ids::CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); $this->map(Ids::CORAL_BLOCK, function(Reader $in) : Block{ return Blocks::CORAL_BLOCK() ->setCoralType($in->readCoralType()) @@ -953,13 +953,13 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ $this->map(Ids::CORAL_FAN_DEAD, fn(Reader $in) => Helper::decodeFloorCoralFan(Blocks::CORAL_FAN(), $in) ->setDead(true)); $this->map(Ids::CORAL_FAN_HANG, fn(Reader $in) => Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) - ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::BRAIN() : CoralType::TUBE())); + ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::BRAIN : CoralType::TUBE)); $this->map(Ids::CORAL_FAN_HANG2, fn(Reader $in) => Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) - ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::FIRE() : CoralType::BUBBLE())); + ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::FIRE : CoralType::BUBBLE)); $this->map(Ids::CORAL_FAN_HANG3, function(Reader $in) : Block{ $in->ignored(StateNames::CORAL_HANG_TYPE_BIT); //the game always writes this, even though it's not used return Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) - ->setCoralType(CoralType::HORN()); + ->setCoralType(CoralType::HORN); }); $this->mapStairs(Ids::DARK_PRISMARINE_STAIRS, fn() => Blocks::DARK_PRISMARINE_STAIRS()); $this->map(Ids::DAYLIGHT_DETECTOR, fn(Reader $in) => Helper::decodeDaylightSensor(Blocks::DAYLIGHT_SENSOR(), $in) @@ -986,12 +986,12 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ $this->map(Ids::DIRT, function(Reader $in) : Block{ return Blocks::DIRT() ->setDirtType(match($value = $in->readString(StateNames::DIRT_TYPE)){ - StringValues::DIRT_TYPE_NORMAL => DirtType::NORMAL(), - StringValues::DIRT_TYPE_COARSE => DirtType::COARSE(), + StringValues::DIRT_TYPE_NORMAL => DirtType::NORMAL, + StringValues::DIRT_TYPE_COARSE => DirtType::COARSE, default => throw $in->badValueException(StateNames::DIRT_TYPE, $value), }); }); - $this->map(Ids::DIRT_WITH_ROOTS, fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED())); + $this->map(Ids::DIRT_WITH_ROOTS, fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED)); $this->map(Ids::DOUBLE_PLANT, function(Reader $in) : Block{ return (match($type = $in->readString(StateNames::DOUBLE_PLANT_TYPE)){ StringValues::DOUBLE_PLANT_TYPE_FERN => Blocks::LARGE_FERN(), @@ -1017,10 +1017,10 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ return Blocks::ENDER_CHEST() ->setFacing($in->readHorizontalFacing()); }); - $this->map(Ids::EXPOSED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::EXPOSED())); - $this->map(Ids::EXPOSED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED())); - $this->mapSlab(Ids::EXPOSED_CUT_COPPER_SLAB, Ids::EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED())); - $this->mapStairs(Ids::EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED())); + $this->map(Ids::EXPOSED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); + $this->map(Ids::EXPOSED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); + $this->mapSlab(Ids::EXPOSED_CUT_COPPER_SLAB, Ids::EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); + $this->mapStairs(Ids::EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); $this->map(Ids::FARMLAND, function(Reader $in) : Block{ return Blocks::FARMLAND() ->setWetness($in->readBoundedInt(StateNames::MOISTURIZED_AMOUNT, 0, 7)); @@ -1091,14 +1091,14 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ return Blocks::LEVER() ->setActivated($in->readBool(StateNames::OPEN_BIT)) ->setFacing(match($value = $in->readString(StateNames::LEVER_DIRECTION)){ - StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH => LeverFacing::DOWN_AXIS_Z(), - StringValues::LEVER_DIRECTION_DOWN_EAST_WEST => LeverFacing::DOWN_AXIS_X(), - StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH => LeverFacing::UP_AXIS_Z(), - StringValues::LEVER_DIRECTION_UP_EAST_WEST => LeverFacing::UP_AXIS_X(), - StringValues::LEVER_DIRECTION_NORTH => LeverFacing::NORTH(), - StringValues::LEVER_DIRECTION_SOUTH => LeverFacing::SOUTH(), - StringValues::LEVER_DIRECTION_WEST => LeverFacing::WEST(), - StringValues::LEVER_DIRECTION_EAST => LeverFacing::EAST(), + StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH => LeverFacing::DOWN_AXIS_Z, + StringValues::LEVER_DIRECTION_DOWN_EAST_WEST => LeverFacing::DOWN_AXIS_X, + StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH => LeverFacing::UP_AXIS_Z, + StringValues::LEVER_DIRECTION_UP_EAST_WEST => LeverFacing::UP_AXIS_X, + StringValues::LEVER_DIRECTION_NORTH => LeverFacing::NORTH, + StringValues::LEVER_DIRECTION_SOUTH => LeverFacing::SOUTH, + StringValues::LEVER_DIRECTION_WEST => LeverFacing::WEST, + StringValues::LEVER_DIRECTION_EAST => LeverFacing::EAST, default => throw $in->badValueException(StateNames::LEVER_DIRECTION, $value), }); }); @@ -1170,12 +1170,12 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ ->setAge($in->readBoundedInt(StateNames::AGE, 0, 3)); }); $this->mapStairs(Ids::NORMAL_STONE_STAIRS, fn() => Blocks::STONE_STAIRS()); - $this->map(Ids::OCHRE_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::OCHRE())->setAxis($in->readPillarAxis())); - $this->map(Ids::OXIDIZED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED())); - $this->map(Ids::OXIDIZED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED())); - $this->mapSlab(Ids::OXIDIZED_CUT_COPPER_SLAB, Ids::OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED())); - $this->mapStairs(Ids::OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED())); - $this->map(Ids::PEARLESCENT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::PEARLESCENT())->setAxis($in->readPillarAxis())); + $this->map(Ids::OCHRE_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::OCHRE)->setAxis($in->readPillarAxis())); + $this->map(Ids::OXIDIZED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); + $this->map(Ids::OXIDIZED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); + $this->mapSlab(Ids::OXIDIZED_CUT_COPPER_SLAB, Ids::OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); + $this->mapStairs(Ids::OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); + $this->map(Ids::PEARLESCENT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::PEARLESCENT)->setAxis($in->readPillarAxis())); $this->map(Ids::PINK_PETALS, function(Reader $in) : Block{ //Pink petals only uses 0-3, but GROWTH state can go up to 7 $growth = $in->readBoundedInt(StateNames::GROWTH, 0, 7); @@ -1493,7 +1493,7 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ $this->map(Ids::UNPOWERED_COMPARATOR, fn(Reader $in) => Helper::decodeComparator(Blocks::REDSTONE_COMPARATOR(), $in)); $this->map(Ids::UNPOWERED_REPEATER, fn(Reader $in) => Helper::decodeRepeater(Blocks::REDSTONE_REPEATER(), $in) ->setPowered(false)); - $this->map(Ids::VERDANT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::VERDANT())->setAxis($in->readPillarAxis())); + $this->map(Ids::VERDANT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::VERDANT)->setAxis($in->readPillarAxis())); $this->map(Ids::VINE, function(Reader $in) : Block{ $vineDirectionFlags = $in->readBoundedInt(StateNames::VINE_DIRECTION_BITS, 0, 15); return Blocks::VINES() @@ -1507,26 +1507,26 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{ ->setFacing($in->readHorizontalFacing()); }); $this->map(Ids::WATER, fn(Reader $in) => Helper::decodeStillLiquid(Blocks::WATER(), $in)); - $this->map(Ids::WAXED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::NONE())); - $this->map(Ids::WAXED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE())); - $this->mapSlab(Ids::WAXED_CUT_COPPER_SLAB, Ids::WAXED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE())); - $this->mapStairs(Ids::WAXED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE())); - $this->map(Ids::WAXED_EXPOSED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::EXPOSED())); - $this->map(Ids::WAXED_EXPOSED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED())); - $this->mapSlab(Ids::WAXED_EXPOSED_CUT_COPPER_SLAB, Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED())); - $this->mapStairs(Ids::WAXED_EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED())); - $this->map(Ids::WAXED_OXIDIZED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED())); - $this->map(Ids::WAXED_OXIDIZED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED())); - $this->mapSlab(Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB, Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED())); - $this->mapStairs(Ids::WAXED_OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED())); - $this->map(Ids::WAXED_WEATHERED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::WEATHERED())); - $this->map(Ids::WAXED_WEATHERED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED())); - $this->mapSlab(Ids::WAXED_WEATHERED_CUT_COPPER_SLAB, Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED())); - $this->mapStairs(Ids::WAXED_WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED())); - $this->map(Ids::WEATHERED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::WEATHERED())); - $this->map(Ids::WEATHERED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED())); - $this->mapSlab(Ids::WEATHERED_CUT_COPPER_SLAB, Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED())); - $this->mapStairs(Ids::WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED())); + $this->map(Ids::WAXED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::NONE)); + $this->map(Ids::WAXED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); + $this->mapSlab(Ids::WAXED_CUT_COPPER_SLAB, Ids::WAXED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); + $this->mapStairs(Ids::WAXED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); + $this->map(Ids::WAXED_EXPOSED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); + $this->map(Ids::WAXED_EXPOSED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); + $this->mapSlab(Ids::WAXED_EXPOSED_CUT_COPPER_SLAB, Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); + $this->mapStairs(Ids::WAXED_EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); + $this->map(Ids::WAXED_OXIDIZED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); + $this->map(Ids::WAXED_OXIDIZED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); + $this->mapSlab(Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB, Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); + $this->mapStairs(Ids::WAXED_OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); + $this->map(Ids::WAXED_WEATHERED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); + $this->map(Ids::WAXED_WEATHERED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); + $this->mapSlab(Ids::WAXED_WEATHERED_CUT_COPPER_SLAB, Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); + $this->mapStairs(Ids::WAXED_WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); + $this->map(Ids::WEATHERED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); + $this->map(Ids::WEATHERED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); + $this->mapSlab(Ids::WEATHERED_CUT_COPPER_SLAB, Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); + $this->mapStairs(Ids::WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); $this->map(Ids::WEEPING_VINES, function(Reader $in) : Block{ return Blocks::WEEPING_VINES() ->setAge($in->readBoundedInt(StateNames::WEEPING_VINES_AGE, 0, 25)); diff --git a/src/data/bedrock/block/convert/BlockStateWriter.php b/src/data/bedrock/block/convert/BlockStateWriter.php index 2e2d8daae..7c7274f2f 100644 --- a/src/data/bedrock/block/convert/BlockStateWriter.php +++ b/src/data/bedrock/block/convert/BlockStateWriter.php @@ -246,10 +246,10 @@ final class BlockStateWriter{ /** @return $this */ public function writeSlabPosition(SlabType $slabType) : self{ - $this->writeBool(BlockStateNames::TOP_SLOT_BIT, match($slabType->id()){ - SlabType::TOP()->id() => true, - SlabType::BOTTOM()->id() => false, - default => throw new BlockStateSerializeException("Invalid slab type " . $slabType->name()) + $this->writeBool(BlockStateNames::TOP_SLOT_BIT, match($slabType){ + SlabType::TOP => true, + SlabType::BOTTOM => false, + default => throw new BlockStateSerializeException("Invalid slab type " . $slabType->name) }); return $this; } @@ -270,39 +270,37 @@ final class BlockStateWriter{ /** @return $this */ public function writeLegacyWoodType(WoodType $treeType) : self{ - $this->writeString(BlockStateNames::WOOD_TYPE, match($treeType->id()){ - WoodType::OAK()->id() => StringValues::WOOD_TYPE_OAK, - WoodType::SPRUCE()->id() => StringValues::WOOD_TYPE_SPRUCE, - WoodType::BIRCH()->id() => StringValues::WOOD_TYPE_BIRCH, - WoodType::JUNGLE()->id() => StringValues::WOOD_TYPE_JUNGLE, - WoodType::ACACIA()->id() => StringValues::WOOD_TYPE_ACACIA, - WoodType::DARK_OAK()->id() => StringValues::WOOD_TYPE_DARK_OAK, - default => throw new BlockStateSerializeException("Invalid Wood type " . $treeType->name()) + $this->writeString(BlockStateNames::WOOD_TYPE, match($treeType){ + WoodType::OAK => StringValues::WOOD_TYPE_OAK, + WoodType::SPRUCE => StringValues::WOOD_TYPE_SPRUCE, + WoodType::BIRCH => StringValues::WOOD_TYPE_BIRCH, + WoodType::JUNGLE => StringValues::WOOD_TYPE_JUNGLE, + WoodType::ACACIA => StringValues::WOOD_TYPE_ACACIA, + WoodType::DARK_OAK => StringValues::WOOD_TYPE_DARK_OAK, + default => throw new BlockStateSerializeException("Invalid legacy wood type " . $treeType->name) }); return $this; } /** @return $this */ public function writeCoralType(CoralType $coralType) : self{ - $this->writeString(BlockStateNames::CORAL_COLOR, match($coralType->id()){ - CoralType::TUBE()->id() => StringValues::CORAL_COLOR_BLUE, - CoralType::BRAIN()->id() => StringValues::CORAL_COLOR_PINK, - CoralType::BUBBLE()->id() => StringValues::CORAL_COLOR_PURPLE, - CoralType::FIRE()->id() => StringValues::CORAL_COLOR_RED, - CoralType::HORN()->id() => StringValues::CORAL_COLOR_YELLOW, - default => throw new BlockStateSerializeException("Invalid Coral type " . $coralType->name()) + $this->writeString(BlockStateNames::CORAL_COLOR, match($coralType){ + CoralType::TUBE => StringValues::CORAL_COLOR_BLUE, + CoralType::BRAIN => StringValues::CORAL_COLOR_PINK, + CoralType::BUBBLE => StringValues::CORAL_COLOR_PURPLE, + CoralType::FIRE => StringValues::CORAL_COLOR_RED, + CoralType::HORN => StringValues::CORAL_COLOR_YELLOW, }); return $this; } /** @return $this */ public function writeBellAttachmentType(BellAttachmentType $attachmentType) : self{ - $this->writeString(BlockStateNames::ATTACHMENT, match($attachmentType->id()){ - BellAttachmentType::FLOOR()->id() => StringValues::ATTACHMENT_STANDING, - BellAttachmentType::CEILING()->id() => StringValues::ATTACHMENT_HANGING, - BellAttachmentType::ONE_WALL()->id() => StringValues::ATTACHMENT_SIDE, - BellAttachmentType::TWO_WALLS()->id() => StringValues::ATTACHMENT_MULTIPLE, - default => throw new BlockStateSerializeException("Invalid Bell attachment type " . $attachmentType->name()) + $this->writeString(BlockStateNames::ATTACHMENT, match($attachmentType){ + BellAttachmentType::FLOOR => StringValues::ATTACHMENT_STANDING, + BellAttachmentType::CEILING => StringValues::ATTACHMENT_HANGING, + BellAttachmentType::ONE_WALL => StringValues::ATTACHMENT_SIDE, + BellAttachmentType::TWO_WALLS => StringValues::ATTACHMENT_MULTIPLE, }); return $this; } @@ -311,9 +309,8 @@ final class BlockStateWriter{ public function writeWallConnectionType(string $name, ?WallConnectionType $wallConnectionType) : self{ $this->writeString($name, match($wallConnectionType){ null => StringValues::WALL_CONNECTION_TYPE_EAST_NONE, - WallConnectionType::SHORT() => StringValues::WALL_CONNECTION_TYPE_EAST_SHORT, - WallConnectionType::TALL() => StringValues::WALL_CONNECTION_TYPE_EAST_TALL, - default => throw new BlockStateSerializeException("Invalid Wall connection type " . $wallConnectionType->name()) + WallConnectionType::SHORT => StringValues::WALL_CONNECTION_TYPE_EAST_SHORT, + WallConnectionType::TALL => StringValues::WALL_CONNECTION_TYPE_EAST_TALL, }); return $this; } diff --git a/src/data/runtime/RuntimeDataReader.php b/src/data/runtime/RuntimeDataReader.php index 8b0a4b30c..1677cea36 100644 --- a/src/data/runtime/RuntimeDataReader.php +++ b/src/data/runtime/RuntimeDataReader.php @@ -30,6 +30,7 @@ use pocketmine\math\Axis; use pocketmine\math\Facing; use pocketmine\utils\AssumptionFailedError; use function intdiv; +use function spl_object_id; final class RuntimeDataReader implements RuntimeDataDescriber{ use RuntimeEnumDeserializerTrait; @@ -165,8 +166,8 @@ final class RuntimeDataReader implements RuntimeDataDescriber{ $type = intdiv($packed, (3 ** $offset)) % 3; if($type !== 0){ $result[$facing] = match($type){ - 1 => WallConnectionType::SHORT(), - 2 => WallConnectionType::TALL(), + 1 => WallConnectionType::SHORT, + 2 => WallConnectionType::TALL, default => throw new AssumptionFailedError("Unreachable") }; } @@ -182,13 +183,9 @@ final class RuntimeDataReader implements RuntimeDataDescriber{ */ public function brewingStandSlots(array &$slots) : void{ $result = []; - foreach([ - BrewingStandSlot::EAST(), - BrewingStandSlot::NORTHWEST(), - BrewingStandSlot::SOUTHWEST(), - ] as $member){ + foreach(BrewingStandSlot::cases() as $member){ if($this->readBool()){ - $result[$member->id()] = $member; + $result[spl_object_id($member)] = $member; } } diff --git a/src/data/runtime/RuntimeDataSizeCalculator.php b/src/data/runtime/RuntimeDataSizeCalculator.php index 87eec2ba8..352e8e1a1 100644 --- a/src/data/runtime/RuntimeDataSizeCalculator.php +++ b/src/data/runtime/RuntimeDataSizeCalculator.php @@ -85,7 +85,7 @@ final class RuntimeDataSizeCalculator implements RuntimeDataDescriber{ } public function brewingStandSlots(array &$slots) : void{ - $this->addBits(count(BrewingStandSlot::getAll())); + $this->addBits(count(BrewingStandSlot::cases())); } public function railShape(int &$railShape) : void{ diff --git a/src/data/runtime/RuntimeDataWriter.php b/src/data/runtime/RuntimeDataWriter.php index e30296738..3a5855a25 100644 --- a/src/data/runtime/RuntimeDataWriter.php +++ b/src/data/runtime/RuntimeDataWriter.php @@ -27,8 +27,8 @@ use pocketmine\block\utils\BrewingStandSlot; use pocketmine\block\utils\WallConnectionType; use pocketmine\math\Axis; use pocketmine\math\Facing; -use pocketmine\utils\AssumptionFailedError; use function array_flip; +use function spl_object_id; final class RuntimeDataWriter implements RuntimeDataDescriber{ use RuntimeEnumSerializerTrait; @@ -148,9 +148,8 @@ final class RuntimeDataWriter implements RuntimeDataDescriber{ foreach(Facing::HORIZONTAL as $facing){ $packed += match($connections[$facing] ?? null){ null => 0, - WallConnectionType::SHORT() => 1, - WallConnectionType::TALL() => 2, - default => throw new AssumptionFailedError("Unreachable") + WallConnectionType::SHORT => 1, + WallConnectionType::TALL => 2, } * (3 ** $offset); $offset++; } @@ -162,12 +161,8 @@ final class RuntimeDataWriter implements RuntimeDataDescriber{ * @phpstan-param array $slots */ public function brewingStandSlots(array &$slots) : void{ - foreach([ - BrewingStandSlot::EAST(), - BrewingStandSlot::NORTHWEST(), - BrewingStandSlot::SOUTHWEST(), - ] as $member){ - $this->writeBool(isset($slots[$member->id()])); + foreach(BrewingStandSlot::cases() as $member){ + $this->writeBool(isset($slots[spl_object_id($member)])); } } diff --git a/src/item/Armor.php b/src/item/Armor.php index e52732caf..e9667a8a8 100644 --- a/src/item/Armor.php +++ b/src/item/Armor.php @@ -150,7 +150,7 @@ class Armor extends Durable{ //if the stack size was bigger than 1 (usually won't happen, but might be caused by plugins) $returnedItems[] = $thisCopy; } - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } protected function deserializeCompoundTag(CompoundTag $tag) : void{ diff --git a/src/item/BoatType.php b/src/item/BoatType.php index 5ef0c9255..518a1324e 100644 --- a/src/item/BoatType.php +++ b/src/item/BoatType.php @@ -24,13 +24,11 @@ declare(strict_types=1); namespace pocketmine\item; use pocketmine\block\utils\WoodType; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static BoatType ACACIA() * @method static BoatType BIRCH() @@ -40,33 +38,30 @@ use pocketmine\utils\EnumTrait; * @method static BoatType OAK() * @method static BoatType SPRUCE() */ -final class BoatType{ - use EnumTrait { - __construct as Enum___construct; - } +enum BoatType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("oak", WoodType::OAK()), - new self("spruce", WoodType::SPRUCE()), - new self("birch", WoodType::BIRCH()), - new self("jungle", WoodType::JUNGLE()), - new self("acacia", WoodType::ACACIA()), - new self("dark_oak", WoodType::DARK_OAK()), - new self("mangrove", WoodType::MANGROVE()), - ); - } + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + case MANGROVE; - private function __construct( - string $enumName, - private WoodType $woodType, - ){ - $this->Enum___construct($enumName); + public function getWoodType() : WoodType{ + return match($this){ + self::OAK => WoodType::OAK, + self::SPRUCE => WoodType::SPRUCE, + self::BIRCH => WoodType::BIRCH, + self::JUNGLE => WoodType::JUNGLE, + self::ACACIA => WoodType::ACACIA, + self::DARK_OAK => WoodType::DARK_OAK, + self::MANGROVE => WoodType::MANGROVE, + }; } - public function getWoodType() : WoodType{ return $this->woodType; } - public function getDisplayName() : string{ - return $this->woodType->getDisplayName(); + return $this->getWoodType()->getDisplayName(); } } diff --git a/src/item/Bow.php b/src/item/Bow.php index 3c1320f03..1b25312a8 100644 --- a/src/item/Bow.php +++ b/src/item/Bow.php @@ -53,7 +53,7 @@ class Bow extends Tool implements Releasable{ }; if($player->hasFiniteResources() && $inventory === null){ - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $location = $player->getLocation(); @@ -95,7 +95,7 @@ class Bow extends Tool implements Releasable{ if($ev->isCancelled()){ $entity->flagForDespawn(); - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $entity->setMotion($entity->getMotion()->multiply($ev->getForce())); @@ -105,7 +105,7 @@ class Bow extends Tool implements Releasable{ $projectileEv->call(); if($projectileEv->isCancelled()){ $ev->getProjectile()->flagForDespawn(); - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $ev->getProjectile()->spawnToAll(); @@ -121,7 +121,7 @@ class Bow extends Tool implements Releasable{ $this->applyDamage(1); } - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } public function canStartUsingItem(Player $player) : bool{ diff --git a/src/item/Bucket.php b/src/item/Bucket.php index b788a3022..ee69a0a8a 100644 --- a/src/item/Bucket.php +++ b/src/item/Bucket.php @@ -49,7 +49,7 @@ class Bucket extends Item{ default => null }; if($resultItem === null){ - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $ev = new PlayerBucketFillEvent($player, $blockReplace, $face, $this, $resultItem); @@ -60,12 +60,12 @@ class Bucket extends Item{ $this->pop(); $returnedItems[] = $ev->getItem(); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } } diff --git a/src/item/CoralFan.php b/src/item/CoralFan.php index 294eb6d6e..7fdfc9114 100644 --- a/src/item/CoralFan.php +++ b/src/item/CoralFan.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\item; use pocketmine\block\Block; -use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\VanillaBlocks; use pocketmine\data\runtime\RuntimeDataDescriber; @@ -37,7 +36,6 @@ final class CoralFan extends Item{ } public function __construct(ItemIdentifier $identifier){ - $this->coralType = CoralType::TUBE(); parent::__construct($identifier, VanillaBlocks::CORAL_FAN()->getName()); } diff --git a/src/item/FireCharge.php b/src/item/FireCharge.php index 20e7e4f89..a612e0897 100644 --- a/src/item/FireCharge.php +++ b/src/item/FireCharge.php @@ -40,9 +40,9 @@ class FireCharge extends Item{ $this->pop(); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } } diff --git a/src/item/FlintSteel.php b/src/item/FlintSteel.php index 0ff2e754c..3e694eb0d 100644 --- a/src/item/FlintSteel.php +++ b/src/item/FlintSteel.php @@ -40,10 +40,10 @@ class FlintSteel extends Tool{ $this->applyDamage(1); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } public function getMaxDurability() : int{ diff --git a/src/item/GlassBottle.php b/src/item/GlassBottle.php index bda6d132e..135ba3233 100644 --- a/src/item/GlassBottle.php +++ b/src/item/GlassBottle.php @@ -35,9 +35,9 @@ class GlassBottle extends Item{ $this->pop(); $returnedItems[] = VanillaItems::POTION()->setType(PotionType::WATER()); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } } diff --git a/src/item/Item.php b/src/item/Item.php index 775a82d75..1a74345b5 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -588,7 +588,7 @@ class Item implements \JsonSerializable{ * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if the inventory is full) */ public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } /** @@ -598,7 +598,7 @@ class Item implements \JsonSerializable{ * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if the inventory is full) */ public function onClickAir(Player $player, Vector3 $directionVector, array &$returnedItems) : ItemUseResult{ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } /** @@ -608,7 +608,7 @@ class Item implements \JsonSerializable{ * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if the inventory is full) */ public function onReleaseUsing(Player $player, array &$returnedItems) : ItemUseResult{ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } /** diff --git a/src/item/ItemUseResult.php b/src/item/ItemUseResult.php index ff78b94e4..e3fbe10fb 100644 --- a/src/item/ItemUseResult.php +++ b/src/item/ItemUseResult.php @@ -23,26 +23,20 @@ declare(strict_types=1); namespace pocketmine\item; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static ItemUseResult FAIL() * @method static ItemUseResult NONE() * @method static ItemUseResult SUCCESS() */ -final class ItemUseResult{ - use EnumTrait; +enum ItemUseResult{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("none"), - new self("fail"), - new self("success") - ); - } + case NONE; + case FAIL; + case SUCCESS; } diff --git a/src/item/LiquidBucket.php b/src/item/LiquidBucket.php index 740f79b11..eb2cb18ed 100644 --- a/src/item/LiquidBucket.php +++ b/src/item/LiquidBucket.php @@ -56,7 +56,7 @@ class LiquidBucket extends Item{ public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if(!$blockReplace->canBeReplaced()){ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } //TODO: move this to generic placement logic @@ -70,10 +70,10 @@ class LiquidBucket extends Item{ $this->pop(); $returnedItems[] = $ev->getItem(); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } public function getLiquid() : Liquid{ diff --git a/src/item/PaintingItem.php b/src/item/PaintingItem.php index f3821d0b2..a83c8dba8 100644 --- a/src/item/PaintingItem.php +++ b/src/item/PaintingItem.php @@ -39,7 +39,7 @@ class PaintingItem extends Item{ public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if(Facing::axis($face) === Axis::Y){ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } $motives = []; @@ -67,7 +67,7 @@ class PaintingItem extends Item{ } if(count($motives) === 0){ //No space available - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } /** @var PaintingMotive $motive */ @@ -81,6 +81,6 @@ class PaintingItem extends Item{ $entity->spawnToAll(); $player->getWorld()->addSound($replacePos->add(0.5, 0.5, 0.5), new PaintingPlaceSound()); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } } diff --git a/src/item/ProjectileItem.php b/src/item/ProjectileItem.php index 8056af505..47c4583e0 100644 --- a/src/item/ProjectileItem.php +++ b/src/item/ProjectileItem.php @@ -46,7 +46,7 @@ abstract class ProjectileItem extends Item{ $projectileEv->call(); if($projectileEv->isCancelled()){ $projectile->flagForDespawn(); - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $projectile->spawnToAll(); @@ -55,6 +55,6 @@ abstract class ProjectileItem extends Item{ $this->pop(); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } } diff --git a/src/item/SpawnEgg.php b/src/item/SpawnEgg.php index 1147a951d..51dcceebd 100644 --- a/src/item/SpawnEgg.php +++ b/src/item/SpawnEgg.php @@ -43,6 +43,6 @@ abstract class SpawnEgg extends Item{ $this->pop(); $entity->spawnToAll(); //TODO: what if the entity was marked for deletion? - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } } diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index d482e4bef..296dd0341 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -37,6 +37,7 @@ use pocketmine\item\VanillaItems as Items; use pocketmine\utils\SingletonTrait; use pocketmine\utils\StringToTParser; use function array_keys; +use function strtolower; /** * Handles parsing items from strings. This is used to interpret names from the /give command (and others). @@ -77,8 +78,8 @@ final class StringToItemParser extends StringToTParser{ $register("shulker_box", fn() => Blocks::DYED_SHULKER_BOX()->setColor($color)); } - foreach(CoralType::getAll() as $coralType){ - $register = fn(string $name, \Closure $callback) => $result->registerBlock($coralType->name() . "_" . $name, $callback); + foreach(CoralType::cases() as $coralType){ + $register = fn(string $name, \Closure $callback) => $result->registerBlock(strtolower($coralType->name) . "_" . $name, $callback); $register("coral", fn() => Blocks::CORAL()->setCoralType($coralType)); $register("coral_block", fn() => Blocks::CORAL_BLOCK()->setCoralType($coralType)); //wall and floor coral fans are the same item @@ -90,8 +91,8 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("light_block_$i", fn() => Blocks::LIGHT()->setLightLevel($i)); } - foreach(CopperOxidation::getAll() as $oxidation){ - $oxPrefix = $oxidation->equals(CopperOxidation::NONE()) ? "" : $oxidation->name() . "_"; + foreach(CopperOxidation::cases() as $oxidation){ + $oxPrefix = $oxidation === CopperOxidation::NONE ? "" : strtolower($oxidation->name) . "_"; foreach(["" => false, "waxed_" => true] as $waxedPrefix => $waxed){ $register = fn(string $name, \Closure $callback) => $result->registerBlock($waxedPrefix . $oxPrefix . $name, $callback); @@ -102,8 +103,8 @@ final class StringToItemParser extends StringToTParser{ } } - foreach(FroglightType::getAll() as $froglightType){ - $result->registerBlock($froglightType->name() . "_froglight", fn() => Blocks::FROGLIGHT()->setFroglightType($froglightType)); + foreach(FroglightType::cases() as $froglightType){ + $result->registerBlock(strtolower($froglightType->name) . "_froglight", fn() => Blocks::FROGLIGHT()->setFroglightType($froglightType)); } } @@ -238,7 +239,7 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("clay_block", fn() => Blocks::CLAY()); $result->registerBlock("coal_block", fn() => Blocks::COAL()); $result->registerBlock("coal_ore", fn() => Blocks::COAL_ORE()); - $result->registerBlock("coarse_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::COARSE())); + $result->registerBlock("coarse_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::COARSE)); $result->registerBlock("cobble", fn() => Blocks::COBBLESTONE()); $result->registerBlock("cobble_stairs", fn() => Blocks::COBBLESTONE_STAIRS()); $result->registerBlock("cobble_wall", fn() => Blocks::COBBLESTONE_WALL()); @@ -267,10 +268,10 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("coral", fn() => Blocks::CORAL()); $result->registerBlock("coral_block", fn() => Blocks::CORAL_BLOCK()); $result->registerBlock("coral_fan", fn() => Blocks::CORAL_FAN()); - $result->registerBlock("coral_fan_dead", fn() => Blocks::CORAL_FAN()->setCoralType(CoralType::TUBE())->setDead(true)); + $result->registerBlock("coral_fan_dead", fn() => Blocks::CORAL_FAN()->setCoralType(CoralType::TUBE)->setDead(true)); $result->registerBlock("coral_fan_hang", fn() => Blocks::WALL_CORAL_FAN()); - $result->registerBlock("coral_fan_hang2", fn() => Blocks::WALL_CORAL_FAN()->setCoralType(CoralType::BUBBLE())); - $result->registerBlock("coral_fan_hang3", fn() => Blocks::WALL_CORAL_FAN()->setCoralType(CoralType::HORN())); + $result->registerBlock("coral_fan_hang2", fn() => Blocks::WALL_CORAL_FAN()->setCoralType(CoralType::BUBBLE)); + $result->registerBlock("coral_fan_hang3", fn() => Blocks::WALL_CORAL_FAN()->setCoralType(CoralType::HORN)); $result->registerBlock("cornflower", fn() => Blocks::CORNFLOWER()); $result->registerBlock("cracked_deepslate_bricks", fn() => Blocks::CRACKED_DEEPSLATE_BRICKS()); $result->registerBlock("cracked_deepslate_tiles", fn() => Blocks::CRACKED_DEEPSLATE_TILES()); @@ -278,7 +279,7 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("cracked_polished_blackstone_bricks", fn() => Blocks::CRACKED_POLISHED_BLACKSTONE_BRICKS()); $result->registerBlock("cracked_stone_bricks", fn() => Blocks::CRACKED_STONE_BRICKS()); $result->registerBlock("crafting_table", fn() => Blocks::CRAFTING_TABLE()); - $result->registerBlock("creeper_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::CREEPER())); + $result->registerBlock("creeper_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::CREEPER)); $result->registerBlock("crimson_button", fn() => Blocks::CRIMSON_BUTTON()); $result->registerBlock("crimson_door", fn() => Blocks::CRIMSON_DOOR()); $result->registerBlock("crimson_fence", fn() => Blocks::CRIMSON_FENCE()); @@ -353,24 +354,24 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("diorite_slab", fn() => Blocks::DIORITE_SLAB()); $result->registerBlock("diorite_stairs", fn() => Blocks::DIORITE_STAIRS()); $result->registerBlock("diorite_wall", fn() => Blocks::DIORITE_WALL()); - $result->registerBlock("dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::NORMAL())); - $result->registerBlock("dirt_with_roots", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED())); + $result->registerBlock("dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::NORMAL)); + $result->registerBlock("dirt_with_roots", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED)); $result->registerBlock("door_block", fn() => Blocks::OAK_DOOR()); $result->registerBlock("double_plant", fn() => Blocks::SUNFLOWER()); - $result->registerBlock("double_red_sandstone_slab", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_slab", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_slabs", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_stone_slab", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_stone_slab2", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_stone_slab3", fn() => Blocks::END_STONE_BRICK_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_stone_slab4", fn() => Blocks::MOSSY_STONE_BRICK_SLAB()->setSlabType(SlabType::DOUBLE())); + $result->registerBlock("double_red_sandstone_slab", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_slab", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_slabs", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_stone_slab", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_stone_slab2", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_stone_slab3", fn() => Blocks::END_STONE_BRICK_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_stone_slab4", fn() => Blocks::MOSSY_STONE_BRICK_SLAB()->setSlabType(SlabType::DOUBLE)); $result->registerBlock("double_tallgrass", fn() => Blocks::DOUBLE_TALLGRASS()); - $result->registerBlock("double_wood_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_wood_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_wooden_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_wooden_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE())); + $result->registerBlock("double_wood_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_wood_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_wooden_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_wooden_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE)); $result->registerBlock("dragon_egg", fn() => Blocks::DRAGON_EGG()); - $result->registerBlock("dragon_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::DRAGON())); + $result->registerBlock("dragon_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::DRAGON)); $result->registerBlock("dried_kelp_block", fn() => Blocks::DRIED_KELP()); $result->registerBlock("dyed_shulker_box", fn() => Blocks::DYED_SHULKER_BOX()); $result->registerBlock("element_0", fn() => Blocks::ELEMENT_ZERO()); @@ -858,10 +859,10 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("peony", fn() => Blocks::PEONY()); $result->registerBlock("pink_petals", fn() => Blocks::PINK_PETALS()); $result->registerBlock("pink_tulip", fn() => Blocks::PINK_TULIP()); - $result->registerBlock("piglin_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::PIGLIN())); + $result->registerBlock("piglin_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::PIGLIN)); $result->registerBlock("plank", fn() => Blocks::OAK_PLANKS()); $result->registerBlock("planks", fn() => Blocks::OAK_PLANKS()); - $result->registerBlock("player_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::PLAYER())); + $result->registerBlock("player_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::PLAYER)); $result->registerBlock("podzol", fn() => Blocks::PODZOL()); $result->registerBlock("polished_andesite", fn() => Blocks::POLISHED_ANDESITE()); $result->registerBlock("polished_andesite_slab", fn() => Blocks::POLISHED_ANDESITE_SLAB()); @@ -950,7 +951,7 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("repeater", fn() => Blocks::REDSTONE_REPEATER()); $result->registerBlock("repeater_block", fn() => Blocks::REDSTONE_REPEATER()); $result->registerBlock("reserved6", fn() => Blocks::RESERVED6()); - $result->registerBlock("rooted_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED())); + $result->registerBlock("rooted_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED)); $result->registerBlock("rose", fn() => Blocks::POPPY()); $result->registerBlock("rose_bush", fn() => Blocks::ROSE_BUSH()); $result->registerBlock("sand", fn() => Blocks::SAND()); @@ -967,8 +968,8 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("shulker_box", fn() => Blocks::SHULKER_BOX()); $result->registerBlock("sign", fn() => Blocks::OAK_SIGN()); $result->registerBlock("sign_post", fn() => Blocks::OAK_SIGN()); - $result->registerBlock("skeleton_skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::SKELETON())); - $result->registerBlock("skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::SKELETON())); + $result->registerBlock("skeleton_skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::SKELETON)); + $result->registerBlock("skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::SKELETON)); $result->registerBlock("skull_block", fn() => Blocks::MOB_HEAD()); $result->registerBlock("slab", fn() => Blocks::SMOOTH_STONE_SLAB()); $result->registerBlock("slabs", fn() => Blocks::SMOOTH_STONE_SLAB()); @@ -1119,7 +1120,7 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("wheat_block", fn() => Blocks::WHEAT()); $result->registerBlock("white_tulip", fn() => Blocks::WHITE_TULIP()); $result->registerBlock("wither_rose", fn() => Blocks::WITHER_ROSE()); - $result->registerBlock("wither_skeleton_skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::WITHER_SKELETON())); + $result->registerBlock("wither_skeleton_skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::WITHER_SKELETON)); $result->registerBlock("wood", fn() => Blocks::OAK_LOG()->setStripped(false)); $result->registerBlock("wood2", fn() => Blocks::ACACIA_LOG()->setStripped(false)); $result->registerBlock("wood_door_block", fn() => Blocks::OAK_DOOR()); @@ -1139,7 +1140,7 @@ final class StringToItemParser extends StringToTParser{ $result->registerBlock("wool", fn() => Blocks::WOOL()); $result->registerBlock("workbench", fn() => Blocks::CRAFTING_TABLE()); $result->registerBlock("yellow_flower", fn() => Blocks::DANDELION()); - $result->registerBlock("zombie_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::ZOMBIE())); + $result->registerBlock("zombie_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::ZOMBIE)); } private static function registerDynamicItems(self $result) : void{ diff --git a/src/item/VanillaItems.php b/src/item/VanillaItems.php index a5d50c9db..d76452f97 100644 --- a/src/item/VanillaItems.php +++ b/src/item/VanillaItems.php @@ -36,9 +36,9 @@ use pocketmine\item\ItemIdentifier as IID; use pocketmine\item\ItemTypeIds as Ids; use pocketmine\item\VanillaArmorMaterials as ArmorMaterials; use pocketmine\math\Vector3; -use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\CloningRegistryTrait; use pocketmine\world\World; +use function strtolower; /** * This doc-block is generated automatically, do not modify it manually. @@ -546,17 +546,16 @@ final class VanillaItems{ self::register("writable_book", new WritableBook(new IID(Ids::WRITABLE_BOOK), "Book & Quill")); self::register("written_book", new WrittenBook(new IID(Ids::WRITTEN_BOOK), "Written Book")); - foreach(BoatType::getAll() as $type){ + foreach(BoatType::cases() as $type){ //boat type is static, because different types of wood may have different properties - self::register($type->name() . "_boat", new Boat(new IID(match($type){ - BoatType::OAK() => Ids::OAK_BOAT, - BoatType::SPRUCE() => Ids::SPRUCE_BOAT, - BoatType::BIRCH() => Ids::BIRCH_BOAT, - BoatType::JUNGLE() => Ids::JUNGLE_BOAT, - BoatType::ACACIA() => Ids::ACACIA_BOAT, - BoatType::DARK_OAK() => Ids::DARK_OAK_BOAT, - BoatType::MANGROVE() => Ids::MANGROVE_BOAT, - default => throw new AssumptionFailedError("Unhandled tree type " . $type->name()) + self::register(strtolower($type->name) . "_boat", new Boat(new IID(match($type){ + BoatType::OAK => Ids::OAK_BOAT, + BoatType::SPRUCE => Ids::SPRUCE_BOAT, + BoatType::BIRCH => Ids::BIRCH_BOAT, + BoatType::JUNGLE => Ids::JUNGLE_BOAT, + BoatType::ACACIA => Ids::ACACIA_BOAT, + BoatType::DARK_OAK => Ids::DARK_OAK_BOAT, + BoatType::MANGROVE => Ids::MANGROVE_BOAT, }), $type->getDisplayName() . " Boat", $type)); } } diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 5b65ca1b5..d0a4c000a 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -1069,7 +1069,7 @@ class NetworkSession{ $this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName()); return; } - if(!$status->equals(UsedChunkStatus::REQUESTED_SENDING())){ + if($status !== UsedChunkStatus::REQUESTED_SENDING){ //TODO: make this an error //this could be triggered due to the shitty way that chunk resends are handled //right now - not because of the spammy re-requesting, but because the chunk status reverts diff --git a/src/network/mcpe/cache/CraftingDataCache.php b/src/network/mcpe/cache/CraftingDataCache.php index aa70c7d35..0b18cd53d 100644 --- a/src/network/mcpe/cache/CraftingDataCache.php +++ b/src/network/mcpe/cache/CraftingDataCache.php @@ -81,12 +81,11 @@ final class CraftingDataCache{ foreach($manager->getCraftingRecipeIndex() as $index => $recipe){ if($recipe instanceof ShapelessRecipe){ - $typeTag = match($recipe->getType()->id()){ - ShapelessRecipeType::CRAFTING()->id() => CraftingRecipeBlockName::CRAFTING_TABLE, - ShapelessRecipeType::STONECUTTER()->id() => CraftingRecipeBlockName::STONECUTTER, - ShapelessRecipeType::CARTOGRAPHY()->id() => CraftingRecipeBlockName::CARTOGRAPHY_TABLE, - ShapelessRecipeType::SMITHING()->id() => CraftingRecipeBlockName::SMITHING_TABLE, - default => throw new AssumptionFailedError("Unreachable"), + $typeTag = match($recipe->getType()){ + ShapelessRecipeType::CRAFTING => CraftingRecipeBlockName::CRAFTING_TABLE, + ShapelessRecipeType::STONECUTTER => CraftingRecipeBlockName::STONECUTTER, + ShapelessRecipeType::CARTOGRAPHY => CraftingRecipeBlockName::CARTOGRAPHY_TABLE, + ShapelessRecipeType::SMITHING => CraftingRecipeBlockName::SMITHING_TABLE, }; $recipesWithTypeIds[] = new ProtocolShapelessRecipe( CraftingDataPacket::ENTRY_SHAPELESS, diff --git a/src/player/Player.php b/src/player/Player.php index 2059613ad..06d1c3103 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -331,7 +331,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $zSpawnChunk = $spawnLocation->getFloorZ() >> Chunk::COORD_BIT_SIZE; $world->registerChunkLoader($this->chunkLoader, $xSpawnChunk, $zSpawnChunk, true); $world->registerChunkListener($this, $xSpawnChunk, $zSpawnChunk); - $this->usedChunks[World::chunkHash($xSpawnChunk, $zSpawnChunk)] = UsedChunkStatus::NEEDED(); + $this->usedChunks[World::chunkHash($xSpawnChunk, $zSpawnChunk)] = UsedChunkStatus::NEEDED; parent::__construct($spawnLocation, $this->playerInfo->getSkin(), $namedtag); } @@ -768,7 +768,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ protected function spawnEntitiesOnAllChunks() : void{ foreach($this->usedChunks as $chunkHash => $status){ - if($status->equals(UsedChunkStatus::SENT())){ + if($status === UsedChunkStatus::SENT){ World::getXZ($chunkHash, $chunkX, $chunkZ); $this->spawnEntitiesOnChunk($chunkX, $chunkZ); } @@ -810,7 +810,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ ++$count; - $this->usedChunks[$index] = UsedChunkStatus::REQUESTED_GENERATION(); + $this->usedChunks[$index] = UsedChunkStatus::REQUESTED_GENERATION; $this->activeChunkGenerationRequests[$index] = true; unset($this->loadQueue[$index]); $this->getWorld()->registerChunkLoader($this->chunkLoader, $X, $Z, true); @@ -824,17 +824,17 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ if(!$this->isConnected() || !isset($this->usedChunks[$index]) || $world !== $this->getWorld()){ return; } - if(!$this->usedChunks[$index]->equals(UsedChunkStatus::REQUESTED_GENERATION())){ + if($this->usedChunks[$index] !== UsedChunkStatus::REQUESTED_GENERATION){ //We may have previously requested this, decided we didn't want it, and then decided we did want //it again, all before the generation request got executed. In that case, the promise would have //multiple callbacks for this player. In that case, only the first one matters. return; } unset($this->activeChunkGenerationRequests[$index]); - $this->usedChunks[$index] = UsedChunkStatus::REQUESTED_SENDING(); + $this->usedChunks[$index] = UsedChunkStatus::REQUESTED_SENDING; $this->getNetworkSession()->startUsingChunk($X, $Z, function() use ($X, $Z, $index) : void{ - $this->usedChunks[$index] = UsedChunkStatus::SENT(); + $this->usedChunks[$index] = UsedChunkStatus::SENT; if($this->spawnChunkLoadCount === -1){ $this->spawnEntitiesOnChunk($X, $Z); }elseif($this->spawnChunkLoadCount++ === $this->spawnThreshold){ @@ -951,7 +951,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $this->location->getFloorX() >> Chunk::COORD_BIT_SIZE, $this->location->getFloorZ() >> Chunk::COORD_BIT_SIZE ) as $radius => $hash){ - if(!isset($this->usedChunks[$hash]) || $this->usedChunks[$hash]->equals(UsedChunkStatus::NEEDED())){ + if(!isset($this->usedChunks[$hash]) || $this->usedChunks[$hash] === UsedChunkStatus::NEEDED){ $newOrder[$hash] = true; } if($radius < $tickingChunkRadius){ @@ -1005,7 +1005,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ */ public function hasReceivedChunk(int $chunkX, int $chunkZ) : bool{ $status = $this->usedChunks[World::chunkHash($chunkX, $chunkZ)] ?? null; - return $status !== null && $status->equals(UsedChunkStatus::SENT()); + return $status === UsedChunkStatus::SENT; } /** @@ -1612,7 +1612,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $returnedItems = []; $result = $item->onClickAir($this, $directionVector, $returnedItems); - if($result->equals(ItemUseResult::FAIL())){ + if($result === ItemUseResult::FAIL){ return false; } @@ -1672,7 +1672,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $returnedItems = []; $result = $item->onReleaseUsing($this, $returnedItems); - if($result->equals(ItemUseResult::SUCCESS())){ + if($result === ItemUseResult::SUCCESS){ $this->resetItemCooldown($item); $this->returnItemsFromAction($oldItem, $item, $returnedItems); return true; @@ -2694,8 +2694,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ public function onChunkChanged(int $chunkX, int $chunkZ, Chunk $chunk) : void{ $status = $this->usedChunks[$hash = World::chunkHash($chunkX, $chunkZ)] ?? null; - if($status !== null && $status->equals(UsedChunkStatus::SENT())){ - $this->usedChunks[$hash] = UsedChunkStatus::NEEDED(); + if($status === UsedChunkStatus::SENT){ + $this->usedChunks[$hash] = UsedChunkStatus::NEEDED; $this->nextChunkOrderRun = 0; } } diff --git a/src/player/UsedChunkStatus.php b/src/player/UsedChunkStatus.php index 69e249a24..dda41fe7e 100644 --- a/src/player/UsedChunkStatus.php +++ b/src/player/UsedChunkStatus.php @@ -23,28 +23,22 @@ declare(strict_types=1); namespace pocketmine\player; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static UsedChunkStatus NEEDED() * @method static UsedChunkStatus REQUESTED_GENERATION() * @method static UsedChunkStatus REQUESTED_SENDING() * @method static UsedChunkStatus SENT() */ -final class UsedChunkStatus{ - use EnumTrait; +enum UsedChunkStatus{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("NEEDED"), - new self("REQUESTED_GENERATION"), - new self("REQUESTED_SENDING"), - new self("SENT") - ); - } + case NEEDED; + case REQUESTED_GENERATION; + case REQUESTED_SENDING; + case SENT; } diff --git a/src/utils/EnumTrait.php b/src/utils/EnumTrait.php index ba0a4fcf2..ee1bd4e35 100644 --- a/src/utils/EnumTrait.php +++ b/src/utils/EnumTrait.php @@ -29,6 +29,9 @@ namespace pocketmine\utils; * * Classes using this trait need to include \@method tags in their class docblock for every enum member. * Alternatively, just put \@generate-registry-docblock in the docblock and run tools/generate-registry-annotations.php + * + * @deprecated Use native PHP 8.1 enums instead. Use {@link LegacyEnumShimTrait} if you need to provide backwards + * compatible EnumTrait-like API for migrated enums. */ trait EnumTrait{ use RegistryTrait; diff --git a/src/utils/LegacyEnumShimTrait.php b/src/utils/LegacyEnumShimTrait.php new file mode 100644 index 000000000..4bb3587ab --- /dev/null +++ b/src/utils/LegacyEnumShimTrait.php @@ -0,0 +1,92 @@ + 0){ + throw new \ArgumentCountError("Expected exactly 0 arguments, " . count($arguments) . " passed"); + } + return self::getAll()[mb_strtoupper($name)]; + } + + /** + * Returns a list of all cases, indexed by name. + * + * @return self[] + * @phpstan-return array + */ + public static function getAll() : array{ + /** @var array|null $result */ + static $result = null; + if($result === null){ + $result = []; + foreach(self::cases() as $case){ + $result[mb_strtoupper($case->name)] = $case; + } + } + return $result; + } + + /** + * Shim for {@link \UnitEnum::name}. + * + * @deprecated Use the native enum's name property instead. + */ + public function name() : string{ + return $this->name; + } + + /** + * Alias of spl_object_id($this). + * + * @deprecated + */ + public function id() : int{ + return spl_object_id($this); + } + + /** + * Returns whether the two objects are equivalent. + * + * @deprecated Native enums can be safely compared with ===. + */ + public function equals(self $other) : bool{ + return $this === $other; + } +} diff --git a/src/world/World.php b/src/world/World.php index 903cc60e2..2ff2b5b2e 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2127,8 +2127,8 @@ class World implements ChunkManager{ } $result = $item->onInteractBlock($player, $blockReplace, $blockClicked, $face, $clickVector, $returnedItems); - if(!$result->equals(ItemUseResult::NONE())){ - return $result->equals(ItemUseResult::SUCCESS()); + if($result !== ItemUseResult::NONE){ + return $result === ItemUseResult::SUCCESS; } }else{ return false; diff --git a/src/world/biome/BiomeRegistry.php b/src/world/biome/BiomeRegistry.php index 648184209..1af60fcd5 100644 --- a/src/world/biome/BiomeRegistry.php +++ b/src/world/biome/BiomeRegistry.php @@ -54,7 +54,7 @@ final class BiomeRegistry{ $this->register(BiomeIds::EXTREME_HILLS_EDGE, new SmallMountainsBiome()); - $this->register(BiomeIds::BIRCH_FOREST, new ForestBiome(TreeType::BIRCH())); + $this->register(BiomeIds::BIRCH_FOREST, new ForestBiome(TreeType::BIRCH)); } public function register(int $id, Biome $biome) : void{ diff --git a/src/world/biome/ForestBiome.php b/src/world/biome/ForestBiome.php index 8f80cb474..94d3e567c 100644 --- a/src/world/biome/ForestBiome.php +++ b/src/world/biome/ForestBiome.php @@ -33,7 +33,7 @@ class ForestBiome extends GrassyBiome{ public function __construct(?TreeType $type = null){ parent::__construct(); - $this->type = $type ?? TreeType::OAK(); + $this->type = $type ?? TreeType::OAK; $trees = new Tree($type); $trees->setBaseAmount(5); @@ -46,7 +46,7 @@ class ForestBiome extends GrassyBiome{ $this->setElevation(63, 81); - if($this->type->equals(TreeType::BIRCH())){ + if($this->type === TreeType::BIRCH){ $this->temperature = 0.6; $this->rainfall = 0.5; }else{ diff --git a/src/world/biome/TaigaBiome.php b/src/world/biome/TaigaBiome.php index cd68c9748..979ca66ec 100644 --- a/src/world/biome/TaigaBiome.php +++ b/src/world/biome/TaigaBiome.php @@ -32,7 +32,7 @@ class TaigaBiome extends SnowyBiome{ public function __construct(){ parent::__construct(); - $trees = new Tree(TreeType::SPRUCE()); + $trees = new Tree(TreeType::SPRUCE); $trees->setBaseAmount(10); $this->addPopulator($trees); diff --git a/src/world/generator/object/TreeFactory.php b/src/world/generator/object/TreeFactory.php index 1d95a77b1..d1f3dbebb 100644 --- a/src/world/generator/object/TreeFactory.php +++ b/src/world/generator/object/TreeFactory.php @@ -31,27 +31,13 @@ final class TreeFactory{ * @param TreeType|null $type default oak */ public static function get(Random $random, ?TreeType $type = null) : ?Tree{ - $type = $type ?? TreeType::OAK(); - if($type->equals(TreeType::SPRUCE())){ - return new SpruceTree(); - }elseif($type->equals(TreeType::BIRCH())){ - if($random->nextBoundedInt(39) === 0){ - return new BirchTree(true); - }else{ - return new BirchTree(); - } - }elseif($type->equals(TreeType::JUNGLE())){ - return new JungleTree(); - }elseif($type->equals(TreeType::OAK())){ //default - return new OakTree(); - /*if($random->nextRange(0, 9) === 0){ - $tree = new BigTree(); - }else{*/ - - //} - }elseif($type->equals(TreeType::ACACIA())){ - return new AcaciaTree(); - } - return null; + return match($type){ + null, TreeType::OAK => new OakTree(), //TODO: big oak has a 1/10 chance + TreeType::SPRUCE => new SpruceTree(), + TreeType::JUNGLE => new JungleTree(), + TreeType::ACACIA => new AcaciaTree(), + TreeType::BIRCH => new BirchTree($random->nextBoundedInt(39) === 0), + default => null, + }; } } diff --git a/src/world/generator/object/TreeType.php b/src/world/generator/object/TreeType.php index 1e8bf56e9..d4d62946a 100644 --- a/src/world/generator/object/TreeType.php +++ b/src/world/generator/object/TreeType.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\world\generator\object; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static TreeType ACACIA() * @method static TreeType BIRCH() @@ -38,34 +36,27 @@ use pocketmine\utils\EnumTrait; * @method static TreeType OAK() * @method static TreeType SPRUCE() */ -final class TreeType{ - use EnumTrait { - register as Enum_register; - __construct as Enum___construct; - } +enum TreeType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new TreeType("oak", "Oak"), - new TreeType("spruce", "Spruce"), - new TreeType("birch", "Birch"), - new TreeType("jungle", "Jungle"), - new TreeType("acacia", "Acacia"), - new TreeType("dark_oak", "Dark Oak"), - //TODO: cherry blossom, mangrove, azalea - //TODO: do crimson and warped "trees" belong here? I'm not sure if they're actually trees or just fungi - //TODO: perhaps huge mushrooms should be here too??? - ); - } - - private function __construct( - string $enumName, - private string $displayName - ){ - $this->Enum___construct($enumName); - } + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + //TODO: cherry blossom, mangrove, azalea + //TODO: do crimson and warped "trees" belong here? I'm not sure if they're actually trees or just fungi + //TODO: perhaps huge mushrooms should be here too??? public function getDisplayName() : string{ - return $this->displayName; + return match($this){ + self::OAK => "Oak", + self::SPRUCE => "Spruce", + self::BIRCH => "Birch", + self::JUNGLE => "Jungle", + self::ACACIA => "Acacia", + self::DARK_OAK => "Dark Oak", + }; } } diff --git a/src/world/generator/populator/Tree.php b/src/world/generator/populator/Tree.php index 3e5aef0a7..e470c46f0 100644 --- a/src/world/generator/populator/Tree.php +++ b/src/world/generator/populator/Tree.php @@ -40,7 +40,7 @@ class Tree implements Populator{ * @param TreeType|null $type default oak */ public function __construct(?TreeType $type = null){ - $this->type = $type ?? TreeType::OAK(); + $this->type = $type ?? TreeType::OAK; } public function setRandomAmount(int $amount) : void{ diff --git a/src/world/sound/NoteInstrument.php b/src/world/sound/NoteInstrument.php index 87e5d496d..a91d52cf7 100644 --- a/src/world/sound/NoteInstrument.php +++ b/src/world/sound/NoteInstrument.php @@ -23,13 +23,11 @@ declare(strict_types=1); namespace pocketmine\world\sound; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static NoteInstrument BANJO() * @method static NoteInstrument BASS_DRUM() @@ -48,27 +46,23 @@ use pocketmine\utils\EnumTrait; * @method static NoteInstrument SNARE() * @method static NoteInstrument XYLOPHONE() */ -final class NoteInstrument{ - use EnumTrait; +enum NoteInstrument{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("piano"), - new self("bass_drum"), - new self("snare"), - new self("clicks_and_sticks"), - new self("double_bass"), - new self("bell"), - new self("flute"), - new self("chime"), - new self("guitar"), - new self("xylophone"), - new self("iron_xylophone"), - new self("cow_bell"), - new self("didgeridoo"), - new self("bit"), - new self("banjo"), - new self("pling") - ); - } + case PIANO; + case BASS_DRUM; + case SNARE; + case CLICKS_AND_STICKS; + case DOUBLE_BASS; + case BELL; + case FLUTE; + case CHIME; + case GUITAR; + case XYLOPHONE; + case IRON_XYLOPHONE; + case COW_BELL; + case DIDGERIDOO; + case BIT; + case BANJO; + case PLING; }