From 6f6b23d4e46c07260f6970fe9d5e1064d81c74dc Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 29 Aug 2025 21:47:20 +0100 Subject: [PATCH] Integrate dev-major-next version of pocketmine/math this is a reduced version compared to the original, due to the difficulty of getting rid of Facing values internally. --- composer.json | 2 +- composer.lock | 35 +++-- src/block/AmethystCluster.php | 10 +- src/block/Anvil.php | 8 +- src/block/Bamboo.php | 6 +- src/block/BambooSapling.php | 2 +- src/block/Barrel.php | 6 +- src/block/BaseBanner.php | 7 +- src/block/BaseBigDripleaf.php | 6 +- src/block/BaseCake.php | 4 +- src/block/BaseCoral.php | 3 +- src/block/BaseOminousBanner.php | 7 +- src/block/BaseRail.php | 30 +++-- src/block/BaseSign.php | 9 +- src/block/Bed.php | 10 +- src/block/Bell.php | 24 ++-- src/block/BigDripleafHead.php | 8 +- src/block/Block.php | 27 ++-- src/block/BrewingStand.php | 12 +- src/block/Button.php | 8 +- src/block/Cactus.php | 4 +- src/block/Cake.php | 8 +- src/block/CakeWithCandle.php | 6 +- src/block/Campfire.php | 8 +- src/block/Candle.php | 32 ++--- src/block/Carpet.php | 2 +- src/block/CartographyTable.php | 3 +- src/block/Cauldron.php | 8 +- src/block/CaveVines.php | 6 +- src/block/CeilingCenterHangingSign.php | 4 +- src/block/CeilingEdgesHangingSign.php | 4 +- src/block/Chain.php | 4 +- src/block/ChemistryTable.php | 3 +- src/block/Chest.php | 6 +- src/block/ChiseledBookshelf.php | 2 +- src/block/ChorusFlower.php | 10 +- src/block/ChorusPlant.php | 8 +- src/block/CocoaBlock.php | 14 +- src/block/CopperDoor.php | 2 +- src/block/CopperTrapdoor.php | 3 +- src/block/CraftingTable.php | 3 +- src/block/Crops.php | 2 +- src/block/DaylightSensor.php | 6 +- src/block/Dirt.php | 2 +- src/block/Door.php | 8 +- src/block/DoublePitcherCrop.php | 10 +- src/block/DoublePlant.php | 2 +- src/block/DragonEgg.php | 7 +- src/block/EnchantingTable.php | 6 +- src/block/EndPortalFrame.php | 2 +- src/block/EndRod.php | 4 +- src/block/EnderChest.php | 6 +- src/block/Farmland.php | 2 +- src/block/Fence.php | 34 ++--- src/block/FenceGate.php | 8 +- src/block/FillableCauldron.php | 6 +- src/block/FloorBanner.php | 4 +- src/block/FloorCoralFan.php | 8 +- src/block/FloorSign.php | 4 +- src/block/Flowable.php | 5 +- src/block/FlowerPot.php | 4 +- src/block/Furnace.php | 3 +- src/block/GlowLichen.php | 20 +-- src/block/Grass.php | 2 +- src/block/GrassPath.php | 2 +- src/block/Hopper.php | 16 +-- src/block/ItemFrame.php | 10 +- src/block/Jukebox.php | 3 +- src/block/Ladder.php | 8 +- src/block/Lantern.php | 14 +- src/block/LavaCauldron.php | 3 +- src/block/Leaves.php | 4 +- src/block/Lectern.php | 8 +- src/block/Lever.php | 8 +- src/block/Light.php | 5 +- src/block/LightningRod.php | 4 +- src/block/Liquid.php | 6 +- src/block/Loom.php | 3 +- src/block/MobHead.php | 16 +-- src/block/MonsterSpawner.php | 3 +- src/block/NetherPortal.php | 9 +- src/block/NetherVines.php | 10 +- src/block/OminousFloorBanner.php | 4 +- src/block/OminousWallBanner.php | 4 +- src/block/PinkPetals.php | 6 +- src/block/PitcherCrop.php | 10 +- src/block/PotionCauldron.php | 3 +- src/block/PressurePlate.php | 10 +- src/block/Pumpkin.php | 2 +- src/block/Rail.php | 4 +- src/block/RedMushroom.php | 2 +- src/block/RedstoneComparator.php | 6 +- src/block/RedstoneOre.php | 3 +- src/block/RedstoneRepeater.php | 6 +- src/block/ResinClump.php | 5 +- src/block/RespawnAnchor.php | 3 +- src/block/Sapling.php | 2 +- src/block/SeaPickle.php | 9 +- src/block/ShulkerBox.php | 7 +- src/block/Slab.php | 8 +- src/block/SmallDripleaf.php | 6 +- src/block/SmithingTable.php | 3 +- src/block/SnowLayer.php | 6 +- src/block/SoulSand.php | 2 +- src/block/Stair.php | 20 +-- src/block/Stem.php | 6 +- src/block/Stonecutter.php | 6 +- src/block/Sugarcane.php | 4 +- src/block/SweetBerryBush.php | 2 +- src/block/TNT.php | 3 +- src/block/Thin.php | 32 ++--- src/block/Torch.php | 10 +- src/block/TorchflowerCrop.php | 2 +- src/block/Trapdoor.php | 8 +- src/block/TripwireHook.php | 2 +- src/block/Vine.php | 29 ++-- src/block/Wall.php | 40 +++--- src/block/WallBanner.php | 4 +- src/block/WallCoralFan.php | 4 +- src/block/WallHangingSign.php | 8 +- src/block/WallSign.php | 4 +- src/block/WaterCauldron.php | 3 +- src/block/WaterLily.php | 4 +- src/block/Wood.php | 3 +- src/block/tile/Bell.php | 18 ++- src/block/tile/ShulkerBox.php | 16 ++- src/block/utils/AnyFacing.php | 10 +- src/block/utils/AnyFacingTrait.php | 9 +- src/block/utils/CandleTrait.php | 4 +- src/block/utils/CopperTrait.php | 4 +- .../utils/FacesOppositePlacingPlayerTrait.php | 2 +- src/block/utils/HorizontalFacing.php | 14 +- src/block/utils/HorizontalFacingTrait.php | 7 +- src/block/utils/LeverFacing.php | 2 +- src/block/utils/MinimumCostFlowCalculator.php | 15 ++- src/block/utils/MultiAnyFacing.php | 21 +-- src/block/utils/MultiAnyFacingTrait.php | 20 ++- src/block/utils/MultiAnySupportTrait.php | 15 ++- src/block/utils/PillarRotation.php | 11 +- src/block/utils/PillarRotationTrait.php | 10 +- src/block/utils/RailConnectionInfo.php | 40 +++--- src/block/utils/StaticSupportTrait.php | 3 +- .../block/convert/VanillaBlockMappings.php | 29 ++-- .../convert/property/CommonProperties.php | 52 ++++---- .../block/convert/property/ValueMappings.php | 125 +++++++++--------- src/data/runtime/RuntimeDataDescriber.php | 17 +-- src/data/runtime/RuntimeDataReader.php | 43 ++---- .../runtime/RuntimeDataSizeCalculator.php | 19 +-- src/data/runtime/RuntimeDataWriter.php | 56 +++----- src/entity/Entity.php | 29 ++-- src/entity/Living.php | 2 +- src/entity/Location.php | 2 +- src/entity/object/Painting.php | 38 +++--- src/entity/projectile/IceBomb.php | 2 +- src/entity/projectile/Projectile.php | 2 +- src/event/player/PlayerBucketEvent.php | 5 +- src/event/player/PlayerInteractEvent.php | 5 +- src/item/Bamboo.php | 3 +- src/item/BeetrootSeeds.php | 3 +- src/item/Bucket.php | 3 +- src/item/Carrot.php | 3 +- src/item/CocoaBeans.php | 3 +- src/item/CoralFan.php | 2 +- src/item/EndCrystal.php | 6 +- src/item/FireCharge.php | 3 +- src/item/FlintSteel.php | 3 +- src/item/GlassBottle.php | 3 +- src/item/GlowBerries.php | 3 +- src/item/HangingSign.php | 4 +- src/item/Item.php | 9 +- src/item/ItemBlock.php | 3 +- src/item/ItemBlockWallOrFloor.php | 2 +- src/item/LiquidBucket.php | 3 +- src/item/MelonSeeds.php | 3 +- src/item/PaintingItem.php | 2 +- src/item/PitcherPod.php | 3 +- src/item/Potato.php | 3 +- src/item/PumpkinSeeds.php | 3 +- src/item/Redstone.php | 3 +- src/item/SpawnEgg.php | 3 +- src/item/StringItem.php | 3 +- src/item/SweetBerries.php | 3 +- src/item/TorchflowerSeeds.php | 3 +- src/item/WheatSeeds.php | 3 +- .../mcpe/handler/InGamePacketHandler.php | 25 ++-- src/player/Player.php | 20 ++- src/player/SurvivalBlockBreakHandler.php | 7 +- src/world/Position.php | 9 +- src/world/World.php | 8 +- src/world/generator/object/AcaciaTree.php | 2 +- src/world/light/LightPropagationContext.php | 4 +- src/world/light/LightUpdate.php | 5 +- src/world/particle/BlockPunchParticle.php | 9 +- tests/phpstan/configs/actual-problems.neon | 2 +- 194 files changed, 909 insertions(+), 873 deletions(-) diff --git a/composer.json b/composer.json index ff7f6c81e..67c4f16a4 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "pocketmine/errorhandler": "^0.7.0", "pocketmine/locale-data": "~2.25.0", "pocketmine/log": "^0.4.0", - "pocketmine/math": "~1.0.0", + "pocketmine/math": "dev-major-next as 1.0.0", "pocketmine/nbt": "~1.1.0", "pocketmine/raklib": "~1.2.0", "pocketmine/raklib-ipc": "~1.0.0", diff --git a/composer.lock b/composer.lock index d3d57ea4a..c95c2ce8b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6aac4fb3990be02fdbbe03c8dd33a6fa", + "content-hash": "1c81eefad19096d505bd201ff6546367", "packages": [ { "name": "adhocore/json-comment", @@ -535,27 +535,27 @@ }, { "name": "pocketmine/math", - "version": "1.0.0", + "version": "dev-major-next", "source": { "type": "git", "url": "https://github.com/pmmp/Math.git", - "reference": "dc132d93595b32e9f210d78b3c8d43c662a5edbf" + "reference": "7513b9504e4a9d3ebde2f9d4de50266cb1dafd23" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/Math/zipball/dc132d93595b32e9f210d78b3c8d43c662a5edbf", - "reference": "dc132d93595b32e9f210d78b3c8d43c662a5edbf", + "url": "https://api.github.com/repos/pmmp/Math/zipball/7513b9504e4a9d3ebde2f9d4de50266cb1dafd23", + "reference": "7513b9504e4a9d3ebde2f9d4de50266cb1dafd23", "shasum": "" }, "require": { - "php": "^8.0", + "php": "^8.2", "php-64bit": "*" }, "require-dev": { "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "~1.10.3", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^8.5 || ^9.5" + "phpstan/phpstan": "2.1.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^10.0 || ^11.0" }, "type": "library", "autoload": { @@ -570,9 +570,9 @@ "description": "PHP library containing math related code used in PocketMine-MP", "support": { "issues": "https://github.com/pmmp/Math/issues", - "source": "https://github.com/pmmp/Math/tree/1.0.0" + "source": "https://github.com/pmmp/Math/tree/major-next" }, - "time": "2023-08-03T12:56:33+00:00" + "time": "2025-08-29T18:29:53+00:00" }, { "name": "pocketmine/nbt", @@ -2724,9 +2724,18 @@ "time": "2024-03-03T12:36:25+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "pocketmine/math", + "version": "dev-major-next", + "alias": "1.0.0", + "alias_normalized": "1.0.0.0" + } + ], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": { + "pocketmine/math": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/block/AmethystCluster.php b/src/block/AmethystCluster.php index 8a750e974..d939994a2 100644 --- a/src/block/AmethystCluster.php +++ b/src/block/AmethystCluster.php @@ -82,22 +82,22 @@ final class AmethystCluster extends Transparent implements AnyFacing{ if($axis === $myAxis){ continue; } - $box->squash($axis, $this->stage === self::STAGE_SMALL_BUD ? 4 / 16 : 3 / 16); + $box = $box->squashedCopy($axis, $this->stage === self::STAGE_SMALL_BUD ? 4 / 16 : 3 / 16); } - $box->trim($this->facing, 1 - ($this->stage === self::STAGE_CLUSTER ? 7 / 16 : ($this->stage + 3) / 16)); + $box = $box->trimmedCopy($this->facing, 1 - ($this->stage === self::STAGE_CLUSTER ? 7 / 16 : ($this->stage + 3) / 16)); return [$box]; } - private function canBeSupportedAt(Block $block, int $facing) : bool{ + private function canBeSupportedAt(Block $block, Facing $facing) : bool{ return $block->getAdjacentSupportType($facing) === SupportType::FULL; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){ return false; } diff --git a/src/block/Anvil.php b/src/block/Anvil.php index fcb4d045c..1d08e53ae 100644 --- a/src/block/Anvil.php +++ b/src/block/Anvil.php @@ -72,14 +72,14 @@ class Anvil extends Transparent implements Fallable, HorizontalFacing{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->squash(Facing::axis(Facing::rotateY($this->facing, false)), 1 / 8)]; + return [AxisAlignedBB::one()->squashedCopy(Facing::axis(Facing::rotateY($this->facing, false)), 1 / 8)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $player->setCurrentWindow(new AnvilInventory($this->position)); } @@ -87,7 +87,7 @@ class Anvil extends Transparent implements Fallable, HorizontalFacing{ return true; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->facing = Facing::rotateY($player->getHorizontalFacing(), false); } diff --git a/src/block/Bamboo.php b/src/block/Bamboo.php index fd64e10ef..015db6a18 100644 --- a/src/block/Bamboo.php +++ b/src/block/Bamboo.php @@ -90,10 +90,10 @@ class Bamboo extends Transparent{ protected function recalculateCollisionBoxes() : array{ //this places the BB at the northwest corner, not the center $inset = 1 - (($this->thick ? 3 : 2) / 16); - return [AxisAlignedBB::one()->trim(Facing::SOUTH, $inset)->trim(Facing::EAST, $inset)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::SOUTH, $inset)->trimmedCopy(Facing::EAST, $inset)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -138,7 +138,7 @@ class Bamboo extends Transparent{ return $top; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer){ $top = $this->seekToTop(); if($top->grow(self::getMaxHeight($top->position->getFloorX(), $top->position->getFloorZ()), mt_rand(1, 2), $player)){ diff --git a/src/block/BambooSapling.php b/src/block/BambooSapling.php index 67c8a24e0..ddcde9981 100644 --- a/src/block/BambooSapling.php +++ b/src/block/BambooSapling.php @@ -61,7 +61,7 @@ final class BambooSapling extends Flowable{ $supportBlock->hasTypeTag(BlockTypeTags::SAND); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer || $item instanceof ItemBamboo){ if($this->grow($player)){ $item->pop(); diff --git a/src/block/Barrel.php b/src/block/Barrel.php index 7b2ea356e..68f584f10 100644 --- a/src/block/Barrel.php +++ b/src/block/Barrel.php @@ -40,7 +40,7 @@ class Barrel extends Opaque implements AnyFacing{ protected bool $open = false; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->facing($this->facing); + $w->enum($this->facing); $w->bool($this->open); } @@ -54,7 +54,7 @@ class Barrel extends Opaque implements AnyFacing{ return $this; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ if(abs($player->getPosition()->x - $this->position->x) < 2 && abs($player->getPosition()->z - $this->position->z) < 2){ $y = $player->getEyePos()->y; @@ -74,7 +74,7 @@ class Barrel extends Opaque implements AnyFacing{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $barrel = $this->position->getWorld()->getTile($this->position); if($barrel instanceof TileBarrel){ diff --git a/src/block/BaseBanner.php b/src/block/BaseBanner.php index e8bf187ee..dcdc36c60 100644 --- a/src/block/BaseBanner.php +++ b/src/block/BaseBanner.php @@ -31,6 +31,7 @@ use pocketmine\block\utils\SupportType; use pocketmine\item\Banner as ItemBanner; use pocketmine\item\Item; use pocketmine\item\VanillaItems; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\BlockTransaction; @@ -112,7 +113,7 @@ abstract class BaseBanner extends Transparent implements Colored{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -120,7 +121,7 @@ abstract class BaseBanner extends Transparent implements Colored{ return $block->isSolid(); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->canBeSupportedBy($blockReplace->getSide($this->getSupportingFace()))){ return false; } @@ -132,7 +133,7 @@ abstract class BaseBanner extends Transparent implements Colored{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - abstract protected function getSupportingFace() : int; + abstract protected function getSupportingFace() : Facing; public function onNearbyBlockChange() : void{ if(!$this->canBeSupportedBy($this->getSide($this->getSupportingFace()))){ diff --git a/src/block/BaseBigDripleaf.php b/src/block/BaseBigDripleaf.php index 94e2c12a2..452184d74 100644 --- a/src/block/BaseBigDripleaf.php +++ b/src/block/BaseBigDripleaf.php @@ -57,7 +57,7 @@ abstract class BaseBigDripleaf extends Transparent implements HorizontalFacing{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $block = $blockReplace->getSide(Facing::DOWN); if(!$this->canBeSupportedBy($block, true)){ return false; @@ -72,7 +72,7 @@ abstract class BaseBigDripleaf extends Transparent implements HorizontalFacing{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer && $this->grow($player)){ $item->pop(); return true; @@ -131,7 +131,7 @@ abstract class BaseBigDripleaf extends Transparent implements HorizontalFacing{ return 100; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/BaseCake.php b/src/block/BaseCake.php index 4b3903840..47a5f60f9 100644 --- a/src/block/BaseCake.php +++ b/src/block/BaseCake.php @@ -36,7 +36,7 @@ use pocketmine\player\Player; abstract class BaseCake extends Transparent implements FoodSource{ use StaticSupportTrait; - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -44,7 +44,7 @@ abstract class BaseCake extends Transparent implements FoodSource{ return $block->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::AIR; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player !== null){ return $player->consumeObject($this); } diff --git a/src/block/BaseCoral.php b/src/block/BaseCoral.php index c1cc9bb25..936d068ed 100644 --- a/src/block/BaseCoral.php +++ b/src/block/BaseCoral.php @@ -28,6 +28,7 @@ use pocketmine\block\utils\CoralMaterial; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\utils\SupportType; use pocketmine\item\Item; +use pocketmine\math\Facing; use function mt_rand; abstract class BaseCoral extends Transparent implements CoralMaterial{ @@ -72,7 +73,7 @@ abstract class BaseCoral extends Transparent implements CoralMaterial{ protected function recalculateCollisionBoxes() : array{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/BaseOminousBanner.php b/src/block/BaseOminousBanner.php index 192e6fac2..a16e133a7 100644 --- a/src/block/BaseOminousBanner.php +++ b/src/block/BaseOminousBanner.php @@ -28,6 +28,7 @@ use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\SupportType; use pocketmine\item\Item; use pocketmine\item\VanillaItems; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\BlockTransaction; @@ -60,7 +61,7 @@ abstract class BaseOminousBanner extends Transparent{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -68,7 +69,7 @@ abstract class BaseOminousBanner extends Transparent{ return $block->isSolid(); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->canBeSupportedBy($blockReplace->getSide($this->getSupportingFace()))){ return false; } @@ -76,7 +77,7 @@ abstract class BaseOminousBanner extends Transparent{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - abstract protected function getSupportingFace() : int; + abstract protected function getSupportingFace() : Facing; public function onNearbyBlockChange() : void{ if(!$this->canBeSupportedBy($this->getSide($this->getSupportingFace()))){ diff --git a/src/block/BaseRail.php b/src/block/BaseRail.php index 0bcb2f340..15b7d2bec 100644 --- a/src/block/BaseRail.php +++ b/src/block/BaseRail.php @@ -37,7 +37,7 @@ use function in_array; abstract class BaseRail extends Flowable{ - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($blockReplace->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport()){ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -89,8 +89,9 @@ abstract class BaseRail extends Flowable{ /** @var int $connection */ foreach($this->getCurrentShapeConnections() as $connection){ - $other = $this->getSide($connection & ~RailConnectionInfo::FLAG_ASCEND); - $otherConnection = Facing::opposite($connection & ~RailConnectionInfo::FLAG_ASCEND); + $connectionFace = Facing::from($connection & ~RailConnectionInfo::FLAG_ASCEND); + $other = $this->getSide($connectionFace); + $otherConnection = Facing::opposite($connectionFace)->value; if(($connection & RailConnectionInfo::FLAG_ASCEND) !== 0){ $other = $other->getSide(Facing::UP); @@ -122,10 +123,10 @@ abstract class BaseRail extends Flowable{ case 0: //No constraints, can connect in any direction $possible = [ - Facing::NORTH => true, - Facing::SOUTH => true, - Facing::WEST => true, - Facing::EAST => true + Facing::NORTH->value => true, + Facing::SOUTH->value => true, + Facing::WEST->value => true, + Facing::EAST->value => true ]; foreach($possible as $p => $_){ $possible[$p | RailConnectionInfo::FLAG_ASCEND] = true; @@ -146,13 +147,13 @@ abstract class BaseRail extends Flowable{ * @phpstan-return array */ protected function getPossibleConnectionDirectionsOneConstraint(int $constraint) : array{ - $opposite = Facing::opposite($constraint & ~RailConnectionInfo::FLAG_ASCEND); + $opposite = Facing::opposite(Facing::from($constraint & ~RailConnectionInfo::FLAG_ASCEND)); - $possible = [$opposite => true]; + $possible = [$opposite->value => true]; if(($constraint & RailConnectionInfo::FLAG_ASCEND) === 0){ //We can slope the other way if this connection isn't already a slope - $possible[$opposite | RailConnectionInfo::FLAG_ASCEND] = true; + $possible[$opposite->value | RailConnectionInfo::FLAG_ASCEND] = true; } return $possible; @@ -168,9 +169,10 @@ abstract class BaseRail extends Flowable{ $continue = false; foreach($possible as $thisSide => $_){ - $otherSide = Facing::opposite($thisSide & ~RailConnectionInfo::FLAG_ASCEND); + $thisSideEnum = Facing::from($thisSide & ~RailConnectionInfo::FLAG_ASCEND); + $otherSide = Facing::opposite($thisSideEnum)->value; - $other = $this->getSide($thisSide & ~RailConnectionInfo::FLAG_ASCEND); + $other = $this->getSide($thisSideEnum); if(($thisSide & RailConnectionInfo::FLAG_ASCEND) !== 0){ $other = $other->getSide(Facing::UP); @@ -212,7 +214,7 @@ abstract class BaseRail extends Flowable{ */ private function setConnections(array $connections) : void{ if(count($connections) === 1){ - $connections[] = Facing::opposite($connections[0] & ~RailConnectionInfo::FLAG_ASCEND); + $connections[] = Facing::opposite(Facing::from($connections[0] & ~RailConnectionInfo::FLAG_ASCEND))->value; }elseif(count($connections) !== 2){ throw new \InvalidArgumentException("Expected exactly 2 connections, got " . count($connections)); } @@ -226,7 +228,7 @@ abstract class BaseRail extends Flowable{ $world->useBreakOn($this->position); }else{ foreach($this->getCurrentShapeConnections() as $connection){ - if(($connection & RailConnectionInfo::FLAG_ASCEND) !== 0 && !$this->getSide($connection & ~RailConnectionInfo::FLAG_ASCEND)->getSupportType(Facing::UP)->hasEdgeSupport()){ + if(($connection & RailConnectionInfo::FLAG_ASCEND) !== 0 && !$this->getSide(Facing::from($connection & ~RailConnectionInfo::FLAG_ASCEND))->getSupportType(Facing::UP)->hasEdgeSupport()){ $world->useBreakOn($this->position); break; } diff --git a/src/block/BaseSign.php b/src/block/BaseSign.php index 0efaa603c..f631ff60a 100644 --- a/src/block/BaseSign.php +++ b/src/block/BaseSign.php @@ -35,6 +35,7 @@ use pocketmine\event\block\SignChangeEvent; use pocketmine\item\Dye; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\utils\TextFormat; @@ -99,11 +100,11 @@ abstract class BaseSign extends Transparent implements WoodMaterial{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - abstract protected function getSupportingFace() : int; + abstract protected function getSupportingFace() : Facing; public function onNearbyBlockChange() : void{ if($this->getSide($this->getSupportingFace())->getTypeId() === BlockTypeIds::AIR){ @@ -111,7 +112,7 @@ abstract class BaseSign extends Transparent implements WoodMaterial{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->editorEntityRuntimeId = $player->getId(); } @@ -160,7 +161,7 @@ abstract class BaseSign extends Transparent implements WoodMaterial{ return true; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player === null){ return false; } diff --git a/src/block/Bed.php b/src/block/Bed.php index 21bd3a172..84589664a 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -79,10 +79,10 @@ class Bed extends Transparent implements Colored, HorizontalFacing{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 7 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 7 / 16)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -106,7 +106,7 @@ class Bed extends Transparent implements Colored, HorizontalFacing{ return $this; } - private function getOtherHalfSide() : int{ + private function getOtherHalfSide() : Facing{ return $this->head ? Facing::opposite($this->facing) : $this->facing; } @@ -119,7 +119,7 @@ class Bed extends Transparent implements Colored, HorizontalFacing{ return null; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player !== null){ $other = $this->getOtherHalf(); $playerPos = $player->getPosition(); @@ -172,7 +172,7 @@ class Bed extends Transparent implements Colored, HorizontalFacing{ return $entity->getMotion()->y * -3 / 4; // 2/3 in Java, according to the wiki } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($this->canBeSupportedAt($blockReplace)){ $this->facing = $player !== null ? $player->getHorizontalFacing() : Facing::NORTH; diff --git a/src/block/Bell.php b/src/block/Bell.php index 258abc628..cf93f4501 100644 --- a/src/block/Bell.php +++ b/src/block/Bell.php @@ -52,26 +52,26 @@ final class Bell extends Transparent implements HorizontalFacing{ protected function recalculateCollisionBoxes() : array{ if($this->attachmentType === BellAttachmentType::FLOOR){ return [ - AxisAlignedBB::one()->squash(Facing::axis($this->facing), 1 / 4)->trim(Facing::UP, 3 / 16) + AxisAlignedBB::one()->squashedCopy(Facing::axis($this->facing), 1 / 4)->trimmedCopy(Facing::UP, 3 / 16) ]; } if($this->attachmentType === BellAttachmentType::CEILING){ return [ - AxisAlignedBB::one()->contract(1 / 4, 0, 1 / 4)->trim(Facing::DOWN, 1 / 4) + AxisAlignedBB::one()->contractedCopy(1 / 4, 0, 1 / 4)->trimmedCopy(Facing::DOWN, 1 / 4) ]; } $box = AxisAlignedBB::one() - ->squash(Facing::axis(Facing::rotateY($this->facing, true)), 1 / 4) - ->trim(Facing::UP, 1 / 16) - ->trim(Facing::DOWN, 1 / 4); + ->squashedCopy(Facing::axis(Facing::rotateY($this->facing, true)), 1 / 4) + ->trimmedCopy(Facing::UP, 1 / 16) + ->trimmedCopy(Facing::DOWN, 1 / 4); return [ - $this->attachmentType === BellAttachmentType::ONE_WALL ? $box->trim($this->facing, 3 / 16) : $box + $this->attachmentType === BellAttachmentType::ONE_WALL ? $box->trimmedCopy($this->facing, 3 / 16) : $box ]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -83,11 +83,11 @@ final class Bell extends Transparent implements HorizontalFacing{ return $this; } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ 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{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){ return false; } @@ -123,7 +123,7 @@ final class Bell extends Transparent implements HorizontalFacing{ } } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player !== null){ $faceHit = Facing::opposite($player->getHorizontalFacing()); if($this->isValidFaceToRing($faceHit)){ @@ -142,7 +142,7 @@ final class Bell extends Transparent implements HorizontalFacing{ } } - public function ring(int $faceHit) : void{ + public function ring(Facing $faceHit) : void{ $world = $this->position->getWorld(); $world->addSound($this->position, new BellRingSound()); $tile = $world->getTile($this->position); @@ -155,7 +155,7 @@ final class Bell extends Transparent implements HorizontalFacing{ return [$this->asItem()]; } - private function isValidFaceToRing(int $faceHit) : bool{ + private function isValidFaceToRing(Facing $faceHit) : bool{ return match($this->attachmentType){ BellAttachmentType::CEILING => true, BellAttachmentType::FLOOR => Facing::axis($faceHit) === Facing::axis($this->facing), diff --git a/src/block/BigDripleafHead.php b/src/block/BigDripleafHead.php index a9b87bf7f..1244aff1c 100644 --- a/src/block/BigDripleafHead.php +++ b/src/block/BigDripleafHead.php @@ -80,8 +80,8 @@ class BigDripleafHead extends BaseBigDripleaf{ 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()); + ->offsetCopy($this->position->x, $this->position->y, $this->position->z) + ->trimmedCopy(Facing::DOWN, 1 - $this->getLeafTopOffset()); if($entity->getBoundingBox()->intersectsWith($intersection)){ $this->setTiltAndScheduleTick(DripleafState::UNSTABLE); return false; @@ -116,8 +116,8 @@ class BigDripleafHead extends BaseBigDripleaf{ if($this->leafState !== DripleafState::FULL_TILT){ return [ AxisAlignedBB::one() - ->trim(Facing::DOWN, 11 / 16) - ->trim(Facing::UP, $this->getLeafTopOffset()) + ->trimmedCopy(Facing::DOWN, 11 / 16) + ->trimmedCopy(Facing::UP, $this->getLeafTopOffset()) ]; } return []; diff --git a/src/block/Block.php b/src/block/Block.php index 36e08fc0b..7dd4723b0 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -424,7 +424,7 @@ class Block{ * Returns whether this block can replace the given block in the given placement conditions. * This is used to allow slabs of the same type to combine into double slabs. */ - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ return $blockReplace->canBeReplaced(); } @@ -436,13 +436,13 @@ class Block{ * @param Item $item Item used to place the block * @param Block $blockReplace Block expected to be replaced * @param Block $blockClicked Block that was clicked using the item - * @param int $face Face of the clicked block which was clicked + * @param Facing $face Face of the clicked block which was clicked * @param Vector3 $clickVector Exact position inside the clicked block where the click occurred, relative to the block's position * @param Player|null $player Player who placed the block, or null if it was not a player * * @return bool whether the placement should go ahead */ - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $tx->addBlock($blockReplace->position, $this); return true; } @@ -524,7 +524,7 @@ class Block{ * @param Vector3 $clickVector Exact position where the click occurred, relative to the block's integer position * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if the inventory is full) */ - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ return false; } @@ -533,7 +533,7 @@ class Block{ * * @return bool if an action took place, prevents starting to break the block if true. */ - public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ + public function onAttack(Item $item, Facing $face, ?Player $player = null) : bool{ return false; } @@ -770,10 +770,10 @@ class Block{ * * @return Block */ - public function getSide(int $side, int $step = 1){ + public function getSide(Facing $side, int $step = 1){ $position = $this->position; if($position->isValid()){ - [$dx, $dy, $dz] = Facing::OFFSET[$side] ?? [0, 0, 0]; + [$dx, $dy, $dz] = Facing::OFFSET[$side->value] ?? [0, 0, 0]; return $position->getWorld()->getBlockAt( $position->x + ($dx * $step), $position->y + ($dy * $step), @@ -793,7 +793,7 @@ class Block{ public function getHorizontalSides() : \Generator{ $world = $this->position->getWorld(); foreach(Facing::HORIZONTAL as $facing){ - [$dx, $dy, $dz] = Facing::OFFSET[$facing]; + [$dx, $dy, $dz] = Facing::OFFSET[$facing->value]; //TODO: yield Facing as the key? yield $world->getBlockAt( $this->position->x + $dx, @@ -914,11 +914,12 @@ class Block{ */ final public function getCollisionBoxes() : array{ if($this->collisionBoxes === null){ - $this->collisionBoxes = $this->recalculateCollisionBoxes(); + $collisionBoxes = $this->recalculateCollisionBoxes(); $extraOffset = $this->getModelPositionOffset(); $offset = $extraOffset !== null ? $this->position->addVector($extraOffset) : $this->position; - foreach($this->collisionBoxes as $bb){ - $bb->offset($offset->x, $offset->y, $offset->z); + $this->collisionBoxes = []; + foreach($collisionBoxes as $bb){ + $this->collisionBoxes[] = $bb->offsetCopy($offset->x, $offset->y, $offset->z); } } @@ -945,11 +946,11 @@ class Block{ * Returns the type of support that the block can provide on the given face. This is used to determine whether * blocks placed on the given face can be supported by this block. */ - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::FULL; } - protected function getAdjacentSupportType(int $facing) : SupportType{ + protected function getAdjacentSupportType(Facing $facing) : SupportType{ return $this->getSide($facing)->getSupportType(Facing::opposite($facing)); } diff --git a/src/block/BrewingStand.php b/src/block/BrewingStand.php index 039693164..2248f702b 100644 --- a/src/block/BrewingStand.php +++ b/src/block/BrewingStand.php @@ -51,17 +51,17 @@ class BrewingStand extends Transparent{ protected function recalculateCollisionBoxes() : array{ return [ //bottom slab part - in PC this is also inset on X/Z by 1/16, but Bedrock sucks - AxisAlignedBB::one()->trim(Facing::UP, 7 / 8), + AxisAlignedBB::one()->trimmedCopy(Facing::UP, 7 / 8), //center post AxisAlignedBB::one() - ->squash(Axis::X, 7 / 16) - ->squash(Axis::Z, 7 / 16) - ->trim(Facing::UP, 1 / 8) + ->squashedCopy(Axis::X, 7 / 16) + ->squashedCopy(Axis::Z, 7 / 16) + ->trimmedCopy(Facing::UP, 1 / 8) ]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -95,7 +95,7 @@ class BrewingStand extends Transparent{ return $this; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $stand = $this->position->getWorld()->getTile($this->position); if($stand instanceof TileBrewingStand && $stand->canOpenWith($item->getCustomName())){ diff --git a/src/block/Button.php b/src/block/Button.php index 4d1f1bbc5..04f7716f2 100644 --- a/src/block/Button.php +++ b/src/block/Button.php @@ -40,7 +40,7 @@ abstract class Button extends Flowable implements AnyFacing{ protected bool $pressed = false; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->facing($this->facing); + $w->enum($this->facing); $w->bool($this->pressed); } @@ -52,7 +52,7 @@ abstract class Button extends Flowable implements AnyFacing{ return $this; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($this->canBeSupportedAt($blockReplace, $face)){ $this->facing = $face; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -62,7 +62,7 @@ abstract class Button extends Flowable implements AnyFacing{ abstract protected function getActivationTime() : int; - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if(!$this->pressed){ $this->pressed = true; $world = $this->position->getWorld(); @@ -89,7 +89,7 @@ abstract class Button extends Flowable implements AnyFacing{ } } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ return $block->getAdjacentSupportType(Facing::opposite($face))->hasCenterSupport(); } } diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 51c98786b..0e4d7c8ed 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -46,10 +46,10 @@ class Cactus extends Transparent implements Ageable{ protected function recalculateCollisionBoxes() : array{ $shrinkSize = 1 / 16; - return [AxisAlignedBB::one()->contract($shrinkSize, 0, $shrinkSize)->trim(Facing::UP, $shrinkSize)]; + return [AxisAlignedBB::one()->contractedCopy($shrinkSize, 0, $shrinkSize)->trimmedCopy(Facing::UP, $shrinkSize)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } diff --git a/src/block/Cake.php b/src/block/Cake.php index e8c6dc93e..3f4f9db92 100644 --- a/src/block/Cake.php +++ b/src/block/Cake.php @@ -43,9 +43,9 @@ class Cake extends BaseCake{ protected function recalculateCollisionBoxes() : array{ return [ AxisAlignedBB::one() - ->contract(1 / 16, 0, 1 / 16) - ->trim(Facing::UP, 0.5) - ->trim(Facing::WEST, $this->bites / 8) + ->contractedCopy(1 / 16, 0, 1 / 16) + ->trimmedCopy(Facing::UP, 0.5) + ->trimmedCopy(Facing::WEST, $this->bites / 8) ]; } @@ -60,7 +60,7 @@ class Cake extends BaseCake{ return $this; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->bites === 0 && $item instanceof ItemBlock){ $block = $item->getBlock(); $resultBlock = null; diff --git a/src/block/CakeWithCandle.php b/src/block/CakeWithCandle.php index 1462776c2..09a1c1bfa 100644 --- a/src/block/CakeWithCandle.php +++ b/src/block/CakeWithCandle.php @@ -40,8 +40,8 @@ class CakeWithCandle extends BaseCake implements Lightable{ protected function recalculateCollisionBoxes() : array{ return [ AxisAlignedBB::one() - ->contract(1 / 16, 0, 1 / 16) - ->trim(Facing::UP, 0.5) //TODO: not sure if the candle affects height + ->contractedCopy(1 / 16, 0, 1 / 16) + ->trimmedCopy(Facing::UP, 0.5) //TODO: not sure if the candle affects height ]; } @@ -49,7 +49,7 @@ class CakeWithCandle extends BaseCake implements Lightable{ return VanillaBlocks::CANDLE(); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->lit && $face !== Facing::UP){ return true; } diff --git a/src/block/Campfire.php b/src/block/Campfire.php index edfc87ecb..5c81af949 100644 --- a/src/block/Campfire.php +++ b/src/block/Campfire.php @@ -127,12 +127,12 @@ class Campfire extends Transparent implements Lightable, HorizontalFacing{ ]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 9 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 9 / 16)]; } /** @@ -171,7 +171,7 @@ class Campfire extends Transparent implements Lightable, HorizontalFacing{ return $this->cookingTimes[$slot] ?? 0; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($this->getSide(Facing::DOWN) instanceof Campfire){ return false; } @@ -182,7 +182,7 @@ class Campfire extends Transparent implements Lightable, HorizontalFacing{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if(!$this->lit){ if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){ $item->pop(); diff --git a/src/block/Candle.php b/src/block/Candle.php index 977f13a09..df129d961 100644 --- a/src/block/Candle.php +++ b/src/block/Candle.php @@ -71,27 +71,27 @@ class Candle extends Transparent implements Lightable{ return [ (match($this->count){ 1 => AxisAlignedBB::one() - ->squash(Axis::X, 7 / 16) - ->squash(Axis::Z, 7 / 16), + ->squashedCopy(Axis::X, 7 / 16) + ->squashedCopy(Axis::Z, 7 / 16), 2 => AxisAlignedBB::one() - ->squash(Axis::X, 5 / 16) - ->trim(Facing::NORTH, 7 / 16) //0.3 thick on the Z axis - ->trim(Facing::SOUTH, 6 / 16), + ->squashedCopy(Axis::X, 5 / 16) + ->trimmedCopy(Facing::NORTH, 7 / 16) //0.3 thick on the Z axis + ->trimmedCopy(Facing::SOUTH, 6 / 16), 3 => AxisAlignedBB::one() - ->trim(Facing::WEST, 5 / 16) - ->trim(Facing::EAST, 6 / 16) - ->trim(Facing::NORTH, 6 / 16) - ->trim(Facing::SOUTH, 5 / 16), + ->trimmedCopy(Facing::WEST, 5 / 16) + ->trimmedCopy(Facing::EAST, 6 / 16) + ->trimmedCopy(Facing::NORTH, 6 / 16) + ->trimmedCopy(Facing::SOUTH, 5 / 16), 4 => AxisAlignedBB::one() - ->squash(Axis::X, 5 / 16) - ->trim(Facing::NORTH, 5 / 16) - ->trim(Facing::SOUTH, 6 / 16), + ->squashedCopy(Axis::X, 5 / 16) + ->trimmedCopy(Facing::NORTH, 5 / 16) + ->trimmedCopy(Facing::SOUTH, 6 / 16), default => throw new AssumptionFailedError("Unreachable") - })->trim(Facing::UP, 10 / 16) + })->trimmedCopy(Facing::UP, 10 / 16) ]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -99,12 +99,12 @@ class Candle extends Transparent implements Lightable{ return $block instanceof Candle && $block->hasSameTypeId($this) ? $block : null; } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ $candle = $this->getCandleIfCompatibleType($blockReplace); return $candle !== null ? $candle->count < self::MAX_COUNT : parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$blockReplace->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport()){ return false; } diff --git a/src/block/Carpet.php b/src/block/Carpet.php index fd8b42a09..772a93eea 100644 --- a/src/block/Carpet.php +++ b/src/block/Carpet.php @@ -38,7 +38,7 @@ class Carpet extends Flowable implements Colored{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 15 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 15 / 16)]; } private function canBeSupportedAt(Block $block) : bool{ diff --git a/src/block/CartographyTable.php b/src/block/CartographyTable.php index 67d950c5a..df9041448 100644 --- a/src/block/CartographyTable.php +++ b/src/block/CartographyTable.php @@ -25,12 +25,13 @@ namespace pocketmine\block; use pocketmine\block\inventory\CartographyTableInventory; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; final class CartographyTable extends Opaque{ - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player !== null){ $player->setCurrentWindow(new CartographyTableInventory($this->position)); } diff --git a/src/block/Cauldron.php b/src/block/Cauldron.php index 772583a5a..c44da1682 100644 --- a/src/block/Cauldron.php +++ b/src/block/Cauldron.php @@ -51,16 +51,16 @@ final class Cauldron extends Transparent{ protected function recalculateCollisionBoxes() : array{ $result = [ - AxisAlignedBB::one()->trim(Facing::UP, 11 / 16) //bottom of the cauldron + AxisAlignedBB::one()->trimmedCopy(Facing::UP, 11 / 16) //bottom of the cauldron ]; foreach(Facing::HORIZONTAL as $f){ //add the frame parts around the bowl - $result[] = AxisAlignedBB::one()->trim($f, 14 / 16); + $result[] = AxisAlignedBB::one()->trimmedCopy($f, 14 / 16); } return $result; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return $facing === Facing::UP ? SupportType::EDGE : SupportType::NONE; } @@ -75,7 +75,7 @@ final class Cauldron extends Transparent{ $returnedItems[] = $returnedItem; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item->getTypeId() === ItemTypeIds::WATER_BUCKET){ $this->fill(FillableCauldron::MAX_FILL_LEVEL, VanillaBlocks::WATER_CAULDRON(), $item, VanillaItems::BUCKET(), $returnedItems); }elseif($item->getTypeId() === ItemTypeIds::LAVA_BUCKET){ diff --git a/src/block/CaveVines.php b/src/block/CaveVines.php index 84d7d3169..1e42f2ac0 100644 --- a/src/block/CaveVines.php +++ b/src/block/CaveVines.php @@ -84,12 +84,12 @@ class CaveVines extends Flowable implements Ageable{ return $supportBlock->getSupportType(Facing::DOWN) === SupportType::FULL || $supportBlock->hasSameTypeId($this); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->age = mt_rand(0, self::MAX_AGE); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->berries){ $this->position->getWorld()->dropItem($this->position, $this->asItem()); $this->position->getWorld()->addSound($this->position, new GlowBerriesPickSound()); @@ -159,7 +159,7 @@ class CaveVines extends Flowable implements Ageable{ return VanillaItems::GLOW_BERRIES(); } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/CeilingCenterHangingSign.php b/src/block/CeilingCenterHangingSign.php index 1125de553..4d9803617 100644 --- a/src/block/CeilingCenterHangingSign.php +++ b/src/block/CeilingCenterHangingSign.php @@ -36,12 +36,12 @@ final class CeilingCenterHangingSign extends BaseSign implements SignLikeRotatio use SignLikeRotationTrait; use StaticSupportTrait; - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::UP; } //TODO: duplicated code :( - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face !== Facing::DOWN){ return false; } diff --git a/src/block/CeilingEdgesHangingSign.php b/src/block/CeilingEdgesHangingSign.php index 3f7b6489b..e8a347033 100644 --- a/src/block/CeilingEdgesHangingSign.php +++ b/src/block/CeilingEdgesHangingSign.php @@ -35,11 +35,11 @@ use pocketmine\world\BlockTransaction; final class CeilingEdgesHangingSign extends BaseSign implements HorizontalFacing{ use HorizontalFacingTrait; - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::UP; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face !== Facing::DOWN){ return false; } diff --git a/src/block/Chain.php b/src/block/Chain.php index 5ec3b1e2a..12b379852 100644 --- a/src/block/Chain.php +++ b/src/block/Chain.php @@ -33,7 +33,7 @@ use pocketmine\math\Facing; final class Chain extends Transparent implements PillarRotation{ use PillarRotationTrait; - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return $this->axis === Axis::Y && Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } @@ -41,7 +41,7 @@ final class Chain extends Transparent implements PillarRotation{ $bb = AxisAlignedBB::one(); foreach([Axis::Y, Axis::Z, Axis::X] as $axis){ if($axis !== $this->axis){ - $bb->squash($axis, 13 / 32); + $bb = $bb->squashedCopy($axis, 13 / 32); } } return [$bb]; diff --git a/src/block/ChemistryTable.php b/src/block/ChemistryTable.php index 9b5e78f92..c266bd513 100644 --- a/src/block/ChemistryTable.php +++ b/src/block/ChemistryTable.php @@ -26,13 +26,14 @@ namespace pocketmine\block; use pocketmine\block\utils\FacesOppositePlacingPlayerTrait; use pocketmine\block\utils\HorizontalFacing; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; final class ChemistryTable extends Opaque implements HorizontalFacing{ use FacesOppositePlacingPlayerTrait; - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ //TODO return false; } diff --git a/src/block/Chest.php b/src/block/Chest.php index c0dc09d9e..58a7463f5 100644 --- a/src/block/Chest.php +++ b/src/block/Chest.php @@ -39,10 +39,10 @@ class Chest extends Transparent implements HorizontalFacing{ protected function recalculateCollisionBoxes() : array{ //these are slightly bigger than in PC - return [AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05)]; + return [AxisAlignedBB::one()->contractedCopy(0.025, 0, 0.025)->trimmedCopy(Facing::UP, 0.05)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -70,7 +70,7 @@ class Chest extends Transparent implements HorizontalFacing{ } } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $chest = $this->position->getWorld()->getTile($this->position); diff --git a/src/block/ChiseledBookshelf.php b/src/block/ChiseledBookshelf.php index cbe22a94b..1d8d83ed0 100644 --- a/src/block/ChiseledBookshelf.php +++ b/src/block/ChiseledBookshelf.php @@ -143,7 +143,7 @@ class ChiseledBookshelf extends Opaque implements HorizontalFacing{ return $this; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($face !== $this->facing){ return false; } diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index ef48d5a89..14cce40ac 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -106,9 +106,9 @@ final class ChorusFlower extends Flowable implements Ageable{ return [$stemHeight, $endStoneBelow]; } - private function allHorizontalBlocksEmpty(World $world, Vector3 $position, ?int $except) : bool{ + private function allHorizontalBlocksEmpty(World $world, Vector3 $position, ?Facing $except) : bool{ foreach($position->sidesAroundAxis(Axis::Y) as $facing => $sidePosition){ - if($facing === $except){ + if($facing === $except?->value){ continue; } if($world->getBlock($sidePosition)->getTypeId() !== BlockTypeIds::AIR){ @@ -149,7 +149,7 @@ final class ChorusFlower extends Flowable implements Ageable{ return $this->allHorizontalBlocksEmpty($world, $up, null); } - private function grow(int $facing, int $ageChange, ?BlockTransaction $tx) : BlockTransaction{ + private function grow(Facing $facing, int $ageChange, ?BlockTransaction $tx) : BlockTransaction{ if($tx === null){ $tx = new BlockTransaction($this->position->getWorld()); } @@ -176,10 +176,10 @@ final class ChorusFlower extends Flowable implements Ageable{ $facingVisited = []; for($attempts = 0, $maxAttempts = mt_rand(0, $endStoneBelow ? 4 : 3); $attempts < $maxAttempts; $attempts++){ $facing = Facing::HORIZONTAL[array_rand(Facing::HORIZONTAL)]; - if(isset($facingVisited[$facing])){ + if(isset($facingVisited[$facing->value])){ continue; } - $facingVisited[$facing] = true; + $facingVisited[$facing->value] = true; $sidePosition = $this->position->getSide($facing); if( diff --git a/src/block/ChorusPlant.php b/src/block/ChorusPlant.php index 88cf1787c..96a203a10 100644 --- a/src/block/ChorusPlant.php +++ b/src/block/ChorusPlant.php @@ -43,8 +43,8 @@ final class ChorusPlant extends Flowable{ protected function recalculateCollisionBoxes() : array{ $bb = AxisAlignedBB::one(); foreach(Facing::ALL as $facing){ - if(!isset($this->connections[$facing])){ - $bb->trim($facing, 2 / 16); + if(!isset($this->connections[$facing->value])){ + $bb = $bb->trimmedCopy($facing, 2 / 16); } } @@ -62,9 +62,9 @@ final class ChorusPlant extends Flowable{ BlockTypeIds::END_STONE, BlockTypeIds::CHORUS_FLOWER, $this->getTypeId() => true, default => false }){ - $this->connections[$facing] = true; + $this->connections[$facing->value] = true; }else{ - unset($this->connections[$facing]); + unset($this->connections[$facing->value]); } } diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index ae09ccb0a..eec10db2d 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -55,11 +55,11 @@ class CocoaBlock extends Flowable implements Ageable, HorizontalFacing{ protected function recalculateCollisionBoxes() : array{ return [ AxisAlignedBB::one() - ->squash(Facing::axis(Facing::rotateY($this->facing, true)), (6 - $this->age) / 16) //sides - ->trim(Facing::DOWN, (7 - $this->age * 2) / 16) - ->trim(Facing::UP, 0.25) - ->trim(Facing::opposite($this->facing), 1 / 16) //gap between log and pod - ->trim($this->facing, (11 - $this->age * 2) / 16) //outward face + ->squashedCopy(Facing::axis(Facing::rotateY($this->facing, true)), (6 - $this->age) / 16) //sides + ->trimmedCopy(Facing::DOWN, (7 - $this->age * 2) / 16) + ->trimmedCopy(Facing::UP, 0.25) + ->trimmedCopy(Facing::opposite($this->facing), 1 / 16) //gap between log and pod + ->trimmedCopy($this->facing, (11 - $this->age * 2) / 16) //outward face ]; } @@ -67,7 +67,7 @@ class CocoaBlock extends Flowable implements Ageable, HorizontalFacing{ 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{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(Facing::axis($face) !== Axis::Y && $this->canAttachTo($blockClicked)){ $this->facing = $face; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -76,7 +76,7 @@ class CocoaBlock extends Flowable implements Ageable, HorizontalFacing{ return false; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer && $this->grow($player)){ $item->pop(); diff --git a/src/block/CopperDoor.php b/src/block/CopperDoor.php index 82a611206..6a690a109 100644 --- a/src/block/CopperDoor.php +++ b/src/block/CopperDoor.php @@ -35,7 +35,7 @@ class CopperDoor extends Door implements CopperMaterial{ onInteract as onInteractCopper; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if ($player !== null && $player->isSneaking() && $this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems)) { //copy copper properties to other half $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); diff --git a/src/block/CopperTrapdoor.php b/src/block/CopperTrapdoor.php index e7d56fa0c..16a7d4ec0 100644 --- a/src/block/CopperTrapdoor.php +++ b/src/block/CopperTrapdoor.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\block\utils\CopperMaterial; use pocketmine\block\utils\CopperTrait; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -34,7 +35,7 @@ class CopperTrapdoor extends Trapdoor implements CopperMaterial{ onInteract as onInteractCopper; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if ($player !== null && $player->isSneaking() && $this->onInteractCopper($item, $face, $clickVector, $player, $returnedItems)) { return true; } diff --git a/src/block/CraftingTable.php b/src/block/CraftingTable.php index dcd9edce2..6d43dd18f 100644 --- a/src/block/CraftingTable.php +++ b/src/block/CraftingTable.php @@ -25,12 +25,13 @@ namespace pocketmine\block; use pocketmine\block\inventory\CraftingTableInventory; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; class CraftingTable extends Opaque{ - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $player->setCurrentWindow(new CraftingTableInventory($this->position)); } diff --git a/src/block/Crops.php b/src/block/Crops.php index b0488d150..85cddcbed 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -45,7 +45,7 @@ abstract class Crops extends Flowable implements Ageable{ return $block->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->age < self::MAX_AGE && $item instanceof Fertilizer){ $block = clone $this; $tempAge = $block->age + mt_rand(2, 5); diff --git a/src/block/DaylightSensor.php b/src/block/DaylightSensor.php index ed56d2f44..ac3833753 100644 --- a/src/block/DaylightSensor.php +++ b/src/block/DaylightSensor.php @@ -64,14 +64,14 @@ class DaylightSensor extends Transparent implements AnalogRedstoneSignalEmitter{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 10 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 10 / 16)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $this->inverted = !$this->inverted; $this->signalStrength = $this->recalculateSignalStrength(); $this->position->getWorld()->setBlock($this->position, $this); diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 104080d31..f106edc48 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -52,7 +52,7 @@ class Dirt extends Opaque{ return $this; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $world = $this->position->getWorld(); if($face !== Facing::DOWN && $item instanceof Hoe){ $up = $this->getSide(Facing::UP); diff --git a/src/block/Door.php b/src/block/Door.php index 2ff53645c..514d9dda9 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -98,10 +98,10 @@ class Door extends Transparent implements HorizontalFacing{ protected function recalculateCollisionBoxes() : array{ //TODO: doors are 0.1825 blocks thick, instead of 0.1875 like JE (https://bugs.mojang.com/browse/MCPE-19214) - return [AxisAlignedBB::one()->trim($this->open ? Facing::rotateY($this->facing, !$this->hingeRight) : $this->facing, 327 / 400)]; + return [AxisAlignedBB::one()->trimmedCopy($this->open ? Facing::rotateY($this->facing, !$this->hingeRight) : $this->facing, 327 / 400)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -111,7 +111,7 @@ class Door extends Transparent implements HorizontalFacing{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face === Facing::UP){ $blockUp = $this->getSide(Facing::UP); if(!$blockUp->canBeReplaced() || !$this->canBeSupportedAt($blockReplace)){ @@ -139,7 +139,7 @@ class Door extends Transparent implements HorizontalFacing{ return false; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $this->open = !$this->open; $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); diff --git a/src/block/DoublePitcherCrop.php b/src/block/DoublePitcherCrop.php index 89d9e98b5..a4031d2d2 100644 --- a/src/block/DoublePitcherCrop.php +++ b/src/block/DoublePitcherCrop.php @@ -58,10 +58,10 @@ final class DoublePitcherCrop extends DoublePlant implements Ageable{ //the pod exists only in the bottom half of the plant return [ AxisAlignedBB::one() - ->trim(Facing::UP, 11 / 16) - ->squash(Axis::X, 3 / 16) - ->squash(Axis::Z, 3 / 16) - ->extend(Facing::DOWN, 1 / 16) //presumably this is to correct for farmland being 15/16 of a block tall + ->trimmedCopy(Facing::UP, 11 / 16) + ->squashedCopy(Axis::X, 3 / 16) + ->squashedCopy(Axis::Z, 3 / 16) + ->extendedCopy(Facing::DOWN, 1 / 16) //presumably this is to correct for farmland being 15/16 of a block tall ]; } @@ -89,7 +89,7 @@ final class DoublePitcherCrop extends DoublePlant implements Ageable{ } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer && $this->grow($player)){ $item->pop(); return true; diff --git a/src/block/DoublePlant.php b/src/block/DoublePlant.php index aab6d5b04..d1f878561 100644 --- a/src/block/DoublePlant.php +++ b/src/block/DoublePlant.php @@ -45,7 +45,7 @@ class DoublePlant extends Flowable{ return $this; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $down = $blockReplace->getSide(Facing::DOWN); if($down->hasTypeTag(BlockTypeTags::DIRT) && $blockReplace->getSide(Facing::UP)->canBeReplaced()){ $top = clone $this; diff --git a/src/block/DragonEgg.php b/src/block/DragonEgg.php index 10fec6394..89ec4237f 100644 --- a/src/block/DragonEgg.php +++ b/src/block/DragonEgg.php @@ -28,6 +28,7 @@ use pocketmine\block\utils\FallableTrait; use pocketmine\block\utils\SupportType; use pocketmine\event\block\BlockTeleportEvent; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\GameMode; use pocketmine\player\Player; @@ -44,12 +45,12 @@ class DragonEgg extends Transparent implements Fallable{ return 1; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $this->teleport(); return true; } - public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ + public function onAttack(Item $item, Facing $face, ?Player $player = null) : bool{ if($player !== null && $player->getGamemode() !== GameMode::CREATIVE){ $this->teleport(); return true; @@ -81,7 +82,7 @@ class DragonEgg extends Transparent implements Fallable{ } } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/EnchantingTable.php b/src/block/EnchantingTable.php index 53573d064..346dde7cd 100644 --- a/src/block/EnchantingTable.php +++ b/src/block/EnchantingTable.php @@ -34,14 +34,14 @@ use pocketmine\player\Player; class EnchantingTable extends Transparent{ protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 0.25)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 0.25)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ //TODO lock diff --git a/src/block/EndPortalFrame.php b/src/block/EndPortalFrame.php index 6c4865fdd..7169e38f2 100644 --- a/src/block/EndPortalFrame.php +++ b/src/block/EndPortalFrame.php @@ -52,6 +52,6 @@ class EndPortalFrame extends Opaque implements HorizontalFacing{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 3 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 3 / 16)]; } } diff --git a/src/block/EndRod.php b/src/block/EndRod.php index e3d439f6a..b1cd64749 100644 --- a/src/block/EndRod.php +++ b/src/block/EndRod.php @@ -36,7 +36,7 @@ use pocketmine\world\BlockTransaction; class EndRod extends Flowable implements AnyFacing{ use AnyFacingTrait; - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->facing = $face; if($blockClicked instanceof EndRod && $blockClicked->facing === $this->facing){ $this->facing = Facing::opposite($face); @@ -61,7 +61,7 @@ class EndRod extends Flowable implements AnyFacing{ if($axis === $myAxis){ continue; } - $bb->squash($axis, 6 / 16); + $bb->squashedCopy($axis, 6 / 16); } return [$bb]; } diff --git a/src/block/EnderChest.php b/src/block/EnderChest.php index 5dec4f3af..6aa65bdff 100644 --- a/src/block/EnderChest.php +++ b/src/block/EnderChest.php @@ -43,14 +43,14 @@ class EnderChest extends Transparent implements HorizontalFacing{ protected function recalculateCollisionBoxes() : array{ //these are slightly bigger than in PC - return [AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05)]; + return [AxisAlignedBB::one()->contractedCopy(0.025, 0, 0.025)->trimmedCopy(Facing::UP, 0.05)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $enderChest = $this->position->getWorld()->getTile($this->position); if($enderChest instanceof TileEnderChest && $this->getSide(Facing::UP)->isTransparent()){ diff --git a/src/block/Farmland.php b/src/block/Farmland.php index 83bc34561..d0f92a528 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -95,7 +95,7 @@ class Farmland extends Transparent{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 1 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 1 / 16)]; } public function onNearbyBlockChange() : void{ diff --git a/src/block/Fence.php b/src/block/Fence.php index 52256d9f0..1eb8ef900 100644 --- a/src/block/Fence.php +++ b/src/block/Fence.php @@ -45,9 +45,9 @@ 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)) === SupportType::FULL){ - $this->connections[$facing] = true; + $this->connections[$facing->value] = true; }else{ - unset($this->connections[$facing]); + unset($this->connections[$facing->value]); } } @@ -59,43 +59,43 @@ class Fence extends Transparent{ $bbs = []; - $connectWest = isset($this->connections[Facing::WEST]); - $connectEast = isset($this->connections[Facing::EAST]); + $connectWest = isset($this->connections[Facing::WEST->value]); + $connectEast = isset($this->connections[Facing::EAST->value]); if($connectWest || $connectEast){ //X axis (west/east) $bbs[] = AxisAlignedBB::one() - ->squash(Axis::Z, $inset) - ->extend(Facing::UP, 0.5) - ->trim(Facing::WEST, $connectWest ? 0 : $inset) - ->trim(Facing::EAST, $connectEast ? 0 : $inset); + ->squashedCopy(Axis::Z, $inset) + ->extendedCopy(Facing::UP, 0.5) + ->trimmedCopy(Facing::WEST, $connectWest ? 0 : $inset) + ->trimmedCopy(Facing::EAST, $connectEast ? 0 : $inset); } - $connectNorth = isset($this->connections[Facing::NORTH]); - $connectSouth = isset($this->connections[Facing::SOUTH]); + $connectNorth = isset($this->connections[Facing::NORTH->value]); + $connectSouth = isset($this->connections[Facing::SOUTH->value]); if($connectNorth || $connectSouth){ //Z axis (north/south) $bbs[] = AxisAlignedBB::one() - ->squash(Axis::X, $inset) - ->extend(Facing::UP, 0.5) - ->trim(Facing::NORTH, $connectNorth ? 0 : $inset) - ->trim(Facing::SOUTH, $connectSouth ? 0 : $inset); + ->squashedCopy(Axis::X, $inset) + ->extendedCopy(Facing::UP, 0.5) + ->trimmedCopy(Facing::NORTH, $connectNorth ? 0 : $inset) + ->trimmedCopy(Facing::SOUTH, $connectSouth ? 0 : $inset); } if(count($bbs) === 0){ //centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made) return [ AxisAlignedBB::one() - ->extend(Facing::UP, 0.5) - ->contract($inset, 0, $inset) + ->extendedCopy(Facing::UP, 0.5) + ->contractedCopy($inset, 0, $inset) ]; } return $bbs; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } } diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index d8cdfe4e2..1e6ed6dc8 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -67,10 +67,10 @@ class FenceGate extends Transparent implements HorizontalFacing, WoodMaterial{ } protected function recalculateCollisionBoxes() : array{ - return $this->open ? [] : [AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16)]; + return $this->open ? [] : [AxisAlignedBB::one()->extendedCopy(Facing::UP, 0.5)->squashedCopy(Facing::axis($this->facing), 6 / 16)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -81,7 +81,7 @@ class FenceGate extends Transparent implements HorizontalFacing, WoodMaterial{ ); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->facing = $player->getHorizontalFacing(); } @@ -99,7 +99,7 @@ class FenceGate extends Transparent implements HorizontalFacing, WoodMaterial{ } } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $this->open = !$this->open; if($this->open && $player !== null){ $playerFacing = $player->getHorizontalFacing(); diff --git a/src/block/FillableCauldron.php b/src/block/FillableCauldron.php index ceef35299..f6ff3e458 100644 --- a/src/block/FillableCauldron.php +++ b/src/block/FillableCauldron.php @@ -54,16 +54,16 @@ abstract class FillableCauldron extends Transparent{ protected function recalculateCollisionBoxes() : array{ $result = [ - AxisAlignedBB::one()->trim(Facing::UP, 11 / 16) //bottom of the cauldron + AxisAlignedBB::one()->trimmedCopy(Facing::UP, 11 / 16) //bottom of the cauldron ]; foreach(Facing::HORIZONTAL as $f){ //add the frame parts around the bowl - $result[] = AxisAlignedBB::one()->trim($f, 14 / 16); + $result[] = AxisAlignedBB::one()->trimmedCopy($f, 14 / 16); } return $result; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return $facing === Facing::UP ? SupportType::EDGE : SupportType::NONE; } diff --git a/src/block/FloorBanner.php b/src/block/FloorBanner.php index ff57b5973..5df7bfb61 100644 --- a/src/block/FloorBanner.php +++ b/src/block/FloorBanner.php @@ -38,11 +38,11 @@ final class FloorBanner extends BaseBanner implements SignLikeRotation{ return VanillaBlocks::OMINOUS_BANNER()->setRotation($this->rotation); } - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::DOWN; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face !== Facing::UP){ return false; } diff --git a/src/block/FloorCoralFan.php b/src/block/FloorCoralFan.php index 5b74d08af..3adfe0420 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -38,16 +38,16 @@ use function rad2deg; final class FloorCoralFan extends BaseCoral{ use StaticSupportTrait; - private int $axis = Axis::X; + private Axis $axis = Axis::X; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalAxis($this->axis); } - public function getAxis() : int{ return $this->axis; } + public function getAxis() : Axis{ return $this->axis; } /** @return $this */ - public function setAxis(int $axis) : self{ + public function setAxis(Axis $axis) : self{ if($axis !== Axis::X && $axis !== Axis::Z){ throw new \InvalidArgumentException("Axis must be X or Z only"); } @@ -55,7 +55,7 @@ final class FloorCoralFan extends BaseCoral{ return $this; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $playerBlockPos = $player->getPosition()->floor(); $directionVector = $blockReplace->position->subtractVector($playerBlockPos)->normalize(); diff --git a/src/block/FloorSign.php b/src/block/FloorSign.php index 94e51ffe8..3f2bd6d22 100644 --- a/src/block/FloorSign.php +++ b/src/block/FloorSign.php @@ -34,11 +34,11 @@ use pocketmine\world\BlockTransaction; final class FloorSign extends BaseSign implements SignLikeRotation{ use SignLikeRotationTrait; - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::DOWN; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face !== Facing::UP){ return false; } diff --git a/src/block/Flowable.php b/src/block/Flowable.php index 355c9caea..db1b5745b 100644 --- a/src/block/Flowable.php +++ b/src/block/Flowable.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\SupportType; +use pocketmine\math\Facing; use pocketmine\math\Vector3; /** @@ -40,7 +41,7 @@ abstract class Flowable extends Transparent{ return false; } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ return (!$this->canBeFlowedInto() || !$blockReplace instanceof Liquid) && parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } @@ -49,7 +50,7 @@ abstract class Flowable extends Transparent{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/FlowerPot.php b/src/block/FlowerPot.php index 79fb73b12..88d23380b 100644 --- a/src/block/FlowerPot.php +++ b/src/block/FlowerPot.php @@ -84,14 +84,14 @@ class FlowerPot extends Flowable{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8)]; + return [AxisAlignedBB::one()->contractedCopy(3 / 16, 0, 3 / 16)->trimmedCopy(Facing::UP, 5 / 8)]; } private function canBeSupportedAt(Block $block) : bool{ return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport(); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $world = $this->position->getWorld(); $plant = $item->getBlock(); if($this->plant !== null){ diff --git a/src/block/Furnace.php b/src/block/Furnace.php index 43ab463a6..808231b18 100644 --- a/src/block/Furnace.php +++ b/src/block/Furnace.php @@ -31,6 +31,7 @@ use pocketmine\block\utils\LightableTrait; use pocketmine\crafting\FurnaceType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use function mt_rand; @@ -59,7 +60,7 @@ class Furnace extends Opaque implements Lightable, HorizontalFacing{ return $this->lit ? 13 : 0; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $furnace = $this->position->getWorld()->getTile($this->position); if($furnace instanceof TileFurnace && $furnace->canOpenWith($item->getCustomName())){ diff --git a/src/block/GlowLichen.php b/src/block/GlowLichen.php index 4588d647d..0815303a8 100644 --- a/src/block/GlowLichen.php +++ b/src/block/GlowLichen.php @@ -51,7 +51,7 @@ class GlowLichen extends Transparent implements MultiAnyFacing{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -60,13 +60,13 @@ class GlowLichen extends Transparent implements MultiAnyFacing{ } /** - * @return int[] + * @return Facing[] */ protected function getInitialPlaceFaces(Block $blockReplace) : array{ return $blockReplace instanceof GlowLichen ? $blockReplace->faces : []; } - private function getSpreadBlock(Block $replace, int $spreadFace) : ?Block{ + private function getSpreadBlock(Block $replace, Facing $spreadFace) : ?Block{ if($replace instanceof self && $replace->hasSameTypeId($this)){ if($replace->hasFace($spreadFace)){ return null; @@ -81,7 +81,7 @@ class GlowLichen extends Transparent implements MultiAnyFacing{ return $result->setFace($spreadFace, true); } - private function spread(World $world, Vector3 $replacePos, int $spreadFace) : bool{ + private function spread(World $world, Vector3 $replacePos, Facing $spreadFace) : bool{ $supportBlock = $world->getBlock($replacePos->getSide($spreadFace)); $supportFace = Facing::opposite($spreadFace); @@ -99,9 +99,9 @@ class GlowLichen extends Transparent implements MultiAnyFacing{ } /** - * @phpstan-return \Generator + * @phpstan-return \Generator */ - private static function getShuffledSpreadFaces(int $sourceFace) : \Generator{ + private static function getShuffledSpreadFaces(Facing $sourceFace) : \Generator{ $skipAxis = Facing::axis($sourceFace); $faces = Facing::ALL; @@ -113,7 +113,7 @@ class GlowLichen extends Transparent implements MultiAnyFacing{ } } - private function spreadAroundSupport(int $sourceFace) : bool{ + private function spreadAroundSupport(Facing $sourceFace) : bool{ $world = $this->position->getWorld(); $supportPos = $this->position->getSide($sourceFace); @@ -127,7 +127,7 @@ class GlowLichen extends Transparent implements MultiAnyFacing{ return false; } - private function spreadAdjacentToSupport(int $sourceFace) : bool{ + private function spreadAdjacentToSupport(Facing $sourceFace) : bool{ $world = $this->position->getWorld(); foreach(self::getShuffledSpreadFaces($sourceFace) as $spreadFace){ @@ -139,7 +139,7 @@ class GlowLichen extends Transparent implements MultiAnyFacing{ return false; } - private function spreadWithinSelf(int $sourceFace) : bool{ + private function spreadWithinSelf(Facing $sourceFace) : bool{ foreach(self::getShuffledSpreadFaces($sourceFace) as $spreadFace){ if(!$this->hasFace($spreadFace) && $this->spread($this->position->getWorld(), $this->position, $spreadFace)){ return true; @@ -149,7 +149,7 @@ class GlowLichen extends Transparent implements MultiAnyFacing{ return false; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer && count($this->faces) > 0){ $shuffledFaces = $this->faces; shuffle($shuffledFaces); diff --git a/src/block/Grass.php b/src/block/Grass.php index 8a9fea8ea..d8fe435f2 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -81,7 +81,7 @@ class Grass extends Opaque{ } } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->getSide(Facing::UP)->getTypeId() !== BlockTypeIds::AIR){ return false; } diff --git a/src/block/GrassPath.php b/src/block/GrassPath.php index ea56e4b95..7a5985e42 100644 --- a/src/block/GrassPath.php +++ b/src/block/GrassPath.php @@ -30,7 +30,7 @@ use pocketmine\math\Facing; class GrassPath extends Transparent{ protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 1 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 1 / 16)]; } public function onNearbyBlockChange() : void{ diff --git a/src/block/Hopper.php b/src/block/Hopper.php index 4956b668f..8c727a1d2 100644 --- a/src/block/Hopper.php +++ b/src/block/Hopper.php @@ -38,17 +38,17 @@ use pocketmine\world\BlockTransaction; class Hopper extends Transparent implements PoweredByRedstone{ use PoweredByRedstoneTrait; - private int $facing = Facing::DOWN; + private Facing $facing = Facing::DOWN; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facingExcept($this->facing, Facing::UP); $w->bool($this->powered); } - public function getFacing() : int{ return $this->facing; } + public function getFacing() : Facing{ return $this->facing; } /** @return $this */ - public function setFacing(int $facing) : self{ + public function setFacing(Facing $facing) : self{ if($facing === Facing::UP){ throw new \InvalidArgumentException("Hopper may not face upward"); } @@ -58,16 +58,16 @@ class Hopper extends Transparent implements PoweredByRedstone{ protected function recalculateCollisionBoxes() : array{ $result = [ - AxisAlignedBB::one()->trim(Facing::UP, 6 / 16) //the empty area around the bottom is currently considered solid + AxisAlignedBB::one()->trimmedCopy(Facing::UP, 6 / 16) //the empty area around the bottom is currently considered solid ]; foreach(Facing::HORIZONTAL as $f){ //add the frame parts around the bowl - $result[] = AxisAlignedBB::one()->trim($f, 14 / 16); + $result[] = AxisAlignedBB::one()->trimmedCopy($f, 14 / 16); } return $result; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return match($facing){ Facing::UP => SupportType::FULL, Facing::DOWN => $this->facing === Facing::DOWN ? SupportType::CENTER : SupportType::NONE, @@ -75,13 +75,13 @@ class Hopper extends Transparent implements PoweredByRedstone{ }; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->facing = $face === Facing::DOWN ? Facing::DOWN : Facing::opposite($face); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player !== null){ $tile = $this->position->getWorld()->getTile($this->position); if($tile instanceof TileHopper){ //TODO: find a way to have inventories open on click without this boilerplate in every block diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index 0fda77758..ee0c8c452 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -52,7 +52,7 @@ class ItemFrame extends Flowable implements AnyFacing{ protected float $itemDropChance = 1.0; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->facing($this->facing); + $w->enum($this->facing); $w->bool($this->hasMap); } @@ -132,7 +132,7 @@ class ItemFrame extends Flowable implements AnyFacing{ return $this; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->framedItem !== null){ $this->itemRotation = ($this->itemRotation + 1) % self::ROTATIONS; @@ -150,7 +150,7 @@ class ItemFrame extends Flowable implements AnyFacing{ return true; } - public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ + public function onAttack(Item $item, Facing $face, ?Player $player = null) : bool{ if($this->framedItem === null){ return false; } @@ -164,7 +164,7 @@ class ItemFrame extends Flowable implements AnyFacing{ return true; } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ return $block->getAdjacentSupportType($face) !== SupportType::NONE; } @@ -174,7 +174,7 @@ class ItemFrame extends Flowable implements AnyFacing{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){ return false; } diff --git a/src/block/Jukebox.php b/src/block/Jukebox.php index a61dd06db..d2f39c7d7 100644 --- a/src/block/Jukebox.php +++ b/src/block/Jukebox.php @@ -27,6 +27,7 @@ use pocketmine\block\tile\Jukebox as JukeboxTile; use pocketmine\item\Item; use pocketmine\item\Record; use pocketmine\lang\KnownTranslationFactory; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\sound\RecordSound; @@ -40,7 +41,7 @@ class Jukebox extends Opaque{ return 300; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ if($this->record !== null){ $this->ejectRecord(); diff --git a/src/block/Ladder.php b/src/block/Ladder.php index 6edaebbf2..fe7a4b65f 100644 --- a/src/block/Ladder.php +++ b/src/block/Ladder.php @@ -60,14 +60,14 @@ class Ladder extends Transparent implements HorizontalFacing{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim($this->facing, 13 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy($this->facing, 13 / 16)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($this->canBeSupportedAt($blockReplace, Facing::opposite($face)) && Facing::axis($face) !== Axis::Y){ $this->facing = $face; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -82,7 +82,7 @@ class Ladder extends Transparent implements HorizontalFacing{ } } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ return $block->getAdjacentSupportType($face) === SupportType::FULL; } } diff --git a/src/block/Lantern.php b/src/block/Lantern.php index 302e69fd7..02e310768 100644 --- a/src/block/Lantern.php +++ b/src/block/Lantern.php @@ -62,18 +62,18 @@ class Lantern extends Transparent{ protected function recalculateCollisionBoxes() : array{ return [ AxisAlignedBB::one() - ->trim(Facing::UP, $this->hanging ? 6 / 16 : 8 / 16) - ->trim(Facing::DOWN, $this->hanging ? 2 / 16 : 0) - ->squash(Axis::X, 5 / 16) - ->squash(Axis::Z, 5 / 16) + ->trimmedCopy(Facing::UP, $this->hanging ? 6 / 16 : 8 / 16) + ->trimmedCopy(Facing::DOWN, $this->hanging ? 2 / 16 : 0) + ->squashedCopy(Axis::X, 5 / 16) + ->squashedCopy(Axis::Z, 5 / 16) ]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $downSupport = $this->canBeSupportedAt($blockReplace, Facing::DOWN); if(!$downSupport && !$this->canBeSupportedAt($blockReplace, Facing::UP)){ return false; @@ -90,7 +90,7 @@ class Lantern extends Transparent{ } } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ return $block->getAdjacentSupportType($face)->hasCenterSupport(); } } diff --git a/src/block/LavaCauldron.php b/src/block/LavaCauldron.php index 3df903e22..f89addd78 100644 --- a/src/block/LavaCauldron.php +++ b/src/block/LavaCauldron.php @@ -31,6 +31,7 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; use pocketmine\item\VanillaItems; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\sound\CauldronEmptyLavaSound; @@ -61,7 +62,7 @@ final class LavaCauldron extends FillableCauldron{ return new CauldronEmptyLavaSound(); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ match($item->getTypeId()){ ItemTypeIds::BUCKET => $this->removeFillLevels(self::MAX_FILL_LEVEL, $item, VanillaItems::LAVA_BUCKET(), $returnedItems), ItemTypeIds::POWDER_SNOW_BUCKET, ItemTypeIds::WATER_BUCKET => $this->mix($item, VanillaItems::BUCKET(), $returnedItems), diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 847536557..8ed99b411 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -134,7 +134,7 @@ class Leaves extends Transparent{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->noDecay = true; //artificial leaves don't decay return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -188,7 +188,7 @@ class Leaves extends Transparent{ return 60; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/Lectern.php b/src/block/Lectern.php index 9ba01c1c5..bfdbcb3ec 100644 --- a/src/block/Lectern.php +++ b/src/block/Lectern.php @@ -84,10 +84,10 @@ class Lectern extends Transparent implements HorizontalFacing{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 0.1)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 0.1)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -120,7 +120,7 @@ class Lectern extends Transparent implements HorizontalFacing{ return $this; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->book === null && $item instanceof WritableBookBase){ $world = $this->position->getWorld(); $world->setBlock($this->position, $this->setBook($item)); @@ -130,7 +130,7 @@ class Lectern extends Transparent implements HorizontalFacing{ return true; } - public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ + public function onAttack(Item $item, Facing $face, ?Player $player = null) : bool{ if($this->book !== null){ $world = $this->position->getWorld(); $world->dropItem($this->position->up(), $this->book); diff --git a/src/block/Lever.php b/src/block/Lever.php index d2b98efc3..24bbfc502 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -30,7 +30,6 @@ use pocketmine\math\Axis; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\utils\AssumptionFailedError; use pocketmine\world\BlockTransaction; use pocketmine\world\sound\RedstonePowerOffSound; use pocketmine\world\sound\RedstonePowerOnSound; @@ -60,7 +59,7 @@ class Lever extends Flowable{ return $this; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){ return false; } @@ -78,7 +77,6 @@ class Lever extends Flowable{ Facing::SOUTH => LeverFacing::SOUTH, Facing::WEST => LeverFacing::WEST, Facing::EAST => LeverFacing::EAST, - default => throw new AssumptionFailedError("Bad facing value"), }; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -90,7 +88,7 @@ class Lever extends Flowable{ } } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $this->activated = !$this->activated; $world = $this->position->getWorld(); $world->setBlock($this->position, $this); @@ -101,7 +99,7 @@ class Lever extends Flowable{ return true; } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ return $block->getAdjacentSupportType($face)->hasCenterSupport(); } diff --git a/src/block/Light.php b/src/block/Light.php index 29a3a8dfc..27bfbeab4 100644 --- a/src/block/Light.php +++ b/src/block/Light.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -51,12 +52,12 @@ final class Light extends Flowable{ public function canBeReplaced() : bool{ return true; } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ //light blocks behave like solid blocks when placing them on another light block return $blockReplace->canBeReplaced() && $blockReplace->getTypeId() !== $this->getTypeId(); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $this->level = $this->level === self::MAX_LIGHT_LEVEL ? self::MIN_LIGHT_LEVEL : $this->level + 1; diff --git a/src/block/LightningRod.php b/src/block/LightningRod.php index 9c1971229..f26f8212d 100644 --- a/src/block/LightningRod.php +++ b/src/block/LightningRod.php @@ -42,14 +42,14 @@ final class LightningRod extends Transparent implements AnyFacing{ $result = AxisAlignedBB::one(); foreach([Axis::X, Axis::Y, Axis::Z] as $axis){ if($axis !== $myAxis){ - $result->squash($axis, 6 / 16); + $result = $result->squashedCopy($axis, 6 / 16); } } return [$result]; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->facing = $face; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } diff --git a/src/block/Liquid.php b/src/block/Liquid.php index 813d76904..d47e21035 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -92,7 +92,7 @@ abstract class Liquid extends Transparent{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -170,7 +170,7 @@ abstract class Liquid extends Transparent{ $world = $this->position->getWorld(); foreach(Facing::HORIZONTAL as $j){ - [$dx, $dy, $dz] = Facing::OFFSET[$j]; + [$dx, $dy, $dz] = Facing::OFFSET[$j->value]; $sideX = $x + $dx; $sideY = $y + $dy; @@ -206,7 +206,7 @@ abstract class Liquid extends Transparent{ if($this->falling){ foreach(Facing::HORIZONTAL as $facing){ - [$dx, $dy, $dz] = Facing::OFFSET[$facing]; + [$dx, $dy, $dz] = Facing::OFFSET[$facing->value]; if( !$this->canFlowInto($world->getBlockAt($x + $dx, $y + $dy, $z + $dz)) || !$this->canFlowInto($world->getBlockAt($x + $dx, $y + $dy + 1, $z + $dz)) diff --git a/src/block/Loom.php b/src/block/Loom.php index a2b9fc235..693dd118e 100644 --- a/src/block/Loom.php +++ b/src/block/Loom.php @@ -27,13 +27,14 @@ use pocketmine\block\inventory\LoomInventory; use pocketmine\block\utils\FacesOppositePlacingPlayerTrait; use pocketmine\block\utils\HorizontalFacing; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; final class Loom extends Opaque implements HorizontalFacing{ use FacesOppositePlacingPlayerTrait; - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player !== null){ $player->setCurrentWindow(new LoomInventory($this->position)); return true; diff --git a/src/block/MobHead.php b/src/block/MobHead.php index 41e816c55..a943a9a98 100644 --- a/src/block/MobHead.php +++ b/src/block/MobHead.php @@ -41,7 +41,7 @@ class MobHead extends Flowable{ protected MobHeadType $mobHeadType = MobHeadType::SKELETON; - protected int $facing = Facing::NORTH; + protected Facing $facing = Facing::NORTH; protected int $rotation = self::MIN_ROTATION; //TODO: split this into floor skull and wall skull handling public function describeBlockItemState(RuntimeDataDescriber $w) : void{ @@ -82,10 +82,10 @@ class MobHead extends Flowable{ return $this; } - public function getFacing() : int{ return $this->facing; } + public function getFacing() : Facing{ return $this->facing; } /** @return $this */ - public function setFacing(int $facing) : self{ + public function setFacing(Facing $facing) : self{ if($facing === Facing::DOWN){ throw new \InvalidArgumentException("Skull may not face DOWN"); } @@ -106,17 +106,17 @@ class MobHead extends Flowable{ protected function recalculateCollisionBoxes() : array{ $collisionBox = AxisAlignedBB::one() - ->contract(0.25, 0, 0.25) - ->trim(Facing::UP, 0.5); + ->contractedCopy(0.25, 0, 0.25) + ->trimmedCopy(Facing::UP, 0.5); if($this->facing !== Facing::UP){ $collisionBox = $collisionBox - ->offsetTowards(Facing::opposite($this->facing), 0.25) - ->offsetTowards(Facing::UP, 0.25); + ->offsetTowardsCopy(Facing::opposite($this->facing), 0.25) + ->offsetTowardsCopy(Facing::UP, 0.25); } return [$collisionBox]; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face === Facing::DOWN){ return false; } diff --git a/src/block/MonsterSpawner.php b/src/block/MonsterSpawner.php index 5cbe80e0a..c11327507 100644 --- a/src/block/MonsterSpawner.php +++ b/src/block/MonsterSpawner.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\block\utils\SupportType; use pocketmine\item\Item; +use pocketmine\math\Facing; use function mt_rand; class MonsterSpawner extends Transparent{ @@ -41,7 +42,7 @@ class MonsterSpawner extends Transparent{ //TODO } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/NetherPortal.php b/src/block/NetherPortal.php index 1b199c603..2f00b44f2 100644 --- a/src/block/NetherPortal.php +++ b/src/block/NetherPortal.php @@ -28,16 +28,17 @@ use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\Entity; use pocketmine\item\Item; use pocketmine\math\Axis; +use pocketmine\math\Facing; class NetherPortal extends Transparent{ - protected int $axis = Axis::X; + protected Axis $axis = Axis::X; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalAxis($this->axis); } - public function getAxis() : int{ + public function getAxis() : Axis{ return $this->axis; } @@ -45,7 +46,7 @@ class NetherPortal extends Transparent{ * @throws \InvalidArgumentException * @return $this */ - public function setAxis(int $axis) : self{ + public function setAxis(Axis $axis) : self{ if($axis !== Axis::X && $axis !== Axis::Z){ throw new \InvalidArgumentException("Invalid axis"); } @@ -65,7 +66,7 @@ class NetherPortal extends Transparent{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } diff --git a/src/block/NetherVines.php b/src/block/NetherVines.php index 67a0b6f94..98464ed58 100644 --- a/src/block/NetherVines.php +++ b/src/block/NetherVines.php @@ -49,9 +49,9 @@ class NetherVines extends Flowable implements Ageable{ public const MAX_AGE = 25; /** Direction the vine grows towards. */ - private int $growthFace; + private Facing $growthFace; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, int $growthFace){ + public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, Facing $growthFace){ $this->growthFace = $growthFace; parent::__construct($idInfo, $name, $typeInfo); } @@ -80,12 +80,12 @@ class NetherVines extends Flowable implements Ageable{ return $top; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->age = mt_rand(0, self::MAX_AGE - 1); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer){ if($this->grow($player, mt_rand(1, 5))){ $item->pop(); @@ -159,7 +159,7 @@ class NetherVines extends Flowable implements Ageable{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/OminousFloorBanner.php b/src/block/OminousFloorBanner.php index 240aeccfc..f4a03664f 100644 --- a/src/block/OminousFloorBanner.php +++ b/src/block/OminousFloorBanner.php @@ -36,11 +36,11 @@ final class OminousFloorBanner extends BaseOminousBanner implements SignLikeRota //TODO: duplicated code :( - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::DOWN; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face !== Facing::UP){ return false; } diff --git a/src/block/OminousWallBanner.php b/src/block/OminousWallBanner.php index 1eb5ba753..cc89b4192 100644 --- a/src/block/OminousWallBanner.php +++ b/src/block/OminousWallBanner.php @@ -35,11 +35,11 @@ use pocketmine\world\BlockTransaction; final class OminousWallBanner extends BaseOminousBanner implements HorizontalFacing{ use HorizontalFacingTrait; - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::opposite($this->facing); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(Facing::axis($face) === Axis::Y){ return false; } diff --git a/src/block/PinkPetals.php b/src/block/PinkPetals.php index b8b6e248c..83ba482fd 100644 --- a/src/block/PinkPetals.php +++ b/src/block/PinkPetals.php @@ -70,11 +70,11 @@ class PinkPetals extends Flowable implements HorizontalFacing{ return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD); } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ return ($blockReplace instanceof PinkPetals && $blockReplace->count < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($blockReplace instanceof PinkPetals && $blockReplace->count < self::MAX_COUNT){ $this->count = $blockReplace->count + 1; $this->facing = $blockReplace->facing; @@ -84,7 +84,7 @@ class PinkPetals extends Flowable implements HorizontalFacing{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer){ $grew = false; if($this->count < self::MAX_COUNT){ diff --git a/src/block/PitcherCrop.php b/src/block/PitcherCrop.php index 1c771bb8a..7223dc66d 100644 --- a/src/block/PitcherCrop.php +++ b/src/block/PitcherCrop.php @@ -54,10 +54,10 @@ final class PitcherCrop extends Flowable implements Ageable{ $heightTrim = $this->age === 0 ? 13 : 11; return [ AxisAlignedBB::one() - ->trim(Facing::UP, $heightTrim / 16) - ->squash(Axis::X, $widthTrim / 16) - ->squash(Axis::Z, $widthTrim / 16) - ->extend(Facing::DOWN, 1 / 16) //presumably this is to correct for farmland being 15/16 of a block tall + ->trimmedCopy(Facing::UP, $heightTrim / 16) + ->squashedCopy(Axis::X, $widthTrim / 16) + ->squashedCopy(Axis::Z, $widthTrim / 16) + ->extendedCopy(Facing::DOWN, 1 / 16) //presumably this is to correct for farmland being 15/16 of a block tall ]; } @@ -85,7 +85,7 @@ final class PitcherCrop extends Flowable implements Ageable{ return BlockEventHelper::grow($this, (clone $this)->setAge($this->age + 1), $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer && $this->grow($player)){ $item->pop(); return true; diff --git a/src/block/PotionCauldron.php b/src/block/PotionCauldron.php index ca91664e4..92a5507ee 100644 --- a/src/block/PotionCauldron.php +++ b/src/block/PotionCauldron.php @@ -27,6 +27,7 @@ use pocketmine\block\tile\Cauldron as TileCauldron; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; use pocketmine\item\VanillaItems; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\sound\CauldronEmptyPotionSound; @@ -94,7 +95,7 @@ final class PotionCauldron extends FillableCauldron{ } } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ match($item->getTypeId()){ ItemTypeIds::LINGERING_POTION, ItemTypeIds::POTION, ItemTypeIds::SPLASH_POTION => $this->addFillLevelsOrMix(self::POTION_FILL_AMOUNT, $item, VanillaItems::GLASS_BOTTLE(), $returnedItems), ItemTypeIds::GLASS_BOTTLE => $this->potionItem === null ? null : $this->removeFillLevels(self::POTION_FILL_AMOUNT, $item, clone $this->potionItem, $returnedItems), diff --git a/src/block/PressurePlate.php b/src/block/PressurePlate.php index 1dd4b50d9..b96154a15 100644 --- a/src/block/PressurePlate.php +++ b/src/block/PressurePlate.php @@ -57,7 +57,7 @@ abstract class PressurePlate extends Transparent{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -83,10 +83,10 @@ abstract class PressurePlate extends Transparent{ */ protected function getActivationBox() : AxisAlignedBB{ return AxisAlignedBB::one() - ->squash(Axis::X, 1 / 8) - ->squash(Axis::Z, 1 / 8) - ->trim(Facing::UP, 3 / 4) - ->offset($this->position->x, $this->position->y, $this->position->z); + ->squashedCopy(Axis::X, 1 / 8) + ->squashedCopy(Axis::Z, 1 / 8) + ->trimmedCopy(Facing::UP, 3 / 4) + ->offsetCopy($this->position->x, $this->position->y, $this->position->z); } /** diff --git a/src/block/Pumpkin.php b/src/block/Pumpkin.php index 1b7f6a9cd..f268be656 100644 --- a/src/block/Pumpkin.php +++ b/src/block/Pumpkin.php @@ -33,7 +33,7 @@ use function in_array; class Pumpkin extends Opaque{ - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Shears && in_array($face, Facing::HORIZONTAL, true)){ $item->applyDamage(1); $world = $this->position->getWorld(); diff --git a/src/block/Rail.php b/src/block/Rail.php index f516902f0..faed53c9b 100644 --- a/src/block/Rail.php +++ b/src/block/Rail.php @@ -60,8 +60,8 @@ class Rail extends BaseRail{ Facing::WEST, Facing::EAST ] as $d){ - if($constraint !== $d){ - $possible[$d] = true; + if($constraint !== $d->value){ + $possible[$d->value] = true; } } } diff --git a/src/block/RedMushroom.php b/src/block/RedMushroom.php index 81ab940f5..a012fd4c7 100644 --- a/src/block/RedMushroom.php +++ b/src/block/RedMushroom.php @@ -41,7 +41,7 @@ class RedMushroom extends Flowable{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); $position = $this->position; $lightLevel = $position->getWorld()->getFullLightAt($position->x, $position->y, $position->z); diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index 88050b85a..49dc52529 100644 --- a/src/block/RedstoneComparator.php +++ b/src/block/RedstoneComparator.php @@ -83,17 +83,17 @@ class RedstoneComparator extends Flowable implements AnalogRedstoneSignalEmitter } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 7 / 8)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 7 / 8)]; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->facing = Facing::opposite($player->getHorizontalFacing()); } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $this->isSubtractMode = !$this->isSubtractMode; $this->position->getWorld()->setBlock($this->position, $this); return true; diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index 3477a3519..52a5f5432 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -28,6 +28,7 @@ use pocketmine\block\utils\Lightable; use pocketmine\block\utils\LightableTrait; use pocketmine\item\Item; use pocketmine\item\VanillaItems; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use function mt_rand; @@ -39,7 +40,7 @@ class RedstoneOre extends Opaque implements Lightable{ return $this->lit ? 9 : 0; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if(!$this->lit){ $this->lit = true; $this->position->getWorld()->setBlock($this->position, $this); //no return here - this shouldn't prevent block placement diff --git a/src/block/RedstoneRepeater.php b/src/block/RedstoneRepeater.php index 4059ff1cc..e7cf9187c 100644 --- a/src/block/RedstoneRepeater.php +++ b/src/block/RedstoneRepeater.php @@ -65,10 +65,10 @@ class RedstoneRepeater extends Flowable implements PoweredByRedstone, Horizontal } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 7 / 8)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 7 / 8)]; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->facing = Facing::opposite($player->getHorizontalFacing()); } @@ -76,7 +76,7 @@ class RedstoneRepeater extends Flowable implements PoweredByRedstone, Horizontal return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if(++$this->delay > self::MAX_DELAY){ $this->delay = self::MIN_DELAY; } diff --git a/src/block/ResinClump.php b/src/block/ResinClump.php index a56a386d4..044128cf8 100644 --- a/src/block/ResinClump.php +++ b/src/block/ResinClump.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\block\utils\MultiAnyFacing; use pocketmine\block\utils\MultiAnySupportTrait; use pocketmine\block\utils\SupportType; +use pocketmine\math\Facing; final class ResinClump extends Transparent implements MultiAnyFacing{ use MultiAnySupportTrait; @@ -34,7 +35,7 @@ final class ResinClump extends Transparent implements MultiAnyFacing{ return false; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } @@ -43,7 +44,7 @@ final class ResinClump extends Transparent implements MultiAnyFacing{ } /** - * @return int[] + * @return Facing[] */ protected function getInitialPlaceFaces(Block $blockReplace) : array{ return $blockReplace instanceof ResinClump ? $blockReplace->faces : []; diff --git a/src/block/RespawnAnchor.php b/src/block/RespawnAnchor.php index e19ea8f6d..b57d851fe 100644 --- a/src/block/RespawnAnchor.php +++ b/src/block/RespawnAnchor.php @@ -29,6 +29,7 @@ use pocketmine\event\player\PlayerRespawnAnchorUseEvent; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; use pocketmine\lang\KnownTranslationFactory; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\utils\TextFormat; @@ -64,7 +65,7 @@ final class RespawnAnchor extends Opaque{ return $this->charges > 0 ? ($this->charges * 4) - 1 : 0; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item->getTypeId() === ItemTypeIds::fromBlockTypeId(BlockTypeIds::GLOWSTONE) && $this->charges < self::MAX_CHARGES){ $this->position->getWorld()->setBlock($this->position, $this->setCharges($this->charges + 1)); $this->position->getWorld()->addSound($this->position, new RespawnAnchorChargeSound()); diff --git a/src/block/Sapling.php b/src/block/Sapling.php index b3fdf59af..313d8b7d4 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -65,7 +65,7 @@ class Sapling extends Flowable{ return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer && $this->grow($player)){ $item->pop(); diff --git a/src/block/SeaPickle.php b/src/block/SeaPickle.php index 34f5c3e9e..51d450645 100644 --- a/src/block/SeaPickle.php +++ b/src/block/SeaPickle.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\BlockTransaction; @@ -73,16 +74,16 @@ class SeaPickle extends Transparent{ return []; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ //TODO: proper placement logic (needs a supporting face below) return ($blockReplace instanceof SeaPickle && $blockReplace->count < self::MAX_COUNT) || parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->underwater = false; //TODO: implement this once we have new water logic in place if($blockReplace instanceof SeaPickle && $blockReplace->count < self::MAX_COUNT){ $this->count = $blockReplace->count + 1; @@ -91,7 +92,7 @@ class SeaPickle extends Transparent{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ //TODO: bonemeal logic (requires coral) return parent::onInteract($item, $face, $clickVector, $player, $returnedItems); } diff --git a/src/block/ShulkerBox.php b/src/block/ShulkerBox.php index 52a3b83cd..2d46c5712 100644 --- a/src/block/ShulkerBox.php +++ b/src/block/ShulkerBox.php @@ -29,6 +29,7 @@ use pocketmine\block\utils\AnyFacingTrait; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\BlockTransaction; @@ -62,7 +63,7 @@ class ShulkerBox extends Opaque implements AnyFacing{ return 1; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->facing = $face; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -94,7 +95,7 @@ class ShulkerBox extends Opaque implements AnyFacing{ return $result; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $shulker = $this->position->getWorld()->getTile($this->position); @@ -113,7 +114,7 @@ class ShulkerBox extends Opaque implements AnyFacing{ return true; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/Slab.php b/src/block/Slab.php index 2bbb7528c..0ecee2571 100644 --- a/src/block/Slab.php +++ b/src/block/Slab.php @@ -63,7 +63,7 @@ class Slab extends Transparent{ return $this; } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ if(parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock)){ return true; } @@ -79,7 +79,7 @@ class Slab extends Transparent{ return false; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ 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)) @@ -97,10 +97,10 @@ class Slab extends Transparent{ if($this->slabType === SlabType::DOUBLE){ return [AxisAlignedBB::one()]; } - return [AxisAlignedBB::one()->trim($this->slabType === SlabType::TOP ? Facing::DOWN : Facing::UP, 0.5)]; + return [AxisAlignedBB::one()->trimmedCopy($this->slabType === SlabType::TOP ? Facing::DOWN : Facing::UP, 0.5)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ if($this->slabType === SlabType::DOUBLE){ return SupportType::FULL; }elseif(($facing === Facing::UP && $this->slabType === SlabType::TOP) || ($facing === Facing::DOWN && $this->slabType === SlabType::BOTTOM)){ diff --git a/src/block/SmallDripleaf.php b/src/block/SmallDripleaf.php index 846be5c93..76031fd9b 100644 --- a/src/block/SmallDripleaf.php +++ b/src/block/SmallDripleaf.php @@ -75,7 +75,7 @@ class SmallDripleaf extends Transparent implements HorizontalFacing{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $block = $blockReplace->getSide(Facing::UP); if($block->getTypeId() !== BlockTypeIds::AIR || !$this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){ return false; @@ -91,7 +91,7 @@ class SmallDripleaf extends Transparent implements HorizontalFacing{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer && $this->grow($player)){ $item->pop(); return true; @@ -161,7 +161,7 @@ class SmallDripleaf extends Transparent implements HorizontalFacing{ return 100; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } diff --git a/src/block/SmithingTable.php b/src/block/SmithingTable.php index 741e9c02f..818bedf4d 100644 --- a/src/block/SmithingTable.php +++ b/src/block/SmithingTable.php @@ -25,12 +25,13 @@ namespace pocketmine\block; use pocketmine\block\inventory\SmithingTableInventory; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; final class SmithingTable extends Opaque{ - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player !== null){ $player->setCurrentWindow(new SmithingTableInventory($this->position)); } diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index 8549f0b31..8669bdd65 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -67,10 +67,10 @@ class SnowLayer extends Flowable implements Fallable{ protected function recalculateCollisionBoxes() : array{ //TODO: this zero-height BB is intended to stay in lockstep with a MCPE bug - return [AxisAlignedBB::one()->trim(Facing::UP, $this->layers >= 4 ? 0.5 : 1)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, $this->layers >= 4 ? 0.5 : 1)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ if(!$this->canBeReplaced()){ return SupportType::FULL; } @@ -81,7 +81,7 @@ class SnowLayer extends Flowable implements Fallable{ 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{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($blockReplace instanceof SnowLayer){ if($blockReplace->layers >= self::MAX_LAYERS){ return false; diff --git a/src/block/SoulSand.php b/src/block/SoulSand.php index e1285d095..e1b30a90d 100644 --- a/src/block/SoulSand.php +++ b/src/block/SoulSand.php @@ -29,6 +29,6 @@ use pocketmine\math\Facing; class SoulSand extends Opaque{ protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 1 / 8)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 1 / 8)]; } } diff --git a/src/block/Stair.php b/src/block/Stair.php index 56101de13..72e62b6eb 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -83,21 +83,21 @@ class Stair extends Transparent implements HorizontalFacing{ protected function recalculateCollisionBoxes() : array{ $topStepFace = $this->upsideDown ? Facing::DOWN : Facing::UP; $bbs = [ - AxisAlignedBB::one()->trim($topStepFace, 0.5) + AxisAlignedBB::one()->trimmedCopy($topStepFace, 0.5) ]; $topStep = AxisAlignedBB::one() - ->trim(Facing::opposite($topStepFace), 0.5) - ->trim(Facing::opposite($this->facing), 0.5); + ->trimmedCopy(Facing::opposite($topStepFace), 0.5) + ->trimmedCopy(Facing::opposite($this->facing), 0.5); if($this->shape === StairShape::OUTER_LEFT || $this->shape === StairShape::OUTER_RIGHT){ - $topStep->trim(Facing::rotateY($this->facing, $this->shape === StairShape::OUTER_LEFT), 0.5); + $topStep = $topStep->trimmedCopy(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 === StairShape::INNER_LEFT), 0.5); + ->trimmedCopy(Facing::opposite($topStepFace), 0.5) + ->trimmedCopy($this->facing, 0.5) //avoid overlapping with main step + ->trimmedCopy(Facing::rotateY($this->facing, $this->shape === StairShape::INNER_LEFT), 0.5); } $bbs[] = $topStep; @@ -105,7 +105,7 @@ class Stair extends Transparent implements HorizontalFacing{ return $bbs; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ if( $facing === Facing::UP && $this->upsideDown || $facing === Facing::DOWN && !$this->upsideDown || @@ -118,7 +118,7 @@ class Stair extends Transparent implements HorizontalFacing{ return SupportType::NONE; } - private function getPossibleCornerFacing(bool $oppositeFacing) : ?int{ + private function getPossibleCornerFacing(bool $oppositeFacing) : ?Facing{ $side = $this->getSide($oppositeFacing ? Facing::opposite($this->facing) : $this->facing); return ( $side instanceof Stair && @@ -127,7 +127,7 @@ class Stair extends Transparent implements HorizontalFacing{ ) ? $side->facing : null; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->facing = $player->getHorizontalFacing(); } diff --git a/src/block/Stem.php b/src/block/Stem.php index 2b6f2150c..8dbe915f1 100644 --- a/src/block/Stem.php +++ b/src/block/Stem.php @@ -33,17 +33,17 @@ use pocketmine\math\Facing; use function array_rand; abstract class Stem extends Crops{ - protected int $facing = Facing::UP; + protected Facing $facing = Facing::UP; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ parent::describeBlockOnlyState($w); $w->facingExcept($this->facing, Facing::DOWN); } - public function getFacing() : int{ return $this->facing; } + public function getFacing() : Facing{ return $this->facing; } /** @return $this */ - public function setFacing(int $facing) : self{ + public function setFacing(Facing $facing) : self{ if($facing === Facing::DOWN){ throw new \InvalidArgumentException("DOWN is not a valid facing for this block"); } diff --git a/src/block/Stonecutter.php b/src/block/Stonecutter.php index 0fd259326..3f955b785 100644 --- a/src/block/Stonecutter.php +++ b/src/block/Stonecutter.php @@ -36,7 +36,7 @@ use pocketmine\player\Player; class Stonecutter extends Transparent implements HorizontalFacing{ use FacesOppositePlacingPlayerTrait; - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player !== null){ $player->setCurrentWindow(new StonecutterInventory($this->position)); } @@ -44,10 +44,10 @@ class Stonecutter extends Transparent implements HorizontalFacing{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim(Facing::UP, 7 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 7 / 16)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index 0874413c5..0f8d7e13c 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -75,7 +75,7 @@ class Sugarcane extends Flowable implements Ageable{ return $grew; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer){ if($this->grow($this->seekToBottom(), $player)){ $item->pop(); @@ -116,7 +116,7 @@ class Sugarcane extends Flowable implements Ageable{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $down = $blockReplace->getSide(Facing::DOWN); if($down->hasSameTypeId($this)){ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); diff --git a/src/block/SweetBerryBush.php b/src/block/SweetBerryBush.php index baebb7588..1b7ce5bad 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -65,7 +65,7 @@ class SweetBerryBush extends Flowable implements Ageable{ ($supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD)); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $world = $this->position->getWorld(); if($this->age < self::STAGE_MATURE && $item instanceof Fertilizer){ $block = clone $this; diff --git a/src/block/TNT.php b/src/block/TNT.php index a0256bb67..20543dcbd 100644 --- a/src/block/TNT.php +++ b/src/block/TNT.php @@ -32,6 +32,7 @@ use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\FlintSteel; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; +use pocketmine\math\Facing; use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -77,7 +78,7 @@ class TNT extends Opaque{ return parent::onBreak($item, $player, $returnedItems); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE){ $item->pop(); $this->ignite(); diff --git a/src/block/Thin.php b/src/block/Thin.php index 82010697a..585f70a80 100644 --- a/src/block/Thin.php +++ b/src/block/Thin.php @@ -44,9 +44,9 @@ 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)) === SupportType::FULL){ - $this->connections[$facing] = true; + $this->connections[$facing->value] = true; }else{ - unset($this->connections[$facing]); + unset($this->connections[$facing->value]); } } @@ -58,24 +58,24 @@ class Thin extends Transparent{ $bbs = []; - if(isset($this->connections[Facing::WEST]) || isset($this->connections[Facing::EAST])){ - $bb = AxisAlignedBB::one()->squash(Axis::Z, $inset); + if(isset($this->connections[Facing::WEST->value]) || isset($this->connections[Facing::EAST->value])){ + $bb = AxisAlignedBB::one()->squashedCopy(Axis::Z, $inset); - if(!isset($this->connections[Facing::WEST])){ - $bb->trim(Facing::WEST, $inset); - }elseif(!isset($this->connections[Facing::EAST])){ - $bb->trim(Facing::EAST, $inset); + if(!isset($this->connections[Facing::WEST->value])){ + $bb = $bb->trimmedCopy(Facing::WEST, $inset); + }elseif(!isset($this->connections[Facing::EAST->value])){ + $bb = $bb->trimmedCopy(Facing::EAST, $inset); } $bbs[] = $bb; } - if(isset($this->connections[Facing::NORTH]) || isset($this->connections[Facing::SOUTH])){ - $bb = AxisAlignedBB::one()->squash(Axis::X, $inset); + if(isset($this->connections[Facing::NORTH->value]) || isset($this->connections[Facing::SOUTH->value])){ + $bb = AxisAlignedBB::one()->squashedCopy(Axis::X, $inset); - if(!isset($this->connections[Facing::NORTH])){ - $bb->trim(Facing::NORTH, $inset); - }elseif(!isset($this->connections[Facing::SOUTH])){ - $bb->trim(Facing::SOUTH, $inset); + if(!isset($this->connections[Facing::NORTH->value])){ + $bb = $bb->trimmedCopy(Facing::NORTH, $inset); + }elseif(!isset($this->connections[Facing::SOUTH->value])){ + $bb = $bb->trimmedCopy(Facing::SOUTH, $inset); } $bbs[] = $bb; } @@ -83,14 +83,14 @@ class Thin extends Transparent{ if(count($bbs) === 0){ //centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made) return [ - AxisAlignedBB::one()->contract($inset, 0, $inset) + AxisAlignedBB::one()->contractedCopy($inset, 0, $inset) ]; } return $bbs; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } } diff --git a/src/block/Torch.php b/src/block/Torch.php index aee4da32a..3d108a816 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -33,16 +33,16 @@ use pocketmine\world\BlockTransaction; class Torch extends Flowable{ - protected int $facing = Facing::UP; + protected Facing $facing = Facing::UP; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facingExcept($this->facing, Facing::DOWN); } - public function getFacing() : int{ return $this->facing; } + public function getFacing() : Facing{ return $this->facing; } /** @return $this */ - public function setFacing(int $facing) : self{ + public function setFacing(Facing $facing) : self{ if($facing === Facing::DOWN){ throw new \InvalidArgumentException("Torch may not face DOWN"); } @@ -60,7 +60,7 @@ class Torch extends Flowable{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face !== Facing::DOWN && $this->canBeSupportedAt($blockReplace, Facing::opposite($face))){ $this->facing = $face; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -81,7 +81,7 @@ class Torch extends Flowable{ return false; } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ return $face === Facing::DOWN ? $block->getAdjacentSupportType($face)->hasCenterSupport() : $block->getAdjacentSupportType($face) === SupportType::FULL; diff --git a/src/block/TorchflowerCrop.php b/src/block/TorchflowerCrop.php index 033b08552..a5dc2dcbb 100644 --- a/src/block/TorchflowerCrop.php +++ b/src/block/TorchflowerCrop.php @@ -62,7 +62,7 @@ final class TorchflowerCrop extends Flowable{ } } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer){ if(BlockEventHelper::grow($this, $this->getNextState(), $player)){ $item->pop(); diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index 5e8a7dc3f..8b9a10d41 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -64,14 +64,14 @@ class Trapdoor extends Transparent implements HorizontalFacing{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->trim($this->open ? $this->facing : ($this->top ? Facing::DOWN : Facing::UP), 13 / 16)]; + return [AxisAlignedBB::one()->trimmedCopy($this->open ? $this->facing : ($this->top ? Facing::DOWN : Facing::UP), 13 / 16)]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return SupportType::NONE; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->facing = Facing::opposite($player->getHorizontalFacing()); } @@ -82,7 +82,7 @@ class Trapdoor extends Transparent implements HorizontalFacing{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $this->open = !$this->open; $world = $this->position->getWorld(); $world->setBlock($this->position, $this); diff --git a/src/block/TripwireHook.php b/src/block/TripwireHook.php index 4e40cf62e..0fe43da56 100644 --- a/src/block/TripwireHook.php +++ b/src/block/TripwireHook.php @@ -61,7 +61,7 @@ class TripwireHook extends Flowable implements HorizontalFacing{ return $this; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(Facing::axis($face) !== Axis::Y){ //TODO: check face is valid $this->facing = $face; diff --git a/src/block/Vine.php b/src/block/Vine.php index cc516bbca..9ac4a3ade 100644 --- a/src/block/Vine.php +++ b/src/block/Vine.php @@ -36,22 +36,22 @@ use function count; class Vine extends Flowable{ - /** @var int[] */ + /** @var Facing[] */ protected array $faces = []; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacingFlags($this->faces); } - /** @return int[] */ + /** @return Facing[] */ public function getFaces() : array{ return $this->faces; } - public function hasFace(int $face) : bool{ - return isset($this->faces[$face]); + public function hasFace(Facing $face) : bool{ + return isset($this->faces[$face->value]); } /** - * @param int[] $faces + * @param Facing[] $faces * @phpstan-param list $faces * @return $this */ @@ -61,21 +61,21 @@ class Vine extends Flowable{ if($face !== Facing::NORTH && $face !== Facing::SOUTH && $face !== Facing::WEST && $face !== Facing::EAST){ throw new \InvalidArgumentException("Facing can only be north, east, south or west"); } - $uniqueFaces[$face] = $face; + $uniqueFaces[$face->value] = $face; } $this->faces = $uniqueFaces; return $this; } /** @return $this */ - public function setFace(int $face, bool $value) : self{ + public function setFace(Facing $face, bool $value) : self{ if($face !== Facing::NORTH && $face !== Facing::SOUTH && $face !== Facing::WEST && $face !== Facing::EAST){ throw new \InvalidArgumentException("Facing can only be north, east, south or west"); } if($value){ - $this->faces[$face] = $face; + $this->faces[$face->value] = $face; }else{ - unset($this->faces[$face]); + unset($this->faces[$face->value]); } return $this; } @@ -101,13 +101,14 @@ class Vine extends Flowable{ return []; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$blockReplace->getSide(Facing::opposite($face))->isFullCube() || Facing::axis($face) === Axis::Y){ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ + $opposite = Facing::opposite($face); + if(!$blockReplace->getSide($opposite)->isFullCube() || Facing::axis($face) === Axis::Y){ return false; } $this->faces = $blockReplace instanceof Vine ? $blockReplace->faces : []; - $this->faces[Facing::opposite($face)] = Facing::opposite($face); + $this->faces[$opposite->value] = $opposite; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -120,8 +121,8 @@ class Vine extends Flowable{ $supportedFaces = $up instanceof Vine ? array_intersect_key($this->faces, $up->faces) : []; foreach($this->faces as $face){ - if(!isset($supportedFaces[$face]) && !$this->getSide($face)->isSolid()){ - unset($this->faces[$face]); + if(!isset($supportedFaces[$face->value]) && !$this->getSide($face)->isSolid()){ + unset($this->faces[$face->value]); $changed = true; } } diff --git a/src/block/Wall.php b/src/block/Wall.php index 520ced8eb..b39e35c4b 100644 --- a/src/block/Wall.php +++ b/src/block/Wall.php @@ -31,7 +31,7 @@ use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; /** - * @phpstan-type WallConnectionSet array + * @phpstan-type WallConnectionSet array, WallConnectionType> */ class Wall extends Transparent{ @@ -53,8 +53,8 @@ class Wall extends Transparent{ */ public function getConnections() : array{ return $this->connections; } - public function getConnection(int $face) : ?WallConnectionType{ - return $this->connections[$face] ?? null; + public function getConnection(Facing $face) : ?WallConnectionType{ + return $this->connections[$face->value] ?? null; } /** @@ -68,14 +68,14 @@ class Wall extends Transparent{ } /** @return $this */ - public function setConnection(int $face, ?WallConnectionType $type) : self{ + public function setConnection(Facing $face, ?WallConnectionType $type) : self{ if($face !== Facing::NORTH && $face !== Facing::SOUTH && $face !== Facing::WEST && $face !== Facing::EAST){ throw new \InvalidArgumentException("Facing can only be north, east, south or west"); } if($type !== null){ - $this->connections[$face] = $type; + $this->connections[$face->value] = $type; }else{ - unset($this->connections[$face]); + unset($this->connections[$face->value]); } return $this; } @@ -102,12 +102,12 @@ 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)) === SupportType::FULL){ - if(!isset($this->connections[$facing])){ - $this->connections[$facing] = WallConnectionType::SHORT; + if(!isset($this->connections[$facing->value])){ + $this->connections[$facing->value] = WallConnectionType::SHORT; $changed++; } - }elseif(isset($this->connections[$facing])){ - unset($this->connections[$facing]); + }elseif(isset($this->connections[$facing->value])){ + unset($this->connections[$facing->value]); $changed++; } } @@ -124,10 +124,10 @@ class Wall extends Transparent{ protected function recalculateCollisionBoxes() : array{ //walls don't have any special collision boxes like fences do - $north = isset($this->connections[Facing::NORTH]); - $south = isset($this->connections[Facing::SOUTH]); - $west = isset($this->connections[Facing::WEST]); - $east = isset($this->connections[Facing::EAST]); + $north = isset($this->connections[Facing::NORTH->value]); + $south = isset($this->connections[Facing::SOUTH->value]); + $west = isset($this->connections[Facing::WEST->value]); + $east = isset($this->connections[Facing::EAST->value]); $inset = 0.25; if( @@ -143,15 +143,15 @@ class Wall extends Transparent{ return [ AxisAlignedBB::one() - ->extend(Facing::UP, 0.5) - ->trim(Facing::NORTH, $north ? 0 : $inset) - ->trim(Facing::SOUTH, $south ? 0 : $inset) - ->trim(Facing::WEST, $west ? 0 : $inset) - ->trim(Facing::EAST, $east ? 0 : $inset) + ->extendedCopy(Facing::UP, 0.5) + ->trimmedCopy(Facing::NORTH, $north ? 0 : $inset) + ->trimmedCopy(Facing::SOUTH, $south ? 0 : $inset) + ->trimmedCopy(Facing::WEST, $west ? 0 : $inset) + ->trimmedCopy(Facing::EAST, $east ? 0 : $inset) ]; } - public function getSupportType(int $facing) : SupportType{ + public function getSupportType(Facing $facing) : SupportType{ return Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } } diff --git a/src/block/WallBanner.php b/src/block/WallBanner.php index b631e0c81..9159c2485 100644 --- a/src/block/WallBanner.php +++ b/src/block/WallBanner.php @@ -39,11 +39,11 @@ final class WallBanner extends BaseBanner implements HorizontalFacing{ return VanillaBlocks::OMINOUS_WALL_BANNER()->setFacing($this->facing); } - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::opposite($this->facing); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(Facing::axis($face) === Axis::Y){ return false; } diff --git a/src/block/WallCoralFan.php b/src/block/WallCoralFan.php index 67745a537..74ec3dcc4 100644 --- a/src/block/WallCoralFan.php +++ b/src/block/WallCoralFan.php @@ -41,7 +41,7 @@ final class WallCoralFan extends BaseCoral implements HorizontalFacing{ $w->horizontalFacing($this->facing); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $axis = Facing::axis($face); if(($axis !== Axis::X && $axis !== Axis::Z) || !$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){ return false; @@ -62,7 +62,7 @@ final class WallCoralFan extends BaseCoral implements HorizontalFacing{ } } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ return $block->getAdjacentSupportType($face)->hasCenterSupport(); } diff --git a/src/block/WallHangingSign.php b/src/block/WallHangingSign.php index df959c720..f03ff5927 100644 --- a/src/block/WallHangingSign.php +++ b/src/block/WallHangingSign.php @@ -37,7 +37,7 @@ use pocketmine\world\BlockTransaction; final class WallHangingSign extends BaseSign implements HorizontalFacing{ use HorizontalFacingTrait; - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::rotateY($this->facing, clockwise: true); } @@ -47,10 +47,10 @@ final class WallHangingSign extends BaseSign implements HorizontalFacing{ protected function recalculateCollisionBoxes() : array{ //only the cross bar is collidable - return [AxisAlignedBB::one()->trim(Facing::DOWN, 7 / 8)->squash(Facing::axis($this->facing), 3 / 4)]; + return [AxisAlignedBB::one()->trimmedCopy(Facing::DOWN, 7 / 8)->squashedCopy(Facing::axis($this->facing), 3 / 4)]; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player === null){ return false; } @@ -73,7 +73,7 @@ final class WallHangingSign extends BaseSign implements HorizontalFacing{ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - private function canBeSupportedAt(Block $block, int $face) : bool{ + private function canBeSupportedAt(Block $block, Facing $face) : bool{ return ($block instanceof WallHangingSign && Facing::axis(Facing::rotateY($block->getFacing(), clockwise: true)) === Facing::axis($face)) || $block->getSupportType(Facing::opposite($face)) === SupportType::FULL; diff --git a/src/block/WallSign.php b/src/block/WallSign.php index c6b42608d..8a7bd8eb3 100644 --- a/src/block/WallSign.php +++ b/src/block/WallSign.php @@ -35,11 +35,11 @@ use pocketmine\world\BlockTransaction; final class WallSign extends BaseSign implements HorizontalFacing{ use HorizontalFacingTrait; - protected function getSupportingFace() : int{ + protected function getSupportingFace() : Facing{ return Facing::opposite($this->facing); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(Facing::axis($face) === Axis::Y){ return false; } diff --git a/src/block/WaterCauldron.php b/src/block/WaterCauldron.php index 8129f2960..60bdc132e 100644 --- a/src/block/WaterCauldron.php +++ b/src/block/WaterCauldron.php @@ -37,6 +37,7 @@ use pocketmine\item\Potion; use pocketmine\item\PotionType; use pocketmine\item\SplashPotion; use pocketmine\item\VanillaItems; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\sound\CauldronAddDyeSound; @@ -108,7 +109,7 @@ final class WaterCauldron extends FillableCauldron{ return new CauldronEmptyWaterSound(); } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $world = $this->position->getWorld(); if(($dyeColor = match($item->getTypeId()){ ItemTypeIds::LAPIS_LAZULI => DyeColor::BLUE, diff --git a/src/block/WaterLily.php b/src/block/WaterLily.php index b04b1baed..d71a9d85b 100644 --- a/src/block/WaterLily.php +++ b/src/block/WaterLily.php @@ -34,10 +34,10 @@ class WaterLily extends Flowable{ } protected function recalculateCollisionBoxes() : array{ - return [AxisAlignedBB::one()->contract(1 / 16, 0, 1 / 16)->trim(Facing::UP, 63 / 64)]; + return [AxisAlignedBB::one()->contractedCopy(1 / 16, 0, 1 / 16)->trimmedCopy(Facing::UP, 63 / 64)]; } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ return !$blockReplace instanceof Water && $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } diff --git a/src/block/Wood.php b/src/block/Wood.php index 7aa667bc8..6dc27efbe 100644 --- a/src/block/Wood.php +++ b/src/block/Wood.php @@ -30,6 +30,7 @@ use pocketmine\block\utils\WoodTypeTrait; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Axe; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\sound\ItemUseOnBlockSound; @@ -64,7 +65,7 @@ class Wood extends Opaque implements PillarRotation, WoodMaterial{ return $this->woodType->isFlammable() ? 5 : 0; } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if(!$this->stripped && $item instanceof Axe){ $item->applyDamage(1); $this->stripped = true; diff --git a/src/block/tile/Bell.php b/src/block/tile/Bell.php index 7a1e784e3..370964e9e 100644 --- a/src/block/tile/Bell.php +++ b/src/block/tile/Bell.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\block\tile; +use pocketmine\data\SavedDataLoadingException; use pocketmine\math\Facing; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\BlockActorDataPacket; @@ -36,16 +37,16 @@ final class Bell extends Spawnable{ public const TAG_TICKS = "Ticks"; //TAG_Int private bool $ringing = false; - private int $facing = Facing::NORTH; + private Facing $facing = Facing::NORTH; private int $ticks = 0; public function isRinging() : bool{ return $this->ringing; } public function setRinging(bool $ringing) : void{ $this->ringing = $ringing; } - public function getFacing() : int{ return $this->facing; } + public function getFacing() : Facing{ return $this->facing; } - public function setFacing(int $facing) : void{ $this->facing = $facing; } + public function setFacing(Facing $facing) : void{ $this->facing = $facing; } public function getTicks() : int{ return $this->ticks; } @@ -53,19 +54,22 @@ final class Bell extends Spawnable{ protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->setByte(self::TAG_RINGING, $this->ringing ? 1 : 0); - $nbt->setInt(self::TAG_DIRECTION, $this->facing); + //TODO: suspicious use of internal Facing value for network + $nbt->setInt(self::TAG_DIRECTION, $this->facing->value); $nbt->setInt(self::TAG_TICKS, $this->ticks); } public function readSaveData(CompoundTag $nbt) : void{ $this->ringing = $nbt->getByte(self::TAG_RINGING, 0) !== 0; - $this->facing = $nbt->getInt(self::TAG_DIRECTION, Facing::NORTH); + //TODO: suspicious use of internal Facing value for storage + $this->facing = Facing::tryFrom($nbt->getInt(self::TAG_DIRECTION, Facing::NORTH->value)) ?? throw new SavedDataLoadingException("Invalid facing value"); $this->ticks = $nbt->getInt(self::TAG_TICKS, 0); } protected function writeSaveData(CompoundTag $nbt) : void{ $nbt->setByte(self::TAG_RINGING, $this->ringing ? 1 : 0); - $nbt->setInt(self::TAG_DIRECTION, $this->facing); + //TODO: suspicious use of internal Facing value for storage + $nbt->setInt(self::TAG_DIRECTION, $this->facing->value); $nbt->setInt(self::TAG_TICKS, $this->ticks); } @@ -77,7 +81,7 @@ final class Bell extends Spawnable{ * simpler as a BlockEventPacket. It's simpler to implement bells with this hack than to follow Mojang's complicated * mess. */ - public function createFakeUpdatePacket(int $bellHitFace) : BlockActorDataPacket{ + public function createFakeUpdatePacket(Facing $bellHitFace) : BlockActorDataPacket{ $nbt = $this->getSpawnCompound(); $nbt->setByte(self::TAG_RINGING, 1); $nbt->setInt(self::TAG_DIRECTION, match($bellHitFace){ diff --git a/src/block/tile/ShulkerBox.php b/src/block/tile/ShulkerBox.php index a30b75c4e..87221b97a 100644 --- a/src/block/tile/ShulkerBox.php +++ b/src/block/tile/ShulkerBox.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block\tile; use pocketmine\block\inventory\ShulkerBoxInventory; +use pocketmine\data\SavedDataLoadingException; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -38,7 +39,7 @@ class ShulkerBox extends Spawnable implements Container, Nameable{ public const TAG_FACING = "facing"; - protected int $facing = Facing::NORTH; + protected Facing $facing = Facing::NORTH; protected ShulkerBoxInventory $inventory; @@ -50,13 +51,15 @@ class ShulkerBox extends Spawnable implements Container, Nameable{ public function readSaveData(CompoundTag $nbt) : void{ $this->loadName($nbt); $this->loadItems($nbt); - $this->facing = $nbt->getByte(self::TAG_FACING, $this->facing); + //TODO: suspicious use of internal Facing value for storage + $this->facing = Facing::tryFrom($nbt->getByte(self::TAG_FACING, $this->facing->value)) ?? throw new SavedDataLoadingException("Invalid facing value"); } protected function writeSaveData(CompoundTag $nbt) : void{ $this->saveName($nbt); $this->saveItems($nbt); - $nbt->setByte(self::TAG_FACING, $this->facing); + //TODO: suspicious use of internal Facing value for storage + $nbt->setByte(self::TAG_FACING, $this->facing->value); } public function copyDataFromItem(Item $item) : void{ @@ -85,11 +88,11 @@ class ShulkerBox extends Spawnable implements Container, Nameable{ return $nbt; } - public function getFacing() : int{ + public function getFacing() : Facing{ return $this->facing; } - public function setFacing(int $facing) : void{ + public function setFacing(Facing $facing) : void{ $this->facing = $facing; } @@ -106,7 +109,8 @@ class ShulkerBox extends Spawnable implements Container, Nameable{ } protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ - $nbt->setByte(self::TAG_FACING, $this->facing); + //TODO: suspicious use of internal Facing value for network + $nbt->setByte(self::TAG_FACING, $this->facing->value); $this->addNameSpawnData($nbt); } } diff --git a/src/block/utils/AnyFacing.php b/src/block/utils/AnyFacing.php index 8b0885ba8..0cf71632e 100644 --- a/src/block/utils/AnyFacing.php +++ b/src/block/utils/AnyFacing.php @@ -26,16 +26,10 @@ namespace pocketmine\block\utils; use pocketmine\math\Facing; interface AnyFacing{ - - /** - * @see Facing - */ - public function getFacing() : int; + public function getFacing() : Facing; /** * @return $this - * - * @see Facing */ - public function setFacing(int $facing) : self; + public function setFacing(Facing $facing) : self; } diff --git a/src/block/utils/AnyFacingTrait.php b/src/block/utils/AnyFacingTrait.php index 4805b7b7c..a54e0c01e 100644 --- a/src/block/utils/AnyFacingTrait.php +++ b/src/block/utils/AnyFacingTrait.php @@ -27,17 +27,16 @@ use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\math\Facing; trait AnyFacingTrait{ - protected int $facing = Facing::DOWN; + protected Facing $facing = Facing::DOWN; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->facing($this->facing); + $w->enum($this->facing); } - public function getFacing() : int{ return $this->facing; } + public function getFacing() : Facing{ return $this->facing; } /** @return $this */ - public function setFacing(int $facing) : self{ - Facing::validate($this->facing); + public function setFacing(Facing $facing) : self{ $this->facing = $facing; return $this; } diff --git a/src/block/utils/CandleTrait.php b/src/block/utils/CandleTrait.php index 0cbd13044..3f8e164bf 100644 --- a/src/block/utils/CandleTrait.php +++ b/src/block/utils/CandleTrait.php @@ -29,6 +29,7 @@ use pocketmine\item\Durable; use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; +use pocketmine\math\Facing; use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -45,9 +46,10 @@ trait CandleTrait{ /** * @param Item[] &$returnedItems + * * @see Block::onInteract() */ - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE || $item->getTypeId() === ItemTypeIds::FLINT_AND_STEEL || $item->hasEnchantment(VanillaEnchantments::FIRE_ASPECT())){ if($this->lit){ return true; diff --git a/src/block/utils/CopperTrait.php b/src/block/utils/CopperTrait.php index 2ed06b798..1b74331cb 100644 --- a/src/block/utils/CopperTrait.php +++ b/src/block/utils/CopperTrait.php @@ -28,6 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Axe; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\sound\CopperWaxApplySound; @@ -61,9 +62,10 @@ trait CopperTrait{ /** * @param Item[] &$returnedItems + * * @see Block::onInteract() */ - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ + public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if(!$this->waxed && $item->getTypeId() === ItemTypeIds::HONEYCOMB){ $this->waxed = true; $this->position->getWorld()->setBlock($this->position, $this); diff --git a/src/block/utils/FacesOppositePlacingPlayerTrait.php b/src/block/utils/FacesOppositePlacingPlayerTrait.php index 0bca482b5..e1fa05206 100644 --- a/src/block/utils/FacesOppositePlacingPlayerTrait.php +++ b/src/block/utils/FacesOppositePlacingPlayerTrait.php @@ -36,7 +36,7 @@ trait FacesOppositePlacingPlayerTrait{ /** * @see Block::place() */ - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $this->facing = Facing::opposite($player->getHorizontalFacing()); } diff --git a/src/block/utils/HorizontalFacing.php b/src/block/utils/HorizontalFacing.php index 4d0d8cfd6..b94d1a1bd 100644 --- a/src/block/utils/HorizontalFacing.php +++ b/src/block/utils/HorizontalFacing.php @@ -26,16 +26,8 @@ namespace pocketmine\block\utils; use pocketmine\math\Facing; interface HorizontalFacing{ + public function getFacing() : Facing; - /** - * @see Facing - */ - public function getFacing() : int; - - /** - * @return $this - * - * @see Facing - */ - public function setFacing(int $facing) : self; + /** @return $this */ + public function setFacing(Facing $facing) : self; } diff --git a/src/block/utils/HorizontalFacingTrait.php b/src/block/utils/HorizontalFacingTrait.php index a5bd6dcf4..f4f231d33 100644 --- a/src/block/utils/HorizontalFacingTrait.php +++ b/src/block/utils/HorizontalFacingTrait.php @@ -28,16 +28,17 @@ use pocketmine\math\Axis; use pocketmine\math\Facing; trait HorizontalFacingTrait{ - protected int $facing = Facing::NORTH; + //TODO: this really needs a proper HorizontalFacing enum + protected Facing $facing = Facing::NORTH; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); } - public function getFacing() : int{ return $this->facing; } + public function getFacing() : Facing{ return $this->facing; } /** @return $this */ - public function setFacing(int $facing) : self{ + public function setFacing(Facing $facing) : self{ $axis = Facing::axis($facing); if($axis !== Axis::X && $axis !== Axis::Z){ throw new \InvalidArgumentException("Facing must be horizontal"); diff --git a/src/block/utils/LeverFacing.php b/src/block/utils/LeverFacing.php index 6edb29376..73728d08f 100644 --- a/src/block/utils/LeverFacing.php +++ b/src/block/utils/LeverFacing.php @@ -35,7 +35,7 @@ enum LeverFacing{ case SOUTH; case WEST; - public function getFacing() : int{ + public function getFacing() : Facing{ return match($this){ self::UP_AXIS_X, self::UP_AXIS_Z => Facing::UP, self::DOWN_AXIS_X, self::DOWN_AXIS_Z => Facing::DOWN, diff --git a/src/block/utils/MinimumCostFlowCalculator.php b/src/block/utils/MinimumCostFlowCalculator.php index a690a7487..c8e55ded1 100644 --- a/src/block/utils/MinimumCostFlowCalculator.php +++ b/src/block/utils/MinimumCostFlowCalculator.php @@ -27,6 +27,7 @@ use pocketmine\block\Block; use pocketmine\math\Facing; use pocketmine\world\World; use function array_fill_keys; +use function array_map; use function intdiv; use function min; @@ -51,14 +52,14 @@ final class MinimumCostFlowCalculator{ private \Closure $canFlowInto ){} - private function calculateFlowCost(int $blockX, int $blockY, int $blockZ, int $accumulatedCost, int $maxCost, int $originOpposite, int $lastOpposite) : int{ + private function calculateFlowCost(int $blockX, int $blockY, int $blockZ, int $accumulatedCost, int $maxCost, Facing $originOpposite, Facing $lastOpposite) : int{ $cost = 1000; foreach(Facing::HORIZONTAL as $j){ if($j === $originOpposite || $j === $lastOpposite){ continue; } - [$dx, $dy, $dz] = Facing::OFFSET[$j]; + [$dx, $dy, $dz] = Facing::OFFSET[$j->value]; $x = $blockX + $dx; $y = $blockY + $dy; $z = $blockZ + $dz; @@ -99,10 +100,10 @@ final class MinimumCostFlowCalculator{ * @return int[] */ public function getOptimalFlowDirections(int $originX, int $originY, int $originZ) : array{ - $flowCost = array_fill_keys(Facing::HORIZONTAL, 1000); + $flowCost = array_fill_keys(array_map(fn(Facing $f) => $f->value, Facing::HORIZONTAL), 1000); $maxCost = intdiv(4, $this->flowDecayPerBlock); foreach(Facing::HORIZONTAL as $j){ - [$dx, $dy, $dz] = Facing::OFFSET[$j]; + [$dx, $dy, $dz] = Facing::OFFSET[$j->value]; $x = $originX + $dx; $y = $originY + $dy; $z = $originZ + $dz; @@ -111,12 +112,12 @@ final class MinimumCostFlowCalculator{ $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::BLOCKED; }elseif($this->world->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW_DOWN; - $flowCost[$j] = $maxCost = 0; + $flowCost[$j->value] = $maxCost = 0; }elseif($maxCost > 0){ $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW; $opposite = Facing::opposite($j); - $flowCost[$j] = $this->calculateFlowCost($x, $y, $z, 1, $maxCost, $opposite, $opposite); - $maxCost = min($maxCost, $flowCost[$j]); + $flowCost[$j->value] = $this->calculateFlowCost($x, $y, $z, 1, $maxCost, $opposite, $opposite); + $maxCost = min($maxCost, $flowCost[$j->value]); } } diff --git a/src/block/utils/MultiAnyFacing.php b/src/block/utils/MultiAnyFacing.php index dafe041e4..c50e36ff0 100644 --- a/src/block/utils/MultiAnyFacing.php +++ b/src/block/utils/MultiAnyFacing.php @@ -27,27 +27,18 @@ use pocketmine\math\Facing; interface MultiAnyFacing{ - /** - * @return int[] - * @see Facing - */ + /** @return Facing[] */ public function getFaces() : array; - public function hasFace(int $face) : bool; + public function hasFace(Facing $face) : bool; + + /** @return $this */ + public function setFace(Facing $face, bool $value) : self; /** - * @return $this - * - * @see Facing - */ - public function setFace(int $face, bool $value) : self; - - /** - * @param int[] $faces + * @param Facing[] $faces * * @return $this - * - * @see Facing */ public function setFaces(array $faces) : self; diff --git a/src/block/utils/MultiAnyFacingTrait.php b/src/block/utils/MultiAnyFacingTrait.php index 66f26d980..b7cd77901 100644 --- a/src/block/utils/MultiAnyFacingTrait.php +++ b/src/block/utils/MultiAnyFacingTrait.php @@ -31,41 +31,39 @@ use pocketmine\math\Facing; */ trait MultiAnyFacingTrait{ - /** @var int[] */ + /** @var Facing[] */ protected array $faces = []; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->facingFlags($this->faces); } - /** @return int[] */ + /** @return Facing[] */ public function getFaces() : array{ return $this->faces; } - public function hasFace(int $face) : bool{ - return isset($this->faces[$face]); + public function hasFace(Facing $face) : bool{ + return isset($this->faces[$face->value]); } /** - * @param int[] $faces + * @param Facing[] $faces * @return $this */ public function setFaces(array $faces) : self{ $uniqueFaces = []; foreach($faces as $face){ - Facing::validate($face); - $uniqueFaces[$face] = $face; + $uniqueFaces[$face->value] = $face; } $this->faces = $uniqueFaces; return $this; } /** @return $this */ - public function setFace(int $face, bool $value) : self{ - Facing::validate($face); + public function setFace(Facing $face, bool $value) : self{ if($value){ - $this->faces[$face] = $face; + $this->faces[$face->value] = $face; }else{ - unset($this->faces[$face]); + unset($this->faces[$face->value]); } return $this; } diff --git a/src/block/utils/MultiAnySupportTrait.php b/src/block/utils/MultiAnySupportTrait.php index ae1da7bef..55164b6f0 100644 --- a/src/block/utils/MultiAnySupportTrait.php +++ b/src/block/utils/MultiAnySupportTrait.php @@ -42,11 +42,11 @@ trait MultiAnySupportTrait{ /** * Returns a list of faces that block should already have when placed. * - * @return int[] + * @return Facing[] */ abstract protected function getInitialPlaceFaces(Block $blockReplace) : array; - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->faces = $this->getInitialPlaceFaces($blockReplace); $availableFaces = $this->getAvailableFaces(); @@ -55,8 +55,8 @@ trait MultiAnySupportTrait{ } $opposite = Facing::opposite($face); - $placedFace = isset($availableFaces[$opposite]) ? $opposite : array_key_first($availableFaces); - $this->faces[$placedFace] = $placedFace; + $placedFace = isset($availableFaces[$opposite->value]) ? $opposite : $availableFaces[array_key_first($availableFaces)]; + $this->faces[$placedFace->value] = $placedFace; return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -66,7 +66,7 @@ trait MultiAnySupportTrait{ foreach($this->faces as $face){ if($this->getAdjacentSupportType($face) !== SupportType::FULL){ - unset($this->faces[$face]); + unset($this->faces[$face->value]); $changed = true; } } @@ -82,13 +82,14 @@ trait MultiAnySupportTrait{ } /** - * @return array $faces + * @return Facing[] + * @phpstan-return array */ private function getAvailableFaces() : array{ $faces = []; foreach(Facing::ALL as $face){ if(!$this->hasFace($face) && $this->getAdjacentSupportType($face) === SupportType::FULL){ - $faces[$face] = $face; + $faces[$face->value] = $face; } } return $faces; diff --git a/src/block/utils/PillarRotation.php b/src/block/utils/PillarRotation.php index f016ce50c..cfba744f1 100644 --- a/src/block/utils/PillarRotation.php +++ b/src/block/utils/PillarRotation.php @@ -27,13 +27,8 @@ use pocketmine\math\Axis; interface PillarRotation{ - /** @see Axis */ - public function getAxis() : int; + public function getAxis() : Axis; - /** - * @return $this - * - * @see Axis - */ - public function setAxis(int $axis) : self; + /** @return $this */ + public function setAxis(Axis $axis) : self; } diff --git a/src/block/utils/PillarRotationTrait.php b/src/block/utils/PillarRotationTrait.php index 3f0117dec..d789ec75c 100644 --- a/src/block/utils/PillarRotationTrait.php +++ b/src/block/utils/PillarRotationTrait.php @@ -33,17 +33,17 @@ use pocketmine\player\Player; use pocketmine\world\BlockTransaction; trait PillarRotationTrait{ - protected int $axis = Axis::Y; + protected Axis $axis = Axis::Y; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->axis($this->axis); + $w->enum($this->axis); } /** @see Axis */ - public function getAxis() : int{ return $this->axis; } + public function getAxis() : Axis{ return $this->axis; } /** @return $this */ - public function setAxis(int $axis) : self{ + public function setAxis(Axis $axis) : self{ $this->axis = $axis; return $this; } @@ -51,7 +51,7 @@ trait PillarRotationTrait{ /** * @see Block::place() */ - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ + public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->axis = Facing::axis($face); /** @see Block::place() */ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); diff --git a/src/block/utils/RailConnectionInfo.php b/src/block/utils/RailConnectionInfo.php index f343bb726..af13a51c9 100644 --- a/src/block/utils/RailConnectionInfo.php +++ b/src/block/utils/RailConnectionInfo.php @@ -33,50 +33,50 @@ final class RailConnectionInfo{ public const CONNECTIONS = [ //straights BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH => [ - Facing::NORTH, - Facing::SOUTH + Facing::NORTH->value, + Facing::SOUTH->value ], BlockLegacyMetadata::RAIL_STRAIGHT_EAST_WEST => [ - Facing::EAST, - Facing::WEST + Facing::EAST->value, + Facing::WEST->value ], //ascending BlockLegacyMetadata::RAIL_ASCENDING_EAST => [ - Facing::WEST, - Facing::EAST | self::FLAG_ASCEND + Facing::WEST->value, + Facing::EAST->value | self::FLAG_ASCEND ], BlockLegacyMetadata::RAIL_ASCENDING_WEST => [ - Facing::EAST, - Facing::WEST | self::FLAG_ASCEND + Facing::EAST->value, + Facing::WEST->value | self::FLAG_ASCEND ], BlockLegacyMetadata::RAIL_ASCENDING_NORTH => [ - Facing::SOUTH, - Facing::NORTH | self::FLAG_ASCEND + Facing::SOUTH->value, + Facing::NORTH->value | self::FLAG_ASCEND ], BlockLegacyMetadata::RAIL_ASCENDING_SOUTH => [ - Facing::NORTH, - Facing::SOUTH | self::FLAG_ASCEND + Facing::NORTH->value, + Facing::SOUTH->value | self::FLAG_ASCEND ] ]; /* extended meta values for regular rails, to allow curving */ public const CURVE_CONNECTIONS = [ BlockLegacyMetadata::RAIL_CURVE_SOUTHEAST => [ - Facing::SOUTH, - Facing::EAST + Facing::SOUTH->value, + Facing::EAST->value ], BlockLegacyMetadata::RAIL_CURVE_SOUTHWEST => [ - Facing::SOUTH, - Facing::WEST + Facing::SOUTH->value, + Facing::WEST->value ], BlockLegacyMetadata::RAIL_CURVE_NORTHWEST => [ - Facing::NORTH, - Facing::WEST + Facing::NORTH->value, + Facing::WEST->value ], BlockLegacyMetadata::RAIL_CURVE_NORTHEAST => [ - Facing::NORTH, - Facing::EAST + Facing::NORTH->value, + Facing::EAST->value ] ]; } diff --git a/src/block/utils/StaticSupportTrait.php b/src/block/utils/StaticSupportTrait.php index 0e40230cc..a725b74c3 100644 --- a/src/block/utils/StaticSupportTrait.php +++ b/src/block/utils/StaticSupportTrait.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block\utils; use pocketmine\block\Block; +use pocketmine\math\Facing; use pocketmine\math\Vector3; /** @@ -40,7 +41,7 @@ trait StaticSupportTrait{ /** * @see Block::canBePlacedAt() */ - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ + public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock) : bool{ return $this->canBeSupportedAt($blockReplace) && parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } diff --git a/src/data/bedrock/block/convert/VanillaBlockMappings.php b/src/data/bedrock/block/convert/VanillaBlockMappings.php index f339ce3ef..cb42ff2e2 100644 --- a/src/data/bedrock/block/convert/VanillaBlockMappings.php +++ b/src/data/bedrock/block/convert/VanillaBlockMappings.php @@ -122,6 +122,7 @@ use pocketmine\data\bedrock\block\convert\property\ValueFromIntProperty; use pocketmine\data\bedrock\block\convert\property\ValueFromStringProperty; use pocketmine\data\bedrock\block\convert\property\ValueMappings; use pocketmine\data\bedrock\block\convert\property\ValueSetFromIntProperty; +use pocketmine\math\Axis; use pocketmine\math\Facing; use function array_map; use function min; @@ -584,13 +585,14 @@ final class VanillaBlockMappings{ new ValueSetFromIntProperty( StateNames::VINE_DIRECTION_BITS, IntFromRawStateMap::int([ - Facing::NORTH => BlockLegacyMetadata::VINE_FLAG_NORTH, - Facing::SOUTH => BlockLegacyMetadata::VINE_FLAG_SOUTH, - Facing::WEST => BlockLegacyMetadata::VINE_FLAG_WEST, - Facing::EAST => BlockLegacyMetadata::VINE_FLAG_EAST, + Facing::NORTH->value => BlockLegacyMetadata::VINE_FLAG_NORTH, + Facing::SOUTH->value => BlockLegacyMetadata::VINE_FLAG_SOUTH, + Facing::WEST->value => BlockLegacyMetadata::VINE_FLAG_WEST, + Facing::EAST->value => BlockLegacyMetadata::VINE_FLAG_EAST, ]), - fn(Vine $b) => $b->getFaces(), - fn(Vine $b, array $v) => $b->setFaces($v) + //TODO: hack for lack of HorizontalFacing enum :( + fn(Vine $b) => array_map(fn(Facing $facing) => $facing->value, $b->getFaces()), + fn(Vine $b, array $v) => $b->setFaces(array_map(Facing::from(...), $v)) ) ])); @@ -610,13 +612,15 @@ final class VanillaBlockMappings{ $reg->mapFlattenedId(FlattenedIdModel::create(Blocks::CORAL_FAN()) ->idComponents([...$commonProperties->coralIdPrefixes, "_coral_fan"]) ->properties([ - new ValueFromIntProperty(StateNames::CORAL_FAN_DIRECTION, ValueMappings::getInstance()->coralAxis, fn(FloorCoralFan $b) => $b->getAxis(), fn(FloorCoralFan $b, int $v) => $b->setAxis($v)) + //TODO: hack for lack of horizontal axis enum :( + new ValueFromIntProperty(StateNames::CORAL_FAN_DIRECTION, ValueMappings::getInstance()->coralAxis, fn(FloorCoralFan $b) => $b->getAxis()->value, fn(FloorCoralFan $b, int $v) => $b->setAxis(Axis::from($v))) ]) ); $reg->mapFlattenedId(FlattenedIdModel::create(Blocks::WALL_CORAL_FAN()) ->idComponents([...$commonProperties->coralIdPrefixes, "_coral_wall_fan"]) ->properties([ - new ValueFromIntProperty(StateNames::CORAL_DIRECTION, ValueMappings::getInstance()->horizontalFacingCoral, fn(HorizontalFacing $b) => $b->getFacing(), fn(HorizontalFacing $b, int $v) => $b->setFacing($v)), + //TODO: hack for lack of horizontal facing enum :( + new ValueFromIntProperty(StateNames::CORAL_DIRECTION, ValueMappings::getInstance()->horizontalFacingCoral, fn(HorizontalFacing $b) => $b->getFacing()->value, fn(HorizontalFacing $b, int $v) => $b->setFacing(Facing::from($v))), ]) ); } @@ -752,7 +756,7 @@ final class VanillaBlockMappings{ new ValueFromStringProperty("id", ValueMappings::getInstance()->mobHeadType, fn(MobHead $b) => $b->getMobHeadType(), fn(MobHead $b, MobHeadType $v) => $b->setMobHeadType($v)), ]) ->properties([ - new ValueFromIntProperty(StateNames::FACING_DIRECTION, ValueMappings::getInstance()->facingExceptDown, fn(MobHead $b) => $b->getFacing(), fn(MobHead $b, int $v) => $b->setFacing($v)) + new ValueFromIntProperty(StateNames::FACING_DIRECTION, ValueMappings::getInstance()->facingExceptDown, fn(MobHead $b) => $b->getFacing()->value, fn(MobHead $b, int $v) => $b->setFacing(Facing::from($v))) ]) ); @@ -1306,7 +1310,7 @@ final class VanillaBlockMappings{ $commonProperties->horizontalFacingCardinal ])); $reg->mapModel(Model::create(Blocks::END_ROD(), Ids::END_ROD)->properties([ - new ValueFromIntProperty(StateNames::FACING_DIRECTION, ValueMappings::getInstance()->facingEndRod, fn(EndRod $b) => $b->getFacing(), fn(EndRod $b, int $v) => $b->setFacing($v)), + new ValueFromIntProperty(StateNames::FACING_DIRECTION, ValueMappings::getInstance()->facingEndRod, fn(EndRod $b) => $b->getFacing(), fn(EndRod $b, Facing $v) => $b->setFacing($v)), ])); //F @@ -1334,7 +1338,7 @@ final class VanillaBlockMappings{ $reg->mapModel(Model::create(Blocks::HOPPER(), Ids::HOPPER)->properties([ //kinda weird this doesn't use powered_bit? new BoolProperty(StateNames::TOGGLE_BIT, fn(PoweredByRedstone $b) => $b->isPowered(), fn(PoweredByRedstone $b, bool $v) => $b->setPowered($v)), - new ValueFromIntProperty(StateNames::FACING_DIRECTION, ValueMappings::getInstance()->facingExceptUp, fn(Hopper $b) => $b->getFacing(), fn(Hopper $b, int $v) => $b->setFacing($v)), + new ValueFromIntProperty(StateNames::FACING_DIRECTION, ValueMappings::getInstance()->facingExceptUp, fn(Hopper $b) => $b->getFacing()->value, fn(Hopper $b, int $v) => $b->setFacing(Facing::from($v))), ])); //I @@ -1365,7 +1369,8 @@ final class VanillaBlockMappings{ new IntProperty(StateNames::AGE, 0, 3, fn(NetherWartPlant $b) => $b->getAge(), fn(NetherWartPlant $b, int $v) => $b->setAge($v)) ])); $reg->mapModel(Model::create(Blocks::NETHER_PORTAL(), Ids::PORTAL)->properties([ - new ValueFromStringProperty(StateNames::PORTAL_AXIS, ValueMappings::getInstance()->portalAxis, fn(NetherPortal $b) => $b->getAxis(), fn(NetherPortal $b, int $v) => $b->setAxis($v)) + //TODO: hack for lack of horizontal axis enum :( + new ValueFromStringProperty(StateNames::PORTAL_AXIS, ValueMappings::getInstance()->portalAxis, fn(NetherPortal $b) => $b->getAxis()->value, fn(NetherPortal $b, int $v) => $b->setAxis(Axis::from($v))) ])); //P diff --git a/src/data/bedrock/block/convert/property/CommonProperties.php b/src/data/bedrock/block/convert/property/CommonProperties.php index 666637027..54618690b 100644 --- a/src/data/bedrock/block/convert/property/CommonProperties.php +++ b/src/data/bedrock/block/convert/property/CommonProperties.php @@ -55,15 +55,16 @@ use pocketmine\block\Wood; use pocketmine\data\bedrock\block\BlockLegacyMetadata; use pocketmine\data\bedrock\block\BlockStateNames as StateNames; use pocketmine\data\bedrock\block\BlockStateStringValues; +use pocketmine\math\Axis; use pocketmine\math\Facing; use pocketmine\utils\SingletonTrait; final class CommonProperties{ use SingletonTrait; - /** @phpstan-var ValueFromStringProperty */ + /** @phpstan-var ValueFromStringProperty */ public readonly ValueFromStringProperty $blockFace; - /** @phpstan-var ValueFromStringProperty */ + /** @phpstan-var ValueFromStringProperty */ public readonly ValueFromStringProperty $pillarAxis; /** @phpstan-var ValueFromStringProperty */ public readonly ValueFromStringProperty $torchFacing; @@ -77,10 +78,10 @@ final class CommonProperties{ /** @phpstan-var ValueFromIntProperty */ public readonly ValueFromIntProperty $horizontalFacingClassic; - /** @phpstan-var ValueFromIntProperty */ + /** @phpstan-var ValueFromIntProperty */ public readonly ValueFromIntProperty $anyFacingClassic; - /** @phpstan-var ValueSetFromIntProperty */ + /** @phpstan-var ValueSetFromIntProperty */ public readonly ValueSetFromIntProperty $multiFacingFlags; /** @phpstan-var IntProperty */ @@ -206,29 +207,30 @@ final class CommonProperties{ private function __construct(){ $vm = ValueMappings::getInstance(); - $hfGet = fn(HorizontalFacing $v) => $v->getFacing(); - $hfSet = fn(HorizontalFacing $v, int $facing) => $v->setFacing($facing); + //TODO: crude hack here - since we have no HorizontalFacing enum we need to use ints and convert to enum in the accessors + $hfGet = fn(HorizontalFacing $v) => $v->getFacing()->value; + $hfSet = fn(HorizontalFacing $v, int $facing) => $v->setFacing(Facing::from($facing)); $this->horizontalFacingCardinal = new ValueFromStringProperty(StateNames::MC_CARDINAL_DIRECTION, $vm->cardinalDirection, $hfGet, $hfSet); $this->blockFace = new ValueFromStringProperty( StateNames::MC_BLOCK_FACE, $vm->blockFace, fn(AnyFacing $b) => $b->getFacing(), - fn(AnyFacing $b, int $v) => $b->setFacing($v) + fn(AnyFacing $b, Facing $v) => $b->setFacing($v) ); $this->pillarAxis = new ValueFromStringProperty( StateNames::PILLAR_AXIS, $vm->pillarAxis, fn(PillarRotation $b) => $b->getAxis(), - fn(PillarRotation $b, int $v) => $b->setAxis($v) + fn(PillarRotation $b, Axis $v) => $b->setAxis($v) ); $this->torchFacing = new ValueFromStringProperty( StateNames::TORCH_FACING_DIRECTION, $vm->torchFacing, - fn(Torch $b) => $b->getFacing(), - fn(Torch $b, int $v) => $b->setFacing($v) + fn(Torch $b) => $b->getFacing()->value, + fn(Torch $b, int $v) => $b->setFacing(Facing::from($v)) ); $this->horizontalFacingSWNE = new ValueFromIntProperty(StateNames::DIRECTION, $vm->horizontalFacingSWNE, $hfGet, $hfSet); @@ -239,19 +241,19 @@ final class CommonProperties{ StateNames::FACING_DIRECTION, $vm->facing, fn(AnyFacing $b) => $b->getFacing(), - fn(AnyFacing $b, int $v) => $b->setFacing($v) + fn(AnyFacing $b, Facing $v) => $b->setFacing($v) ); $this->multiFacingFlags = new ValueSetFromIntProperty( StateNames::MULTI_FACE_DIRECTION_BITS, - IntFromRawStateMap::int([ + EnumFromRawStateMap::int(Facing::class, fn(Facing $case) => match ($case) { Facing::DOWN => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_DOWN, Facing::UP => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_UP, Facing::NORTH => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_NORTH, Facing::SOUTH => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_SOUTH, Facing::WEST => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_WEST, Facing::EAST => BlockLegacyMetadata::MULTI_FACE_DIRECTION_FLAG_EAST - ]), + }), fn(MultiAnyFacing $b) => $b->getFaces(), fn(MultiAnyFacing $b, array $v) => $b->setFaces($v) ); @@ -355,13 +357,13 @@ final class CommonProperties{ StateNames::MC_CARDINAL_DIRECTION, IntFromRawStateMap::string([ //a door facing "east" is actually facing north - thanks mojang - Facing::NORTH => BlockStateStringValues::MC_CARDINAL_DIRECTION_EAST, - Facing::EAST => BlockStateStringValues::MC_CARDINAL_DIRECTION_SOUTH, - Facing::SOUTH => BlockStateStringValues::MC_CARDINAL_DIRECTION_WEST, - Facing::WEST => BlockStateStringValues::MC_CARDINAL_DIRECTION_NORTH + Facing::NORTH->value => BlockStateStringValues::MC_CARDINAL_DIRECTION_EAST, + Facing::EAST->value => BlockStateStringValues::MC_CARDINAL_DIRECTION_SOUTH, + Facing::SOUTH->value => BlockStateStringValues::MC_CARDINAL_DIRECTION_WEST, + Facing::WEST->value => BlockStateStringValues::MC_CARDINAL_DIRECTION_NORTH ]), - fn(HorizontalFacing $b) => $b->getFacing(), - fn(HorizontalFacing $b, int $v) => $b->setFacing($v) + fn(HorizontalFacing $b) => $b->getFacing()->value, + fn(HorizontalFacing $b, int $v) => $b->setFacing(Facing::from($v)) ) ]; @@ -395,7 +397,7 @@ final class CommonProperties{ ]; $this->stemProperties = [ - new ValueFromIntProperty(StateNames::FACING_DIRECTION, $vm->facingStem, fn(Stem $b) => $b->getFacing(), fn(Stem $b, int $v) => $b->setFacing($v)), + new ValueFromIntProperty(StateNames::FACING_DIRECTION, $vm->facingStem, fn(Stem $b) => $b->getFacing()->value, fn(Stem $b, int $v) => $b->setFacing(Facing::from($v))), $this->cropAgeMax7 ]; @@ -411,11 +413,11 @@ final class CommonProperties{ new BoolProperty(StateNames::WALL_POST_BIT, fn(Wall $b) => $b->isPost(), fn(Wall $b, bool $v) => $b->setPost($v)), ]; foreach([ - Facing::NORTH => StateNames::WALL_CONNECTION_TYPE_NORTH, - Facing::SOUTH => StateNames::WALL_CONNECTION_TYPE_SOUTH, - Facing::WEST => StateNames::WALL_CONNECTION_TYPE_WEST, - Facing::EAST => StateNames::WALL_CONNECTION_TYPE_EAST - ] as $facing => $stateName){ + [Facing::NORTH, StateNames::WALL_CONNECTION_TYPE_NORTH], + [Facing::SOUTH, StateNames::WALL_CONNECTION_TYPE_SOUTH], + [Facing::WEST, StateNames::WALL_CONNECTION_TYPE_WEST], + [Facing::EAST, StateNames::WALL_CONNECTION_TYPE_EAST] + ] as [$facing, $stateName]){ $wallProperties[] = new ValueFromStringProperty( $stateName, EnumFromRawStateMap::string(WallConnectionTypeShim::class, fn(WallConnectionTypeShim $case) => $case->getValue()), diff --git a/src/data/bedrock/block/convert/property/ValueMappings.php b/src/data/bedrock/block/convert/property/ValueMappings.php index 22e9803a5..f51c4fc5b 100644 --- a/src/data/bedrock/block/convert/property/ValueMappings.php +++ b/src/data/bedrock/block/convert/property/ValueMappings.php @@ -65,10 +65,10 @@ final class ValueMappings{ /** @phpstan-var IntFromRawStateMap */ public readonly IntFromRawStateMap $cardinalDirection; - /** @phpstan-var IntFromRawStateMap */ - public readonly IntFromRawStateMap $blockFace; - /** @phpstan-var IntFromRawStateMap */ - public readonly IntFromRawStateMap $pillarAxis; + /** @phpstan-var EnumFromRawStateMap */ + public readonly EnumFromRawStateMap $blockFace; + /** @phpstan-var EnumFromRawStateMap */ + public readonly EnumFromRawStateMap $pillarAxis; /** @phpstan-var IntFromRawStateMap */ public readonly IntFromRawStateMap $torchFacing; /** @phpstan-var IntFromRawStateMap */ @@ -86,10 +86,10 @@ final class ValueMappings{ public readonly IntFromRawStateMap $horizontalFacingCoral; /** @phpstan-var IntFromRawStateMap */ public readonly IntFromRawStateMap $horizontalFacingClassic; - /** @phpstan-var IntFromRawStateMap */ - public readonly IntFromRawStateMap $facing; - /** @phpstan-var IntFromRawStateMap */ - public readonly IntFromRawStateMap $facingEndRod; + /** @phpstan-var EnumFromRawStateMap */ + public readonly EnumFromRawStateMap $facing; + /** @phpstan-var EnumFromRawStateMap */ + public readonly EnumFromRawStateMap $facingEndRod; /** @phpstan-var IntFromRawStateMap */ public readonly IntFromRawStateMap $coralAxis; @@ -190,40 +190,41 @@ final class ValueMappings{ } ); + //TODO: this can't use EnumFromRawStateMap until we have a dedicated HorizontalFacing enum $this->cardinalDirection = IntFromRawStateMap::string([ - Facing::NORTH => StringValues::MC_CARDINAL_DIRECTION_NORTH, - Facing::SOUTH => StringValues::MC_CARDINAL_DIRECTION_SOUTH, - Facing::WEST => StringValues::MC_CARDINAL_DIRECTION_WEST, - Facing::EAST => StringValues::MC_CARDINAL_DIRECTION_EAST, + Facing::NORTH->value => StringValues::MC_CARDINAL_DIRECTION_NORTH, + Facing::SOUTH->value => StringValues::MC_CARDINAL_DIRECTION_SOUTH, + Facing::WEST->value => StringValues::MC_CARDINAL_DIRECTION_WEST, + Facing::EAST->value => StringValues::MC_CARDINAL_DIRECTION_EAST, ]); - $this->blockFace = IntFromRawStateMap::string([ + $this->blockFace = EnumFromRawStateMap::string(Facing::class, fn(Facing $case) => match ($case) { Facing::DOWN => StringValues::MC_BLOCK_FACE_DOWN, Facing::UP => StringValues::MC_BLOCK_FACE_UP, Facing::NORTH => StringValues::MC_BLOCK_FACE_NORTH, Facing::SOUTH => StringValues::MC_BLOCK_FACE_SOUTH, Facing::WEST => StringValues::MC_BLOCK_FACE_WEST, Facing::EAST => StringValues::MC_BLOCK_FACE_EAST, - ]); - $this->pillarAxis = IntFromRawStateMap::string([ + }); + $this->pillarAxis = EnumFromRawStateMap::string(Axis::class, fn(Axis $case) => match ($case) { Axis::X => StringValues::PILLAR_AXIS_X, Axis::Y => StringValues::PILLAR_AXIS_Y, Axis::Z => StringValues::PILLAR_AXIS_Z - ]); + }); $this->torchFacing = IntFromRawStateMap::string([ //TODO: horizontal directions are flipped (MCPE bug: https://bugs.mojang.com/browse/MCPE-152036) - Facing::WEST => StringValues::TORCH_FACING_DIRECTION_EAST, - Facing::SOUTH => StringValues::TORCH_FACING_DIRECTION_NORTH, - Facing::NORTH => StringValues::TORCH_FACING_DIRECTION_SOUTH, - Facing::UP => StringValues::TORCH_FACING_DIRECTION_TOP, - Facing::EAST => StringValues::TORCH_FACING_DIRECTION_WEST, + Facing::WEST->value => StringValues::TORCH_FACING_DIRECTION_EAST, + Facing::SOUTH->value => StringValues::TORCH_FACING_DIRECTION_NORTH, + Facing::NORTH->value => StringValues::TORCH_FACING_DIRECTION_SOUTH, + Facing::UP->value => StringValues::TORCH_FACING_DIRECTION_TOP, + Facing::EAST->value => StringValues::TORCH_FACING_DIRECTION_WEST, ], deserializeAliases: [ - Facing::UP => StringValues::TORCH_FACING_DIRECTION_UNKNOWN //should be illegal, but still supported + Facing::UP->value => StringValues::TORCH_FACING_DIRECTION_UNKNOWN //should be illegal, but still supported ]); $this->portalAxis = IntFromRawStateMap::string([ - Axis::X => StringValues::PORTAL_AXIS_X, - Axis::Z => StringValues::PORTAL_AXIS_Z, + Axis::X->value => StringValues::PORTAL_AXIS_X, + Axis::Z->value => StringValues::PORTAL_AXIS_Z, ], deserializeAliases: [ - Axis::X => StringValues::PORTAL_AXIS_UNKNOWN, + Axis::X->value => StringValues::PORTAL_AXIS_UNKNOWN, ]); $this->bambooLeafSize = IntFromRawStateMap::string([ Bamboo::NO_LEAVES => StringValues::BAMBOO_LEAF_SIZE_NO_LEAVES, @@ -232,74 +233,78 @@ final class ValueMappings{ ]); $this->horizontalFacing5Minus = IntFromRawStateMap::int([ - Facing::EAST => 0, - Facing::WEST => 1, - Facing::SOUTH => 2, - Facing::NORTH => 3 + Facing::EAST->value => 0, + Facing::WEST->value => 1, + Facing::SOUTH->value => 2, + Facing::NORTH->value => 3 ]); $this->horizontalFacingSWNE = IntFromRawStateMap::int([ - Facing::SOUTH => 0, - Facing::WEST => 1, - Facing::NORTH => 2, - Facing::EAST => 3 + Facing::SOUTH->value => 0, + Facing::WEST->value => 1, + Facing::NORTH->value => 2, + Facing::EAST->value => 3 ]); $this->horizontalFacingSWNEInverted = IntFromRawStateMap::int([ - Facing::NORTH => 0, - Facing::EAST => 1, - Facing::SOUTH => 2, - Facing::WEST => 3, + Facing::NORTH->value => 0, + Facing::EAST->value => 1, + Facing::SOUTH->value => 2, + Facing::WEST->value => 3, ]); $this->horizontalFacingCoral = IntFromRawStateMap::int([ - Facing::WEST => 0, - Facing::EAST => 1, - Facing::NORTH => 2, - Facing::SOUTH => 3 + Facing::WEST->value => 0, + Facing::EAST->value => 1, + Facing::NORTH->value => 2, + Facing::SOUTH->value => 3 ]); $horizontalFacingClassicTable = [ + Facing::NORTH->value => 2, + Facing::SOUTH->value => 3, + Facing::WEST->value => 4, + Facing::EAST->value => 5 + ]; + $this->horizontalFacingClassic = IntFromRawStateMap::int($horizontalFacingClassicTable, deserializeAliases: [ + Facing::NORTH->value => [0, 1] //should be illegal but still technically possible + ]); + + $this->facing = EnumFromRawStateMap::int(Facing::class, fn(Facing $case) => match ($case) { + Facing::DOWN => 0, + Facing::UP => 1, Facing::NORTH => 2, Facing::SOUTH => 3, Facing::WEST => 4, Facing::EAST => 5 - ]; - $this->horizontalFacingClassic = IntFromRawStateMap::int($horizontalFacingClassicTable, deserializeAliases: [ - Facing::NORTH => [0, 1] //should be illegal but still technically possible - ]); - - $this->facing = IntFromRawStateMap::int([ - Facing::DOWN => 0, - Facing::UP => 1 - ] + $horizontalFacingClassicTable); + }); //end rods have all the horizontal facing values opposite to classic facing - $this->facingEndRod = IntFromRawStateMap::int([ + $this->facingEndRod = EnumFromRawStateMap::int(Facing::class, fn(Facing $case) => match ($case) { Facing::DOWN => 0, Facing::UP => 1, Facing::SOUTH => 2, Facing::NORTH => 3, Facing::EAST => 4, Facing::WEST => 5, - ]); + }); $this->coralAxis = IntFromRawStateMap::int([ - Axis::X => 0, - Axis::Z => 1, + Axis::X->value => 0, + Axis::Z->value => 1, ]); //TODO: shitty copy pasta job, we can do this better but this is good enough for now $this->facingExceptDown = IntFromRawStateMap::int( - [Facing::UP => 1] + $horizontalFacingClassicTable, - deserializeAliases: [Facing::UP => 0]); + [Facing::UP->value => 1] + $horizontalFacingClassicTable, + deserializeAliases: [Facing::UP->value => 0]); $this->facingExceptUp = IntFromRawStateMap::int( - [Facing::DOWN => 0] + $horizontalFacingClassicTable, - deserializeAliases: [Facing::DOWN => 1] + [Facing::DOWN->value => 0] + $horizontalFacingClassicTable, + deserializeAliases: [Facing::DOWN->value => 1] ); //In PM, we use Facing::UP to indicate that the stem is not attached to a pumpkin/melon, since this makes the //most intuitive sense (the stem is pointing at the sky). However, Bedrock uses the DOWN state for this, which //is absurd, and I refuse to make our API similarly absurd. $this->facingStem = IntFromRawStateMap::int( - [Facing::UP => 0] + $horizontalFacingClassicTable, - deserializeAliases: [Facing::UP => 1] + [Facing::UP->value => 0] + $horizontalFacingClassicTable, + deserializeAliases: [Facing::UP->value => 1] ); } } diff --git a/src/data/runtime/RuntimeDataDescriber.php b/src/data/runtime/RuntimeDataDescriber.php index 8df675f70..b06133022 100644 --- a/src/data/runtime/RuntimeDataDescriber.php +++ b/src/data/runtime/RuntimeDataDescriber.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\data\runtime; use pocketmine\block\utils\WallConnectionType; +use pocketmine\math\Axis; use pocketmine\math\Facing; /** @@ -45,29 +46,25 @@ interface RuntimeDataDescriber{ public function bool(bool &$value) : void; - public function horizontalFacing(int &$facing) : void; + public function horizontalFacing(Facing &$facing) : void; /** - * @param int[] $faces + * @param Facing[] $faces */ public function facingFlags(array &$faces) : void; /** - * @param int[] $faces + * @param Facing[] $faces */ public function horizontalFacingFlags(array &$faces) : void; - public function facing(int &$facing) : void; + public function facingExcept(Facing &$facing, Facing $except) : void; - public function facingExcept(int &$facing, int $except) : void; - - public function axis(int &$axis) : void; - - public function horizontalAxis(int &$axis) : void; + public function horizontalAxis(Axis &$axis) : void; /** * @param WallConnectionType[] $connections - * @phpstan-param array $connections + * @phpstan-param array, WallConnectionType> $connections */ public function wallConnections(array &$connections) : void; diff --git a/src/data/runtime/RuntimeDataReader.php b/src/data/runtime/RuntimeDataReader.php index c230a52ae..64e5e0f80 100644 --- a/src/data/runtime/RuntimeDataReader.php +++ b/src/data/runtime/RuntimeDataReader.php @@ -77,7 +77,7 @@ final class RuntimeDataReader implements RuntimeDataDescriber{ $value = $this->readBool(); } - public function horizontalFacing(int &$facing) : void{ + public function horizontalFacing(Facing &$facing) : void{ $facing = match($this->readInt(2)){ 0 => Facing::NORTH, 1 => Facing::EAST, @@ -88,13 +88,13 @@ final class RuntimeDataReader implements RuntimeDataDescriber{ } /** - * @param int[] $faces + * @param Facing[] $faces */ public function facingFlags(array &$faces) : void{ $result = []; foreach(Facing::ALL as $facing){ if($this->readBool()){ - $result[$facing] = $facing; + $result[$facing->value] = $facing; } } @@ -102,34 +102,22 @@ final class RuntimeDataReader implements RuntimeDataDescriber{ } /** - * @param int[] $faces + * @param Facing[] $faces */ public function horizontalFacingFlags(array &$faces) : void{ $result = []; foreach(Facing::HORIZONTAL as $facing){ if($this->readBool()){ - $result[$facing] = $facing; + $result[$facing->value] = $facing; } } $faces = $result; } - public function facing(int &$facing) : void{ - $facing = match($this->readInt(3)){ - 0 => Facing::DOWN, - 1 => Facing::UP, - 2 => Facing::NORTH, - 3 => Facing::SOUTH, - 4 => Facing::WEST, - 5 => Facing::EAST, - default => throw new InvalidSerializedRuntimeDataException("Invalid facing value") - }; - } - - public function facingExcept(int &$facing, int $except) : void{ - $result = 0; - $this->facing($result); + public function facingExcept(Facing &$facing, Facing $except) : void{ + $result = Facing::DOWN; + $this->enum($result); if($result === $except){ throw new InvalidSerializedRuntimeDataException("Illegal facing value"); } @@ -137,16 +125,7 @@ final class RuntimeDataReader implements RuntimeDataDescriber{ $facing = $result; } - public function axis(int &$axis) : void{ - $axis = match($this->readInt(2)){ - 0 => Axis::X, - 1 => Axis::Z, - 2 => Axis::Y, - default => throw new InvalidSerializedRuntimeDataException("Invalid axis value") - }; - } - - public function horizontalAxis(int &$axis) : void{ + public function horizontalAxis(Axis &$axis) : void{ $axis = match($this->readInt(1)){ 0 => Axis::X, 1 => Axis::Z, @@ -156,7 +135,7 @@ final class RuntimeDataReader implements RuntimeDataDescriber{ /** * @param WallConnectionType[] $connections - * @phpstan-param array $connections + * @phpstan-param array, WallConnectionType> $connections */ public function wallConnections(array &$connections) : void{ $result = []; @@ -165,7 +144,7 @@ final class RuntimeDataReader implements RuntimeDataDescriber{ foreach(Facing::HORIZONTAL as $facing){ $type = intdiv($packed, (3 ** $offset)) % 3; if($type !== 0){ - $result[$facing] = match($type){ + $result[$facing->value] = match($type){ 1 => WallConnectionType::SHORT, 2 => WallConnectionType::TALL, default => throw new AssumptionFailedError("Unreachable") diff --git a/src/data/runtime/RuntimeDataSizeCalculator.php b/src/data/runtime/RuntimeDataSizeCalculator.php index 6725aace6..213279cb1 100644 --- a/src/data/runtime/RuntimeDataSizeCalculator.php +++ b/src/data/runtime/RuntimeDataSizeCalculator.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\data\runtime; +use pocketmine\math\Axis; use pocketmine\math\Facing; use function count; use function log; @@ -50,31 +51,23 @@ final class RuntimeDataSizeCalculator implements RuntimeDataDescriber{ $this->addBits(1); } - public function horizontalFacing(int &$facing) : void{ + public function horizontalFacing(Facing &$facing) : void{ $this->addBits(2); } public function facingFlags(array &$faces) : void{ - $this->addBits(count(Facing::ALL)); + $this->addBits(count(Facing::cases())); } public function horizontalFacingFlags(array &$faces) : void{ $this->addBits(count(Facing::HORIZONTAL)); } - public function facing(int &$facing) : void{ - $this->addBits(3); + public function facingExcept(Facing &$facing, Facing $except) : void{ + $this->enum($facing); } - public function facingExcept(int &$facing, int $except) : void{ - $this->facing($facing); - } - - public function axis(int &$axis) : void{ - $this->addBits(2); - } - - public function horizontalAxis(int &$axis) : void{ + public function horizontalAxis(Axis &$axis) : void{ $this->addBits(1); } diff --git a/src/data/runtime/RuntimeDataWriter.php b/src/data/runtime/RuntimeDataWriter.php index 382aa9bf6..c36a436d2 100644 --- a/src/data/runtime/RuntimeDataWriter.php +++ b/src/data/runtime/RuntimeDataWriter.php @@ -26,7 +26,6 @@ namespace pocketmine\data\runtime; use pocketmine\block\utils\WallConnectionType; use pocketmine\math\Axis; use pocketmine\math\Facing; -use function array_flip; use function log; use function spl_object_id; @@ -74,78 +73,63 @@ final class RuntimeDataWriter implements RuntimeDataDescriber{ $this->writeBool($value); } - public function horizontalFacing(int &$facing) : void{ + public function horizontalFacing(Facing &$facing) : void{ $this->writeInt(2, match($facing){ Facing::NORTH => 0, Facing::EAST => 1, Facing::SOUTH => 2, Facing::WEST => 3, - default => throw new \InvalidArgumentException("Invalid horizontal facing $facing") + default => throw new \InvalidArgumentException("Invalid horizontal facing $facing->name") }); } /** - * @param int[] $faces + * @param Facing[] $faces */ public function facingFlags(array &$faces) : void{ - $uniqueFaces = array_flip($faces); + $uniqueFaces = []; + foreach($faces as $face){ + $uniqueFaces[$face->value] = true; + } foreach(Facing::ALL as $facing){ - $this->writeBool(isset($uniqueFaces[$facing])); + $this->writeBool(isset($uniqueFaces[$facing->value])); } } /** - * @param int[] $faces + * @param Facing[] $faces */ public function horizontalFacingFlags(array &$faces) : void{ - $uniqueFaces = array_flip($faces); + $uniqueFaces = []; + foreach($faces as $face){ + $uniqueFaces[$face->value] = true; + } foreach(Facing::HORIZONTAL as $facing){ - $this->writeBool(isset($uniqueFaces[$facing])); + $this->writeBool(isset($uniqueFaces[$facing->value])); } } - public function facing(int &$facing) : void{ - $this->writeInt(3, match($facing){ - 0 => Facing::DOWN, - 1 => Facing::UP, - 2 => Facing::NORTH, - 3 => Facing::SOUTH, - 4 => Facing::WEST, - 5 => Facing::EAST, - default => throw new \InvalidArgumentException("Invalid facing $facing") - }); + public function facingExcept(Facing &$facing, Facing $except) : void{ + $this->enum($facing); } - public function facingExcept(int &$facing, int $except) : void{ - $this->facing($facing); - } - - public function axis(int &$axis) : void{ - $this->writeInt(2, match($axis){ - Axis::X => 0, - Axis::Z => 1, - Axis::Y => 2, - default => throw new \InvalidArgumentException("Invalid axis $axis") - }); - } - - public function horizontalAxis(int &$axis) : void{ + public function horizontalAxis(Axis &$axis) : void{ $this->writeInt(1, match($axis){ Axis::X => 0, Axis::Z => 1, - default => throw new \InvalidArgumentException("Invalid horizontal axis $axis") + default => throw new \InvalidArgumentException("Invalid horizontal axis $axis->name") }); } /** * @param WallConnectionType[] $connections - * @phpstan-param array $connections + * @phpstan-param array, WallConnectionType> $connections */ public function wallConnections(array &$connections) : void{ $packed = 0; $offset = 0; foreach(Facing::HORIZONTAL as $facing){ - $packed += match($connections[$facing] ?? null){ + $packed += match($connections[$facing->value] ?? null){ null => 0, WallConnectionType::SHORT => 1, WallConnectionType::TALL => 2, diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 18cd75306..582df4b94 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -939,7 +939,7 @@ abstract class Entity{ return false; } - public function getHorizontalFacing() : int{ + public function getHorizontalFacing() : Facing{ $angle = fmod($this->location->yaw, 360); if($angle < 0){ $angle += 360.0; @@ -1161,7 +1161,7 @@ abstract class Entity{ $wantedZ = $dz; if($this->keepMovement){ - $this->boundingBox->offset($dx, $dy, $dz); + $this->boundingBox = $this->boundingBox->offsetCopy($dx, $dy, $dz); }else{ $this->ySize *= self::STEP_CLIP_MULTIPLIER; @@ -1175,7 +1175,7 @@ abstract class Entity{ $dy = $bb->calculateYOffset($moveBB, $dy); } - $moveBB->offset(0, $dy, 0); + $moveBB = $moveBB->offsetCopy(0, $dy, 0); $fallingFlag = ($this->onGround || ($dy !== $wantedY && $wantedY < 0)); @@ -1183,13 +1183,13 @@ abstract class Entity{ $dx = $bb->calculateXOffset($moveBB, $dx); } - $moveBB->offset($dx, 0, 0); + $moveBB = $moveBB->offsetCopy($dx, 0, 0); foreach($list as $bb){ $dz = $bb->calculateZOffset($moveBB, $dz); } - $moveBB->offset(0, 0, $dz); + $moveBB = $moveBB->offsetCopy(0, 0, $dz); $stepHeight = $this->getStepHeight(); @@ -1208,26 +1208,26 @@ abstract class Entity{ $dy = $bb->calculateYOffset($stepBB, $dy); } - $stepBB->offset(0, $dy, 0); + $stepBB = $stepBB->offsetCopy(0, $dy, 0); foreach($list as $bb){ $dx = $bb->calculateXOffset($stepBB, $dx); } - $stepBB->offset($dx, 0, 0); + $stepBB = $stepBB->offsetCopy($dx, 0, 0); foreach($list as $bb){ $dz = $bb->calculateZOffset($stepBB, $dz); } - $stepBB->offset(0, 0, $dz); + $stepBB = $stepBB->offsetCopy(0, 0, $dz); $reverseDY = -$dy; foreach($list as $bb){ $reverseDY = $bb->calculateYOffset($stepBB, $reverseDY); } $dy += $reverseDY; - $stepBB->offset(0, $reverseDY, 0); + $stepBB = $stepBB->offsetCopy(0, $reverseDY, 0); if(($cx ** 2 + $cz ** 2) >= ($dx ** 2 + $dz ** 2)){ $dx = $cx; @@ -1401,8 +1401,15 @@ abstract class Entity{ public function setRotation(float $yaw, float $pitch) : void{ Utils::checkFloatNotInfOrNaN("yaw", $yaw); Utils::checkFloatNotInfOrNaN("pitch", $pitch); - $this->location->yaw = $yaw; - $this->location->pitch = $pitch; + //TODO: maybe it's time to think about pulling rotation into a separate structure? + $this->location = new Location( + $this->location->x, + $this->location->y, + $this->location->z, + $this->location->world, + $yaw, + $pitch + ); $this->scheduleUpdate(); } diff --git a/src/entity/Living.php b/src/entity/Living.php index 6d62c85d2..888567c08 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -741,7 +741,7 @@ abstract class Living extends Entity{ if( !$block->isSameState($liquid) || $world->getBlockAt($x, $y + 1, $z)->getTypeId() !== BlockTypeIds::AIR || - count($world->getNearbyEntities(AxisAlignedBB::one()->offset($x, $y, $z))) !== 0 + count($world->getNearbyEntities(AxisAlignedBB::one()->offsetCopy($x, $y, $z))) !== 0 ){ continue; } diff --git a/src/entity/Location.php b/src/entity/Location.php index d9c101882..cfd3ebc01 100644 --- a/src/entity/Location.php +++ b/src/entity/Location.php @@ -27,7 +27,7 @@ use pocketmine\math\Vector3; use pocketmine\world\Position; use pocketmine\world\World; -class Location extends Position{ +readonly class Location extends Position{ public float $yaw; public float $pitch; diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index 78a006d77..f09dcc231 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -58,17 +58,17 @@ class Painting extends Entity{ 3 => Facing::EAST ]; private const FACING_TO_DATA = [ - Facing::SOUTH => 0, - Facing::WEST => 1, - Facing::NORTH => 2, - Facing::EAST => 3 + Facing::SOUTH->value => 0, + Facing::WEST->value => 1, + Facing::NORTH->value => 2, + Facing::EAST->value => 3 ]; protected Vector3 $blockIn; - protected int $facing; + protected Facing $facing; protected PaintingMotive $motive; - public function __construct(Location $location, Vector3 $blockIn, int $facing, PaintingMotive $motive, ?CompoundTag $nbt = null){ + public function __construct(Location $location, Vector3 $blockIn, Facing $facing, PaintingMotive $motive, ?CompoundTag $nbt = null){ $this->motive = $motive; $this->blockIn = $blockIn->asVector3(); $this->facing = $facing; @@ -96,8 +96,8 @@ class Painting extends Entity{ $nbt->setInt(self::TAG_TILE_Y, (int) $this->blockIn->y); $nbt->setInt(self::TAG_TILE_Z, (int) $this->blockIn->z); - $nbt->setByte(self::TAG_FACING_JE, self::FACING_TO_DATA[$this->facing]); - $nbt->setByte(self::TAG_DIRECTION_BE, self::FACING_TO_DATA[$this->facing]); //Save both for full compatibility + $nbt->setByte(self::TAG_FACING_JE, self::FACING_TO_DATA[$this->facing->value]); + $nbt->setByte(self::TAG_DIRECTION_BE, self::FACING_TO_DATA[$this->facing->value]); //Save both for full compatibility $nbt->setString(self::TAG_MOTIVE, $this->motive->getName()); @@ -125,7 +125,7 @@ class Painting extends Entity{ protected function recalculateBoundingBox() : void{ $side = $this->blockIn->getSide($this->facing); - $this->boundingBox = self::getPaintingBB($this->facing, $this->getMotive())->offset($side->x, $side->y, $side->z); + $this->boundingBox = self::getPaintingBB($this->facing, $this->getMotive())->offsetCopy($side->x, $side->y, $side->z); } public function onNearbyBlockChange() : void{ @@ -161,7 +161,7 @@ class Painting extends Entity{ ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2 ), - self::FACING_TO_DATA[$this->facing], + self::FACING_TO_DATA[$this->facing->value], $this->motive->getName() )); } @@ -177,14 +177,14 @@ class Painting extends Entity{ return $this->motive; } - public function getFacing() : int{ + public function getFacing() : Facing{ return $this->facing; } /** * Returns the bounding-box a painting with the specified motive would have at the given position and direction. */ - private static function getPaintingBB(int $facing, PaintingMotive $motive) : AxisAlignedBB{ + private static function getPaintingBB(Facing $facing, PaintingMotive $motive) : AxisAlignedBB{ $width = $motive->getWidth(); $height = $motive->getHeight(); @@ -192,17 +192,17 @@ class Painting extends Entity{ $verticalStart = (int) (ceil($height / 2) - 1); return AxisAlignedBB::one() - ->trim($facing, 15 / 16) - ->extend(Facing::rotateY($facing, true), $horizontalStart) - ->extend(Facing::rotateY($facing, false), -$horizontalStart + $width - 1) - ->extend(Facing::DOWN, $verticalStart) - ->extend(Facing::UP, -$verticalStart + $height - 1); + ->trimmedCopy($facing, 15 / 16) + ->extendedCopy(Facing::rotateY($facing, true), $horizontalStart) + ->extendedCopy(Facing::rotateY($facing, false), -$horizontalStart + $width - 1) + ->extendedCopy(Facing::DOWN, $verticalStart) + ->extendedCopy(Facing::UP, -$verticalStart + $height - 1); } /** * Returns whether a painting with the specified motive can be placed at the given position. */ - public static function canFit(World $world, Vector3 $blockIn, int $facing, bool $checkOverlap, PaintingMotive $motive) : bool{ + public static function canFit(World $world, Vector3 $blockIn, Facing $facing, bool $checkOverlap, PaintingMotive $motive) : bool{ $width = $motive->getWidth(); $height = $motive->getHeight(); @@ -227,7 +227,7 @@ class Painting extends Entity{ } if($checkOverlap){ - $bb = self::getPaintingBB($facing, $motive)->offset($blockIn->x, $blockIn->y, $blockIn->z); + $bb = self::getPaintingBB($facing, $motive)->offsetCopy($blockIn->x, $blockIn->y, $blockIn->z); foreach($world->getNearbyEntities($bb) as $entity){ if($entity instanceof self){ diff --git a/src/entity/projectile/IceBomb.php b/src/entity/projectile/IceBomb.php index 5a3525c74..db4393a52 100644 --- a/src/entity/projectile/IceBomb.php +++ b/src/entity/projectile/IceBomb.php @@ -46,7 +46,7 @@ class IceBomb extends Throwable{ if($block->getTypeId() === BlockTypeIds::WATER){ $pos = $block->getPosition(); - return AxisAlignedBB::one()->offset($pos->x, $pos->y, $pos->z)->calculateIntercept($start, $end); + return AxisAlignedBB::one()->offsetCopy($pos->x, $pos->y, $pos->z)->calculateIntercept($start, $end); } return parent::calculateInterceptWithBlock($block, $start, $end); diff --git a/src/entity/projectile/Projectile.php b/src/entity/projectile/Projectile.php index 68b6c4763..a6735b3fe 100644 --- a/src/entity/projectile/Projectile.php +++ b/src/entity/projectile/Projectile.php @@ -186,7 +186,7 @@ abstract class Projectile extends Entity{ $entityDistance = PHP_INT_MAX; $newDiff = $end->subtractVector($start); - foreach($world->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){ + foreach($world->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expandedCopy(1, 1, 1), $this) as $entity){ if($entity->getId() === $this->getOwningEntityId() && $this->ticksLived < 5){ continue; } diff --git a/src/event/player/PlayerBucketEvent.php b/src/event/player/PlayerBucketEvent.php index 30a55a472..d80de0dce 100644 --- a/src/event/player/PlayerBucketEvent.php +++ b/src/event/player/PlayerBucketEvent.php @@ -27,6 +27,7 @@ use pocketmine\block\Block; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\player\Player; /** @@ -38,7 +39,7 @@ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{ public function __construct( Player $who, private Block $blockClicked, - private int $blockFace, + private Facing $blockFace, private Item $bucket, private Item $itemInHand ){ @@ -67,7 +68,7 @@ abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable{ return $this->blockClicked; } - public function getBlockFace() : int{ + public function getBlockFace() : Facing{ return $this->blockFace; } } diff --git a/src/event/player/PlayerInteractEvent.php b/src/event/player/PlayerInteractEvent.php index 46daf7081..395e95b53 100644 --- a/src/event/player/PlayerInteractEvent.php +++ b/src/event/player/PlayerInteractEvent.php @@ -27,6 +27,7 @@ use pocketmine\block\Block; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; use pocketmine\item\Item; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -50,7 +51,7 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{ protected Item $item, protected Block $blockTouched, ?Vector3 $touchVector, - protected int $blockFace, + protected Facing $blockFace, protected int $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK ){ $this->player = $player; @@ -73,7 +74,7 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{ return $this->touchVector; } - public function getFace() : int{ + public function getFace() : Facing{ return $this->blockFace; } diff --git a/src/item/Bamboo.php b/src/item/Bamboo.php index d928000e0..4247f5015 100644 --- a/src/item/Bamboo.php +++ b/src/item/Bamboo.php @@ -25,6 +25,7 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; final class Bamboo extends Item{ @@ -32,7 +33,7 @@ final class Bamboo extends Item{ return 50; } - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::BAMBOO_SAPLING(); } } diff --git a/src/item/BeetrootSeeds.php b/src/item/BeetrootSeeds.php index 64c140086..f4be6f591 100644 --- a/src/item/BeetrootSeeds.php +++ b/src/item/BeetrootSeeds.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class BeetrootSeeds extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::BEETROOTS(); } } diff --git a/src/item/Bucket.php b/src/item/Bucket.php index ee69a0a8a..0fce40ef6 100644 --- a/src/item/Bucket.php +++ b/src/item/Bucket.php @@ -28,6 +28,7 @@ use pocketmine\block\BlockTypeIds; use pocketmine\block\Liquid; use pocketmine\block\VanillaBlocks; use pocketmine\event\player\PlayerBucketFillEvent; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -37,7 +38,7 @@ class Bucket extends Item{ return 16; } - public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ //TODO: move this to generic placement logic if($blockClicked instanceof Liquid && $blockClicked->isSource()){ $stack = clone $this; diff --git a/src/item/Carrot.php b/src/item/Carrot.php index fd4a93f2f..b55e0167d 100644 --- a/src/item/Carrot.php +++ b/src/item/Carrot.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class Carrot extends Food{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::CARROTS(); } diff --git a/src/item/CocoaBeans.php b/src/item/CocoaBeans.php index 57053cd8d..fb7be46fe 100644 --- a/src/item/CocoaBeans.php +++ b/src/item/CocoaBeans.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class CocoaBeans extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::COCOA_POD(); } } diff --git a/src/item/CoralFan.php b/src/item/CoralFan.php index 7fdfc9114..a5cb6b774 100644 --- a/src/item/CoralFan.php +++ b/src/item/CoralFan.php @@ -46,7 +46,7 @@ final class CoralFan extends Item{ $this->encodeCoralType($w); } - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ $block = $clickedFace !== null && Facing::axis($clickedFace) !== Axis::Y ? VanillaBlocks::WALL_CORAL_FAN() : VanillaBlocks::CORAL_FAN(); return $block->setCoralType($this->coralType)->setDead($this->dead); diff --git a/src/item/EndCrystal.php b/src/item/EndCrystal.php index 320d657e6..e39d16ae0 100644 --- a/src/item/EndCrystal.php +++ b/src/item/EndCrystal.php @@ -35,13 +35,13 @@ use function count; class EndCrystal extends Item{ - public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if($blockClicked->getTypeId() === BlockTypeIds::OBSIDIAN || $blockClicked->getTypeId() === BlockTypeIds::BEDROCK){ $pos = $blockClicked->getPosition(); $world = $pos->getWorld(); $bb = AxisAlignedBB::one() - ->offset($pos->getX(), $pos->getY(), $pos->getZ()) - ->extend(Facing::UP, 1); + ->offsetCopy($pos->getX(), $pos->getY(), $pos->getZ()) + ->extendedCopy(Facing::UP, 1); if( count($world->getNearbyEntities($bb)) === 0 && $blockClicked->getSide(Facing::UP)->getTypeId() === BlockTypeIds::AIR && diff --git a/src/item/FireCharge.php b/src/item/FireCharge.php index a612e0897..56b192d99 100644 --- a/src/item/FireCharge.php +++ b/src/item/FireCharge.php @@ -26,13 +26,14 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\BlockTypeIds; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\sound\BlazeShootSound; class FireCharge extends Item{ - public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if($blockReplace->getTypeId() === BlockTypeIds::AIR){ $world = $player->getWorld(); $world->setBlock($blockReplace->getPosition(), VanillaBlocks::FIRE()); diff --git a/src/item/FlintSteel.php b/src/item/FlintSteel.php index 3e694eb0d..8345a8b19 100644 --- a/src/item/FlintSteel.php +++ b/src/item/FlintSteel.php @@ -26,13 +26,14 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\BlockTypeIds; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\sound\FlintSteelSound; class FlintSteel extends Tool{ - public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if($blockReplace->getTypeId() === BlockTypeIds::AIR){ $world = $player->getWorld(); $world->setBlock($blockReplace->getPosition(), VanillaBlocks::FIRE()); diff --git a/src/item/GlassBottle.php b/src/item/GlassBottle.php index c638b109f..38a1e0ba1 100644 --- a/src/item/GlassBottle.php +++ b/src/item/GlassBottle.php @@ -25,12 +25,13 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\BlockTypeIds; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; class GlassBottle extends Item{ - public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if($blockClicked->getTypeId() === BlockTypeIds::WATER){ $this->pop(); $returnedItems[] = VanillaItems::POTION()->setType(PotionType::WATER); diff --git a/src/item/GlowBerries.php b/src/item/GlowBerries.php index e959b7b9e..60d1626b3 100644 --- a/src/item/GlowBerries.php +++ b/src/item/GlowBerries.php @@ -25,6 +25,7 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class GlowBerries extends Food{ @@ -36,7 +37,7 @@ class GlowBerries extends Food{ return 0.4; } - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::CAVE_VINES(); } } diff --git a/src/item/HangingSign.php b/src/item/HangingSign.php index a6752087a..58c58d627 100644 --- a/src/item/HangingSign.php +++ b/src/item/HangingSign.php @@ -41,7 +41,7 @@ final class HangingSign extends Item{ parent::__construct($identifier, $name); } - public function getPlacementTransaction(Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : ?BlockTransaction{ + public function getPlacementTransaction(Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : ?BlockTransaction{ if($face !== Facing::DOWN){ return $this->tryPlacementTransaction(clone $this->wallVariant, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -52,7 +52,7 @@ final class HangingSign extends Item{ return $ceilingEdgeTx ?? $this->tryPlacementTransaction(clone $this->centerPointCeilingVariant, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ //we don't have enough information here to decide which ceiling type to use return $clickedFace === Facing::DOWN ? clone $this->centerPointCeilingVariant : clone $this->wallVariant; } diff --git a/src/item/Item.php b/src/item/Item.php index 1a9202fc8..d9b9d835b 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -38,6 +38,7 @@ use pocketmine\data\SavedDataLoadingException; use pocketmine\entity\Entity; use pocketmine\entity\Living; use pocketmine\item\enchantment\EnchantmentInstance; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\nbt\LittleEndianNbtSerializer; use pocketmine\nbt\NBT; @@ -489,7 +490,7 @@ class Item implements \JsonSerializable{ return $this->getBlock()->canBePlaced(); } - protected final function tryPlacementTransaction(Block $blockPlace, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player) : ?BlockTransaction{ + protected final function tryPlacementTransaction(Block $blockPlace, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player) : ?BlockTransaction{ $position = $blockReplace->getPosition(); $blockPlace->position($position->getWorld(), $position->getFloorX(), $position->getFloorY(), $position->getFloorZ()); if(!$blockPlace->canBePlacedAt($blockReplace, $clickVector, $face, $blockReplace->getPosition()->equals($blockClicked->getPosition()))){ @@ -499,14 +500,14 @@ class Item implements \JsonSerializable{ return $blockPlace->place($transaction, $this, $blockReplace, $blockClicked, $face, $clickVector, $player) ? $transaction : null; } - public function getPlacementTransaction(Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : ?BlockTransaction{ + public function getPlacementTransaction(Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : ?BlockTransaction{ return $this->tryPlacementTransaction($this->getBlock($face), $blockReplace, $blockClicked, $face, $clickVector, $player); } /** * Returns the block corresponding to this Item. */ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::AIR(); } @@ -605,7 +606,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{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ return ItemUseResult::NONE; } diff --git a/src/item/ItemBlock.php b/src/item/ItemBlock.php index 015c78471..9d10f5e87 100644 --- a/src/item/ItemBlock.php +++ b/src/item/ItemBlock.php @@ -26,6 +26,7 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\BlockTypeIds; use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\math\Facing; /** * Class used for Items that directly represent blocks, such as stone, dirt, wood etc. @@ -44,7 +45,7 @@ final class ItemBlock extends Item{ $this->block->describeBlockItemState($w); } - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return clone $this->block; } diff --git a/src/item/ItemBlockWallOrFloor.php b/src/item/ItemBlockWallOrFloor.php index c20c73a1d..963b3cfb9 100644 --- a/src/item/ItemBlockWallOrFloor.php +++ b/src/item/ItemBlockWallOrFloor.php @@ -38,7 +38,7 @@ class ItemBlockWallOrFloor extends Item{ $this->wallVariant = $wallVariant->getStateId(); } - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ if($clickedFace !== null && Facing::axis($clickedFace) !== Axis::Y){ return RuntimeBlockStateRegistry::getInstance()->fromStateId($this->wallVariant); } diff --git a/src/item/LiquidBucket.php b/src/item/LiquidBucket.php index eb2cb18ed..c2f0d143e 100644 --- a/src/item/LiquidBucket.php +++ b/src/item/LiquidBucket.php @@ -27,6 +27,7 @@ use pocketmine\block\Block; use pocketmine\block\Lava; use pocketmine\block\Liquid; use pocketmine\event\player\PlayerBucketEmptyEvent; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -54,7 +55,7 @@ class LiquidBucket extends Item{ return VanillaItems::BUCKET(); } - public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if(!$blockReplace->canBeReplaced()){ return ItemUseResult::NONE; } diff --git a/src/item/MelonSeeds.php b/src/item/MelonSeeds.php index feecf09c7..f9604712b 100644 --- a/src/item/MelonSeeds.php +++ b/src/item/MelonSeeds.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class MelonSeeds extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::MELON_STEM(); } } diff --git a/src/item/PaintingItem.php b/src/item/PaintingItem.php index a83c8dba8..48589e3e8 100644 --- a/src/item/PaintingItem.php +++ b/src/item/PaintingItem.php @@ -37,7 +37,7 @@ use function count; class PaintingItem extends Item{ - public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if(Facing::axis($face) === Axis::Y){ return ItemUseResult::NONE; } diff --git a/src/item/PitcherPod.php b/src/item/PitcherPod.php index be9393515..0a82c5f84 100644 --- a/src/item/PitcherPod.php +++ b/src/item/PitcherPod.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; final class PitcherPod extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::PITCHER_CROP(); } } diff --git a/src/item/Potato.php b/src/item/Potato.php index 8fe7fc8c7..61ba36b6f 100644 --- a/src/item/Potato.php +++ b/src/item/Potato.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class Potato extends Food{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::POTATOES(); } diff --git a/src/item/PumpkinSeeds.php b/src/item/PumpkinSeeds.php index 3502500cc..bb31a17f7 100644 --- a/src/item/PumpkinSeeds.php +++ b/src/item/PumpkinSeeds.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class PumpkinSeeds extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::PUMPKIN_STEM(); } } diff --git a/src/item/Redstone.php b/src/item/Redstone.php index ffa58167c..92a7fc303 100644 --- a/src/item/Redstone.php +++ b/src/item/Redstone.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class Redstone extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::REDSTONE_WIRE(); } } diff --git a/src/item/SpawnEgg.php b/src/item/SpawnEgg.php index ab4f0e149..c6756e4f9 100644 --- a/src/item/SpawnEgg.php +++ b/src/item/SpawnEgg.php @@ -25,6 +25,7 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\entity\Entity; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\utils\Utils; @@ -34,7 +35,7 @@ abstract class SpawnEgg extends Item{ abstract protected function createEntity(World $world, Vector3 $pos, float $yaw, float $pitch) : Entity; - public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ + public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ $entity = $this->createEntity($player->getWorld(), $blockReplace->getPosition()->add(0.5, 0, 0.5), Utils::getRandomFloat() * 360, 0); if($this->hasCustomName()){ diff --git a/src/item/StringItem.php b/src/item/StringItem.php index 2474f9ac9..7a1fc6367 100644 --- a/src/item/StringItem.php +++ b/src/item/StringItem.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class StringItem extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::TRIPWIRE(); } } diff --git a/src/item/SweetBerries.php b/src/item/SweetBerries.php index e377175c2..e1ebbf933 100644 --- a/src/item/SweetBerries.php +++ b/src/item/SweetBerries.php @@ -25,6 +25,7 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class SweetBerries extends Food{ @@ -36,7 +37,7 @@ class SweetBerries extends Food{ return 1.2; } - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::SWEET_BERRY_BUSH(); } } diff --git a/src/item/TorchflowerSeeds.php b/src/item/TorchflowerSeeds.php index 123af35a0..22725c733 100644 --- a/src/item/TorchflowerSeeds.php +++ b/src/item/TorchflowerSeeds.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; final class TorchflowerSeeds extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::TORCHFLOWER_CROP(); } } diff --git a/src/item/WheatSeeds.php b/src/item/WheatSeeds.php index 775cc59c2..6657681fe 100644 --- a/src/item/WheatSeeds.php +++ b/src/item/WheatSeeds.php @@ -25,10 +25,11 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\VanillaBlocks; +use pocketmine\math\Facing; class WheatSeeds extends Item{ - public function getBlock(?int $clickedFace = null) : Block{ + public function getBlock(?Facing $clickedFace = null) : Block{ return VanillaBlocks::WHEAT(); } } diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index b5990d38f..8503f4eec 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -110,7 +110,6 @@ use function count; use function fmod; use function get_debug_type; use function implode; -use function in_array; use function is_infinite; use function is_nan; use function json_decode; @@ -280,7 +279,7 @@ class InGamePacketHandler extends PacketHandler{ foreach(Utils::promoteKeys($blockActions) as $k => $blockAction){ $actionHandled = false; if($blockAction instanceof PlayerBlockActionStopBreak){ - $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), new BlockPosition(0, 0, 0), Facing::DOWN); + $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), new BlockPosition(0, 0, 0), 0); }elseif($blockAction instanceof PlayerBlockActionWithBlockInfo){ $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), $blockAction->getBlockPosition(), $blockAction->getFace()); } @@ -493,16 +492,16 @@ class InGamePacketHandler extends PacketHandler{ } //TODO: end hack for client spam bug - self::validateFacing($data->getFace()); + $face = self::deserializeFacing($data->getFace()); $blockPos = $data->getBlockPosition(); $vBlockPos = new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ()); - $this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos); + $this->player->interactBlock($vBlockPos, $face, $clickPos); //always sync this in case plugins caused a different result than the client expected //we *could* try to enhance detection of plugin-altered behaviour, but this would require propagating //more information up the stack. For now I think this is good enough. //if only the client would tell us what blocks it thinks changed... - $this->syncBlocksNearby($vBlockPos, $data->getFace()); + $this->syncBlocksNearby($vBlockPos, $face); return true; case UseItemTransactionData::ACTION_CLICK_AIR: if($this->player->isUsingItem()){ @@ -522,16 +521,19 @@ class InGamePacketHandler extends PacketHandler{ /** * @throws PacketHandlingException */ - private static function validateFacing(int $facing) : void{ - if(!in_array($facing, Facing::ALL, true)){ + private static function deserializeFacing(int $facing) : Facing{ + //TODO: dodgy use of network facing values as internal values here - they may not be the same in the future + $case = Facing::tryFrom($facing); + if($case === null){ throw new PacketHandlingException("Invalid facing value $facing"); } + return $case; } /** * Syncs blocks nearby to ensure that the client and server agree on the world's blocks after a block interaction. */ - private function syncBlocksNearby(Vector3 $blockPos, ?int $face) : void{ + private function syncBlocksNearby(Vector3 $blockPos, ?Facing $face) : void{ if($blockPos->distanceSquared($this->player->getLocation()) < 10000){ $blocks = $blockPos->sidesArray(); if($face !== null){ @@ -676,13 +678,13 @@ class InGamePacketHandler extends PacketHandler{ return $this->handlePlayerActionFromData($packet->action, $packet->blockPosition, $packet->face); } - private function handlePlayerActionFromData(int $action, BlockPosition $blockPosition, int $face) : bool{ + private function handlePlayerActionFromData(int $action, BlockPosition $blockPosition, int $extraData) : bool{ $pos = new Vector3($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ()); switch($action){ case PlayerAction::START_BREAK: case PlayerAction::CONTINUE_DESTROY_BLOCK: //destroy the next block while holding down left click - self::validateFacing($face); + $face = self::deserializeFacing($extraData); if($this->lastBlockAttacked !== null && $blockPosition->equals($this->lastBlockAttacked)){ //the client will send CONTINUE_DESTROY_BLOCK for the currently targeted block directly before it //sends PREDICT_DESTROY_BLOCK, but also when it starts to break the block @@ -710,7 +712,7 @@ class InGamePacketHandler extends PacketHandler{ $this->player->stopSleep(); break; case PlayerAction::CRACK_BREAK: - self::validateFacing($face); + $face = self::deserializeFacing($extraData); $this->player->continueBreakBlock($pos, $face); $this->lastBlockAttacked = $blockPosition; break; @@ -720,6 +722,7 @@ class InGamePacketHandler extends PacketHandler{ //TODO: do we need to handle this? case PlayerAction::PREDICT_DESTROY_BLOCK: if(!$this->player->breakBlock($pos)){ + $face = self::deserializeFacing($extraData); $this->syncBlocksNearby($pos, $face); } $this->lastBlockAttacked = null; diff --git a/src/player/Player.php b/src/player/Player.php index 762187b24..20ef235d9 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -105,6 +105,8 @@ use pocketmine\item\Releasable; use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\Language; use pocketmine\lang\Translatable; +use pocketmine\math\AxisAlignedBB; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; @@ -1311,9 +1313,15 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ if($this->gamemode === GameMode::SPECTATOR){ $this->onGround = false; }else{ - $bb = clone $this->boundingBox; - $bb->minY = $this->location->y - 0.2; - $bb->maxY = $this->location->y + 0.2; + //TODO: AxisAlignedBB::withComponents() would be nice here + $bb = new AxisAlignedBB( + $this->boundingBox->minX, + $this->location->y - 0.2, + $this->boundingBox->minZ, + $this->boundingBox->maxX, + $this->location->y + 0.2, + $this->boundingBox->maxZ + ); //we're already at the new position at this point; check if there are blocks we might have landed on between //the old and new positions (running down stairs necessitates this) @@ -1853,7 +1861,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ * * @return bool if an action took place successfully */ - public function attackBlock(Vector3 $pos, int $face) : bool{ + public function attackBlock(Vector3 $pos, Facing $face) : bool{ if($pos->distanceSquared($this->location) > 10000){ return false; //TODO: maybe this should throw an exception instead? } @@ -1887,7 +1895,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ return true; } - public function continueBreakBlock(Vector3 $pos, int $face) : void{ + public function continueBreakBlock(Vector3 $pos, Facing $face) : void{ if($this->blockBreakHandler !== null && $this->blockBreakHandler->getBlockPos()->distanceSquared($pos) < 0.0001){ $this->blockBreakHandler->setTargetedFace($face); } @@ -1930,7 +1938,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ * * @return bool if it did something */ - public function interactBlock(Vector3 $pos, int $face, Vector3 $clickOffset) : bool{ + public function interactBlock(Vector3 $pos, Facing $face, Vector3 $clickOffset) : bool{ $this->setUsingItem(false); if($this->canInteract($pos->add(0.5, 0.5, 0.5), $this->isCreative() ? self::MAX_REACH_DISTANCE_CREATIVE : self::MAX_REACH_DISTANCE_SURVIVAL)){ diff --git a/src/player/SurvivalBlockBreakHandler.php b/src/player/SurvivalBlockBreakHandler.php index 57c2842ce..ee52fde0e 100644 --- a/src/player/SurvivalBlockBreakHandler.php +++ b/src/player/SurvivalBlockBreakHandler.php @@ -47,7 +47,7 @@ final class SurvivalBlockBreakHandler{ private Player $player, private Vector3 $blockPos, private Block $block, - private int $targetedFace, + private Facing $targetedFace, private int $maxPlayerDistance, private int $fxTickInterval = self::DEFAULT_FX_INTERVAL_TICKS ){ @@ -123,12 +123,11 @@ final class SurvivalBlockBreakHandler{ return $this->blockPos; } - public function getTargetedFace() : int{ + public function getTargetedFace() : Facing{ return $this->targetedFace; } - public function setTargetedFace(int $face) : void{ - Facing::validate($face); + public function setTargetedFace(Facing $face) : void{ $this->targetedFace = $face; } diff --git a/src/world/Position.php b/src/world/Position.php index 62a4b51f5..79bbefdd9 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -23,12 +23,13 @@ declare(strict_types=1); namespace pocketmine\world; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\utils\AssumptionFailedError; use function assert; -class Position extends Vector3{ - public ?World $world = null; +readonly class Position extends Vector3{ + public ?World $world; public function __construct(float|int $x, float|int $y, float|int $z, ?World $world){ parent::__construct($x, $y, $z); @@ -71,8 +72,6 @@ class Position extends Vector3{ */ public function isValid() : bool{ if($this->world !== null && !$this->world->isLoaded()){ - $this->world = null; - return false; } @@ -84,7 +83,7 @@ class Position extends Vector3{ * * @return Position */ - public function getSide(int $side, int $step = 1){ + public function getSide(Facing $side, int $step = 1){ assert($this->isValid()); return Position::fromObject(parent::getSide($side, $step), $this->world); diff --git a/src/world/World.php b/src/world/World.php index 951eb53f8..ee70bc99b 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -983,7 +983,7 @@ class World implements ChunkManager{ continue; } } - foreach($this->getNearbyEntities(AxisAlignedBB::one()->offset($x, $y, $z)) as $entity){ + foreach($this->getNearbyEntities(AxisAlignedBB::one()->offsetCopy($x, $y, $z)) as $entity){ $entity->onNearbyBlockChange(); } $block->onNearbyBlockChange(); @@ -1611,7 +1611,7 @@ class World implements ChunkManager{ $stateCollisionInfo = $this->getBlockCollisionInfo($x, $y, $z, $collisionInfo); $boxes = match($stateCollisionInfo){ RuntimeBlockStateRegistry::COLLISION_NONE => [], - RuntimeBlockStateRegistry::COLLISION_CUBE => [AxisAlignedBB::one()->offset($x, $y, $z)], + RuntimeBlockStateRegistry::COLLISION_CUBE => [AxisAlignedBB::one()->offsetCopy($x, $y, $z)], default => $this->getBlockAt($x, $y, $z)->getCollisionBoxes() }; @@ -1625,7 +1625,7 @@ class World implements ChunkManager{ $stateCollisionInfo = $this->getBlockCollisionInfo($offsetX, $offsetY, $offsetZ, $collisionInfo); if($stateCollisionInfo === RuntimeBlockStateRegistry::COLLISION_MAY_OVERFLOW){ //avoid allocating this unless it's needed - $cellBB ??= AxisAlignedBB::one()->offset($x, $y, $z); + $cellBB ??= AxisAlignedBB::one()->offsetCopy($x, $y, $z); $extraBoxes = $this->getBlockAt($offsetX, $offsetY, $offsetZ)->getCollisionBoxes(); foreach($extraBoxes as $extraBox){ if($extraBox->intersectsWith($cellBB)){ @@ -2219,7 +2219,7 @@ class World implements ChunkManager{ * @param bool $playSound Whether to play a block-place sound if the block was placed successfully. * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped if the inventory is full) */ - public function useItemOn(Vector3 $vector, Item &$item, int $face, ?Vector3 $clickVector = null, ?Player $player = null, bool $playSound = false, array &$returnedItems = []) : bool{ + public function useItemOn(Vector3 $vector, Item &$item, Facing $face, ?Vector3 $clickVector = null, ?Player $player = null, bool $playSound = false, array &$returnedItems = []) : bool{ $blockClicked = $this->getBlock($vector); $blockReplace = $blockClicked->getSide($face); diff --git a/src/world/generator/object/AcaciaTree.php b/src/world/generator/object/AcaciaTree.php index 75e58a9b3..f5ab5665c 100644 --- a/src/world/generator/object/AcaciaTree.php +++ b/src/world/generator/object/AcaciaTree.php @@ -84,7 +84,7 @@ final class AcaciaTree extends Tree{ } } - protected function placeBranch(BlockTransaction $transaction, Vector3 $start, int $branchFacing, int $maxDiagonal, int $length) : Vector3{ + protected function placeBranch(BlockTransaction $transaction, Vector3 $start, Facing $branchFacing, int $maxDiagonal, int $length) : Vector3{ $diagonalPlaced = 0; $nextBlockPos = $start; diff --git a/src/world/light/LightPropagationContext.php b/src/world/light/LightPropagationContext.php index c3d45b3c6..7f363c785 100644 --- a/src/world/light/LightPropagationContext.php +++ b/src/world/light/LightPropagationContext.php @@ -23,13 +23,15 @@ declare(strict_types=1); namespace pocketmine\world\light; +use pocketmine\math\Facing; + final class LightPropagationContext{ /** @phpstan-var \SplQueue */ public \SplQueue $spreadQueue; /** * @var int[]|true[] - * @phpstan-var array + * @phpstan-var array */ public array $spreadVisited = []; diff --git a/src/world/light/LightUpdate.php b/src/world/light/LightUpdate.php index b7455c6cc..039d4d991 100644 --- a/src/world/light/LightUpdate.php +++ b/src/world/light/LightUpdate.php @@ -156,11 +156,12 @@ abstract class LightUpdate{ continue; } - foreach(Facing::OFFSET as $side => [$ox, $oy, $oz]){ + foreach(Facing::ALL as $side){ if($from === $side){ //don't check the side that this node received its initial light from continue; } + [$ox, $oy, $oz] = Facing::OFFSET[$side->value]; $cx = $x + $ox; $cy = $y + $oy; $cz = $z + $oz; @@ -204,7 +205,7 @@ abstract class LightUpdate{ } } - protected function computeSpreadLight(int $x, int $y, int $z, int $newAdjacentLevel, LightPropagationContext $context, LightArray $lightArray, SubChunk $subChunk, int $side) : void{ + protected function computeSpreadLight(int $x, int $y, int $z, int $newAdjacentLevel, LightPropagationContext $context, LightArray $lightArray, SubChunk $subChunk, Facing $side) : void{ $lx = $x & SubChunk::COORD_MASK; $ly = $y & SubChunk::COORD_MASK; $lz = $z & SubChunk::COORD_MASK; diff --git a/src/world/particle/BlockPunchParticle.php b/src/world/particle/BlockPunchParticle.php index 74478ca95..f023501ea 100644 --- a/src/world/particle/BlockPunchParticle.php +++ b/src/world/particle/BlockPunchParticle.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\world\particle; use pocketmine\block\Block; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\network\mcpe\convert\TypeConverter; use pocketmine\network\mcpe\protocol\LevelEventPacket; @@ -35,10 +36,14 @@ use pocketmine\network\mcpe\protocol\types\LevelEvent; class BlockPunchParticle implements Particle{ public function __construct( private Block $block, - private int $face + private Facing $face ){} public function encode(Vector3 $pos) : array{ - return [LevelEventPacket::create(LevelEvent::PARTICLE_PUNCH_BLOCK, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->block->getStateId()) | ($this->face << 24), $pos)]; + return [LevelEventPacket::create( + LevelEvent::PARTICLE_PUNCH_BLOCK, + //TODO: dodgy use of internal value for protocol - this should be properly translated + TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($this->block->getStateId()) | ($this->face->value << 24), $pos) + ]; } } diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index 06abe7fee..04e476e96 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -601,7 +601,7 @@ parameters: path: ../../../src/crash/CrashDumpRenderer.php - - message: '#^Parameter \#1 \$faces of method pocketmine\\block\\Vine\:\:setFaces\(\) expects list\<2\|3\|4\|5\>, array\ given\.$#' + message: '#^Parameter \#1 \$faces of method pocketmine\\block\\Vine\:\:setFaces\(\) expects list\, array\ given\.$#' identifier: argument.type count: 1 path: ../../../src/data/bedrock/block/convert/VanillaBlockMappings.php