diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index c6a5a8ed2a..fefc06c0a9 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -28,7 +28,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Clone pmmp/PocketMine-Docker repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: pmmp/PocketMine-Docker fetch-depth: 1 diff --git a/.github/workflows/discord-release-embed.php b/.github/workflows/discord-release-embed.php index 9bcb41bc8c..5acffdf2e1 100644 --- a/.github/workflows/discord-release-embed.php +++ b/.github/workflows/discord-release-embed.php @@ -18,7 +18,12 @@ /** * @phpstan-return array */ -function generateDiscordEmbed(string $version, string $channel, string $description, string $detailsUrl, string $sourceUrl, string $pharDownloadUrl, string $buildLogUrl, int $newsPingRoleId) : array{ +function generateDiscordEmbed(string $version, string $channel, string $description, string $detailsUrl, string $sourceUrl, string $pharDownloadUrl, string $buildLogUrl, int $newsPingRoleId, ?string $phpDownloadUrl) : array{ + if($phpDownloadUrl !== null){ + $phpEmbedLink = " | [PHP Binaries]($phpDownloadUrl)"; + }else{ + $phpEmbedLink = ""; + } return [ "content" => "<@&$newsPingRoleId> New PocketMine-MP release: $version ($channel)", "embeds" => [ @@ -27,7 +32,7 @@ function generateDiscordEmbed(string $version, string $channel, string $descript "description" => << $detailsUrl, "color" => $channel === "stable" ? 0x57ab5a : 0xc69026 @@ -84,10 +89,21 @@ function generateDiscordEmbed(string $version, string $channel, string $descript $sourceUrl = $buildInfoJson["source_url"]; $pharDownloadUrl = $buildInfoJson["download_url"]; $buildLogUrl = $buildInfoJson["build_log_url"]; +$phpBinaryUrl = $buildInfoJson["php_download_url"] ?? null; $description = $releaseInfoJson["body"]; -$discordPayload = generateDiscordEmbed($buildInfoJson["base_version"], $buildInfoJson["channel"], $description, $detailsUrl, $sourceUrl, $pharDownloadUrl, $buildLogUrl, (int) $newsPingRoleId); +$discordPayload = generateDiscordEmbed( + $buildInfoJson["base_version"], + $buildInfoJson["channel"], + $description, + $detailsUrl, + $sourceUrl, + $pharDownloadUrl, + $buildLogUrl, + (int) $newsPingRoleId, + $phpBinaryUrl +); $response = Internet::postURL( $hookURL, diff --git a/.github/workflows/discord-release-notify.yml b/.github/workflows/discord-release-notify.yml index a8282f542a..a749229380 100644 --- a/.github/workflows/discord-release-notify.yml +++ b/.github/workflows/discord-release-notify.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP and tools uses: shivammathur/setup-php@2.25.5 diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 5b76a9d053..4cf78f57ef 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -11,16 +11,18 @@ jobs: runs-on: ubuntu-20.04 strategy: fail-fast: false + matrix: + php-version: [8.1] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Setup PHP uses: shivammathur/setup-php@2.25.5 with: - php-version: 8.1 + php-version: ${{ matrix.php-version }} - name: Restore Composer package cache uses: actions/cache@v3 @@ -58,8 +60,21 @@ jobs: echo CHANGELOG_SUFFIX=$(php -r 'require "vendor/autoload.php"; echo \pocketmine\VersionInfo::BUILD_CHANNEL === "stable" ? "" : "-" . \pocketmine\VersionInfo::BUILD_CHANNEL;') >> $GITHUB_OUTPUT echo PRERELEASE=$(php -r 'require "vendor/autoload.php"; echo \pocketmine\VersionInfo::BUILD_CHANNEL === "stable" ? "false" : "true";') >> $GITHUB_OUTPUT + - name: Generate PHP binary download URL + id: php-binary-url + run: | + echo PHP_BINARY_URL="${{ github.server_url }}/${{ github.repository_owner }}/PHP-Binaries/releases/tag/php-${{ matrix.php-version }}-latest" >> $GITHUB_OUTPUT + - name: Generate build info - run: php build/generate-build-info-json.php ${{ github.sha }} ${{ steps.get-pm-version.outputs.PM_VERSION }} ${{ github.repository }} ${{ steps.build-number.outputs.BUILD_NUMBER }} ${{ github.run_id }} > build_info.json + run: | + php build/generate-build-info-json.php \ + ${{ github.sha }} \ + ${{ steps.get-pm-version.outputs.PM_VERSION }} \ + ${{ github.repository }} \ + ${{ steps.build-number.outputs.BUILD_NUMBER }} \ + ${{ github.run_id }} \ + ${{ steps.php-binary-url.outputs.PHP_BINARY_URL }} \ + > build_info.json - name: Upload release artifacts uses: actions/upload-artifact@v3 @@ -71,7 +86,7 @@ jobs: ${{ github.workspace }}/build_info.json - name: Create draft release - uses: ncipollo/release-action@v1.12.0 + uses: ncipollo/release-action@v1.13.0 with: artifacts: ${{ github.workspace }}/PocketMine-MP.phar,${{ github.workspace }}/start.*,${{ github.workspace }}/build_info.json commit: ${{ github.sha }} @@ -84,3 +99,5 @@ jobs: **For Minecraft: Bedrock Edition ${{ steps.get-pm-version.outputs.MCPE_VERSION }}** Please see the [changelogs](${{ github.server_url }}/${{ github.repository }}/blob/${{ steps.get-pm-version.outputs.PM_VERSION }}/changelogs/${{ steps.get-pm-version.outputs.PM_VERSION_SHORT }}${{ steps.get-pm-version.outputs.CHANGELOG_SUFFIX }}.md#${{ steps.get-pm-version.outputs.PM_VERSION_MD }}) for details. + + :information_source: Download the recommended PHP binary [here](${{ steps.php-binary-url.outputs.PHP_BINARY_URL }}). diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e045d5e9d9..e9bc329f12 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: php: ["8.1", "8.2"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: pmmp/setup-php-action@2.0.0 @@ -50,7 +50,7 @@ jobs: php: ["8.1", "8.2"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: pmmp/setup-php-action@2.0.0 @@ -85,7 +85,7 @@ jobs: php: ["8.1", "8.2"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true @@ -122,7 +122,7 @@ jobs: php: ["8.1", "8.2"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: pmmp/setup-php-action@2.0.0 @@ -150,12 +150,12 @@ jobs: - name: Regenerate KnownTranslation APIs run: php build/generate-known-translation-apis.php - - name: Regenerate RuntimeEnum(De)serializer - run: php build/generate-runtime-enum-serializers.php - - name: Regenerate BedrockData available files constants run: php build/generate-bedrockdata-path-consts.php + - name: Regenerate YmlServerProperties constants + run: php build/generate-pocketmine-yml-property-consts.php + - name: Verify code is unchanged run: | git diff @@ -168,7 +168,7 @@ jobs: fail-fast: false steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP and tools uses: shivammathur/setup-php@2.25.5 diff --git a/.github/workflows/update-updater-api.yml b/.github/workflows/update-updater-api.yml index 7a695306be..3f42062fdb 100644 --- a/.github/workflows/update-updater-api.yml +++ b/.github/workflows/update-updater-api.yml @@ -14,7 +14,7 @@ jobs: - name: Install jq run: sudo apt update && sudo apt install jq -y - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: repository: ${{ github.repository_owner }}/update.pmmp.io ssh-key: ${{ secrets.UPDATE_PMMP_IO_DEPLOY_KEY }} diff --git a/build/generate-build-info-json.php b/build/generate-build-info-json.php index f0ffe7df87..b29d1c7285 100644 --- a/build/generate-build-info-json.php +++ b/build/generate-build-info-json.php @@ -23,13 +23,13 @@ require dirname(__DIR__) . '/vendor/autoload.php'; -if(count($argv) !== 6){ - fwrite(STDERR, "required args: \n"); +if(count($argv) !== 7){ + fwrite(STDERR, "required args: \n"); exit(1); } echo json_encode([ - "php_version" => sprintf("%d.%d", PHP_MAJOR_VERSION, PHP_MINOR_VERSION), + "php_version" => sprintf("%d.%d", PHP_MAJOR_VERSION, PHP_MINOR_VERSION), //deprecated "base_version" => \pocketmine\VersionInfo::BASE_VERSION, "build" => (int) $argv[4], "is_dev" => \pocketmine\VersionInfo::IS_DEVELOPMENT_BUILD, @@ -41,4 +41,5 @@ "download_url" => "https://github.com/$argv[3]/releases/download/$argv[2]/PocketMine-MP.phar", "source_url" => "https://github.com/$argv[3]/tree/$argv[2]", "build_log_url" => "https://github.com/$argv[3]/actions/runs/$argv[5]", + "php_download_url" => $argv[6], ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR) . "\n"; diff --git a/build/generate-pocketmine-yml-property-consts.php b/build/generate-pocketmine-yml-property-consts.php new file mode 100644 index 0000000000..dcc574f8ab --- /dev/null +++ b/build/generate-pocketmine-yml-property-consts.php @@ -0,0 +1,120 @@ + $constants + * @phpstan-param-out array $constants + */ +function collectProperties(string $prefix, array $properties, array &$constants) : void{ + foreach($properties as $propertyName => $property){ + $fullPropertyName = ($prefix !== "" ? $prefix . "." : "") . $propertyName; + + $constName = str_replace([".", "-"], "_", strtoupper($fullPropertyName)); + $constants[$constName] = $fullPropertyName; + + if(is_array($property)){ + collectProperties($fullPropertyName, $property, $constants); + } + } +} + +collectProperties("", $defaultConfig, $constants); +ksort($constants, SORT_STRING); + +$file = fopen(dirname(__DIR__) . '/src/YmlServerProperties.php', 'wb'); +if($file === false){ + fwrite(STDERR, "Failed to open output file\n"); + exit(1); +} +fwrite($file, " $propertyName){ + fwrite($file, "\tpublic const $constName = '$propertyName';\n"); +} +fwrite($file, "}\n"); + +fclose($file); + +echo "Done. Don't forget to run CS fixup after generating code.\n"; diff --git a/build/generate-runtime-enum-serializers.php b/build/generate-runtime-enum-serializers.php deleted file mode 100644 index 805ed18e12..0000000000 --- a/build/generate-runtime-enum-serializers.php +++ /dev/null @@ -1,265 +0,0 @@ - $memberNames - * - * @return string[] - * @phpstan-return list - */ -function buildWriterFunc(string $virtualTypeName, string $nativeTypeName, array $memberNames, string $functionName) : array{ - $bits = getBitsRequired($memberNames); - $lines = []; - - $lines[] = "public function $functionName(\\$nativeTypeName &\$value) : void{"; - $lines[] = "\t\$this->writeInt($bits, match(\$value){"; - - foreach($memberNames as $key => $memberName){ - $lines[] = "\t\t$memberName => $key,"; - } - $lines[] = "\t\tdefault => throw new \pocketmine\utils\AssumptionFailedError(\"All $virtualTypeName cases should be covered\")"; - $lines[] = "\t});"; - $lines[] = "}"; - - return $lines; -} - -/** - * @param string[] $memberNames - * @phpstan-param list $memberNames - * - * @return string[] - * @phpstan-return list - */ -function buildReaderFunc(string $virtualTypeName, string $nativeTypeName, array $memberNames, string $functionName) : array{ - $bits = getBitsRequired($memberNames); - $lines = []; - - $lines[] = "public function $functionName(\\$nativeTypeName &\$value) : void{"; - $lines[] = "\t\$value = match(\$this->readInt($bits)){"; - - foreach($memberNames as $key => $memberName){ - $lines[] = "\t\t$key => $memberName,"; - } - $lines[] = "\t\tdefault => throw new InvalidSerializedRuntimeDataException(\"Invalid serialized value for $virtualTypeName\")"; - $lines[] = "\t};"; - $lines[] = "}"; - - return $lines; -} - -function buildInterfaceFunc(string $nativeTypeName, string $functionName) : string{ - return "public function $functionName(\\$nativeTypeName &\$value) : void;"; -} - -/** - * @param string[] $memberNames - * @phpstan-param list $memberNames - * - * @return string[] - * @phpstan-return list - */ -function buildSizeCalculationFunc(string $nativeTypeName, string $functionName, array $memberNames) : array{ - $lines = []; - $lines[] = "public function $functionName(\\$nativeTypeName &\$value) : void{"; - $lines[] = "\t\$this->addBits(" . getBitsRequired($memberNames) . ");"; - $lines[] = "}"; - - return $lines; -} - -/** - * @param mixed[] $members - */ -function getBitsRequired(array $members) : int{ - return (int) ceil(log(count($members), 2)); -} - -/** - * @param object[] $members - * @phpstan-param array $members - * - * @return string[] - * @phpstan-return list - */ -function stringifyEnumMembers(array $members, string $enumClass) : array{ - ksort($members, SORT_STRING); - return array_map(fn(string $enumCaseName) => "\\$enumClass::$enumCaseName()", array_keys($members)); -} - -$enumsUsed = [ - BellAttachmentType::getAll(), - CopperOxidation::getAll(), - CoralType::getAll(), - DirtType::getAll(), - DripleafState::getAll(), - DyeColor::getAll(), - FroglightType::getAll(), - LeverFacing::getAll(), - MedicineType::getAll(), - MushroomBlockType::getAll(), - MobHeadType::getAll(), - SlabType::getAll(), - SuspiciousStewType::getAll(), - PotionType::getAll() -]; - -$readerFuncs = [ - "" => [ - "abstract protected function readInt(int \$bits) : int;" - ] -]; -$writerFuncs = [ - "" => [ - "abstract protected function writeInt(int \$bits, int \$value) : void;" - ] -]; -$interfaceFuncs = []; -$sizeCalculationFuncs = [ - "" => [ - "abstract protected function addBits(int \$bits) : void;" - ] -]; - -foreach($enumsUsed as $enumMembers){ - if(count($enumMembers) === 0){ - throw new \InvalidArgumentException("Enum members cannot be empty"); - } - $reflect = new \ReflectionClass($enumMembers[array_key_first($enumMembers)]); - $virtualTypeName = $reflect->getShortName(); - $nativeTypeName = $reflect->getName(); - $functionName = lcfirst($virtualTypeName); - - $stringifiedMembers = stringifyEnumMembers($enumMembers, $nativeTypeName); - $writerFuncs[$functionName] = buildWriterFunc( - $virtualTypeName, - $nativeTypeName, - $stringifiedMembers, - $functionName - ); - $readerFuncs[$functionName] = buildReaderFunc( - $virtualTypeName, - $nativeTypeName, - $stringifiedMembers, - $functionName - ); - $interfaceFuncs[$functionName] = [buildInterfaceFunc( - $nativeTypeName, - $functionName - )]; - $sizeCalculationFuncs[$functionName] = buildSizeCalculationFunc( - $nativeTypeName, - $functionName, - $stringifiedMembers - ); -} - -/** - * @param string[][] $functions - * @phpstan-param array> $functions - */ -function printFunctions(array $functions, string $className, string $classType) : void{ - ksort($functions, SORT_STRING); - - ob_start(); - - echo <<<'HEADER' - "\t" . implode("\n\t", $functionLines), $functions)); - echo "\n\n}\n"; - - file_put_contents(dirname(__DIR__) . '/src/data/runtime/' . $className . '.php', ob_get_clean()); -} - -printFunctions($writerFuncs, "RuntimeEnumSerializerTrait", "trait"); -printFunctions($readerFuncs, "RuntimeEnumDeserializerTrait", "trait"); -printFunctions($interfaceFuncs, "RuntimeEnumDescriber", "interface"); -printFunctions($sizeCalculationFuncs, "RuntimeEnumSizeCalculatorTrait", "trait"); - -echo "Done. Don't forget to run CS fixup after generating code.\n"; diff --git a/changelogs/4.23.md b/changelogs/4.23.md index 750261e4b0..317b6b458d 100644 --- a/changelogs/4.23.md +++ b/changelogs/4.23.md @@ -60,3 +60,9 @@ Released 9th August 2023. - Fixed `PluginBase->saveResource()` leaking file resources when the data file already exists in the plugin's data folder. This bug existed since 2014 and was only discovered recently. - Fixed coral blocks becoming dead after calling `getDropsForCompatibleTool()` on them. - Fixed `BlockDeathEvent->getOldState()` returning a block which is already dead. + +# 4.23.6 +Released 21st August 2023. + +## Fixes +- Added a workaround for armor and other inventories not working correctly after inventory sync. This is caused by a client bug. diff --git a/changelogs/4.24.md b/changelogs/4.24.md new file mode 100644 index 0000000000..2d28e90649 --- /dev/null +++ b/changelogs/4.24.md @@ -0,0 +1,17 @@ +# 4.24.0 +Released 20th September 2023. + +**For Minecraft: Bedrock Edition 1.20.30** + +This is a support release for Minecraft: Bedrock Edition 1.20.30. + +**Plugin compatibility:** Plugins for previous 4.x versions will run unchanged on this release, unless they use internal APIs, reflection, or packages like the `pocketmine\network\mcpe` namespace. +Do not update plugin minimum API versions unless you need new features added in this release. + +**WARNING: If your plugin uses the `pocketmine\network\mcpe` namespace, you're not shielded by API change constraints.** +Consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you're using packets directly. + +## General +- Added support for Minecraft: Bedrock Edition 1.20.30. +- Removed support for older versions. +- Updated 4.x obsoletion message. diff --git a/changelogs/5.4.md b/changelogs/5.4.md index bdaec51cb2..43f6096207 100644 --- a/changelogs/5.4.md +++ b/changelogs/5.4.md @@ -107,3 +107,27 @@ Released 9th August 2023. ## Fixes - Fixed cake accepting candle placement when slices have already been eaten. - Fixed fire charges not lighting candles. + +# 5.4.3 +Released 21st August 2023. + +## Included releases +- [4.23.6](https://github.com/pmmp/PocketMine-MP/blob/4.23.6/changelogs/4.23.md#4236) - Armor inventory client bug workaround + +## Fixes +- Fixed crashdumps not generating correctly on fatal errors. +- Fixed `PotionCauldron::setPotionItem()` not validating the item type. +- Fixed chorus fruit not considering teleport destinations below y=0. +- Fixed cake dropping itself when mined. + +# 5.4.4 +Released 6th September 2023. + +## General +- Crashdumps caused by non-phar plugins are now submitted to the Crash Archive, the same as other plugins. Previously, non-phar plugin crashes would not be submitted, causing maintainers to potentially miss important issues. + +## Fixes +- Fixed player Y coordinates sometimes being slightly below the top of the block they were standing on (floating point error due to subtracting eye height). +- Fixed template slot of smithing tables not accepting any items. +- `tools/generate-bedrock-data-from-packets.php` is now significantly less spammy when warning about duplicated recipes. +- Fixed empty stack traces in `lastError` data of crashdumps. diff --git a/changelogs/5.5-beta.md b/changelogs/5.5-beta.md new file mode 100644 index 0000000000..84153c2796 --- /dev/null +++ b/changelogs/5.5-beta.md @@ -0,0 +1,156 @@ +# 5.5.0-BETA1 +Released 23rd August 2023. + +**For Minecraft: Bedrock Edition 1.20.10** + +This is a minor feature release, including performance improvements, new API methods, and new gameplay features. + +**Plugin compatibility:** Plugins for previous 5.x versions will run unchanged on this release, unless they use internal APIs, reflection, or packages like the `pocketmine\network\mcpe` or `pocketmine\data` namespace. +Do not update plugin minimum API versions unless you need new features added in this release. + +**WARNING: If your plugin uses the `pocketmine\network\mcpe` namespace, you're not shielded by API change constraints.** +Consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you're using packets directly. + +## Dependencies +- Updated `pocketmine/math` dependency to [`1.0.0`](https://github.com/pmmp/Math/releases/tag/1.0.0). +- Updated `pocketmine/nbt` dependency to [`1.0.0`](https://github.com/pmmp/NBT/releases/tag/1.0.0). + +## Performance +- Some events are now no longer fired if no handlers are registered. + - This improves performance by avoiding unnecessary object allocations and function calls. + - Events such as `DataPacketReceiveEvent`, `DataPacketSendEvent` and `PlayerMoveEvent` are optimized away almost completely by this change, offering some much-needed performance gains. +- Significantly improved performance of small moving entities, such as dropped items. + - This was achieved by a combination of changes, which together improved observed performance with 2000 item entities moving in water by 30-40%. + - The benefit of this will be most noticeable in SkyBlock servers, where large cactus farms can generate thousands of dropped items. +- `World->getCollisionBoxes()` now uses an improved search method, which reduces the work done by the function by almost 90% for small entities. + - This improves performance of collision detection for small entities, such as dropped items. + +## Gameplay +### General +- Implemented enchanting using an enchanting table (yes, finally!) + - Thanks to [@S3v3Nice](https://github.com/S3v3Nice) for investing lots of time and effort into developing this. + - Since this feature is quite complex, it's possible there may be bugs. Please be vigilant and report any issues you find. + +### Blocks +- The following new blocks have been implemented: + - Pink Petals +- Pressure plates are now functional, in the sense that they react when entities stand on them and perform the correct logic. + - Note that since redstone is not yet implemented, pressure plates do not activate any redstone devices, similar to buttons and levers. +- Signs can now be edited by right-clicking them. +- Signs can now be waxed using a honeycomb, which prevents them from being edited. + +### Items +- The following new items have been implemented: + - Enchanted Book + +## API +### `pocketmine\block` +- The following new API methods have been added: + - `public Block->getEnchantmentTags() : list` returns a list of strings indicating which types of enchantment can be applied to the block when in item form + - `public BlockTypeInfo->getEnchantmentTags() : list` + - `protected PressurePlate->getActivationBox() : AxisAlignedBB` - returns the AABB entities must intersect with in order to activate the pressure plate (not the same as the visual shape) + - `protected PressurePlate->hasOutputSignal() : bool` - returns whether the pressure plate has an output signal - this should be implemented by subclasses + - `protected PressurePlate->calculatePlateState() : array{Block, ?bool}` - returns the state the pressure plate will change to if the given list of entities are standing on it, and a bool indicating whether the plate activated or deactivated this tick + - `protected PressurePlate->filterIrrelevantEntities(list $entities) : list` - returns the given list filtered of entities that don't affect the plate's state (e.g. dropped items don't affect stone pressure plates) + - `public BaseSign->isWaxed() : bool` + - `public BaseSign->setWaxed(bool $waxed) : $this` + - `public inventory\EnchantInventory->getInput() : Item` + - `public inventory\EnchantInventory->getLapis() : Item` + - `public inventory\EnchantInventory->getOutput(int $optionId) : ?Item` - returns the item that would be produced if the input item was enchanted with the selected option, or `null` if the option is invalid + - `public inventory\EnchantInventory->getOption(int $optionId) : EnchantOption` - returns the enchanting option at the given index +- The following API methods have signature changes: + - `BlockTypeInfo->__construct()` now accepts an optional `list $enchantmentTags` parameter + - `PressurePlate->__construct()` now accepts an optional `int $deactivationDelayTicks` parameter + - `WeightedPressurePlate->__construct()` now accepts optional `int $deactivationDelayTicks` and `float $signalStrengthFactor` parameters + - `SimplePressurePlate->__construct()` now accepts an optional `int $deactivationDelayTicks` parameter +- The following new classes have been added: + - `PinkPetals` + - `utils\BlockEventHelper` - provides helper methods for calling block-related events +- The following classes have been deprecated: + - `WeightedPressurePlateLight` + - `WeightedPressurePlateHeavy` + +### `pocketmine\entity` +- The following new API methods have been added: + - `public Human->getEnchantmentSeed() : int` - returns the current seed used to randomize options shown on the enchanting table for this human + - `public Human->setEnchantmentSeed(int $seed) : void` + - `public Human->regenerateEnchantmentSeed() : void` - returns a new randomly generated seed which can be set with `setEnchantmentSeed()` + +### `pocketmine\event` +- The following new classes have been added: + - `block\FarmlandHydrationChangeEvent` - called when farmland is hydrated or dehydrated + - `block\PressurePlateUpdateEvent` - called when a pressure plate is activated or changes its power output + - `player\PlayerEnchantingOptionsRequestEvent` - called when a player puts an item to be enchanted into an enchanting table, to allow plugins to modify the enchanting options shown + - `player\PlayerItemEnchantEvent` - called when a player enchants an item in an enchanting table + - `world\WorldDifficultyChangeEvent` - called when a world's difficulty is changed +- The following new API methods have been added: + - `public static Event::hasHandlers() : bool` - returns whether the event class has any registered handlers - used like `SomeEvent::hasHandlers()` + - `public HandlerListManager->getHandlersFor(class-string $event) : list` - returns a list of all registered listeners for the given event class, using cache if available + +### `pocketmine\inventory\transaction` +- The following new classes have been added: + - `EnchantingTransaction` - used when a player enchants an item in an enchanting table + +### `pocketmine\item` +- The following new API methods have been added: + - `public Armor->getMaterial() : ArmorMaterial` - returns an object containing properties shared by all items of the same armor material + - `public ArmorTypeInfo->getMaterial() : ArmorMaterial` + - `public Item->getEnchantability() : int` - returns the enchantability value of the item - higher values increase the chance of more powerful enchantments being offered by an enchanting table + - `public Item->getEnchantmentTags() : list` - returns a list of strings indicating which types of enchantment can be applied to the item + - `public ToolTier->getEnchantability() : int` +- The following API methods have signature changes: + - `Item->__construct()` now accepts an optional `list $enchantmentTags` parameter + - `ArmorTypeInfo->__construct()` now accepts an optional `?ArmorMaterial $material` parameter +- The following new classes have been added: + - `ArmorMaterial` - container for shared armor properties + - `VanillaArmorMaterials` - all vanilla armor materials + - `EnchantedBook` - represents an enchanted book item + +### `pocketmine\item\enchantment` +- The following new classes have been added: + - `AvailableEnchantmentRegistry` - enchantments to be displayed on the enchanting table are selected from here - custom enchantments may be added + - `EnchantingHelper` - static class containing various helper methods for enchanting tables + - `EnchantingOption` - represents an option on the enchanting table menu + - `IncompatibleEnchantmentGroups` - list of constants naming groups of enchantments that are incompatible with each other - custom enchantments may be added using these group names to make them incompatible with existing enchantments in the same group + - `IncompatibleEnchantmentRegistry` - manages which enchantments are considered incompatible with each other - custom enchantments may be added using existing group names to make them incompatible with existing enchantments in the same group, or to entirely new groups + - `ItemEnchantmentTagRegistry` - manages item enchantment compatibility tags and which tags include which other tags + - `ItemEnchantmentTags` - list of constants naming item types for enchantment compatibility checks +- The following classes have been deprecated + - `ItemFlags` +- The following API methods have been added: + - `public Enchantment->isCompatibleWith(Enchantment $other) : bool` + - `public Enchantment->getMinEnchantingPower()` - returns the minimum enchanting power (derived from enchantability and number of bookshelves) needed to allow this enchantment to show on the enchanting table with a given level + - `public Enchantment->getMaxEnchantingPower()` - upper limit of enchanting power for this enchantment to be offered on the enchanting table with a given level +- The following API methods have signature changes: + - `Enchantment->__construct()` now accepts optional `(\Closure(int $level) : int)|null $minEnchantingPower` and `int $enchantingPowerRange` parameters + - `Enchantment->__construct()` parameters `$primaryItemFlags` and `$secondaryItemFlags` are now deprecated and no longer used + - `ProtectionEnchantment->__construct()` has extra parameters to reflect `Enchantment->__construct()` changes +- The following API methods have been deprecated: + - `Enchantment->getPrimaryItemFlags()` - use API methods provided by `AvailableEnchantmentRegistry` instead + - `Enchantment->getSecondaryItemFlags()` - use API methods provided by `AvailableEnchantmentRegistry` instead + - `Enchantment->hasPrimaryItemType()` + - `Enchantment->hasSecondaryItemType()` + +### `pocketmine\plugin` +- The following new API methods have been added: + - `public PluginBase->getResourcePath(string $filename) : string` - returns a URI to an embedded resource file that can be used with `file_get_contents()` and similar functions + - `public PluginBase->getResourceFolder() : string` - returns a URI to the plugin's folder of embedded resources +- The following API methods have been deprecated: + - `PluginBase->getResource()` - prefer using `getResourcePath()` with `file_get_contents()` or other PHP built-in functions instead + +### `pocketmine\resourcepacks` +- The following new API methods have been added: + - `public ResourcePackManager->setResourcePacksRequired(bool $value) : void` - sets whether players must accept resource packs in order to join + +### `pocketmine\world\generator` +- The following new API methods have been added: + - `public GeneratorManager->addAlias(string $name, string $alias) : void` - allows registering a generator alias without copying the generator registration parameters + +### `pocketmine\world\sound` +- The following new classes have been added: +- `PressurePlateActivateSound` +- `PressurePlateDeactivateSound` + +### `pocketmine\utils` +- The following new API methods have been added: + - `public StringToTParser->registerAlias(string $existing, string $alias) : void` - allows registering a string alias without copying registration parameters diff --git a/changelogs/5.5.md b/changelogs/5.5.md new file mode 100644 index 0000000000..750e211290 --- /dev/null +++ b/changelogs/5.5.md @@ -0,0 +1,162 @@ +# 5.5.0 +Released 6th September 2023. + +**For Minecraft: Bedrock Edition 1.20.10** + +This is a minor feature release, including performance improvements, new API methods, and new gameplay features. + +**Plugin compatibility:** Plugins for previous 5.x versions will run unchanged on this release, unless they use internal APIs, reflection, or packages like the `pocketmine\network\mcpe` or `pocketmine\data` namespace. +Do not update plugin minimum API versions unless you need new features added in this release. + +**WARNING: If your plugin uses the `pocketmine\network\mcpe` namespace, you're not shielded by API change constraints.** +Consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you're using packets directly. + +## Dependencies +- Updated `pocketmine/math` dependency to [`1.0.0`](https://github.com/pmmp/Math/releases/tag/1.0.0). +- Updated `pocketmine/nbt` dependency to [`1.0.0`](https://github.com/pmmp/NBT/releases/tag/1.0.0). + +## Performance +- Some events are now no longer fired if no handlers are registered. + - This improves performance by avoiding unnecessary object allocations and function calls. + - Events such as `DataPacketReceiveEvent`, `DataPacketSendEvent` and `PlayerMoveEvent` are optimized away almost completely by this change, offering some much-needed performance gains. +- Significantly improved performance of small moving entities, such as dropped items. + - This was achieved by a combination of changes, which together improved observed performance with 2000 item entities moving in water by 30-40%. + - The benefit of this will be most noticeable in SkyBlock servers, where large cactus farms can generate thousands of dropped items. +- `World->getCollisionBoxes()` now uses an improved search method, which reduces the work done by the function by almost 90% for small entities. + - This improves performance of collision detection for small entities, such as dropped items. + +## Gameplay +### General +- Implemented enchanting using an enchanting table (yes, finally!) + - Thanks to [@S3v3Nice](https://github.com/S3v3Nice) for investing lots of time and effort into developing this. + - Since this feature is quite complex, it's possible there may be bugs. Please be vigilant and report any issues you find. + +### Blocks +- The following new blocks have been implemented: + - Pink Petals +- Pressure plates are now functional, in the sense that they react when entities stand on them and perform the correct logic. + - Note that since redstone is not yet implemented, pressure plates do not activate any redstone devices, similar to buttons and levers. +- Signs can now be edited by right-clicking them. +- Signs can now be waxed using a honeycomb, which prevents them from being edited. + +### Items +- The following new items have been implemented: + - Enchanted Book + +## API +### `pocketmine\block` +- The following new API methods have been added: + - `public Block->getEnchantmentTags() : list` returns a list of strings indicating which types of enchantment can be applied to the block when in item form + - `public BlockTypeInfo->getEnchantmentTags() : list` + - `protected PressurePlate->getActivationBox() : AxisAlignedBB` - returns the AABB entities must intersect with in order to activate the pressure plate (not the same as the visual shape) + - `protected PressurePlate->hasOutputSignal() : bool` - returns whether the pressure plate has an output signal - this should be implemented by subclasses + - `protected PressurePlate->calculatePlateState() : array{Block, ?bool}` - returns the state the pressure plate will change to if the given list of entities are standing on it, and a bool indicating whether the plate activated or deactivated this tick + - `protected PressurePlate->filterIrrelevantEntities(list $entities) : list` - returns the given list filtered of entities that don't affect the plate's state (e.g. dropped items don't affect stone pressure plates) + - `public BaseSign->isWaxed() : bool` + - `public BaseSign->setWaxed(bool $waxed) : $this` + - `public inventory\EnchantInventory->getInput() : Item` + - `public inventory\EnchantInventory->getLapis() : Item` + - `public inventory\EnchantInventory->getOutput(int $optionId) : ?Item` - returns the item that would be produced if the input item was enchanted with the selected option, or `null` if the option is invalid + - `public inventory\EnchantInventory->getOption(int $optionId) : EnchantOption` - returns the enchanting option at the given index +- The following API methods have signature changes: + - `BlockTypeInfo->__construct()` now accepts an optional `list $enchantmentTags` parameter + - `PressurePlate->__construct()` now accepts an optional `int $deactivationDelayTicks` parameter + - `WeightedPressurePlate->__construct()` now accepts optional `int $deactivationDelayTicks` and `float $signalStrengthFactor` parameters + - `SimplePressurePlate->__construct()` now accepts an optional `int $deactivationDelayTicks` parameter +- The following new classes have been added: + - `PinkPetals` + - `utils\BlockEventHelper` - provides helper methods for calling block-related events +- The following classes have been deprecated: + - `WeightedPressurePlateLight` + - `WeightedPressurePlateHeavy` + +### `pocketmine\entity` +- The following new API methods have been added: + - `public Human->getEnchantmentSeed() : int` - returns the current seed used to randomize options shown on the enchanting table for this human + - `public Human->setEnchantmentSeed(int $seed) : void` + - `public Human->regenerateEnchantmentSeed() : void` - returns a new randomly generated seed which can be set with `setEnchantmentSeed()` + +### `pocketmine\event` +- The following new classes have been added: + - `block\FarmlandHydrationChangeEvent` - called when farmland is hydrated or dehydrated + - `block\PressurePlateUpdateEvent` - called when a pressure plate is activated or changes its power output + - `player\PlayerEnchantingOptionsRequestEvent` - called when a player puts an item to be enchanted into an enchanting table, to allow plugins to modify the enchanting options shown + - `player\PlayerItemEnchantEvent` - called when a player enchants an item in an enchanting table + - `world\WorldDifficultyChangeEvent` - called when a world's difficulty is changed +- The following new API methods have been added: + - `public static Event::hasHandlers() : bool` - returns whether the event class has any registered handlers - used like `SomeEvent::hasHandlers()` + - `public HandlerListManager->getHandlersFor(class-string $event) : list` - returns a list of all registered listeners for the given event class, using cache if available + +### `pocketmine\inventory\transaction` +- The following new classes have been added: + - `EnchantingTransaction` - used when a player enchants an item in an enchanting table + +### `pocketmine\item` +- The following new API methods have been added: + - `public Armor->getMaterial() : ArmorMaterial` - returns an object containing properties shared by all items of the same armor material + - `public ArmorTypeInfo->getMaterial() : ArmorMaterial` + - `public Item->getEnchantability() : int` - returns the enchantability value of the item - higher values increase the chance of more powerful enchantments being offered by an enchanting table + - `public Item->getEnchantmentTags() : list` - returns a list of strings indicating which types of enchantment can be applied to the item + - `public ToolTier->getEnchantability() : int` +- The following API methods have signature changes: + - `Item->__construct()` now accepts an optional `list $enchantmentTags` parameter + - `ArmorTypeInfo->__construct()` now accepts an optional `?ArmorMaterial $material` parameter +- The following new classes have been added: + - `ArmorMaterial` - container for shared armor properties + - `VanillaArmorMaterials` - all vanilla armor materials + - `EnchantedBook` - represents an enchanted book item + +### `pocketmine\item\enchantment` +- The following new classes have been added: + - `AvailableEnchantmentRegistry` - enchantments to be displayed on the enchanting table are selected from here - custom enchantments may be added + - `EnchantingHelper` - static class containing various helper methods for enchanting tables + - `EnchantingOption` - represents an option on the enchanting table menu + - `IncompatibleEnchantmentGroups` - list of constants naming groups of enchantments that are incompatible with each other - custom enchantments may be added using these group names to make them incompatible with existing enchantments in the same group + - `IncompatibleEnchantmentRegistry` - manages which enchantments are considered incompatible with each other - custom enchantments may be added using existing group names to make them incompatible with existing enchantments in the same group, or to entirely new groups + - `ItemEnchantmentTagRegistry` - manages item enchantment compatibility tags and which tags include which other tags + - `ItemEnchantmentTags` - list of constants naming item types for enchantment compatibility checks +- The following classes have been deprecated + - `ItemFlags` +- The following API methods have been added: + - `public Enchantment->isCompatibleWith(Enchantment $other) : bool` + - `public Enchantment->getMinEnchantingPower()` - returns the minimum enchanting power (derived from enchantability and number of bookshelves) needed to allow this enchantment to show on the enchanting table with a given level + - `public Enchantment->getMaxEnchantingPower()` - upper limit of enchanting power for this enchantment to be offered on the enchanting table with a given level +- The following API methods have signature changes: + - `Enchantment->__construct()` now accepts optional `(\Closure(int $level) : int)|null $minEnchantingPower` and `int $enchantingPowerRange` parameters + - `Enchantment->__construct()` parameters `$primaryItemFlags` and `$secondaryItemFlags` are now deprecated and no longer used + - `ProtectionEnchantment->__construct()` has extra parameters to reflect `Enchantment->__construct()` changes +- The following API methods have been deprecated: + - `Enchantment->getPrimaryItemFlags()` - use API methods provided by `AvailableEnchantmentRegistry` instead + - `Enchantment->getSecondaryItemFlags()` - use API methods provided by `AvailableEnchantmentRegistry` instead + - `Enchantment->hasPrimaryItemType()` + - `Enchantment->hasSecondaryItemType()` + +### `pocketmine\plugin` +- The following new API methods have been added: + - `public PluginBase->getResourcePath(string $filename) : string` - returns a URI to an embedded resource file that can be used with `file_get_contents()` and similar functions + - `public PluginBase->getResourceFolder() : string` - returns a URI to the plugin's folder of embedded resources +- The following API methods have been deprecated: + - `PluginBase->getResource()` - prefer using `getResourcePath()` with `file_get_contents()` or other PHP built-in functions instead + +### `pocketmine\resourcepacks` +- The following new API methods have been added: + - `public ResourcePackManager->setResourcePacksRequired(bool $value) : void` - sets whether players must accept resource packs in order to join + +### `pocketmine\world\generator` +- The following new API methods have been added: + - `public GeneratorManager->addAlias(string $name, string $alias) : void` - allows registering a generator alias without copying the generator registration parameters + +### `pocketmine\world\sound` +- The following new classes have been added: +- `PressurePlateActivateSound` +- `PressurePlateDeactivateSound` + +### `pocketmine\utils` +- The following new API methods have been added: + - `public StringToTParser->registerAlias(string $existing, string $alias) : void` - allows registering a string alias without copying registration parameters + +## Internals +- Various `TypeIdMap` classes in the `pocketmine\data\bedrock` package now use the new `IntSaveIdMapTrait` to reduce code duplication. +- Added a new `ServerProperties` class containing constants for all known `server.properties` keys. +- Added a new `YmlServerProperties` class containing generated constants for all known `pocketmine.yml` keys. These keys can be used with `Config->getNested()`. + diff --git a/changelogs/5.6.md b/changelogs/5.6.md new file mode 100644 index 0000000000..d4914f527f --- /dev/null +++ b/changelogs/5.6.md @@ -0,0 +1,20 @@ +# 5.6.0 +Released 20th September 2023. + +**For Minecraft: Bedrock Edition 1.20.30** + +This is a support release for Minecraft: Bedrock Edition 1.20.30. + +**Plugin compatibility:** Plugins for previous 5.x versions will run unchanged on this release, unless they use internal APIs, reflection, or packages like the `pocketmine\network\mcpe` or `pocketmine\data` namespace. +Do not update plugin minimum API versions unless you need new features added in this release. + +**WARNING: If your plugin uses the `pocketmine\network\mcpe` namespace, you're not shielded by API change constraints.** +Consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if you're using packets directly. + +## General +- Added support for Minecraft: Bedrock Edition 1.20.30. +- Removed support for older versions. + +## Fixes +- Fixed support conditions for hanging roots, cave vines and dead bushes. +- Fixed connection conditions for fences, glass panes, iron bars, and walls. diff --git a/composer.json b/composer.json index 7448293ac9..0c9240607d 100644 --- a/composer.json +++ b/composer.json @@ -33,9 +33,9 @@ "composer-runtime-api": "^2.0", "adhocore/json-comment": "~1.2.0", "pocketmine/netresearch-jsonmapper": "~v4.2.1000", - "pocketmine/bedrock-block-upgrade-schema": "~3.1.0+bedrock-1.20.10", + "pocketmine/bedrock-block-upgrade-schema": "~3.2.0+bedrock-1.20.30", "nethergamesmc/bedrock-data": "dev-master", - "pocketmine/bedrock-item-upgrade-schema": "~1.4.0+bedrock-1.20.10", + "pocketmine/bedrock-item-upgrade-schema": "~1.5.0+bedrock-1.20.30", "nethergamesmc/bedrock-protocol": "dev-master", "pocketmine/binaryutils": "^0.2.1", "pocketmine/callback-validator": "^1.0.2", @@ -44,7 +44,7 @@ "pocketmine/locale-data": "~2.19.0", "pocketmine/log": "^0.4.0", "pocketmine/math": "~1.0.0", - "pocketmine/nbt": "^0.3.2", + "pocketmine/nbt": "~1.0.0", "pocketmine/raklib": "^0.15.0", "pocketmine/raklib-ipc": "^0.2.0", "pocketmine/snooze": "^0.5.0", @@ -52,7 +52,7 @@ "symfony/filesystem": "~6.3.0" }, "require-dev": { - "phpstan/phpstan": "1.10.16", + "phpstan/phpstan": "1.10.35", "phpstan/phpstan-phpunit": "^1.1.0", "phpstan/phpstan-strict-rules": "^1.2.0", "phpunit/phpunit": "^10.1" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 94bc894a59..0c94f7910f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -10,6 +10,7 @@ includes: - vendor/phpstan/phpstan-strict-rules/rules.neon rules: + - pocketmine\phpstan\rules\DeprecatedLegacyEnumAccessRule - pocketmine\phpstan\rules\DisallowEnumComparisonRule - pocketmine\phpstan\rules\DisallowForeachByReferenceRule - pocketmine\phpstan\rules\UnsafeForeachArrayOfStringRule @@ -44,7 +45,6 @@ parameters: stubFiles: - tests/phpstan/stubs/JsonMapper.stub - tests/phpstan/stubs/leveldb.stub - - tests/phpstan/stubs/phpasn1.stub - tests/phpstan/stubs/pmmpthread.stub - tests/phpstan/stubs/xxhash.stub reportUnmatchedIgnoredErrors: false #no other way to silence platform-specific non-warnings diff --git a/src/MemoryManager.php b/src/MemoryManager.php index 0e8502ff88..96e3bf49cd 100644 --- a/src/MemoryManager.php +++ b/src/MemoryManager.php @@ -30,6 +30,7 @@ use pocketmine\timings\Timings; use pocketmine\utils\Process; use pocketmine\utils\Utils; +use pocketmine\YmlServerProperties as Yml; use Symfony\Component\Filesystem\Path; use function arsort; use function count; @@ -109,7 +110,7 @@ public function __construct( } private function init(ServerConfigGroup $config) : void{ - $this->memoryLimit = $config->getPropertyInt("memory.main-limit", 0) * 1024 * 1024; + $this->memoryLimit = $config->getPropertyInt(Yml::MEMORY_MAIN_LIMIT, 0) * 1024 * 1024; $defaultMemory = 1024; @@ -127,7 +128,7 @@ private function init(ServerConfigGroup $config) : void{ } } - $hardLimit = $config->getPropertyInt("memory.main-hard-limit", $defaultMemory); + $hardLimit = $config->getPropertyInt(Yml::MEMORY_MAIN_HARD_LIMIT, $defaultMemory); if($hardLimit <= 0){ ini_set("memory_limit", '-1'); @@ -135,22 +136,22 @@ private function init(ServerConfigGroup $config) : void{ ini_set("memory_limit", $hardLimit . "M"); } - $this->globalMemoryLimit = $config->getPropertyInt("memory.global-limit", 0) * 1024 * 1024; - $this->checkRate = $config->getPropertyInt("memory.check-rate", self::DEFAULT_CHECK_RATE); - $this->continuousTrigger = $config->getPropertyBool("memory.continuous-trigger", true); - $this->continuousTriggerRate = $config->getPropertyInt("memory.continuous-trigger-rate", self::DEFAULT_CONTINUOUS_TRIGGER_RATE); + $this->globalMemoryLimit = $config->getPropertyInt(Yml::MEMORY_GLOBAL_LIMIT, 0) * 1024 * 1024; + $this->checkRate = $config->getPropertyInt(Yml::MEMORY_CHECK_RATE, self::DEFAULT_CHECK_RATE); + $this->continuousTrigger = $config->getPropertyBool(Yml::MEMORY_CONTINUOUS_TRIGGER, true); + $this->continuousTriggerRate = $config->getPropertyInt(Yml::MEMORY_CONTINUOUS_TRIGGER_RATE, self::DEFAULT_CONTINUOUS_TRIGGER_RATE); - $this->garbageCollectionPeriod = $config->getPropertyInt("memory.garbage-collection.period", self::DEFAULT_TICKS_PER_GC); - $this->garbageCollectionTrigger = $config->getPropertyBool("memory.garbage-collection.low-memory-trigger", true); - $this->garbageCollectionAsync = $config->getPropertyBool("memory.garbage-collection.collect-async-worker", true); + $this->garbageCollectionPeriod = $config->getPropertyInt(Yml::MEMORY_GARBAGE_COLLECTION_PERIOD, self::DEFAULT_TICKS_PER_GC); + $this->garbageCollectionTrigger = $config->getPropertyBool(Yml::MEMORY_GARBAGE_COLLECTION_LOW_MEMORY_TRIGGER, true); + $this->garbageCollectionAsync = $config->getPropertyBool(Yml::MEMORY_GARBAGE_COLLECTION_COLLECT_ASYNC_WORKER, true); - $this->lowMemChunkRadiusOverride = $config->getPropertyInt("memory.max-chunks.chunk-radius", 4); - $this->lowMemChunkGC = $config->getPropertyBool("memory.max-chunks.trigger-chunk-collect", true); + $this->lowMemChunkRadiusOverride = $config->getPropertyInt(Yml::MEMORY_MAX_CHUNKS_CHUNK_RADIUS, 4); + $this->lowMemChunkGC = $config->getPropertyBool(Yml::MEMORY_MAX_CHUNKS_TRIGGER_CHUNK_COLLECT, true); - $this->lowMemDisableChunkCache = $config->getPropertyBool("memory.world-caches.disable-chunk-cache", true); - $this->lowMemClearWorldCache = $config->getPropertyBool("memory.world-caches.low-memory-trigger", true); + $this->lowMemDisableChunkCache = $config->getPropertyBool(Yml::MEMORY_WORLD_CACHES_DISABLE_CHUNK_CACHE, true); + $this->lowMemClearWorldCache = $config->getPropertyBool(Yml::MEMORY_WORLD_CACHES_LOW_MEMORY_TRIGGER, true); - $this->dumpWorkers = $config->getPropertyBool("memory.memory-dump.dump-async-worker", true); + $this->dumpWorkers = $config->getPropertyBool(Yml::MEMORY_MEMORY_DUMP_DUMP_ASYNC_WORKER, true); gc_enable(); } @@ -359,7 +360,7 @@ public static function dumpMemory(mixed $startingObject, string $outputFolder, i '_SESSION' => true ]; - foreach(Utils::stringifyKeys($GLOBALS) as $varName => $value){ + foreach($GLOBALS as $varName => $value){ if(isset($ignoredGlobals[$varName])){ continue; } diff --git a/src/Server.php b/src/Server.php index b43550eaf4..0322179006 100644 --- a/src/Server.php +++ b/src/Server.php @@ -120,6 +120,7 @@ use pocketmine\world\World; use pocketmine\world\WorldCreationOptions; use pocketmine\world\WorldManager; +use pocketmine\YmlServerProperties as Yml; use Ramsey\Uuid\UuidInterface; use Symfony\Component\Filesystem\Path; use function array_fill; @@ -369,15 +370,15 @@ public function requiresAuthentication() : bool{ } public function getPort() : int{ - return $this->configGroup->getConfigInt("server-port", self::DEFAULT_PORT_IPV4); + return $this->configGroup->getConfigInt(ServerProperties::SERVER_PORT_IPV4, self::DEFAULT_PORT_IPV4); } public function getPortV6() : int{ - return $this->configGroup->getConfigInt("server-portv6", self::DEFAULT_PORT_IPV6); + return $this->configGroup->getConfigInt(ServerProperties::SERVER_PORT_IPV6, self::DEFAULT_PORT_IPV6); } public function getViewDistance() : int{ - return max(2, $this->configGroup->getConfigInt("view-distance", self::DEFAULT_MAX_VIEW_DISTANCE)); + return max(2, $this->configGroup->getConfigInt(ServerProperties::VIEW_DISTANCE, self::DEFAULT_MAX_VIEW_DISTANCE)); } /** @@ -388,12 +389,12 @@ public function getAllowedViewDistance(int $distance) : int{ } public function getIp() : string{ - $str = $this->configGroup->getConfigString("server-ip"); + $str = $this->configGroup->getConfigString(ServerProperties::SERVER_IPV4); return $str !== "" ? $str : "0.0.0.0"; } public function getIpV6() : string{ - $str = $this->configGroup->getConfigString("server-ipv6"); + $str = $this->configGroup->getConfigString(ServerProperties::SERVER_IPV6); return $str !== "" ? $str : "::"; } @@ -402,30 +403,30 @@ public function getServerUniqueId() : UuidInterface{ } public function getGamemode() : GameMode{ - return GameMode::fromString($this->configGroup->getConfigString("gamemode", GameMode::SURVIVAL()->name())) ?? GameMode::SURVIVAL(); + return GameMode::fromString($this->configGroup->getConfigString(ServerProperties::GAME_MODE)) ?? GameMode::SURVIVAL; } public function getForceGamemode() : bool{ - return $this->configGroup->getConfigBool("force-gamemode", false); + return $this->configGroup->getConfigBool(ServerProperties::FORCE_GAME_MODE, false); } /** * Returns Server global difficulty. Note that this may be overridden in individual worlds. */ public function getDifficulty() : int{ - return $this->configGroup->getConfigInt("difficulty", World::DIFFICULTY_NORMAL); + return $this->configGroup->getConfigInt(ServerProperties::DIFFICULTY, World::DIFFICULTY_NORMAL); } public function hasWhitelist() : bool{ - return $this->configGroup->getConfigBool("white-list", false); + return $this->configGroup->getConfigBool(ServerProperties::WHITELIST, false); } public function isHardcore() : bool{ - return $this->configGroup->getConfigBool("hardcore", false); + return $this->configGroup->getConfigBool(ServerProperties::HARDCORE, false); } public function getMotd() : string{ - return $this->configGroup->getConfigString("motd", self::DEFAULT_SERVER_NAME); + return $this->configGroup->getConfigString(ServerProperties::MOTD, self::DEFAULT_SERVER_NAME); } public function getLoader() : ThreadSafeClassLoader{ @@ -508,7 +509,7 @@ public function getOnlinePlayers() : array{ } public function shouldSavePlayerData() : bool{ - return $this->configGroup->getPropertyBool("player.save-player-data", true); + return $this->configGroup->getPropertyBool(Yml::PLAYER_SAVE_PLAYER_DATA, true); } public function getOfflinePlayer(string $name) : Player|OfflinePlayer|null{ @@ -748,7 +749,7 @@ public function getOps() : Config{ * @return string[][] */ public function getCommandAliases() : array{ - $section = $this->configGroup->getProperty("aliases"); + $section = $this->configGroup->getProperty(YmlServerProperties::ALIASES); $result = []; if(is_array($section)){ foreach($section as $key => $value){ @@ -823,36 +824,36 @@ public function __construct( $this->configGroup = new ServerConfigGroup( new Config($pocketmineYmlPath, Config::YAML, []), new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES, [ - "motd" => self::DEFAULT_SERVER_NAME, - "server-port" => self::DEFAULT_PORT_IPV4, - "server-portv6" => self::DEFAULT_PORT_IPV6, - "enable-ipv6" => true, - "white-list" => false, - "max-players" => self::DEFAULT_MAX_PLAYERS, - "gamemode" => GameMode::SURVIVAL()->name(), - "force-gamemode" => false, - "hardcore" => false, - "pvp" => true, - "difficulty" => World::DIFFICULTY_NORMAL, - "generator-settings" => "", - "level-name" => "world", - "level-seed" => "", - "level-type" => "DEFAULT", - "enable-query" => true, - "auto-save" => true, - "view-distance" => self::DEFAULT_MAX_VIEW_DISTANCE, - "xbox-auth" => true, - "language" => "eng" + ServerProperties::MOTD => self::DEFAULT_SERVER_NAME, + ServerProperties::SERVER_PORT_IPV4 => self::DEFAULT_PORT_IPV4, + ServerProperties::SERVER_PORT_IPV6 => self::DEFAULT_PORT_IPV6, + ServerProperties::ENABLE_IPV6 => true, + ServerProperties::WHITELIST => false, + ServerProperties::MAX_PLAYERS => self::DEFAULT_MAX_PLAYERS, + ServerProperties::GAME_MODE => GameMode::SURVIVAL->name, //TODO: this probably shouldn't use the enum name directly + ServerProperties::FORCE_GAME_MODE => false, + ServerProperties::HARDCORE => false, + ServerProperties::PVP => true, + ServerProperties::DIFFICULTY => World::DIFFICULTY_NORMAL, + ServerProperties::DEFAULT_WORLD_GENERATOR_SETTINGS => "", + ServerProperties::DEFAULT_WORLD_NAME => "world", + ServerProperties::DEFAULT_WORLD_SEED => "", + ServerProperties::DEFAULT_WORLD_GENERATOR => "DEFAULT", + ServerProperties::ENABLE_QUERY => true, + ServerProperties::AUTO_SAVE => true, + ServerProperties::VIEW_DISTANCE => self::DEFAULT_MAX_VIEW_DISTANCE, + ServerProperties::XBOX_AUTH => true, + ServerProperties::LANGUAGE => "eng" ]) ); - $debugLogLevel = $this->configGroup->getPropertyInt("debug.level", 1); + $debugLogLevel = $this->configGroup->getPropertyInt(Yml::DEBUG_LEVEL, 1); if($this->logger instanceof MainLogger){ $this->logger->setLogDebug($debugLogLevel > 1); } - $this->forceLanguage = $this->configGroup->getPropertyBool("settings.force-language", false); - $selectedLang = $this->configGroup->getConfigString("language", $this->configGroup->getPropertyString("settings.language", Language::FALLBACK_LANGUAGE)); + $this->forceLanguage = $this->configGroup->getPropertyBool(Yml::SETTINGS_FORCE_LANGUAGE, false); + $selectedLang = $this->configGroup->getConfigString(ServerProperties::LANGUAGE, $this->configGroup->getPropertyString("settings.language", Language::FALLBACK_LANGUAGE)); try{ $this->language = new Language($selectedLang); }catch(LanguageNotFoundException $e){ @@ -868,11 +869,11 @@ public function __construct( $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::language_selected($this->getLanguage()->getName(), $this->getLanguage()->getLang()))); if(VersionInfo::IS_DEVELOPMENT_BUILD){ - if(!$this->configGroup->getPropertyBool("settings.enable-dev-builds", false)){ + if(!$this->configGroup->getPropertyBool(Yml::SETTINGS_ENABLE_DEV_BUILDS, false)){ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error1(VersionInfo::NAME))); $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error2())); $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error3())); - $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error4("settings.enable-dev-builds"))); + $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error4(YmlServerProperties::SETTINGS_ENABLE_DEV_BUILDS))); $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_devBuild_error5("https://github.com/pmmp/PocketMine-MP/releases"))); $this->forceShutdownExit(); @@ -890,7 +891,7 @@ public function __construct( $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_start(TextFormat::AQUA . $this->getVersion() . TextFormat::RESET))); - if(($poolSize = $this->configGroup->getPropertyString("settings.async-workers", "auto")) === "auto"){ + if(($poolSize = $this->configGroup->getPropertyString(Yml::SETTINGS_ASYNC_WORKERS, "auto")) === "auto"){ $poolSize = 2; $processors = Utils::getCoreCount() - 2; @@ -901,32 +902,32 @@ public function __construct( $poolSize = max(1, (int) $poolSize); } - $this->asyncPool = new AsyncPool($poolSize, max(-1, $this->configGroup->getPropertyInt("memory.async-worker-hard-limit", 256)), $this->autoloader, $this->logger, $this->tickSleeper); + $this->asyncPool = new AsyncPool($poolSize, max(-1, $this->configGroup->getPropertyInt(Yml::MEMORY_ASYNC_WORKER_HARD_LIMIT, 256)), $this->autoloader, $this->logger, $this->tickSleeper); $netCompressionThreshold = -1; - if($this->configGroup->getPropertyInt("network.batch-threshold", 256) >= 0){ - $netCompressionThreshold = $this->configGroup->getPropertyInt("network.batch-threshold", 256); + if($this->configGroup->getPropertyInt(Yml::NETWORK_BATCH_THRESHOLD, 256) >= 0){ + $netCompressionThreshold = $this->configGroup->getPropertyInt(Yml::NETWORK_BATCH_THRESHOLD, 256); } if($netCompressionThreshold < 0){ $netCompressionThreshold = null; } - $netCompressionLevel = $this->configGroup->getPropertyInt("network.compression-level", 6); + $netCompressionLevel = $this->configGroup->getPropertyInt(Yml::NETWORK_COMPRESSION_LEVEL, 6); if($netCompressionLevel < 1 || $netCompressionLevel > 9){ $this->logger->warning("Invalid network compression level $netCompressionLevel set, setting to default 6"); $netCompressionLevel = 6; } ZlibCompressor::setInstance(new ZlibCompressor($netCompressionLevel, $netCompressionThreshold, ZlibCompressor::DEFAULT_MAX_DECOMPRESSION_SIZE)); - $this->networkCompressionAsync = $this->configGroup->getPropertyBool("network.async-compression", true); + $this->networkCompressionAsync = $this->configGroup->getPropertyBool(Yml::NETWORK_ASYNC_COMPRESSION, true); $this->networkCompressionAsyncThreshold = max( - $this->configGroup->getPropertyInt("network.async-compression-threshold", self::DEFAULT_ASYNC_COMPRESSION_THRESHOLD), + $this->configGroup->getPropertyInt(Yml::NETWORK_ASYNC_COMPRESSION_THRESHOLD, self::DEFAULT_ASYNC_COMPRESSION_THRESHOLD), $netCompressionThreshold ?? self::DEFAULT_ASYNC_COMPRESSION_THRESHOLD ); - EncryptionContext::$ENABLED = $this->configGroup->getPropertyBool("network.enable-encryption", true); + EncryptionContext::$ENABLED = $this->configGroup->getPropertyBool(Yml::NETWORK_ENABLE_ENCRYPTION, true); - $this->doTitleTick = $this->configGroup->getPropertyBool("console.title-tick", true) && Terminal::hasFormattingCodes(); + $this->doTitleTick = $this->configGroup->getPropertyBool(Yml::CONSOLE_TITLE_TICK, true) && Terminal::hasFormattingCodes(); $this->operators = new Config(Path::join($this->dataPath, "ops.txt"), Config::ENUM); $this->whitelist = new Config(Path::join($this->dataPath, "white-list.txt"), Config::ENUM); @@ -944,9 +945,9 @@ public function __construct( $this->banByIP = new BanList($bannedIpsTxt); $this->banByIP->load(); - $this->maxPlayers = $this->configGroup->getConfigInt("max-players", self::DEFAULT_MAX_PLAYERS); + $this->maxPlayers = $this->configGroup->getConfigInt(ServerProperties::MAX_PLAYERS, self::DEFAULT_MAX_PLAYERS); - $this->onlineMode = $this->configGroup->getConfigBool("xbox-auth", true); + $this->onlineMode = $this->configGroup->getConfigBool(ServerProperties::XBOX_AUTH, true); if($this->onlineMode){ $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_auth_enabled())); }else{ @@ -955,8 +956,8 @@ public function __construct( $this->logger->warning($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_authProperty_disabled())); } - if($this->configGroup->getConfigBool("hardcore", false) && $this->getDifficulty() < World::DIFFICULTY_HARD){ - $this->configGroup->setConfigInt("difficulty", World::DIFFICULTY_HARD); + if($this->configGroup->getConfigBool(ServerProperties::HARDCORE, false) && $this->getDifficulty() < World::DIFFICULTY_HARD){ + $this->configGroup->setConfigInt(ServerProperties::DIFFICULTY, World::DIFFICULTY_HARD); } @cli_set_process_title($this->getName() . " " . $this->getPocketMineVersion()); @@ -975,8 +976,8 @@ public function __construct( ))); $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_license($this->getName()))); - TimingsHandler::setEnabled($this->configGroup->getPropertyBool("settings.enable-profiling", false)); - $this->profilingTickRate = $this->configGroup->getPropertyInt("settings.profile-report-trigger", self::TARGET_TICKS_PER_SECOND); + TimingsHandler::setEnabled($this->configGroup->getPropertyBool(Yml::SETTINGS_ENABLE_PROFILING, false)); + $this->profilingTickRate = $this->configGroup->getPropertyInt(Yml::SETTINGS_PROFILE_REPORT_TRIGGER, self::TARGET_TICKS_PER_SECOND); DefaultPermissions::registerCorePermissions(); @@ -998,14 +999,14 @@ public function __construct( $this->forceShutdownExit(); return; } - $this->pluginManager = new PluginManager($this, $this->configGroup->getPropertyBool("plugins.legacy-data-dir", true) ? null : Path::join($this->getDataPath(), "plugin_data"), $pluginGraylist); + $this->pluginManager = new PluginManager($this, $this->configGroup->getPropertyBool(Yml::PLUGINS_LEGACY_DATA_DIR, true) ? null : Path::join($this->getDataPath(), "plugin_data"), $pluginGraylist); $this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader)); $this->pluginManager->registerInterface(new ScriptPluginLoader()); $this->pluginManager->registerInterface(new FolderPluginLoader($this->autoloader)); $providerManager = new WorldProviderManager(); if( - ($format = $providerManager->getProviderByName($formatName = $this->configGroup->getPropertyString("level-settings.default-format", ""))) !== null && + ($format = $providerManager->getProviderByName($formatName = $this->configGroup->getPropertyString(Yml::LEVEL_SETTINGS_DEFAULT_FORMAT, ""))) !== null && $format instanceof WritableWorldProviderManagerEntry ){ $providerManager->setDefault($format); @@ -1014,10 +1015,10 @@ public function __construct( } $this->worldManager = new WorldManager($this, Path::join($this->dataPath, "worlds"), $providerManager); - $this->worldManager->setAutoSave($this->configGroup->getConfigBool("auto-save", $this->worldManager->getAutoSave())); - $this->worldManager->setAutoSaveInterval($this->configGroup->getPropertyInt("ticks-per.autosave", $this->worldManager->getAutoSaveInterval())); + $this->worldManager->setAutoSave($this->configGroup->getConfigBool(ServerProperties::AUTO_SAVE, $this->worldManager->getAutoSave())); + $this->worldManager->setAutoSaveInterval($this->configGroup->getPropertyInt(Yml::TICKS_PER_AUTOSAVE, $this->worldManager->getAutoSaveInterval())); - $this->updater = new UpdateChecker($this, $this->configGroup->getPropertyString("auto-updater.host", "update.pmmp.io")); + $this->updater = new UpdateChecker($this, $this->configGroup->getPropertyString(Yml::AUTO_UPDATER_HOST, "update.pmmp.io")); $this->queryInfo = new QueryInfo($this); @@ -1032,7 +1033,7 @@ public function __construct( $this->forceShutdownExit(); return; } - if(!$this->enablePlugins(PluginEnableOrder::STARTUP())){ + if(!$this->enablePlugins(PluginEnableOrder::STARTUP)){ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_plugin_someEnableErrors())); $this->forceShutdownExit(); return; @@ -1043,7 +1044,7 @@ public function __construct( return; } - if(!$this->enablePlugins(PluginEnableOrder::POSTWORLD())){ + if(!$this->enablePlugins(PluginEnableOrder::POSTWORLD)){ $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_plugin_someEnableErrors())); $this->forceShutdownExit(); return; @@ -1054,7 +1055,7 @@ public function __construct( return; } - if($this->configGroup->getPropertyBool("anonymous-statistics.enabled", true)){ + if($this->configGroup->getPropertyBool(Yml::ANONYMOUS_STATISTICS_ENABLED, true)){ $this->sendUsageTicker = self::TICKS_PER_STATS_REPORT; $this->sendUsage(SendUsageTask::TYPE_OPEN); } @@ -1070,7 +1071,7 @@ public function __construct( $this->subscribeToBroadcastChannel(self::BROADCAST_CHANNEL_USERS, $forwarder); //TODO: move console parts to a separate component - if($this->configGroup->getPropertyBool("console.enable-input", true)){ + if($this->configGroup->getPropertyBool(Yml::CONSOLE_ENABLE_INPUT, true)){ $this->console = new ConsoleReaderChildProcessDaemon($this->logger); } @@ -1105,7 +1106,7 @@ private function startupPrepareWorlds() : bool{ $anyWorldFailedToLoad = false; - foreach((array) $this->configGroup->getProperty("worlds", []) as $name => $options){ + foreach((array) $this->configGroup->getProperty(Yml::WORLDS, []) as $name => $options){ if($options === null){ $options = []; }elseif(!is_array($options)){ @@ -1149,11 +1150,11 @@ private function startupPrepareWorlds() : bool{ } if($this->worldManager->getDefaultWorld() === null){ - $default = $this->configGroup->getConfigString("level-name", "world"); + $default = $this->configGroup->getConfigString(ServerProperties::DEFAULT_WORLD_NAME, "world"); if(trim($default) == ""){ $this->getLogger()->warning("level-name cannot be null, using default"); $default = "world"; - $this->configGroup->setConfigString("level-name", "world"); + $this->configGroup->setConfigString(ServerProperties::DEFAULT_WORLD_NAME, "world"); } if(!$this->worldManager->loadWorld($default, true)){ if($this->worldManager->isWorldGenerated($default)){ @@ -1161,8 +1162,8 @@ private function startupPrepareWorlds() : bool{ return false; } - $generatorName = $this->configGroup->getConfigString("level-type"); - $generatorOptions = $this->configGroup->getConfigString("generator-settings"); + $generatorName = $this->configGroup->getConfigString(ServerProperties::DEFAULT_WORLD_GENERATOR); + $generatorOptions = $this->configGroup->getConfigString(ServerProperties::DEFAULT_WORLD_GENERATOR_SETTINGS); $generatorClass = $getGenerator($generatorName, $generatorOptions, $default); if($generatorClass === null){ @@ -1172,7 +1173,7 @@ private function startupPrepareWorlds() : bool{ $creationOptions = WorldCreationOptions::create() ->setGeneratorClass($generatorClass) ->setGeneratorOptions($generatorOptions); - $convertedSeed = Generator::convertSeed($this->configGroup->getConfigString("level-seed")); + $convertedSeed = Generator::convertSeed($this->configGroup->getConfigString(ServerProperties::DEFAULT_WORLD_SEED)); if($convertedSeed !== null){ $creationOptions->setSeed($convertedSeed); } @@ -1226,7 +1227,7 @@ private function startupPrepareConnectableNetworkInterfaces( } private function startupPrepareNetworkInterfaces() : bool{ - $useQuery = $this->configGroup->getConfigBool("enable-query", true); + $useQuery = $this->configGroup->getConfigBool(ServerProperties::ENABLE_QUERY, true); $typeConverter = TypeConverter::getInstance(); $packetSerializerContext = $this->getPacketSerializerContext($typeConverter); @@ -1236,7 +1237,7 @@ private function startupPrepareNetworkInterfaces() : bool{ if( !$this->startupPrepareConnectableNetworkInterfaces($this->getIp(), $this->getPort(), false, $useQuery, $packetBroadcaster, $entityEventBroadcaster, $packetSerializerContext, $typeConverter) || ( - $this->configGroup->getConfigBool("enable-ipv6", true) && + $this->configGroup->getConfigBool(ServerProperties::ENABLE_IPV6, true) && !$this->startupPrepareConnectableNetworkInterfaces($this->getIpV6(), $this->getPortV6(), true, $useQuery, $packetBroadcaster, $entityEventBroadcaster, $packetSerializerContext, $typeConverter) ) ){ @@ -1251,7 +1252,7 @@ private function startupPrepareNetworkInterfaces() : bool{ $this->network->blockAddress($entry->getName(), -1); } - if($this->configGroup->getPropertyBool("network.upnp-forwarding", false)){ + if($this->configGroup->getPropertyBool(Yml::NETWORK_UPNP_FORWARDING, false)){ $this->network->registerInterface(new UPnPNetworkInterface($this->logger, Internet::getInternalIP(), $this->getPort())); } @@ -1398,14 +1399,14 @@ public function prepareBatch(string $buffer, Compressor $compressor, ?bool $sync public function enablePlugins(PluginEnableOrder $type) : bool{ $allSuccess = true; foreach($this->pluginManager->getPlugins() as $plugin){ - if(!$plugin->isEnabled() && $plugin->getDescription()->getOrder()->equals($type)){ + if(!$plugin->isEnabled() && $plugin->getDescription()->getOrder() === $type){ if(!$this->pluginManager->enablePlugin($plugin)){ $allSuccess = false; } } } - if($type->equals(PluginEnableOrder::POSTWORLD())){ + if($type === PluginEnableOrder::POSTWORLD){ $this->commandMap->registerServerAliases(); } @@ -1472,7 +1473,7 @@ public function forceShutdown() : void{ } if(isset($this->network)){ - $this->network->getSessionManager()->close($this->configGroup->getPropertyString("settings.shutdown-message", "Server closed")); + $this->network->getSessionManager()->close($this->configGroup->getPropertyString(YmlServerProperties::SETTINGS_SHUTDOWN_MESSAGE, "Server closed")); } if(isset($this->worldManager)){ @@ -1609,7 +1610,7 @@ public function crashDump() : void{ $this->logger->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_crash_submit($crashDumpPath))); - if($this->configGroup->getPropertyBool("auto-report.enabled", true)){ + if($this->configGroup->getPropertyBool(Yml::AUTO_REPORT_ENABLED, true)){ $report = true; $stamp = Path::join($this->getDataPath(), "crashdumps", ".last_crash"); @@ -1630,7 +1631,7 @@ public function crashDump() : void{ } if($report){ - $url = ($this->configGroup->getPropertyBool("auto-report.use-https", true) ? "https" : "http") . "://" . $this->configGroup->getPropertyString("auto-report.host", "crash.pmmp.io") . "/submit/api"; + $url = ($this->configGroup->getPropertyBool(Yml::AUTO_REPORT_USE_HTTPS, true) ? "https" : "http") . "://" . $this->configGroup->getPropertyString(Yml::AUTO_REPORT_HOST, "crash.pmmp.io") . "/submit/api"; $postUrlError = "Unknown error"; $reply = Internet::postURL($url, [ "report" => "yes", @@ -1741,7 +1742,7 @@ public function removeOnlinePlayer(Player $player) : void{ } public function sendUsage(int $type = SendUsageTask::TYPE_STATUS) : void{ - if($this->configGroup->getPropertyBool("anonymous-statistics.enabled", true)){ + if($this->configGroup->getPropertyBool(Yml::ANONYMOUS_STATISTICS_ENABLED, true)){ $this->asyncPool->submitTask(new SendUsageTask($this, $type, $this->uniquePlayers)); } $this->uniquePlayers = []; diff --git a/src/ServerProperties.php b/src/ServerProperties.php new file mode 100644 index 0000000000..ddbbd81340 --- /dev/null +++ b/src/ServerProperties.php @@ -0,0 +1,58 @@ +getSide(Facing::DOWN); return - $block->getTypeId() === BlockTypeIds::GRAVEL || - $block->hasTypeTag(BlockTypeTags::DIRT) || - $block->hasTypeTag(BlockTypeTags::MUD) || - $block->hasTypeTag(BlockTypeTags::SAND); + $supportBlock->hasSameTypeId($this) || + $supportBlock->getTypeId() === BlockTypeIds::GRAVEL || + $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || + $supportBlock->hasTypeTag(BlockTypeTags::MUD) || + $supportBlock->hasTypeTag(BlockTypeTags::SAND); } private function seekToTop() : Bamboo{ @@ -153,14 +157,6 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return false; } - public function onNearbyBlockChange() : void{ - $world = $this->position->getWorld(); - $below = $world->getBlock($this->position->down()); - if(!$this->canBeSupportedBy($below) && !$below->hasSameTypeId($this)){ - $world->useBreakOn($this->position); - } - } - private function grow(int $maxHeight, int $growAmount, ?Player $player) : bool{ $world = $this->position->getWorld(); if(!$world->getBlock($this->position->up())->canBeReplaced()){ diff --git a/src/block/BambooSapling.php b/src/block/BambooSapling.php index 6be42546ab..67c8a24e0b 100644 --- a/src/block/BambooSapling.php +++ b/src/block/BambooSapling.php @@ -23,17 +23,21 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Bamboo as ItemBamboo; use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\item\VanillaItems; +use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\BlockTransaction; final class BambooSapling extends Flowable{ + use StaticSupportTrait; + private bool $ready = false; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ @@ -48,19 +52,13 @@ public function setReady(bool $ready) : self{ return $this; } - private function canBeSupportedBy(Block $block) : bool{ + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); return - $block->getTypeId() === BlockTypeIds::GRAVEL || - $block->hasTypeTag(BlockTypeTags::DIRT) || - $block->hasTypeTag(BlockTypeTags::MUD) || - $block->hasTypeTag(BlockTypeTags::SAND); - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedBy($blockReplace->position->getWorld()->getBlock($blockReplace->position->down()))){ - return false; - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); + $supportBlock->getTypeId() === BlockTypeIds::GRAVEL || + $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || + $supportBlock->hasTypeTag(BlockTypeTags::MUD) || + $supportBlock->hasTypeTag(BlockTypeTags::SAND); } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ @@ -73,13 +71,6 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return false; } - public function onNearbyBlockChange() : void{ - $world = $this->position->getWorld(); - if(!$this->canBeSupportedBy($world->getBlock($this->position->down()))){ - $world->useBreakOn($this->position); - } - } - private function grow(?Player $player) : bool{ $world = $this->position->getWorld(); if(!$world->getBlock($this->position->up())->canBeReplaced()){ diff --git a/src/block/BaseBanner.php b/src/block/BaseBanner.php index 439ada202a..23810efee9 100644 --- a/src/block/BaseBanner.php +++ b/src/block/BaseBanner.php @@ -26,7 +26,6 @@ use pocketmine\block\tile\Banner as TileBanner; use pocketmine\block\utils\BannerPatternLayer; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\SupportType; use pocketmine\item\Banner as ItemBanner; use pocketmine\item\Item; @@ -48,11 +47,6 @@ abstract class BaseBanner extends Transparent{ */ protected array $patterns = []; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::BLACK(); - parent::__construct($idInfo, $name, $typeInfo); - } - public function readStateFromWorld() : Block{ parent::readStateFromWorld(); $tile = $this->position->getWorld()->getTile($this->position); @@ -111,7 +105,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } private function canBeSupportedBy(Block $block) : bool{ diff --git a/src/block/BaseBigDripleaf.php b/src/block/BaseBigDripleaf.php index ba634b08ae..1cfed6af6b 100644 --- a/src/block/BaseBigDripleaf.php +++ b/src/block/BaseBigDripleaf.php @@ -131,7 +131,7 @@ public function getFlammability() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function getWaterloggingLevel() : int{ diff --git a/src/block/BaseCake.php b/src/block/BaseCake.php index 21fd6336a0..4b39038402 100644 --- a/src/block/BaseCake.php +++ b/src/block/BaseCake.php @@ -23,6 +23,7 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\SupportType; use pocketmine\entity\effect\EffectInstance; use pocketmine\entity\FoodSource; @@ -31,27 +32,16 @@ use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; abstract class BaseCake extends Transparent implements FoodSource{ + use StaticSupportTrait; public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - $down = $this->getSide(Facing::DOWN); - if($down->getTypeId() !== BlockTypeIds::AIR){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - return false; - } - - public function onNearbyBlockChange() : void{ - if($this->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::AIR){ //Replace with common break method - $this->position->getWorld()->useBreakOn($this->position); - } + private function canBeSupportedAt(Block $block) : bool{ + return $block->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::AIR; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/BaseCoral.php b/src/block/BaseCoral.php index e603ae295a..4fa713b291 100644 --- a/src/block/BaseCoral.php +++ b/src/block/BaseCoral.php @@ -24,7 +24,6 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockEventHelper; -use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\utils\SupportType; use pocketmine\item\Item; @@ -33,11 +32,6 @@ abstract class BaseCoral extends Transparent{ use CoralTypeTrait; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->coralType = CoralType::TUBE(); - parent::__construct($idInfo, $name, $typeInfo); - } - public function onNearbyBlockChange() : void{ if(!$this->dead){ $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200)); @@ -71,6 +65,6 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/BaseSign.php b/src/block/BaseSign.php index c3805f0899..89c8ef3e09 100644 --- a/src/block/BaseSign.php +++ b/src/block/BaseSign.php @@ -49,6 +49,8 @@ abstract class BaseSign extends Transparent{ use WoodTypeTrait; protected SignText $text; + private bool $waxed = false; + protected ?int $editorEntityRuntimeId = null; /** @var \Closure() : Item */ @@ -69,6 +71,7 @@ public function readStateFromWorld() : Block{ $tile = $this->position->getWorld()->getTile($this->position); if($tile instanceof TileSign){ $this->text = $tile->getText(); + $this->waxed = $tile->isWaxed(); $this->editorEntityRuntimeId = $tile->getEditorEntityRuntimeId(); } @@ -80,6 +83,7 @@ public function writeStateToWorld() : void{ $tile = $this->position->getWorld()->getTile($this->position); assert($tile instanceof TileSign); $tile->setText($this->text); + $tile->setWaxed($this->waxed); $tile->setEditorEntityRuntimeId($this->editorEntityRuntimeId); } @@ -99,7 +103,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } abstract protected function getSupportingFace() : int; @@ -147,32 +151,53 @@ private function changeSignGlowingState(bool $glowing, Player $player, Item $ite return false; } + private function wax(Player $player, Item $item) : bool{ + if($this->waxed){ + return false; + } + + $this->waxed = true; + $this->position->getWorld()->setBlock($this->position, $this); + $item->pop(); + + return true; + } + public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player === null){ return false; } + if($this->waxed){ + return true; + } + $dyeColor = $item instanceof Dye ? $item->getColor() : match($item->getTypeId()){ - ItemTypeIds::BONE_MEAL => DyeColor::WHITE(), - ItemTypeIds::LAPIS_LAZULI => DyeColor::BLUE(), - ItemTypeIds::COCOA_BEANS => DyeColor::BROWN(), + ItemTypeIds::BONE_MEAL => DyeColor::WHITE, + ItemTypeIds::LAPIS_LAZULI => DyeColor::BLUE, + ItemTypeIds::COCOA_BEANS => DyeColor::BROWN, default => null }; if($dyeColor !== null){ - $color = $dyeColor->equals(DyeColor::BLACK()) ? new Color(0, 0, 0) : $dyeColor->getRgbValue(); - if($color->toARGB() === $this->text->getBaseColor()->toARGB()){ - return false; - } - - if($this->doSignChange(new SignText($this->text->getLines(), $color, $this->text->isGlowing()), $player, $item)){ + $color = $dyeColor === DyeColor::BLACK ? new Color(0, 0, 0) : $dyeColor->getRgbValue(); + if( + $color->toARGB() !== $this->text->getBaseColor()->toARGB() && + $this->doSignChange(new SignText($this->text->getLines(), $color, $this->text->isGlowing()), $player, $item) + ){ $this->position->getWorld()->addSound($this->position, new DyeUseSound()); return true; } - }elseif($item->getTypeId() === ItemTypeIds::INK_SAC){ - return $this->changeSignGlowingState(false, $player, $item); - }elseif($item->getTypeId() === ItemTypeIds::GLOW_INK_SAC){ - return $this->changeSignGlowingState(true, $player, $item); + }elseif(match($item->getTypeId()){ + ItemTypeIds::INK_SAC => $this->changeSignGlowingState(false, $player, $item), + ItemTypeIds::GLOW_INK_SAC => $this->changeSignGlowingState(true, $player, $item), + ItemTypeIds::HONEYCOMB => $this->wax($player, $item), + default => false + }){ + return true; } - return false; + + $player->openSignEditor($this->position); + + return true; } /** @@ -188,6 +213,17 @@ public function setText(SignText $text) : self{ return $this; } + /** + * Returns whether the sign has been waxed using a honeycomb. If true, the sign cannot be edited by a player. + */ + public function isWaxed() : bool{ return $this->waxed; } + + /** @return $this */ + public function setWaxed(bool $waxed) : self{ + $this->waxed = $waxed; + return $this; + } + /** * Sets the runtime entity ID of the player editing this sign. Only this player will be able to edit the sign. * This is used to prevent multiple players from editing the same sign at the same time, and to prevent players @@ -217,8 +253,8 @@ public function updateText(Player $author, SignText $text) : bool{ } $ev = new SignChangeEvent($this, $author, new SignText(array_map(function(string $line) : string{ return TextFormat::clean($line, false); - }, $text->getLines()))); - if($this->editorEntityRuntimeId === null || $this->editorEntityRuntimeId !== $author->getId()){ + }, $text->getLines()), $this->text->getBaseColor(), $this->text->isGlowing())); + if($this->waxed || $this->editorEntityRuntimeId !== $author->getId()){ $ev->cancel(); } $ev->call(); diff --git a/src/block/Bed.php b/src/block/Bed.php index 1b6b918fa4..400fca7bd3 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -48,11 +48,6 @@ class Bed extends Transparent{ protected bool $occupied = false; protected bool $head = false; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::RED(); - parent::__construct($idInfo, $name, $typeInfo); - } - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->bool($this->occupied); @@ -65,6 +60,8 @@ public function readStateFromWorld() : Block{ $tile = $this->position->getWorld()->getTile($this->position); if($tile instanceof TileBed){ $this->color = $tile->getColor(); + }else{ + $this->color = DyeColor::RED; //legacy pre-1.1 beds don't have tiles } return $this; @@ -87,7 +84,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function isHeadPart() : bool{ @@ -213,7 +210,7 @@ public function getWaterloggingLevel() : int{ } private function canBeSupportedAt(Block $block) : bool{ - return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE; } public function getMaxStackSize() : int{ return 1; } diff --git a/src/block/Bell.php b/src/block/Bell.php index ac835dbb42..2c80de8406 100644 --- a/src/block/Bell.php +++ b/src/block/Bell.php @@ -35,32 +35,26 @@ use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\utils\AssumptionFailedError; use pocketmine\world\BlockTransaction; use pocketmine\world\sound\BellRingSound; final class Bell extends Transparent{ use HorizontalFacingTrait; - private BellAttachmentType $attachmentType; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->attachmentType = BellAttachmentType::FLOOR(); - parent::__construct($idInfo, $name, $typeInfo); - } + private BellAttachmentType $attachmentType = BellAttachmentType::FLOOR; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->bellAttachmentType($this->attachmentType); + $w->enum($this->attachmentType); $w->horizontalFacing($this->facing); } protected function recalculateCollisionBoxes() : array{ - if($this->attachmentType->equals(BellAttachmentType::FLOOR())){ + if($this->attachmentType === BellAttachmentType::FLOOR){ return [ AxisAlignedBB::one()->squash(Facing::axis($this->facing), 1 / 4)->trim(Facing::UP, 3 / 16) ]; } - if($this->attachmentType->equals(BellAttachmentType::CEILING())){ + if($this->attachmentType === BellAttachmentType::CEILING){ return [ AxisAlignedBB::one()->contract(1 / 4, 0, 1 / 4)->trim(Facing::DOWN, 1 / 4) ]; @@ -72,12 +66,12 @@ protected function recalculateCollisionBoxes() : array{ ->trim(Facing::DOWN, 1 / 4); return [ - $this->attachmentType->equals(BellAttachmentType::ONE_WALL()) ? $box->trim($this->facing, 3 / 16) : $box + $this->attachmentType === BellAttachmentType::ONE_WALL ? $box->trim($this->facing, 3 / 16) : $box ]; } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function getAttachmentType() : BellAttachmentType{ return $this->attachmentType; } @@ -89,7 +83,7 @@ public function setAttachmentType(BellAttachmentType $attachmentType) : self{ } private function canBeSupportedAt(Block $block, int $face) : bool{ - return !$block->getAdjacentSupportType($face)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType($face) !== SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ @@ -100,15 +94,15 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo if($player !== null){ $this->setFacing(Facing::opposite($player->getHorizontalFacing())); } - $this->setAttachmentType(BellAttachmentType::FLOOR()); + $this->setAttachmentType(BellAttachmentType::FLOOR); }elseif($face === Facing::DOWN){ - $this->setAttachmentType(BellAttachmentType::CEILING()); + $this->setAttachmentType(BellAttachmentType::CEILING); }else{ $this->setFacing($face); $this->setAttachmentType( $this->canBeSupportedAt($blockReplace, $face) ? - BellAttachmentType::TWO_WALLS() : - BellAttachmentType::ONE_WALL() + BellAttachmentType::TWO_WALLS : + BellAttachmentType::ONE_WALL ); } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -116,11 +110,10 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo public function onNearbyBlockChange() : void{ foreach(match($this->attachmentType){ - BellAttachmentType::CEILING() => [Facing::UP], - BellAttachmentType::FLOOR() => [Facing::DOWN], - BellAttachmentType::ONE_WALL() => [Facing::opposite($this->facing)], - BellAttachmentType::TWO_WALLS() => [$this->facing, Facing::opposite($this->facing)], - default => throw new AssumptionFailedError("All cases of BellAttachmentType must be handled") + BellAttachmentType::CEILING => [Facing::UP], + BellAttachmentType::FLOOR => [Facing::DOWN], + BellAttachmentType::ONE_WALL => [Facing::opposite($this->facing)], + BellAttachmentType::TWO_WALLS => [$this->facing, Facing::opposite($this->facing)] } as $supportBlockDirection){ if(!$this->canBeSupportedAt($this, $supportBlockDirection)){ $this->position->getWorld()->useBreakOn($this->position); @@ -159,10 +152,9 @@ public function ring(int $faceHit) : void{ private function isValidFaceToRing(int $faceHit) : bool{ return match($this->attachmentType){ - BellAttachmentType::CEILING() => true, - BellAttachmentType::FLOOR() => Facing::axis($faceHit) === Facing::axis($this->facing), - BellAttachmentType::ONE_WALL(), BellAttachmentType::TWO_WALLS() => $faceHit === Facing::rotateY($this->facing, false) || $faceHit === Facing::rotateY($this->facing, true), - default => throw new AssumptionFailedError("All cases of BellAttachmentType must be handled") + BellAttachmentType::CEILING => true, + BellAttachmentType::FLOOR => Facing::axis($faceHit) === Facing::axis($this->facing), + BellAttachmentType::ONE_WALL, BellAttachmentType::TWO_WALLS => $faceHit === Facing::rotateY($this->facing, false) || $faceHit === Facing::rotateY($this->facing, true), }; } diff --git a/src/block/BigDripleafHead.php b/src/block/BigDripleafHead.php index d5bd226ca1..a9b87bf7f7 100644 --- a/src/block/BigDripleafHead.php +++ b/src/block/BigDripleafHead.php @@ -30,22 +30,16 @@ use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\RayTraceResult; -use pocketmine\utils\AssumptionFailedError; use pocketmine\world\sound\DripleafTiltDownSound; use pocketmine\world\sound\DripleafTiltUpSound; class BigDripleafHead extends BaseBigDripleaf{ - protected DripleafState $leafState; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->leafState = DripleafState::STABLE(); - parent::__construct($idInfo, $name, $typeInfo); - } + protected DripleafState $leafState = DripleafState::STABLE; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ parent::describeBlockOnlyState($w); - $w->dripleafState($this->leafState); + $w->enum($this->leafState); } protected function isHead() : bool{ @@ -76,20 +70,20 @@ private function setTiltAndScheduleTick(DripleafState $tilt) : void{ private function getLeafTopOffset() : float{ return match($this->leafState){ - DripleafState::STABLE(), DripleafState::UNSTABLE() => 1 / 16, - DripleafState::PARTIAL_TILT() => 3 / 16, + DripleafState::STABLE, DripleafState::UNSTABLE => 1 / 16, + DripleafState::PARTIAL_TILT => 3 / 16, default => 0 }; } public function onEntityInside(Entity $entity) : bool{ - if(!$entity instanceof Projectile && $this->leafState->equals(DripleafState::STABLE())){ + if(!$entity instanceof Projectile && $this->leafState === DripleafState::STABLE){ //the entity must be standing on top of the leaf - do not collapse if the entity is standing underneath $intersection = AxisAlignedBB::one() ->offset($this->position->x, $this->position->y, $this->position->z) ->trim(Facing::DOWN, 1 - $this->getLeafTopOffset()); if($entity->getBoundingBox()->intersectsWith($intersection)){ - $this->setTiltAndScheduleTick(DripleafState::UNSTABLE()); + $this->setTiltAndScheduleTick(DripleafState::UNSTABLE); return false; } } @@ -97,22 +91,21 @@ public function onEntityInside(Entity $entity) : bool{ } public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ - if(!$this->leafState->equals(DripleafState::FULL_TILT())){ - $this->setTiltAndScheduleTick(DripleafState::FULL_TILT()); + if($this->leafState !== DripleafState::FULL_TILT){ + $this->setTiltAndScheduleTick(DripleafState::FULL_TILT); $this->position->getWorld()->addSound($this->position, new DripleafTiltDownSound()); } } public function onScheduledUpdate() : void{ - if(!$this->leafState->equals(DripleafState::STABLE())){ - if($this->leafState->equals(DripleafState::FULL_TILT())){ - $this->position->getWorld()->setBlock($this->position, $this->setLeafState(DripleafState::STABLE())); + if($this->leafState !== DripleafState::STABLE){ + if($this->leafState === DripleafState::FULL_TILT){ + $this->position->getWorld()->setBlock($this->position, $this->setLeafState(DripleafState::STABLE)); $this->position->getWorld()->addSound($this->position, new DripleafTiltUpSound()); }else{ - $this->setTiltAndScheduleTick(match($this->leafState->id()){ - DripleafState::UNSTABLE()->id() => DripleafState::PARTIAL_TILT(), - DripleafState::PARTIAL_TILT()->id() => DripleafState::FULL_TILT(), - default => throw new AssumptionFailedError("All types should be covered") + $this->setTiltAndScheduleTick(match($this->leafState){ + DripleafState::UNSTABLE => DripleafState::PARTIAL_TILT, + DripleafState::PARTIAL_TILT => DripleafState::FULL_TILT, }); $this->position->getWorld()->addSound($this->position, new DripleafTiltDownSound()); } @@ -120,7 +113,7 @@ public function onScheduledUpdate() : void{ } protected function recalculateCollisionBoxes() : array{ - if(!$this->leafState->equals(DripleafState::FULL_TILT())){ + if($this->leafState !== DripleafState::FULL_TILT){ return [ AxisAlignedBB::one() ->trim(Facing::DOWN, 11 / 16) diff --git a/src/block/Block.php b/src/block/Block.php index c41940f2fb..251e2f5c8a 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -904,7 +904,7 @@ protected function recalculateCollisionBoxes() : array{ * blocks placed on the given face can be supported by this block. */ public function getSupportType(int $facing) : SupportType{ - return SupportType::FULL(); + return SupportType::FULL; } protected function getAdjacentSupportType(int $facing) : SupportType{ diff --git a/src/block/BrewingStand.php b/src/block/BrewingStand.php index 5894e982fd..5344a36c69 100644 --- a/src/block/BrewingStand.php +++ b/src/block/BrewingStand.php @@ -34,6 +34,7 @@ use pocketmine\math\Vector3; use pocketmine\player\Player; use function array_key_exists; +use function spl_object_id; class BrewingStand extends Transparent{ @@ -61,18 +62,18 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function hasSlot(BrewingStandSlot $slot) : bool{ - return array_key_exists($slot->id(), $this->slots); + return array_key_exists(spl_object_id($slot), $this->slots); } public function setSlot(BrewingStandSlot $slot, bool $occupied) : self{ if($occupied){ - $this->slots[$slot->id()] = $slot; + $this->slots[spl_object_id($slot)] = $slot; }else{ - unset($this->slots[$slot->id()]); + unset($this->slots[spl_object_id($slot)]); } return $this; } @@ -89,7 +90,7 @@ public function getSlots() : array{ public function setSlots(array $slots) : self{ $this->slots = []; foreach($slots as $slot){ - $this->slots[$slot->id()] = $slot; + $this->slots[spl_object_id($slot)] = $slot; } return $this; } @@ -114,7 +115,7 @@ public function onScheduledUpdate() : void{ } $changed = false; - foreach(BrewingStandSlot::getAll() as $slot){ + foreach(BrewingStandSlot::cases() as $slot){ $occupied = !$brewing->getInventory()->isSlotEmpty($slot->getSlotNumber()); if($occupied !== $this->hasSlot($slot)){ $this->setSlot($slot, $occupied); diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 7023c8cdab..397a6dc4ed 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -23,38 +23,21 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\Entity; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; -use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; class Cactus extends Transparent{ - public const MAX_AGE = 15; - - protected int $age = 0; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(4, 0, self::MAX_AGE, $this->age); - } - - public function getAge() : int{ return $this->age; } + use AgeableTrait; + use StaticSupportTrait; - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE); - } - $this->age = $age; - return $this; - } + public const MAX_AGE = 15; public function hasEntityCollision() : bool{ return true; @@ -69,7 +52,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onEntityInside(Entity $entity) : bool{ @@ -78,23 +61,18 @@ public function onEntityInside(Entity $entity) : bool{ return true; } - private function canBeSupportedBy(Block $block) : bool{ - return $block->hasSameTypeId($this) || $block->hasTypeTag(BlockTypeTags::SAND); - } - - public function onNearbyBlockChange() : void{ - $world = $this->position->getWorld(); - if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){ - $world->useBreakOn($this->position); - }else{ - foreach(Facing::HORIZONTAL as $side){ - $b = $this->getSide($side); - if($b->isSolid()){ - $world->useBreakOn($this->position); - break; - } + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); + if(!$supportBlock->hasSameTypeId($this) && !$supportBlock->hasTypeTag(BlockTypeTags::SAND)){ + return false; + } + foreach(Facing::HORIZONTAL as $side){ + if($block->getSide($side)->isSolid()){ + return false; } } + + return true; } public function ticksRandomly() : bool{ @@ -125,20 +103,6 @@ public function onRandomTick() : void{ } } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->canBeSupportedBy($this->getSide(Facing::DOWN))){ - foreach(Facing::HORIZONTAL as $side){ - if($this->getSide($side)->isSolid()){ - return false; - } - } - - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - return false; - } - public function getWaterloggingLevel() : int{ return 1; } diff --git a/src/block/CakeWithDyedCandle.php b/src/block/CakeWithDyedCandle.php index e01ad3e1b9..0dff358e16 100644 --- a/src/block/CakeWithDyedCandle.php +++ b/src/block/CakeWithDyedCandle.php @@ -30,7 +30,7 @@ class CakeWithDyedCandle extends CakeWithCandle{ use ColoredTrait; public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); + $this->color = DyeColor::WHITE; parent::__construct($idInfo, $name, $typeInfo); } diff --git a/src/block/Candle.php b/src/block/Candle.php index 929a046c16..a72764e310 100644 --- a/src/block/Candle.php +++ b/src/block/Candle.php @@ -91,7 +91,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } protected function getCandleIfCompatibleType(Block $block) : ?Candle{ diff --git a/src/block/Carpet.php b/src/block/Carpet.php index 22897b5492..eb820e5261 100644 --- a/src/block/Carpet.php +++ b/src/block/Carpet.php @@ -24,21 +24,13 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; -use pocketmine\item\Item; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; class Carpet extends Flowable{ use ColoredTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } + use StaticSupportTrait; public function isSolid() : bool{ return true; @@ -51,19 +43,8 @@ protected function recalculateCollisionBoxes() : array{ return [AxisAlignedBB::one()->trim(Facing::UP, 15 / 16)]; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - $down = $this->getSide(Facing::DOWN); - if($down->getTypeId() !== BlockTypeIds::AIR){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - return false; - } - - public function onNearbyBlockChange() : void{ - if($this->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::AIR){ - $this->position->getWorld()->useBreakOn($this->position); - } + private function canBeSupportedAt(Block $block) : bool{ + return $block->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::AIR; } public function getFlameEncouragement() : int{ diff --git a/src/block/Cauldron.php b/src/block/Cauldron.php index b2e02b1b65..34b1f40f7b 100644 --- a/src/block/Cauldron.php +++ b/src/block/Cauldron.php @@ -61,7 +61,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return $facing === Facing::UP ? SupportType::EDGE() : SupportType::NONE(); + return $facing === Facing::UP ? SupportType::EDGE : SupportType::NONE; } /** @@ -83,7 +83,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player }elseif($item->getTypeId() === ItemTypeIds::POWDER_SNOW_BUCKET){ //TODO: powder snow cauldron }elseif($item instanceof Potion || $item instanceof SplashPotion){ //TODO: lingering potion - if($item->getType()->equals(PotionType::WATER())){ + if($item->getType() === PotionType::WATER){ $this->fill(WaterCauldron::WATER_BOTTLE_FILL_AMOUNT, VanillaBlocks::WATER_CAULDRON(), $item, VanillaItems::GLASS_BOTTLE(), $returnedItems); }else{ $this->fill(PotionCauldron::POTION_FILL_AMOUNT, VanillaBlocks::POTION_CAULDRON()->setPotionItem($item), $item, VanillaItems::GLASS_BOTTLE(), $returnedItems); diff --git a/src/block/CaveVines.php b/src/block/CaveVines.php index 6ff934881d..bc42a6788b 100644 --- a/src/block/CaveVines.php +++ b/src/block/CaveVines.php @@ -23,7 +23,9 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\Entity; @@ -38,9 +40,11 @@ use function mt_rand; class CaveVines extends Flowable{ + use AgeableTrait; + use StaticSupportTrait; + public const MAX_AGE = 25; - protected int $age = 0; protected bool $berries = false; protected bool $head = false; @@ -66,19 +70,6 @@ public function setHead(bool $head) : self{ return $this; } - public function getAge() : int{ - return $this->age; - } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0-" . self::MAX_AGE); - } - $this->age = $age; - return $this; - } - public function canClimb() : bool{ return true; } @@ -88,19 +79,11 @@ public function getLightLevel() : int{ } private function canBeSupportedAt(Block $block) : bool{ - return $block->getAdjacentSupportType(Facing::UP)->equals(SupportType::FULL()) || $block->hasSameTypeId($this); - } - - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } + $supportBlock = $block->getSide(Facing::UP); + 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{ - if(!$this->canBeSupportedAt($blockReplace)){ - return false; - } $this->age = mt_rand(0, self::MAX_AGE); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -176,6 +159,6 @@ public function asItem() : Item{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Chain.php b/src/block/Chain.php index 85ba92c4e3..2cd735ee40 100644 --- a/src/block/Chain.php +++ b/src/block/Chain.php @@ -33,7 +33,7 @@ final class Chain extends Transparent{ use PillarRotationTrait; public function getSupportType(int $facing) : SupportType{ - return $this->axis === Axis::Y && Facing::axis($facing) === Axis::Y ? SupportType::CENTER() : SupportType::NONE(); + return $this->axis === Axis::Y && Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } protected function recalculateCollisionBoxes() : array{ diff --git a/src/block/Chest.php b/src/block/Chest.php index 501c732444..f15eaeb340 100644 --- a/src/block/Chest.php +++ b/src/block/Chest.php @@ -45,7 +45,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onPostPlace() : void{ diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index 5c5077f22a..03f34dd072 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -23,52 +23,38 @@ namespace pocketmine\block; -use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\block\utils\AgeableTrait; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\entity\projectile\Projectile; use pocketmine\event\block\StructureGrowEvent; -use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; -use pocketmine\player\Player; use pocketmine\world\BlockTransaction; -use pocketmine\world\Position; use pocketmine\world\sound\ChorusFlowerDieSound; use pocketmine\world\sound\ChorusFlowerGrowSound; use pocketmine\world\World; use function array_rand; +use function min; use function mt_rand; final class ChorusFlower extends Flowable{ + use AgeableTrait; + use StaticSupportTrait; + public const MIN_AGE = 0; public const MAX_AGE = 5; private const MAX_STEM_HEIGHT = 5; - private int $age = self::MIN_AGE; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(3, self::MIN_AGE, self::MAX_AGE, $this->age); - } - - public function getAge() : int{ return $this->age; } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < self::MIN_AGE || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in the range " . self::MIN_AGE . " ... " . self::MAX_AGE); - } - $this->age = $age; - return $this; - } - protected function recalculateCollisionBoxes() : array{ return [AxisAlignedBB::one()]; } - private function canBeSupportedAt(Position $position) : bool{ + private function canBeSupportedAt(Block $block) : bool{ + $position = $block->getPosition(); $world = $position->getWorld(); $down = $world->getBlock($position->down()); @@ -93,19 +79,6 @@ private function canBeSupportedAt(Position $position) : bool{ return $plantAdjacent; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedAt($blockReplace->getPosition())){ - return false; - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this->position)){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ $this->position->getWorld()->useBreakOn($this->position); } @@ -181,7 +154,7 @@ private function grow(int $facing, int $ageChange, ?BlockTransaction $tx) : Bloc if($tx === null){ $tx = new BlockTransaction($this->position->getWorld()); } - $tx->addBlock($this->position->getSide($facing), (clone $this)->setAge($this->getAge() + $ageChange)); + $tx->addBlock($this->position->getSide($facing), (clone $this)->setAge(min(self::MAX_AGE, $this->getAge() + $ageChange))); return $tx; } diff --git a/src/block/ChorusPlant.php b/src/block/ChorusPlant.php index f7642bd048..e3cc8de9d0 100644 --- a/src/block/ChorusPlant.php +++ b/src/block/ChorusPlant.php @@ -23,18 +23,16 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; -use pocketmine\world\Position; use function mt_rand; final class ChorusPlant extends Flowable{ + use StaticSupportTrait; protected function recalculateCollisionBoxes() : array{ $bb = AxisAlignedBB::one(); @@ -52,7 +50,8 @@ private function canBeSupportedBy(Block $block) : bool{ return $block->hasSameTypeId($this) || $block->getTypeId() === BlockTypeIds::END_STONE; } - private function canStay(Position $position) : bool{ + private function canBeSupportedAt(Block $block) : bool{ + $position = $block->getPosition(); $world = $position->getWorld(); $down = $world->getBlock($position->down()); @@ -72,24 +71,7 @@ private function canStay(Position $position) : bool{ } } - if($this->canBeSupportedBy($down)){ - return true; - } - - return false; - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canStay($blockReplace->getPosition())){ - return false; - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - public function onNearbyBlockChange() : void{ - if(!$this->canStay($this->position)){ - $this->position->getWorld()->useBreakOn($this->position); - } + return $this->canBeSupportedBy($down); } public function getDropsForCompatibleTool(Item $item) : array{ diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index 69f94eaf6f..a765142496 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -23,6 +23,7 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; @@ -41,27 +42,15 @@ class CocoaBlock extends Transparent{ use HorizontalFacingTrait; + use AgeableTrait; public const MAX_AGE = 2; - protected int $age = 0; - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); $w->boundedInt(2, 0, self::MAX_AGE, $this->age); } - public function getAge() : int{ return $this->age; } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE); - } - $this->age = $age; - return $this; - } - /** * @return AxisAlignedBB[] */ @@ -77,11 +66,11 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } private function canAttachTo(Block $block) : bool{ - return $block instanceof Wood && $block->getWoodType()->equals(WoodType::JUNGLE()); + return $block instanceof Wood && $block->getWoodType() === WoodType::JUNGLE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/Concrete.php b/src/block/Concrete.php index cb8ee3b529..fae6f8e2f8 100644 --- a/src/block/Concrete.php +++ b/src/block/Concrete.php @@ -24,13 +24,7 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; class Concrete extends Opaque{ use ColoredTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/ConcretePowder.php b/src/block/ConcretePowder.php index 635d3ff2cf..59f14bc722 100644 --- a/src/block/ConcretePowder.php +++ b/src/block/ConcretePowder.php @@ -25,7 +25,6 @@ use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\Fallable; use pocketmine\block\utils\FallableTrait; use pocketmine\math\Facing; @@ -36,11 +35,6 @@ class ConcretePowder extends Opaque implements Fallable{ onNearbyBlockChange as protected startFalling; } - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } - public function onNearbyBlockChange() : void{ if(($water = $this->getAdjacentWater()) !== null){ BlockEventHelper::form($this, VanillaBlocks::CONCRETE()->setColor($this->color), $water); diff --git a/src/block/CopperStairs.php b/src/block/CopperStairs.php index fe52616ce9..b16d49ec1e 100644 --- a/src/block/CopperStairs.php +++ b/src/block/CopperStairs.php @@ -23,14 +23,8 @@ namespace pocketmine\block; -use pocketmine\block\utils\CopperOxidation; use pocketmine\block\utils\CopperTrait; class CopperStairs extends Stair{ use CopperTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->oxidation = CopperOxidation::NONE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/Coral.php b/src/block/Coral.php index 837a818574..96c6d4fe0e 100644 --- a/src/block/Coral.php +++ b/src/block/Coral.php @@ -23,29 +23,11 @@ namespace pocketmine\block; -use pocketmine\item\Item; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; final class Coral extends BaseCoral{ - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedAt($blockReplace)){ - return false; - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - public function onNearbyBlockChange() : void{ - $world = $this->position->getWorld(); - if(!$this->canBeSupportedAt($this)){ - $world->useBreakOn($this->position); - }else{ - parent::onNearbyBlockChange(); - } - } + use StaticSupportTrait; private function canBeSupportedAt(Block $block) : bool{ return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport(); diff --git a/src/block/CoralBlock.php b/src/block/CoralBlock.php index 5ce58f413d..3e7ca8224f 100644 --- a/src/block/CoralBlock.php +++ b/src/block/CoralBlock.php @@ -24,7 +24,6 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockEventHelper; -use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\item\Item; use function mt_rand; @@ -32,11 +31,6 @@ final class CoralBlock extends Opaque{ use CoralTypeTrait; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->coralType = CoralType::TUBE(); - parent::__construct($idInfo, $name, $typeInfo); - } - public function onNearbyBlockChange() : void{ if(!$this->dead){ $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200)); diff --git a/src/block/Crops.php b/src/block/Crops.php index d6e84c4243..e47e63be81 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -23,51 +23,34 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; -use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; use function mt_rand; abstract class Crops extends Flowable{ - public const MAX_AGE = 7; - - protected int $age = 0; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(3, 0, self::MAX_AGE, $this->age); - } - - public function getAge() : int{ return $this->age; } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE); - } - $this->age = $age; - return $this; - } + use AgeableTrait; + use StaticSupportTrait; - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($blockReplace->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } + public const MAX_AGE = 7; - return false; + private function canBeSupportedAt(Block $block) : bool{ + return $block->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($this->age < self::MAX_AGE && $item instanceof Fertilizer){ $block = clone $this; - $block->age += mt_rand(2, 5); - if($block->age > self::MAX_AGE){ - $block->age = self::MAX_AGE; + $tempAge = $block->age + mt_rand(2, 5); + if($tempAge > self::MAX_AGE){ + $tempAge = self::MAX_AGE; } + $block->age = $tempAge; if(BlockEventHelper::grow($this, $block, $player)){ $item->pop(); } @@ -78,12 +61,6 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return false; } - public function onNearbyBlockChange() : void{ - if($this->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::FARMLAND){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - public function ticksRandomly() : bool{ return true; } diff --git a/src/block/DaylightSensor.php b/src/block/DaylightSensor.php index 008d49851d..a3178e2a05 100644 --- a/src/block/DaylightSensor.php +++ b/src/block/DaylightSensor.php @@ -70,7 +70,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/DeadBush.php b/src/block/DeadBush.php index 6d78986083..49b665a0f9 100644 --- a/src/block/DeadBush.php +++ b/src/block/DeadBush.php @@ -23,29 +23,14 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; use function mt_rand; class DeadBush extends Flowable{ - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->canBeSupportedBy($this->getSide(Facing::DOWN))){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - return false; - } - - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){ - $this->position->getWorld()->useBreakOn($this->position); - } - } + use StaticSupportTrait; public function getDropsForIncompatibleTool(Item $item) : array{ return [ @@ -69,14 +54,21 @@ public function getWaterloggingLevel() : int{ return 1; } - private function canBeSupportedBy(Block $block) : bool{ - $blockId = $block->getTypeId(); - return $blockId === BlockTypeIds::SAND - || $blockId === BlockTypeIds::RED_SAND - || $blockId === BlockTypeIds::PODZOL - || $blockId === BlockTypeIds::MYCELIUM - || $blockId === BlockTypeIds::DIRT - || $blockId === BlockTypeIds::HARDENED_CLAY - || $blockId === BlockTypeIds::STAINED_CLAY; + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); + return + $supportBlock->hasTypeTag(BlockTypeTags::SAND) || + $supportBlock->hasTypeTag(BlockTypeTags::MUD) || + match($supportBlock->getTypeId()){ + //can't use DIRT tag here because it includes farmland + BlockTypeIds::PODZOL, + BlockTypeIds::MYCELIUM, + BlockTypeIds::DIRT, + BlockTypeIds::GRASS, + BlockTypeIds::HARDENED_CLAY, + BlockTypeIds::STAINED_CLAY => true, + //TODO: moss block + default => false, + }; } } diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 539454b415..b3a3c6090b 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -38,15 +38,10 @@ use pocketmine\world\sound\WaterSplashSound; class Dirt extends Opaque{ - protected DirtType $dirtType; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->dirtType = DirtType::NORMAL(); - parent::__construct($idInfo, $name, $typeInfo); - } + protected DirtType $dirtType = DirtType::NORMAL; public function describeBlockItemState(RuntimeDataDescriber $w) : void{ - $w->dirtType($this->dirtType); + $w->enum($this->dirtType); } public function getDirtType() : DirtType{ return $this->dirtType; } @@ -62,16 +57,16 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player if($face === Facing::UP && $item instanceof Hoe){ $item->applyDamage(1); - $newBlock = $this->dirtType->equals(DirtType::NORMAL()) ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT(); + $newBlock = $this->dirtType === DirtType::NORMAL ? VanillaBlocks::FARMLAND() : VanillaBlocks::DIRT(); $center = $this->position->add(0.5, 0.5, 0.5); $world->addSound($center, new ItemUseOnBlockSound($newBlock)); $world->setBlock($this->position, $newBlock); - if($this->dirtType->equals(DirtType::ROOTED())){ + if($this->dirtType === DirtType::ROOTED){ $world->dropItem($center, VanillaBlocks::HANGING_ROOTS()->asItem()); } return true; - }elseif($this->dirtType->equals(DirtType::ROOTED()) && $item instanceof Fertilizer){ + }elseif($this->dirtType === DirtType::ROOTED && $item instanceof Fertilizer){ $down = $this->getSide(Facing::DOWN); if($down->getTypeId() !== BlockTypeIds::AIR){ return true; @@ -80,7 +75,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $item->pop(); $world->setBlock($down->position, VanillaBlocks::HANGING_ROOTS()); //TODO: bonemeal particles, growth sounds - }elseif(($item instanceof Potion || $item instanceof SplashPotion) && $item->getType()->equals(PotionType::WATER())){ + }elseif(($item instanceof Potion || $item instanceof SplashPotion) && $item->getType() === PotionType::WATER){ $item->pop(); $world->setBlock($this->position, VanillaBlocks::MUD()); $world->addSound($this->position, new WaterSplashSound(0.5)); diff --git a/src/block/Door.php b/src/block/Door.php index 8018ed6a8e..396bb0da20 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -102,7 +102,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onNearbyBlockChange() : void{ diff --git a/src/block/DragonEgg.php b/src/block/DragonEgg.php index f897a7147d..e39aa70576 100644 --- a/src/block/DragonEgg.php +++ b/src/block/DragonEgg.php @@ -50,7 +50,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player } public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ - if($player !== null && !$player->getGamemode()->equals(GameMode::CREATIVE())){ + if($player !== null && $player->getGamemode() !== GameMode::CREATIVE){ $this->teleport(); return true; } @@ -86,6 +86,6 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/DyedCandle.php b/src/block/DyedCandle.php index 55d76e4066..a495e8d003 100644 --- a/src/block/DyedCandle.php +++ b/src/block/DyedCandle.php @@ -24,19 +24,13 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; class DyedCandle extends Candle{ use ColoredTrait; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } - protected function getCandleIfCompatibleType(Block $block) : ?Candle{ $result = parent::getCandleIfCompatibleType($block); //different coloured candles can't be combined in the same block - return $result instanceof DyedCandle && $result->color->equals($this->color) ? $result : null; + return $result instanceof DyedCandle && $result->color === $this->color ? $result : null; } } diff --git a/src/block/DyedShulkerBox.php b/src/block/DyedShulkerBox.php index 196ee02822..5eae9237e4 100644 --- a/src/block/DyedShulkerBox.php +++ b/src/block/DyedShulkerBox.php @@ -24,13 +24,7 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; final class DyedShulkerBox extends ShulkerBox{ use ColoredTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/EnchantingTable.php b/src/block/EnchantingTable.php index 188b2c855b..3008604980 100644 --- a/src/block/EnchantingTable.php +++ b/src/block/EnchantingTable.php @@ -41,7 +41,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/EnderChest.php b/src/block/EnderChest.php index b600ad3ad7..c3203b5ba2 100644 --- a/src/block/EnderChest.php +++ b/src/block/EnderChest.php @@ -49,7 +49,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/Fence.php b/src/block/Fence.php index cbfd5c812b..899015915c 100644 --- a/src/block/Fence.php +++ b/src/block/Fence.php @@ -42,7 +42,7 @@ public function readStateFromWorld() : Block{ foreach(Facing::HORIZONTAL as $facing){ $block = $this->getSide($facing); - if($block instanceof static || $block instanceof FenceGate || ($block->isSolid() && !$block->isTransparent())){ + if($block instanceof static || $block instanceof FenceGate || $block->getSupportType(Facing::opposite($facing)) === SupportType::FULL){ $this->connections[$facing] = true; }else{ unset($this->connections[$facing]); @@ -102,6 +102,6 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return Facing::axis($facing) === Axis::Y ? SupportType::CENTER() : SupportType::NONE(); + return Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } } diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index 3664a87802..ce9ca4b2b7 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -72,7 +72,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } private function checkInWall() : bool{ diff --git a/src/block/FillableCauldron.php b/src/block/FillableCauldron.php index 84705ea9d5..6c9b2940b8 100644 --- a/src/block/FillableCauldron.php +++ b/src/block/FillableCauldron.php @@ -64,7 +64,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return $facing === Facing::UP ? SupportType::EDGE() : SupportType::NONE(); + return $facing === Facing::UP ? SupportType::EDGE : SupportType::NONE; } protected function withFillLevel(int $fillLevel) : Block{ diff --git a/src/block/Fire.php b/src/block/Fire.php index 11378b82b0..5487c34ede 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -23,9 +23,9 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\event\block\BlockBurnEvent; use pocketmine\math\Facing; use pocketmine\world\format\Chunk; @@ -36,31 +36,16 @@ use function mt_rand; class Fire extends BaseFire{ - public const MAX_AGE = 15; - - protected int $age = 0; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(4, 0, self::MAX_AGE, $this->age); - } + use AgeableTrait; - public function getAge() : int{ return $this->age; } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE); - } - $this->age = $age; - return $this; - } + public const MAX_AGE = 15; protected function getFireDamage() : int{ return 1; } private function canBeSupportedBy(Block $block) : bool{ - return $block->getSupportType(Facing::UP)->equals(SupportType::FULL()); + return $block->getSupportType(Facing::UP) === SupportType::FULL; } public function onNearbyBlockChange() : void{ diff --git a/src/block/FloorCoralFan.php b/src/block/FloorCoralFan.php index a267a03857..81ea88186b 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -23,6 +23,7 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; use pocketmine\item\VanillaItems; @@ -35,6 +36,8 @@ use function rad2deg; final class FloorCoralFan extends BaseCoral{ + use StaticSupportTrait; + private int $axis = Axis::X; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ @@ -53,9 +56,6 @@ public function setAxis(int $axis) : self{ } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedAt($blockReplace)){ - return false; - } if($player !== null){ $playerBlockPos = $player->getPosition()->floor(); $directionVector = $blockReplace->getPosition()->subtractVector($playerBlockPos)->normalize(); @@ -73,15 +73,6 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } - public function onNearbyBlockChange() : void{ - $world = $this->position->getWorld(); - if(!$this->canBeSupportedAt($this)){ - $world->useBreakOn($this->position); - }else{ - parent::onNearbyBlockChange(); - } - } - private function canBeSupportedAt(Block $block) : bool{ return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport(); } diff --git a/src/block/Flowable.php b/src/block/Flowable.php index 2b4e8a02bd..795fe27561 100644 --- a/src/block/Flowable.php +++ b/src/block/Flowable.php @@ -48,6 +48,6 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Flower.php b/src/block/Flower.php index fca5dd98fd..ef79813fe2 100644 --- a/src/block/Flower.php +++ b/src/block/Flower.php @@ -23,28 +23,15 @@ namespace pocketmine\block; -use pocketmine\item\Item; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; class Flower extends Flowable{ + use StaticSupportTrait; - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - $down = $this->getSide(Facing::DOWN); - if($down->hasTypeTag(BlockTypeTags::DIRT) || $down->hasTypeTag(BlockTypeTags::MUD)){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - return false; - } - - public function onNearbyBlockChange() : void{ - $down = $this->getSide(Facing::DOWN); - if(!$down->hasTypeTag(BlockTypeTags::DIRT) && !$down->hasTypeTag(BlockTypeTags::MUD)){ - $this->position->getWorld()->useBreakOn($this->position); - } + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); + return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD); } public function getFlameEncouragement() : int{ diff --git a/src/block/FlowerPot.php b/src/block/FlowerPot.php index 3b7072b249..dbdfd94198 100644 --- a/src/block/FlowerPot.php +++ b/src/block/FlowerPot.php @@ -24,15 +24,16 @@ namespace pocketmine\block; use pocketmine\block\tile\FlowerPot as TileFlowerPot; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; use function assert; class FlowerPot extends Flowable{ + use StaticSupportTrait; protected ?Block $plant = null; @@ -89,20 +90,6 @@ protected function recalculateCollisionBoxes() : array{ return [AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8)]; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedAt($blockReplace)){ - return false; - } - - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - private function canBeSupportedAt(Block $block) : bool{ return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport(); } diff --git a/src/block/Froglight.php b/src/block/Froglight.php index f33fc82613..562b33f174 100644 --- a/src/block/Froglight.php +++ b/src/block/Froglight.php @@ -28,15 +28,10 @@ final class Froglight extends SimplePillar{ - private FroglightType $froglightType; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->froglightType = FroglightType::OCHRE(); - parent::__construct($idInfo, $name, $typeInfo); - } + private FroglightType $froglightType = FroglightType::OCHRE; public function describeBlockItemState(RuntimeDataDescriber $w) : void{ - $w->froglightType($this->froglightType); + $w->enum($this->froglightType); } public function getFroglightType() : FroglightType{ return $this->froglightType; } diff --git a/src/block/FrostedIce.php b/src/block/FrostedIce.php index 039fe49f36..3e85923067 100644 --- a/src/block/FrostedIce.php +++ b/src/block/FrostedIce.php @@ -23,29 +23,14 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; -use pocketmine\data\runtime\RuntimeDataDescriber; use function mt_rand; class FrostedIce extends Ice{ - public const MAX_AGE = 3; - - protected int $age = 0; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(2, 0, self::MAX_AGE, $this->age); - } + use AgeableTrait; - public function getAge() : int{ return $this->age; } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE); - } - $this->age = $age; - return $this; - } + public const MAX_AGE = 3; public function onNearbyBlockChange() : void{ $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(20, 40)); diff --git a/src/block/GlazedTerracotta.php b/src/block/GlazedTerracotta.php index b49347aef0..15b3254e5d 100644 --- a/src/block/GlazedTerracotta.php +++ b/src/block/GlazedTerracotta.php @@ -24,15 +24,9 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\FacesOppositePlacingPlayerTrait; class GlazedTerracotta extends Opaque{ use ColoredTrait; use FacesOppositePlacingPlayerTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::BLACK(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/GlowLichen.php b/src/block/GlowLichen.php index e01ece9b4d..4088dad3b9 100644 --- a/src/block/GlowLichen.php +++ b/src/block/GlowLichen.php @@ -95,7 +95,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function canBeReplaced() : bool{ @@ -121,7 +121,7 @@ public function onNearbyBlockChange() : void{ $changed = false; foreach($this->faces as $face){ - if(!$this->getAdjacentSupportType($face)->equals(SupportType::FULL())){ + if($this->getAdjacentSupportType($face) !== SupportType::FULL){ unset($this->faces[$face]); $changed = true; } @@ -156,7 +156,7 @@ private function spread(World $world, Vector3 $replacePos, int $spreadFace) : bo $supportBlock = $world->getBlock($replacePos->getSide($spreadFace)); $supportFace = Facing::opposite($spreadFace); - if(!$supportBlock->getSupportType($supportFace)->equals(SupportType::FULL())){ + if($supportBlock->getSupportType($supportFace) !== SupportType::FULL){ return false; } @@ -268,7 +268,7 @@ public function getFlammability() : int{ private function getAvailableFaces() : array{ $faces = []; foreach(Facing::ALL as $face){ - if(!$this->hasFace($face) && $this->getAdjacentSupportType($face)->equals(SupportType::FULL())){ + if(!$this->hasFace($face) && $this->getAdjacentSupportType($face) === SupportType::FULL){ $faces[$face] = $face; } } diff --git a/src/block/Grass.php b/src/block/Grass.php index 709dc6a9de..db2f8b922b 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -69,7 +69,7 @@ public function onRandomTick() : void{ $b = $world->getBlockAt($x, $y, $z); if( !($b instanceof Dirt) || - !$b->getDirtType()->equals(DirtType::NORMAL()) || + $b->getDirtType() !== DirtType::NORMAL || $world->getFullLightAt($x, $y + 1, $z) < 4 || $world->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 ){ diff --git a/src/block/HangingRoots.php b/src/block/HangingRoots.php index 8f58471444..c1a2117be7 100644 --- a/src/block/HangingRoots.php +++ b/src/block/HangingRoots.php @@ -23,30 +23,16 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\Item; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; final class HangingRoots extends Flowable{ + use StaticSupportTrait; - private function canBeSupportedBy(Block $block) : bool{ - return $block->isSolid(); //TODO: not sure if this is the correct logic - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$blockReplace->getSide(Facing::UP)->isSolid()){ - return false; - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedBy($this->getSide(Facing::UP))){ - $this->position->getWorld()->useBreakOn($this->position); - } + private function canBeSupportedAt(Block $block) : bool{ + return $block->getAdjacentSupportType(Facing::UP)->hasCenterSupport(); //weird I know, but they can be placed on the bottom of fences } public function getDropsForIncompatibleTool(Item $item) : array{ diff --git a/src/block/Hopper.php b/src/block/Hopper.php index 14d4b6d006..e7be2c11fa 100644 --- a/src/block/Hopper.php +++ b/src/block/Hopper.php @@ -68,9 +68,9 @@ protected function recalculateCollisionBoxes() : array{ public function getSupportType(int $facing) : SupportType{ return match($facing){ - Facing::UP => SupportType::FULL(), - Facing::DOWN => $this->facing === Facing::DOWN ? SupportType::CENTER() : SupportType::NONE(), - default => SupportType::NONE() + Facing::UP => SupportType::FULL, + Facing::DOWN => $this->facing === Facing::DOWN ? SupportType::CENTER : SupportType::NONE, + default => SupportType::NONE }; } diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index c92bae6e9e..3da2fbf8a5 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -164,7 +164,7 @@ public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ } private function canBeSupportedAt(Block $block, int $face) : bool{ - return !$block->getAdjacentSupportType($face)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType($face) !== SupportType::NONE; } public function onNearbyBlockChange() : void{ diff --git a/src/block/Ladder.php b/src/block/Ladder.php index 3fbe70193a..b564fd79e9 100644 --- a/src/block/Ladder.php +++ b/src/block/Ladder.php @@ -66,7 +66,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ @@ -89,6 +89,6 @@ public function getWaterloggingLevel() : int{ } private function canBeSupportedAt(Block $block, int $face) : bool{ - return $block->getAdjacentSupportType($face)->equals(SupportType::FULL()); + return $block->getAdjacentSupportType($face) === SupportType::FULL; } } diff --git a/src/block/Lantern.php b/src/block/Lantern.php index c6e25abb8f..908721bff0 100644 --- a/src/block/Lantern.php +++ b/src/block/Lantern.php @@ -73,7 +73,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 47fe69c4c6..ddaf3d916a 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -33,7 +33,6 @@ use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\utils\AssumptionFailedError; use pocketmine\world\BlockTransaction; use pocketmine\world\World; use function mt_rand; @@ -147,23 +146,22 @@ public function getDropsForCompatibleTool(Item $item) : array{ if(FortuneDropHelper::bonusChanceDivisor($item, 20, 4)){ //Saplings // TODO: according to the wiki, the jungle saplings have a different drop rate $sapling = (match($this->leavesType){ - LeavesType::ACACIA() => VanillaBlocks::ACACIA_SAPLING(), - LeavesType::BIRCH() => VanillaBlocks::BIRCH_SAPLING(), - LeavesType::DARK_OAK() => VanillaBlocks::DARK_OAK_SAPLING(), - LeavesType::JUNGLE() => VanillaBlocks::JUNGLE_SAPLING(), - LeavesType::OAK() => VanillaBlocks::OAK_SAPLING(), - LeavesType::SPRUCE() => VanillaBlocks::SPRUCE_SAPLING(), - LeavesType::MANGROVE(), //TODO: mangrove propagule - LeavesType::AZALEA(), LeavesType::FLOWERING_AZALEA() => null, //TODO: azalea - LeavesType::CHERRY() => null, //TODO: cherry - default => throw new AssumptionFailedError("Unreachable") + LeavesType::ACACIA => VanillaBlocks::ACACIA_SAPLING(), + LeavesType::BIRCH => VanillaBlocks::BIRCH_SAPLING(), + LeavesType::DARK_OAK => VanillaBlocks::DARK_OAK_SAPLING(), + LeavesType::JUNGLE => VanillaBlocks::JUNGLE_SAPLING(), + LeavesType::OAK => VanillaBlocks::OAK_SAPLING(), + LeavesType::SPRUCE => VanillaBlocks::SPRUCE_SAPLING(), + LeavesType::MANGROVE, //TODO: mangrove propagule + LeavesType::AZALEA, LeavesType::FLOWERING_AZALEA => null, //TODO: azalea + LeavesType::CHERRY => null, //TODO: cherry })?->asItem(); if($sapling !== null){ $drops[] = $sapling; } } if( - ($this->leavesType->equals(LeavesType::OAK()) || $this->leavesType->equals(LeavesType::DARK_OAK())) && + ($this->leavesType === LeavesType::OAK || $this->leavesType === LeavesType::DARK_OAK) && FortuneDropHelper::bonusChanceDivisor($item, 200, 20) ){ //Apples $drops[] = VanillaItems::APPLE(); @@ -192,6 +190,6 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Lectern.php b/src/block/Lectern.php index b0bf17daac..a8c35e617f 100644 --- a/src/block/Lectern.php +++ b/src/block/Lectern.php @@ -87,7 +87,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function isProducingSignal() : bool{ return $this->producingSignal; } diff --git a/src/block/Lever.php b/src/block/Lever.php index ecc8f84907..4eec42cd26 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -36,16 +36,11 @@ use pocketmine\world\sound\RedstonePowerOnSound; class Lever extends Flowable{ - protected LeverFacing $facing; + protected LeverFacing $facing = LeverFacing::UP_AXIS_X; protected bool $activated = false; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->facing = LeverFacing::UP_AXIS_X(); - parent::__construct($idInfo, $name, $typeInfo); - } - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->leverFacing($this->facing); + $w->enum($this->facing); $w->bool($this->activated); } @@ -77,12 +72,12 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo return $x; }; $this->facing = match($face){ - Facing::DOWN => $selectUpDownPos(LeverFacing::DOWN_AXIS_X(), LeverFacing::DOWN_AXIS_Z()), - Facing::UP => $selectUpDownPos(LeverFacing::UP_AXIS_X(), LeverFacing::UP_AXIS_Z()), - Facing::NORTH => LeverFacing::NORTH(), - Facing::SOUTH => LeverFacing::SOUTH(), - Facing::WEST => LeverFacing::WEST(), - Facing::EAST => LeverFacing::EAST(), + Facing::DOWN => $selectUpDownPos(LeverFacing::DOWN_AXIS_X, LeverFacing::DOWN_AXIS_Z), + Facing::UP => $selectUpDownPos(LeverFacing::UP_AXIS_X, LeverFacing::UP_AXIS_Z), + Facing::NORTH => LeverFacing::NORTH, + Facing::SOUTH => LeverFacing::SOUTH, + Facing::WEST => LeverFacing::WEST, + Facing::EAST => LeverFacing::EAST, default => throw new AssumptionFailedError("Bad facing value"), }; diff --git a/src/block/Liquid.php b/src/block/Liquid.php index 610ebc2076..0cb8d44cbf 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -98,7 +98,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function getDropsForCompatibleTool(Item $item) : array{ diff --git a/src/block/MobHead.php b/src/block/MobHead.php index 1cc0820727..d412106cac 100644 --- a/src/block/MobHead.php +++ b/src/block/MobHead.php @@ -39,18 +39,13 @@ class MobHead extends Flowable{ public const MIN_ROTATION = 0; public const MAX_ROTATION = 15; - protected MobHeadType $mobHeadType; + protected MobHeadType $mobHeadType = MobHeadType::SKELETON; protected int $facing = Facing::NORTH; protected int $rotation = self::MIN_ROTATION; //TODO: split this into floor skull and wall skull handling - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->mobHeadType = MobHeadType::SKELETON(); //TODO: this should be a parameter - parent::__construct($idInfo, $name, $typeInfo); - } - public function describeBlockItemState(RuntimeDataDescriber $w) : void{ - $w->mobHeadType($this->mobHeadType); + $w->enum($this->mobHeadType); } protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ diff --git a/src/block/MonsterSpawner.php b/src/block/MonsterSpawner.php index 4b622ce9af..c2488bfa84 100644 --- a/src/block/MonsterSpawner.php +++ b/src/block/MonsterSpawner.php @@ -46,6 +46,6 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Mycelium.php b/src/block/Mycelium.php index 08b0b3e750..05b63d9bff 100644 --- a/src/block/Mycelium.php +++ b/src/block/Mycelium.php @@ -52,7 +52,7 @@ public function onRandomTick() : void{ $z = mt_rand($this->position->z - 1, $this->position->z + 1); $world = $this->position->getWorld(); $block = $world->getBlockAt($x, $y, $z); - if($block instanceof Dirt && $block->getDirtType()->equals(DirtType::NORMAL())){ + if($block instanceof Dirt && $block->getDirtType() === DirtType::NORMAL){ if($block->getSide(Facing::UP) instanceof Transparent){ BlockEventHelper::spread($block, VanillaBlocks::MYCELIUM(), $this); } diff --git a/src/block/NetherPortal.php b/src/block/NetherPortal.php index a2524914ab..6a45fb7a0a 100644 --- a/src/block/NetherPortal.php +++ b/src/block/NetherPortal.php @@ -70,7 +70,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function getDrops(Item $item) : array{ diff --git a/src/block/NetherVines.php b/src/block/NetherVines.php index c78000fa1e..dba86d2595 100644 --- a/src/block/NetherVines.php +++ b/src/block/NetherVines.php @@ -23,9 +23,10 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\FortuneDropHelper; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\Entity; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Fertilizer; @@ -41,36 +42,19 @@ * This class is used for Weeping & Twisting vines, because they have same behaviour */ class NetherVines extends Flowable{ + use AgeableTrait; + use StaticSupportTrait; + public const MAX_AGE = 25; /** Direction the vine grows towards. */ private int $growthFace; - protected int $age = 0; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, int $growthFace){ $this->growthFace = $growthFace; parent::__construct($idInfo, $name, $typeInfo); } - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(5, 0, self::MAX_AGE, $this->age); - } - - public function getAge() : int{ - return $this->age; - } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0-" . self::MAX_AGE); - } - - $this->age = $age; - return $this; - } - public function isAffectedBySilkTouch() : bool{ return true; } @@ -88,12 +72,6 @@ private function canBeSupportedAt(Block $block) : bool{ return $supportBlock->getSupportType($this->growthFace)->hasCenterSupport() || $supportBlock->hasSameTypeId($this); } - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - /** * Returns the block at the end of the vine structure furthest from the supporting block. */ @@ -106,9 +84,6 @@ private function seekToTip() : NetherVines{ } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedAt($blockReplace)){ - return false; - } $this->age = mt_rand(0, self::MAX_AGE - 1); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -184,6 +159,6 @@ public function getDropsForCompatibleTool(Item $item) : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/NetherWartPlant.php b/src/block/NetherWartPlant.php index d7e5874417..17aa9c4f8c 100644 --- a/src/block/NetherWartPlant.php +++ b/src/block/NetherWartPlant.php @@ -23,49 +23,22 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\FortuneDropHelper; -use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\Item; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; use function mt_rand; class NetherWartPlant extends Flowable{ - public const MAX_AGE = 3; - - protected int $age = 0; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(2, 0, self::MAX_AGE, $this->age); - } + use AgeableTrait; + use StaticSupportTrait; - public function getAge() : int{ return $this->age; } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0 ..." . self::MAX_AGE); - } - $this->age = $age; - return $this; - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - $down = $this->getSide(Facing::DOWN); - if($down->getTypeId() === BlockTypeIds::SOUL_SAND){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - return false; - } + public const MAX_AGE = 3; - public function onNearbyBlockChange() : void{ - if($this->getSide(Facing::DOWN)->getTypeId() !== BlockTypeIds::SOUL_SAND){ - $this->position->getWorld()->useBreakOn($this->position); - } + private function canBeSupportedAt(Block $block) : bool{ + return $block->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::SOUL_SAND; } public function ticksRandomly() : bool{ diff --git a/src/block/PinkPetals.php b/src/block/PinkPetals.php index 9271e7ddc6..5f11302065 100644 --- a/src/block/PinkPetals.php +++ b/src/block/PinkPetals.php @@ -25,6 +25,7 @@ use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\HorizontalFacingTrait; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Fertilizer; use pocketmine\item\Item; @@ -35,6 +36,9 @@ class PinkPetals extends Flowable{ use HorizontalFacingTrait; + use StaticSupportTrait { + canBePlacedAt as supportedWhenPlacedAt; + } public const MIN_COUNT = 1; public const MAX_COUNT = 4; @@ -65,20 +69,11 @@ private function canBeSupportedAt(Block $block) : bool{ return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD); } - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ - return ($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT) || parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); + return ($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedAt($this)){ - return false; - } if($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT){ $this->count = $blockReplace->getCount() + 1; $this->facing = $blockReplace->getFacing(); diff --git a/src/block/PressurePlate.php b/src/block/PressurePlate.php index 3773b44b3b..1f887c09c3 100644 --- a/src/block/PressurePlate.php +++ b/src/block/PressurePlate.php @@ -23,21 +23,19 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\SupportType; use pocketmine\entity\Entity; use pocketmine\event\block\PressurePlateUpdateEvent; -use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; use pocketmine\world\sound\PressurePlateActivateSound; use pocketmine\world\sound\PressurePlateDeactivateSound; use function count; abstract class PressurePlate extends Transparent{ + use StaticSupportTrait; private readonly int $deactivationDelayTicks; @@ -64,24 +62,11 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->canBeSupportedAt($blockReplace)){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - return false; + return SupportType::NONE; } private function canBeSupportedAt(Block $block) : bool{ - return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE()); - } - - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } + return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE; } public function hasEntityCollision() : bool{ diff --git a/src/block/RedMushroomBlock.php b/src/block/RedMushroomBlock.php index ecac38e18c..0a7cb30f25 100644 --- a/src/block/RedMushroomBlock.php +++ b/src/block/RedMushroomBlock.php @@ -29,17 +29,12 @@ use function mt_rand; class RedMushroomBlock extends Opaque{ - protected MushroomBlockType $mushroomBlockType; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->mushroomBlockType = MushroomBlockType::ALL_CAP(); - parent::__construct($idInfo, $name, $typeInfo); - } + protected MushroomBlockType $mushroomBlockType = MushroomBlockType::ALL_CAP; public function describeBlockItemState(RuntimeDataDescriber $w) : void{ //these blocks always drop as all-cap, but may exist in other forms in the inventory (particularly creative), //so this information needs to be kept in the type info - $w->mushroomBlockType($this->mushroomBlockType); + $w->enum($this->mushroomBlockType); } public function getMushroomBlockType() : MushroomBlockType{ return $this->mushroomBlockType; } @@ -61,10 +56,10 @@ public function isAffectedBySilkTouch() : bool{ } public function getSilkTouchDrops(Item $item) : array{ - return [(clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP())->asItem()]; + return [(clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP)->asItem()]; } public function getPickedItem(bool $addUserData = false) : Item{ - return (clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP())->asItem(); + return (clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP)->asItem(); } } diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index 7ae8e6b974..697aacb26f 100644 --- a/src/block/RedstoneComparator.php +++ b/src/block/RedstoneComparator.php @@ -27,6 +27,7 @@ use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\PoweredByRedstoneTrait; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; @@ -41,6 +42,7 @@ class RedstoneComparator extends Flowable{ use HorizontalFacingTrait; use AnalogRedstoneSignalEmitterTrait; use PoweredByRedstoneTrait; + use StaticSupportTrait; protected bool $isSubtractMode = false; @@ -85,14 +87,10 @@ protected function recalculateCollisionBoxes() : array{ } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->canBeSupportedAt($blockReplace)){ - if($player !== null){ - $this->facing = Facing::opposite($player->getHorizontalFacing()); - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); + if($player !== null){ + $this->facing = Facing::opposite($player->getHorizontalFacing()); } - - return false; + 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{ @@ -101,18 +99,12 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return true; } - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - public function getWaterloggingLevel() : int{ return 2; } private function canBeSupportedAt(Block $block) : bool{ - return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE; } //TODO: redstone functionality diff --git a/src/block/RedstoneRepeater.php b/src/block/RedstoneRepeater.php index d27ac6bf50..9a0b8dfea8 100644 --- a/src/block/RedstoneRepeater.php +++ b/src/block/RedstoneRepeater.php @@ -25,6 +25,7 @@ use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\PoweredByRedstoneTrait; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\SupportType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; @@ -37,6 +38,7 @@ class RedstoneRepeater extends Flowable{ use HorizontalFacingTrait; use PoweredByRedstoneTrait; + use StaticSupportTrait; public const MIN_DELAY = 1; public const MAX_DELAY = 4; @@ -68,15 +70,11 @@ protected function recalculateCollisionBoxes() : array{ } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->canBeSupportedAt($blockReplace)){ - if($player !== null){ - $this->facing = Facing::opposite($player->getHorizontalFacing()); - } - - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); + if($player !== null){ + $this->facing = Facing::opposite($player->getHorizontalFacing()); } - return false; + 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{ @@ -87,18 +85,12 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return true; } - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - public function getWaterloggingLevel() : int{ return 2; } private function canBeSupportedAt(Block $block) : bool{ - return !$block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::NONE()); + return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE; } //TODO: redstone functionality diff --git a/src/block/RedstoneWire.php b/src/block/RedstoneWire.php index 167365f56e..a2d293fca0 100644 --- a/src/block/RedstoneWire.php +++ b/src/block/RedstoneWire.php @@ -24,22 +24,14 @@ namespace pocketmine\block; use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; class RedstoneWire extends Flowable{ use AnalogRedstoneSignalEmitterTrait; - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->canBeSupportedAt($blockReplace)){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - return false; - } + use StaticSupportTrait; public function readStateFromWorld() : Block{ parent::readStateFromWorld(); @@ -48,12 +40,6 @@ public function readStateFromWorld() : Block{ return $this; } - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - private function canBeSupportedAt(Block $block) : bool{ return $block->getAdjacentSupportType(Facing::DOWN)->hasCenterSupport(); } diff --git a/src/block/Sapling.php b/src/block/Sapling.php index b1f255f0d7..b3fdf59af6 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -24,6 +24,7 @@ namespace pocketmine\block; use pocketmine\block\utils\SaplingType; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Fertilizer; @@ -32,11 +33,12 @@ use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\utils\Random; -use pocketmine\world\BlockTransaction; use pocketmine\world\generator\object\TreeFactory; use function mt_rand; class Sapling extends Flowable{ + use StaticSupportTrait; + protected bool $ready = false; private SaplingType $saplingType; @@ -58,13 +60,9 @@ public function setReady(bool $ready) : self{ return $this; } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - $down = $this->getSide(Facing::DOWN); - if($down->hasTypeTag(BlockTypeTags::DIRT) || $down->hasTypeTag(BlockTypeTags::MUD)){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - return false; + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); + return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD); } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ @@ -77,13 +75,6 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return false; } - public function onNearbyBlockChange() : void{ - $down = $this->getSide(Facing::DOWN); - if(!$down->hasTypeTag(BlockTypeTags::DIRT) && !$down->hasTypeTag(BlockTypeTags::MUD)){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - public function ticksRandomly() : bool{ return true; } diff --git a/src/block/SeaPickle.php b/src/block/SeaPickle.php index 068da36c3a..ff28348c79 100644 --- a/src/block/SeaPickle.php +++ b/src/block/SeaPickle.php @@ -78,7 +78,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ diff --git a/src/block/ShulkerBox.php b/src/block/ShulkerBox.php index a0dd626ada..21e614c0e9 100644 --- a/src/block/ShulkerBox.php +++ b/src/block/ShulkerBox.php @@ -117,6 +117,6 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Slab.php b/src/block/Slab.php index 248e285ffa..85ebdab9e6 100644 --- a/src/block/Slab.php +++ b/src/block/Slab.php @@ -34,19 +34,18 @@ use pocketmine\world\BlockTransaction; class Slab extends Transparent{ - protected SlabType $slabType; + protected SlabType $slabType = SlabType::BOTTOM; public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->slabType = SlabType::BOTTOM(); parent::__construct($idInfo, $name . " Slab", $typeInfo); } protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->slabType($this->slabType); + $w->enum($this->slabType); } public function isTransparent() : bool{ - return !$this->slabType->equals(SlabType::DOUBLE()); + return $this->slabType !== SlabType::DOUBLE; } /** @@ -69,8 +68,8 @@ public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $fa return true; } - if($blockReplace instanceof Slab && !$blockReplace->slabType->equals(SlabType::DOUBLE()) && $blockReplace->hasSameTypeId($this)){ - if($blockReplace->slabType->equals(SlabType::TOP())){ //Trying to combine with top slab + if($blockReplace instanceof Slab && $blockReplace->slabType !== SlabType::DOUBLE && $blockReplace->hasSameTypeId($this)){ + if($blockReplace->slabType === SlabType::TOP){ //Trying to combine with top slab return $clickVector->y <= 0.5 || (!$isClickedBlock && $face === Facing::UP); }else{ return $clickVector->y >= 0.5 || (!$isClickedBlock && $face === Facing::DOWN); @@ -81,14 +80,14 @@ public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $fa } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($blockReplace instanceof Slab && !$blockReplace->slabType->equals(SlabType::DOUBLE()) && $blockReplace->hasSameTypeId($this) && ( - ($blockReplace->slabType->equals(SlabType::TOP()) && ($clickVector->y <= 0.5 || $face === Facing::UP)) || - ($blockReplace->slabType->equals(SlabType::BOTTOM()) && ($clickVector->y >= 0.5 || $face === Facing::DOWN)) + if($blockReplace instanceof Slab && $blockReplace->slabType !== SlabType::DOUBLE && $blockReplace->hasSameTypeId($this) && ( + ($blockReplace->slabType === SlabType::TOP && ($clickVector->y <= 0.5 || $face === Facing::UP)) || + ($blockReplace->slabType === SlabType::BOTTOM && ($clickVector->y >= 0.5 || $face === Facing::DOWN)) )){ //Clicked in empty half of existing slab - $this->slabType = SlabType::DOUBLE(); + $this->slabType = SlabType::DOUBLE; }else{ - $this->slabType = (($face !== Facing::UP && $clickVector->y > 0.5) || $face === Facing::DOWN) ? SlabType::TOP() : SlabType::BOTTOM(); + $this->slabType = (($face !== Facing::UP && $clickVector->y > 0.5) || $face === Facing::DOWN) ? SlabType::TOP : SlabType::BOTTOM; } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); @@ -98,23 +97,23 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo * @return AxisAlignedBB[] */ protected function recalculateCollisionBoxes() : array{ - if($this->slabType->equals(SlabType::DOUBLE())){ + if($this->slabType === SlabType::DOUBLE){ return [AxisAlignedBB::one()]; } - return [AxisAlignedBB::one()->trim($this->slabType->equals(SlabType::TOP()) ? Facing::DOWN : Facing::UP, 0.5)]; + return [AxisAlignedBB::one()->trim($this->slabType === SlabType::TOP ? Facing::DOWN : Facing::UP, 0.5)]; } public function getSupportType(int $facing) : SupportType{ - if($this->slabType->equals(SlabType::DOUBLE())){ - return SupportType::FULL(); - }elseif(($facing === Facing::UP && $this->slabType->equals(SlabType::TOP())) || ($facing === Facing::DOWN && $this->slabType->equals(SlabType::BOTTOM()))){ - return SupportType::FULL(); + if($this->slabType === SlabType::DOUBLE){ + return SupportType::FULL; + }elseif(($facing === Facing::UP && $this->slabType === SlabType::TOP) || ($facing === Facing::DOWN && $this->slabType === SlabType::BOTTOM)){ + return SupportType::FULL; } - return SupportType::NONE(); + return SupportType::NONE; } public function getDropsForCompatibleTool(Item $item) : array{ - return [$this->asItem()->setCount($this->slabType->equals(SlabType::DOUBLE()) ? 2 : 1)]; + return [$this->asItem()->setCount($this->slabType === SlabType::DOUBLE ? 2 : 1)]; } public function getWaterloggingLevel() : int{ diff --git a/src/block/SmallDripleaf.php b/src/block/SmallDripleaf.php index 478df3df9f..17034384a6 100644 --- a/src/block/SmallDripleaf.php +++ b/src/block/SmallDripleaf.php @@ -161,7 +161,7 @@ public function getFlammability() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } protected function recalculateCollisionBoxes() : array{ diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index 05fc884213..fd7258d914 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -75,13 +75,13 @@ protected function recalculateCollisionBoxes() : array{ public function getSupportType(int $facing) : SupportType{ if(!$this->canBeReplaced()){ - return SupportType::FULL(); + return SupportType::FULL; } - return SupportType::NONE(); + return SupportType::NONE; } private function canBeSupportedAt(Block $block) : bool{ - return $block->getAdjacentSupportType(Facing::DOWN)->equals(SupportType::FULL()); + return $block->getAdjacentSupportType(Facing::DOWN) === SupportType::FULL; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/SporeBlossom.php b/src/block/SporeBlossom.php index 9099321780..3ca5fa1f20 100644 --- a/src/block/SporeBlossom.php +++ b/src/block/SporeBlossom.php @@ -23,30 +23,14 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\SupportType; -use pocketmine\item\Item; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; final class SporeBlossom extends Flowable{ + use StaticSupportTrait; private function canBeSupportedAt(Block $block) : bool{ - return $block->getAdjacentSupportType(Facing::UP)->equals(SupportType::FULL()); - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedAt($blockReplace)){ - return false; - } - - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedAt($this)){ - $this->position->getWorld()->useBreakOn($this->position); - } + return $block->getAdjacentSupportType(Facing::UP) === SupportType::FULL; } } diff --git a/src/block/StainedGlass.php b/src/block/StainedGlass.php index 5b4b6a883c..bc0d848770 100644 --- a/src/block/StainedGlass.php +++ b/src/block/StainedGlass.php @@ -24,13 +24,7 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; final class StainedGlass extends Glass{ use ColoredTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/StainedGlassPane.php b/src/block/StainedGlassPane.php index 2a592395dd..18ecfdee0e 100644 --- a/src/block/StainedGlassPane.php +++ b/src/block/StainedGlassPane.php @@ -24,13 +24,7 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; final class StainedGlassPane extends GlassPane{ use ColoredTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/StainedHardenedClay.php b/src/block/StainedHardenedClay.php index 1a9d68737b..2c2c01ba3a 100644 --- a/src/block/StainedHardenedClay.php +++ b/src/block/StainedHardenedClay.php @@ -24,13 +24,7 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; final class StainedHardenedClay extends HardenedClay{ use ColoredTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/StainedHardenedGlass.php b/src/block/StainedHardenedGlass.php index 85d5fcec0f..cc609a49a9 100644 --- a/src/block/StainedHardenedGlass.php +++ b/src/block/StainedHardenedGlass.php @@ -24,13 +24,7 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; final class StainedHardenedGlass extends HardenedGlass{ use ColoredTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/StainedHardenedGlassPane.php b/src/block/StainedHardenedGlassPane.php index 4a61f9778b..63dbe1f776 100644 --- a/src/block/StainedHardenedGlassPane.php +++ b/src/block/StainedHardenedGlassPane.php @@ -24,13 +24,7 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; final class StainedHardenedGlassPane extends HardenedGlassPane{ use ColoredTrait; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } } diff --git a/src/block/Stair.php b/src/block/Stair.php index be218b099a..21ad34b406 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -39,12 +39,7 @@ class Stair extends Transparent{ use HorizontalFacingTrait; protected bool $upsideDown = false; - protected StairShape $shape; - - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->shape = StairShape::STRAIGHT(); - parent::__construct($idInfo, $name, $typeInfo); - } + protected StairShape $shape = StairShape::STRAIGHT; protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ $w->horizontalFacing($this->facing); @@ -56,11 +51,11 @@ public function readStateFromWorld() : Block{ $clockwise = Facing::rotateY($this->facing, true); if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){ - $this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT() : StairShape::OUTER_LEFT(); + $this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT : StairShape::OUTER_LEFT; }elseif(($frontFacing = $this->getPossibleCornerFacing(true)) !== null){ - $this->shape = $frontFacing === $clockwise ? StairShape::INNER_RIGHT() : StairShape::INNER_LEFT(); + $this->shape = $frontFacing === $clockwise ? StairShape::INNER_RIGHT : StairShape::INNER_LEFT; }else{ - $this->shape = StairShape::STRAIGHT(); + $this->shape = StairShape::STRAIGHT; } return $this; @@ -92,14 +87,14 @@ protected function recalculateCollisionBoxes() : array{ ->trim(Facing::opposite($topStepFace), 0.5) ->trim(Facing::opposite($this->facing), 0.5); - if($this->shape->equals(StairShape::OUTER_LEFT()) || $this->shape->equals(StairShape::OUTER_RIGHT())){ - $topStep->trim(Facing::rotateY($this->facing, $this->shape->equals(StairShape::OUTER_LEFT())), 0.5); - }elseif($this->shape->equals(StairShape::INNER_LEFT()) || $this->shape->equals(StairShape::INNER_RIGHT())){ + if($this->shape === StairShape::OUTER_LEFT || $this->shape === StairShape::OUTER_RIGHT){ + $topStep->trim(Facing::rotateY($this->facing, $this->shape === StairShape::OUTER_LEFT), 0.5); + }elseif($this->shape === StairShape::INNER_LEFT || $this->shape === StairShape::INNER_RIGHT){ //add an extra cube $bbs[] = AxisAlignedBB::one() ->trim(Facing::opposite($topStepFace), 0.5) ->trim($this->facing, 0.5) //avoid overlapping with main step - ->trim(Facing::rotateY($this->facing, $this->shape->equals(StairShape::INNER_LEFT())), 0.5); + ->trim(Facing::rotateY($this->facing, $this->shape === StairShape::INNER_LEFT), 0.5); } $bbs[] = $topStep; @@ -111,13 +106,13 @@ public function getSupportType(int $facing) : SupportType{ if( $facing === Facing::UP && $this->isUpsideDown() || $facing === Facing::DOWN && !$this->isUpsideDown() || - ($facing === $this->facing && !$this->shape->equals(StairShape::OUTER_LEFT()) && !$this->shape->equals(StairShape::OUTER_RIGHT())) || - ($facing === Facing::rotate($this->facing, Axis::Y, false) && $this->shape->equals(StairShape::INNER_LEFT())) || - ($facing === Facing::rotate($this->facing, Axis::Y, true) && $this->shape->equals(StairShape::INNER_RIGHT())) + ($facing === $this->facing && $this->shape !== StairShape::OUTER_LEFT && $this->shape !== StairShape::OUTER_RIGHT) || + ($facing === Facing::rotate($this->facing, Axis::Y, false) && $this->shape === StairShape::INNER_LEFT) || + ($facing === Facing::rotate($this->facing, Axis::Y, true) && $this->shape === StairShape::INNER_RIGHT) ){ - return SupportType::FULL(); + return SupportType::FULL; } - return SupportType::NONE(); + return SupportType::NONE; } private function getPossibleCornerFacing(bool $oppositeFacing) : ?int{ diff --git a/src/block/Stonecutter.php b/src/block/Stonecutter.php index fbd9e67139..4b14212859 100644 --- a/src/block/Stonecutter.php +++ b/src/block/Stonecutter.php @@ -47,7 +47,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function getWaterloggingLevel() : int{ diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index 3757e45772..97b4aee9c1 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -23,8 +23,9 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; -use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\Fertilizer; use pocketmine\item\Item; use pocketmine\math\Facing; @@ -34,13 +35,10 @@ use pocketmine\world\Position; class Sugarcane extends Flowable{ - public const MAX_AGE = 15; - - protected int $age = 0; + use AgeableTrait; + use StaticSupportTrait; - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(4, 0, self::MAX_AGE, $this->age); - } + public const MAX_AGE = 15; private function seekToBottom() : Position{ $world = $this->position->getWorld(); @@ -74,17 +72,6 @@ private function grow(Position $pos, ?Player $player = null) : bool{ return $grew; } - public function getAge() : int{ return $this->age; } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < 0 || $age > self::MAX_AGE){ - throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE); - } - $this->age = $age; - return $this; - } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item instanceof Fertilizer){ if($this->grow($this->seekToBottom(), $player)){ @@ -97,18 +84,12 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player return false; } - private function canBeSupportedBy(Block $block) : bool{ - return - $block->hasTypeTag(BlockTypeTags::MUD) || - $block->hasTypeTag(BlockTypeTags::DIRT) || - $block->hasTypeTag(BlockTypeTags::SAND); - } - - public function onNearbyBlockChange() : void{ - $down = $this->getSide(Facing::DOWN); - if(!$down->hasSameTypeId($this) && !$this->canBeSupportedBy($down)){ - $this->position->getWorld()->useBreakOn($this->position); - } + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); + return $supportBlock->hasSameTypeId($this) || + $supportBlock->hasTypeTag(BlockTypeTags::MUD) || + $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || + $supportBlock->hasTypeTag(BlockTypeTags::SAND); } public function ticksRandomly() : bool{ @@ -127,15 +108,16 @@ public function onRandomTick() : void{ } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - $down = $this->getSide(Facing::DOWN); + $down = $blockReplace->getSide(Facing::DOWN); if($down->hasSameTypeId($this)){ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - }elseif($this->canBeSupportedBy($down)){ - foreach(Facing::HORIZONTAL as $side){ - $sideBlock = $down->getSide($side); - if($sideBlock instanceof Water || $sideBlock instanceof FrostedIce){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } + } + + //support criteria are checked by FixedSupportTrait, but this part applies to placement only + foreach(Facing::HORIZONTAL as $side){ + $sideBlock = $down->getSide($side); + if($sideBlock instanceof Water || $sideBlock instanceof FrostedIce){ + return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } } diff --git a/src/block/SweetBerryBush.php b/src/block/SweetBerryBush.php index ef1169df53..c34df3de51 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -23,9 +23,10 @@ namespace pocketmine\block; +use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; use pocketmine\block\utils\FortuneDropHelper; -use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\entity\Entity; use pocketmine\entity\Living; use pocketmine\event\entity\EntityDamageByBlockEvent; @@ -35,31 +36,17 @@ use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; use function mt_rand; class SweetBerryBush extends Flowable{ + use AgeableTrait; + use StaticSupportTrait; + public const STAGE_SAPLING = 0; public const STAGE_BUSH_NO_BERRIES = 1; public const STAGE_BUSH_SOME_BERRIES = 2; public const STAGE_MATURE = 3; - - protected int $age = self::STAGE_SAPLING; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->boundedInt(3, self::STAGE_SAPLING, self::STAGE_MATURE, $this->age); - } - - public function getAge() : int{ return $this->age; } - - /** @return $this */ - public function setAge(int $age) : self{ - if($age < self::STAGE_SAPLING || $age > self::STAGE_MATURE){ - throw new \InvalidArgumentException("Age must be in range 0-3"); - } - $this->age = $age; - return $this; - } + public const MAX_AGE = self::STAGE_MATURE; public function getBerryDropAmount() : int{ if($this->age === self::STAGE_MATURE){ @@ -70,16 +57,17 @@ public function getBerryDropAmount() : int{ return 0; } + /** + * @deprecated + */ protected function canBeSupportedBy(Block $block) : bool{ return $block->getTypeId() !== BlockTypeIds::FARMLAND && //bedrock-specific thing (bug?) ($block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD)); } - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){ - return false; - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); + return $this->canBeSupportedBy($supportBlock); } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ @@ -113,12 +101,6 @@ public function getDropsForCompatibleTool(Item $item) : array{ ]; } - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - public function ticksRandomly() : bool{ return true; } diff --git a/src/block/TallGrass.php b/src/block/TallGrass.php index d8c34b0010..459751c4e9 100644 --- a/src/block/TallGrass.php +++ b/src/block/TallGrass.php @@ -23,31 +23,16 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\block\utils\TallGrassTrait; -use pocketmine\item\Item; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; class TallGrass extends Flowable{ use TallGrassTrait; + use StaticSupportTrait; - private function canBeSupportedBy(Block $block) : bool{ - return $block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD); - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($this->canBeSupportedBy($this->getSide(Facing::DOWN))){ - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - - return false; - } - - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){ //Replace with common break method - $this->position->getWorld()->useBreakOn($this->position); - } + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); + return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD); } } diff --git a/src/block/Thin.php b/src/block/Thin.php index 5aa3f8f98a..cba5115492 100644 --- a/src/block/Thin.php +++ b/src/block/Thin.php @@ -41,7 +41,7 @@ public function readStateFromWorld() : Block{ foreach(Facing::HORIZONTAL as $facing){ $side = $this->getSide($facing); - if($side instanceof Thin || $side instanceof Wall || $side->isFullCube()){ + if($side instanceof Thin || $side instanceof Wall || $side->getSupportType(Facing::opposite($facing)) === SupportType::FULL){ $this->connections[$facing] = true; }else{ unset($this->connections[$facing]); @@ -94,6 +94,6 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } } diff --git a/src/block/Torch.php b/src/block/Torch.php index 66b62bc19a..aee4da32aa 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -84,6 +84,6 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo private function canBeSupportedAt(Block $block, int $face) : bool{ return $face === Facing::DOWN ? $block->getAdjacentSupportType($face)->hasCenterSupport() : - $block->getAdjacentSupportType($face)->equals(SupportType::FULL()); + $block->getAdjacentSupportType($face) === SupportType::FULL; } } diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index f21d7431b3..f10f94f631 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -70,7 +70,7 @@ protected function recalculateCollisionBoxes() : array{ } public function getSupportType(int $facing) : SupportType{ - return SupportType::NONE(); + return SupportType::NONE; } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index a41c3985b6..196816b304 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -68,6 +68,7 @@ use pocketmine\world\sound\AmethystBlockChimeSound; use pocketmine\world\sound\BlockPunchSound; use function mb_strtolower; +use function strtolower; /** * This doc-block is generated automatically, do not modify it manually. @@ -782,7 +783,7 @@ protected static function setup() : void{ $railBreakInfo = new Info(new BlockBreakInfo(0.7)); self::register("activator_rail", new ActivatorRail(new BID(Ids::ACTIVATOR_RAIL), "Activator Rail", $railBreakInfo)); self::register("air", new Air(new BID(Ids::AIR), "Air", new Info(BreakInfo::indestructible(-1.0)))); - self::register("anvil", new Anvil(new BID(Ids::ANVIL), "Anvil", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD(), 6000.0)))); + self::register("anvil", new Anvil(new BID(Ids::ANVIL), "Anvil", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD, 6000.0)))); self::register("bamboo", new Bamboo(new BID(Ids::BAMBOO), "Bamboo", new Info(new class(2.0 /* 1.0 in PC */, ToolType::AXE) extends BreakInfo{ public function getBreakTime(Item $item) : float{ if($item->getBlockToolType() === ToolType::SWORD){ @@ -803,13 +804,13 @@ public function getBreakTime(Item $item) : float{ self::register("bedrock", new Bedrock(new BID(Ids::BEDROCK), "Bedrock", new Info(BreakInfo::indestructible()))); self::register("beetroots", new Beetroot(new BID(Ids::BEETROOTS), "Beetroot Block", new Info(BreakInfo::instant()))); - self::register("bell", new Bell(new BID(Ids::BELL, TileBell::class), "Bell", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD())))); + self::register("bell", new Bell(new BID(Ids::BELL, TileBell::class), "Bell", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD)))); self::register("blue_ice", new BlueIce(new BID(Ids::BLUE_ICE), "Blue Ice", new Info(BreakInfo::pickaxe(2.8)))); - self::register("bone_block", new BoneBlock(new BID(Ids::BONE_BLOCK), "Bone Block", new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD())))); + self::register("bone_block", new BoneBlock(new BID(Ids::BONE_BLOCK), "Bone Block", new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD)))); self::register("bookshelf", new Bookshelf(new BID(Ids::BOOKSHELF), "Bookshelf", new Info(BreakInfo::axe(1.5)))); - self::register("brewing_stand", new BrewingStand(new BID(Ids::BREWING_STAND, TileBrewingStand::class), "Brewing Stand", new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD())))); + self::register("brewing_stand", new BrewingStand(new BID(Ids::BREWING_STAND, TileBrewingStand::class), "Brewing Stand", new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD)))); - $bricksBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD(), 30.0)); + $bricksBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0)); self::register("brick_stairs", new Stair(new BID(Ids::BRICK_STAIRS), "Brick Stairs", $bricksBreakInfo)); self::register("bricks", new Opaque(new BID(Ids::BRICKS), "Bricks", $bricksBreakInfo)); @@ -821,9 +822,9 @@ public function getBreakTime(Item $item) : float{ $chestBreakInfo = new Info(BreakInfo::axe(2.5)); self::register("chest", new Chest(new BID(Ids::CHEST, TileChest::class), "Chest", $chestBreakInfo)); self::register("clay", new Clay(new BID(Ids::CLAY), "Clay Block", new Info(BreakInfo::shovel(0.6)))); - self::register("coal", new Coal(new BID(Ids::COAL), "Coal Block", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD(), 30.0)))); + self::register("coal", new Coal(new BID(Ids::COAL), "Coal Block", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD, 30.0)))); - $cobblestoneBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD(), 30.0)); + $cobblestoneBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0)); self::register("cobblestone", $cobblestone = new Opaque(new BID(Ids::COBBLESTONE), "Cobblestone", $cobblestoneBreakInfo)); self::register("mossy_cobblestone", new Opaque(new BID(Ids::MOSSY_COBBLESTONE), "Mossy Cobblestone", $cobblestoneBreakInfo)); self::register("cobblestone_stairs", new Stair(new BID(Ids::COBBLESTONE_STAIRS), "Cobblestone Stairs", $cobblestoneBreakInfo)); @@ -831,12 +832,12 @@ public function getBreakTime(Item $item) : float{ self::register("cobweb", new Cobweb(new BID(Ids::COBWEB), "Cobweb", new Info(new BreakInfo(4.0, ToolType::SWORD | ToolType::SHEARS, 1)))); self::register("cocoa_pod", new CocoaBlock(new BID(Ids::COCOA_POD), "Cocoa Block", new Info(BreakInfo::axe(0.2, null, 15.0)))); - self::register("coral_block", new CoralBlock(new BID(Ids::CORAL_BLOCK), "Coral Block", new Info(BreakInfo::pickaxe(7.0, ToolTier::WOOD())))); + self::register("coral_block", new CoralBlock(new BID(Ids::CORAL_BLOCK), "Coral Block", new Info(BreakInfo::pickaxe(7.0, ToolTier::WOOD)))); self::register("daylight_sensor", new DaylightSensor(new BID(Ids::DAYLIGHT_SENSOR, TileDaylightSensor::class), "Daylight Sensor", new Info(BreakInfo::axe(0.2)))); self::register("dead_bush", new DeadBush(new BID(Ids::DEAD_BUSH), "Dead Bush", new Info(BreakInfo::instant(ToolType::SHEARS, 1), [Tags::POTTABLE_PLANTS]))); self::register("detector_rail", new DetectorRail(new BID(Ids::DETECTOR_RAIL), "Detector Rail", $railBreakInfo)); - self::register("diamond", new Opaque(new BID(Ids::DIAMOND), "Diamond Block", new Info(BreakInfo::pickaxe(5.0, ToolTier::IRON(), 30.0)))); + self::register("diamond", new Opaque(new BID(Ids::DIAMOND), "Diamond Block", new Info(BreakInfo::pickaxe(5.0, ToolTier::IRON, 30.0)))); self::register("dirt", new Dirt(new BID(Ids::DIRT), "Dirt", new Info(BreakInfo::shovel(0.5), [Tags::DIRT]))); self::register("sunflower", new DoublePlant(new BID(Ids::SUNFLOWER), "Sunflower", new Info(BreakInfo::instant()))); self::register("lilac", new DoublePlant(new BID(Ids::LILAC), "Lilac", new Info(BreakInfo::instant()))); @@ -845,19 +846,19 @@ public function getBreakTime(Item $item) : float{ self::register("pink_petals", new PinkPetals(new BID(Ids::PINK_PETALS), "Pink Petals", new Info(BreakInfo::instant()))); self::register("double_tallgrass", new DoubleTallGrass(new BID(Ids::DOUBLE_TALLGRASS), "Double Tallgrass", new Info(BreakInfo::instant(ToolType::SHEARS, 1)))); self::register("large_fern", new DoubleTallGrass(new BID(Ids::LARGE_FERN), "Large Fern", new Info(BreakInfo::instant(ToolType::SHEARS, 1)))); - self::register("dragon_egg", new DragonEgg(new BID(Ids::DRAGON_EGG), "Dragon Egg", new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD())))); + self::register("dragon_egg", new DragonEgg(new BID(Ids::DRAGON_EGG), "Dragon Egg", new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD)))); self::register("dried_kelp", new DriedKelp(new BID(Ids::DRIED_KELP), "Dried Kelp Block", new Info(new BreakInfo(0.5, ToolType::NONE, 0, 12.5)))); - self::register("emerald", new Opaque(new BID(Ids::EMERALD), "Emerald Block", new Info(BreakInfo::pickaxe(5.0, ToolTier::IRON(), 30.0)))); - self::register("enchanting_table", new EnchantingTable(new BID(Ids::ENCHANTING_TABLE, TileEnchantingTable::class), "Enchanting Table", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD(), 6000.0)))); + self::register("emerald", new Opaque(new BID(Ids::EMERALD), "Emerald Block", new Info(BreakInfo::pickaxe(5.0, ToolTier::IRON, 30.0)))); + self::register("enchanting_table", new EnchantingTable(new BID(Ids::ENCHANTING_TABLE, TileEnchantingTable::class), "Enchanting Table", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD, 6000.0)))); self::register("end_portal_frame", new EndPortalFrame(new BID(Ids::END_PORTAL_FRAME), "End Portal Frame", new Info(BreakInfo::indestructible()))); self::register("end_rod", new EndRod(new BID(Ids::END_ROD), "End Rod", new Info(BreakInfo::instant()))); - self::register("end_stone", new Opaque(new BID(Ids::END_STONE), "End Stone", new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD(), 45.0)))); + self::register("end_stone", new Opaque(new BID(Ids::END_STONE), "End Stone", new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD, 45.0)))); - $endBrickBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD(), 4.0)); + $endBrickBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD, 4.0)); self::register("end_stone_bricks", new Opaque(new BID(Ids::END_STONE_BRICKS), "End Stone Bricks", $endBrickBreakInfo)); self::register("end_stone_brick_stairs", new Stair(new BID(Ids::END_STONE_BRICK_STAIRS), "End Stone Brick Stairs", $endBrickBreakInfo)); - self::register("ender_chest", new EnderChest(new BID(Ids::ENDER_CHEST, TileEnderChest::class), "Ender Chest", new Info(BreakInfo::pickaxe(22.5, ToolTier::WOOD(), 3000.0)))); + self::register("ender_chest", new EnderChest(new BID(Ids::ENDER_CHEST, TileEnderChest::class), "Ender Chest", new Info(BreakInfo::pickaxe(22.5, ToolTier::WOOD, 3000.0)))); self::register("farmland", new Farmland(new BID(Ids::FARMLAND), "Farmland", new Info(BreakInfo::shovel(0.6), [Tags::DIRT]))); self::register("fire", new Fire(new BID(Ids::FIRE), "Fire Block", new Info(BreakInfo::instant(), [Tags::FIRE]))); @@ -876,31 +877,31 @@ public function getBreakTime(Item $item) : float{ self::register("white_tulip", new Flower(new BID(Ids::WHITE_TULIP), "White Tulip", $flowerTypeInfo)); self::register("flower_pot", new FlowerPot(new BID(Ids::FLOWER_POT, TileFlowerPot::class), "Flower Pot", new Info(BreakInfo::instant()))); self::register("frosted_ice", new FrostedIce(new BID(Ids::FROSTED_ICE), "Frosted Ice", new Info(BreakInfo::pickaxe(2.5)))); - self::register("furnace", new Furnace(new BID(Ids::FURNACE, TileNormalFurnace::class), "Furnace", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD())), FurnaceType::FURNACE())); - self::register("blast_furnace", new Furnace(new BID(Ids::BLAST_FURNACE, TileBlastFurnace::class), "Blast Furnace", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD())), FurnaceType::BLAST_FURNACE())); - self::register("smoker", new Furnace(new BID(Ids::SMOKER, TileSmoker::class), "Smoker", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD())), FurnaceType::SMOKER())); + self::register("furnace", new Furnace(new BID(Ids::FURNACE, TileNormalFurnace::class), "Furnace", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD)), FurnaceType::FURNACE)); + self::register("blast_furnace", new Furnace(new BID(Ids::BLAST_FURNACE, TileBlastFurnace::class), "Blast Furnace", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD)), FurnaceType::BLAST_FURNACE)); + self::register("smoker", new Furnace(new BID(Ids::SMOKER, TileSmoker::class), "Smoker", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD)), FurnaceType::SMOKER)); $glassBreakInfo = new Info(new BreakInfo(0.3)); self::register("glass", new Glass(new BID(Ids::GLASS), "Glass", $glassBreakInfo)); self::register("glass_pane", new GlassPane(new BID(Ids::GLASS_PANE), "Glass Pane", $glassBreakInfo)); - self::register("glowing_obsidian", new GlowingObsidian(new BID(Ids::GLOWING_OBSIDIAN), "Glowing Obsidian", new Info(BreakInfo::pickaxe(10.0, ToolTier::DIAMOND(), 50.0)))); + self::register("glowing_obsidian", new GlowingObsidian(new BID(Ids::GLOWING_OBSIDIAN), "Glowing Obsidian", new Info(BreakInfo::pickaxe(10.0, ToolTier::DIAMOND, 50.0)))); self::register("glowstone", new Glowstone(new BID(Ids::GLOWSTONE), "Glowstone", new Info(BreakInfo::pickaxe(0.3)))); self::register("glow_lichen", new GlowLichen(new BID(Ids::GLOW_LICHEN), "Glow Lichen", new Info(BreakInfo::axe(0.2, null, 0.2)))); - self::register("gold", new Opaque(new BID(Ids::GOLD), "Gold Block", new Info(BreakInfo::pickaxe(3.0, ToolTier::IRON(), 30.0)))); + self::register("gold", new Opaque(new BID(Ids::GOLD), "Gold Block", new Info(BreakInfo::pickaxe(3.0, ToolTier::IRON, 30.0)))); $grassBreakInfo = BreakInfo::shovel(0.6); self::register("grass", new Grass(new BID(Ids::GRASS), "Grass", new Info($grassBreakInfo, [Tags::DIRT]))); self::register("grass_path", new GrassPath(new BID(Ids::GRASS_PATH), "Grass Path", new Info($grassBreakInfo))); self::register("gravel", new Gravel(new BID(Ids::GRAVEL), "Gravel", new Info(BreakInfo::shovel(0.6)))); - $hardenedClayBreakInfo = new Info(BreakInfo::pickaxe(1.25, ToolTier::WOOD(), 21.0)); + $hardenedClayBreakInfo = new Info(BreakInfo::pickaxe(1.25, ToolTier::WOOD, 21.0)); self::register("hardened_clay", new HardenedClay(new BID(Ids::HARDENED_CLAY), "Hardened Clay", $hardenedClayBreakInfo)); $hardenedGlassBreakInfo = new Info(new BreakInfo(10.0)); self::register("hardened_glass", new HardenedGlass(new BID(Ids::HARDENED_GLASS), "Hardened Glass", $hardenedGlassBreakInfo)); self::register("hardened_glass_pane", new HardenedGlassPane(new BID(Ids::HARDENED_GLASS_PANE), "Hardened Glass Pane", $hardenedGlassBreakInfo)); self::register("hay_bale", new HayBale(new BID(Ids::HAY_BALE), "Hay Bale", new Info(new BreakInfo(0.5)))); - self::register("hopper", new Hopper(new BID(Ids::HOPPER, TileHopper::class), "Hopper", new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD(), 15.0)))); + self::register("hopper", new Hopper(new BID(Ids::HOPPER, TileHopper::class), "Hopper", new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD, 15.0)))); self::register("ice", new Ice(new BID(Ids::ICE), "Ice", new Info(BreakInfo::pickaxe(0.5)))); $updateBlockBreakInfo = new Info(new BreakInfo(1.0)); @@ -908,10 +909,10 @@ public function getBreakTime(Item $item) : float{ self::register("info_update2", new Opaque(new BID(Ids::INFO_UPDATE2), "ate!upd", $updateBlockBreakInfo)); self::register("invisible_bedrock", new Transparent(new BID(Ids::INVISIBLE_BEDROCK), "Invisible Bedrock", new Info(BreakInfo::indestructible()))); - $ironBreakInfo = new Info(BreakInfo::pickaxe(5.0, ToolTier::STONE(), 30.0)); + $ironBreakInfo = new Info(BreakInfo::pickaxe(5.0, ToolTier::STONE, 30.0)); self::register("iron", new Opaque(new BID(Ids::IRON), "Iron Block", $ironBreakInfo)); self::register("iron_bars", new Thin(new BID(Ids::IRON_BARS), "Iron Bars", $ironBreakInfo)); - $ironDoorBreakInfo = new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD(), 25.0)); + $ironDoorBreakInfo = new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD, 25.0)); self::register("iron_door", new Door(new BID(Ids::IRON_DOOR), "Iron Door", $ironDoorBreakInfo)); self::register("iron_trapdoor", new Trapdoor(new BID(Ids::IRON_TRAPDOOR), "Iron Trapdoor", $ironDoorBreakInfo)); @@ -922,21 +923,21 @@ public function getBreakTime(Item $item) : float{ self::register("jukebox", new Jukebox(new BID(Ids::JUKEBOX, TileJukebox::class), "Jukebox", new Info(BreakInfo::axe(0.8)))); //TODO: in PC the hardness is 2.0, not 0.8, unsure if this is a MCPE bug or not self::register("ladder", new Ladder(new BID(Ids::LADDER), "Ladder", new Info(BreakInfo::axe(0.4)))); - $lanternBreakInfo = new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD())); + $lanternBreakInfo = new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD)); self::register("lantern", new Lantern(new BID(Ids::LANTERN), "Lantern", $lanternBreakInfo, 15)); self::register("soul_lantern", new Lantern(new BID(Ids::SOUL_LANTERN), "Soul Lantern", $lanternBreakInfo, 10)); - self::register("lapis_lazuli", new Opaque(new BID(Ids::LAPIS_LAZULI), "Lapis Lazuli Block", new Info(BreakInfo::pickaxe(3.0, ToolTier::STONE())))); + self::register("lapis_lazuli", new Opaque(new BID(Ids::LAPIS_LAZULI), "Lapis Lazuli Block", new Info(BreakInfo::pickaxe(3.0, ToolTier::STONE)))); self::register("lava", new Lava(new BID(Ids::LAVA), "Lava", new Info(BreakInfo::indestructible(500.0)))); self::register("lectern", new Lectern(new BID(Ids::LECTERN, TileLectern::class), "Lectern", new Info(BreakInfo::axe(2.0)))); self::register("lever", new Lever(new BID(Ids::LEVER), "Lever", new Info(new BreakInfo(0.5)))); - self::register("magma", new Magma(new BID(Ids::MAGMA), "Magma Block", new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD())))); + self::register("magma", new Magma(new BID(Ids::MAGMA), "Magma Block", new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD)))); self::register("melon", new Melon(new BID(Ids::MELON), "Melon Block", new Info(BreakInfo::axe(1.0)))); self::register("melon_stem", new MelonStem(new BID(Ids::MELON_STEM), "Melon Stem", new Info(BreakInfo::instant()))); - self::register("monster_spawner", new MonsterSpawner(new BID(Ids::MONSTER_SPAWNER, TileMonsterSpawner::class), "Monster Spawner", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD())))); + self::register("monster_spawner", new MonsterSpawner(new BID(Ids::MONSTER_SPAWNER, TileMonsterSpawner::class), "Monster Spawner", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD)))); self::register("mycelium", new Mycelium(new BID(Ids::MYCELIUM), "Mycelium", new Info(BreakInfo::shovel(0.6), [Tags::DIRT]))); - $netherBrickBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD(), 30.0)); + $netherBrickBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0)); self::register("nether_bricks", new Opaque(new BID(Ids::NETHER_BRICKS), "Nether Bricks", $netherBrickBreakInfo)); self::register("red_nether_bricks", new Opaque(new BID(Ids::RED_NETHER_BRICKS), "Red Nether Bricks", $netherBrickBreakInfo)); self::register("nether_brick_fence", new Fence(new BID(Ids::NETHER_BRICK_FENCE), "Nether Brick Fence", $netherBrickBreakInfo)); @@ -946,18 +947,18 @@ public function getBreakTime(Item $item) : float{ self::register("cracked_nether_bricks", new Opaque(new BID(Ids::CRACKED_NETHER_BRICKS), "Cracked Nether Bricks", $netherBrickBreakInfo)); self::register("nether_portal", new NetherPortal(new BID(Ids::NETHER_PORTAL), "Nether Portal", new Info(BreakInfo::indestructible(0.0)))); - self::register("nether_reactor_core", new NetherReactor(new BID(Ids::NETHER_REACTOR_CORE), "Nether Reactor Core", new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD())))); + self::register("nether_reactor_core", new NetherReactor(new BID(Ids::NETHER_REACTOR_CORE), "Nether Reactor Core", new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD)))); self::register("nether_wart_block", new Opaque(new BID(Ids::NETHER_WART_BLOCK), "Nether Wart Block", new Info(new BreakInfo(1.0, ToolType::HOE)))); self::register("nether_wart", new NetherWartPlant(new BID(Ids::NETHER_WART), "Nether Wart", new Info(BreakInfo::instant()))); - self::register("netherrack", new Netherrack(new BID(Ids::NETHERRACK), "Netherrack", new Info(BreakInfo::pickaxe(0.4, ToolTier::WOOD())))); + self::register("netherrack", new Netherrack(new BID(Ids::NETHERRACK), "Netherrack", new Info(BreakInfo::pickaxe(0.4, ToolTier::WOOD)))); self::register("note_block", new Note(new BID(Ids::NOTE_BLOCK, TileNote::class), "Note Block", new Info(BreakInfo::axe(0.8)))); - self::register("obsidian", new Opaque(new BID(Ids::OBSIDIAN), "Obsidian", new Info(BreakInfo::pickaxe(35.0 /* 50 in PC */, ToolTier::DIAMOND(), 6000.0)))); + self::register("obsidian", new Opaque(new BID(Ids::OBSIDIAN), "Obsidian", new Info(BreakInfo::pickaxe(35.0 /* 50 in PC */, ToolTier::DIAMOND, 6000.0)))); self::register("packed_ice", new PackedIce(new BID(Ids::PACKED_ICE), "Packed Ice", new Info(BreakInfo::pickaxe(0.5)))); self::register("podzol", new Podzol(new BID(Ids::PODZOL), "Podzol", new Info(BreakInfo::shovel(0.5), [Tags::DIRT]))); self::register("potatoes", new Potato(new BID(Ids::POTATOES), "Potato Block", new Info(BreakInfo::instant()))); self::register("powered_rail", new PoweredRail(new BID(Ids::POWERED_RAIL), "Powered Rail", $railBreakInfo)); - $prismarineBreakInfo = new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD(), 30.0)); + $prismarineBreakInfo = new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD, 30.0)); self::register("prismarine", new Opaque(new BID(Ids::PRISMARINE), "Prismarine", $prismarineBreakInfo)); self::register("dark_prismarine", new Opaque(new BID(Ids::DARK_PRISMARINE), "Dark Prismarine", $prismarineBreakInfo)); self::register("prismarine_bricks", new Opaque(new BID(Ids::PRISMARINE_BRICKS), "Prismarine Bricks", $prismarineBreakInfo)); @@ -972,12 +973,12 @@ public function getBreakTime(Item $item) : float{ self::register("pumpkin_stem", new PumpkinStem(new BID(Ids::PUMPKIN_STEM), "Pumpkin Stem", new Info(BreakInfo::instant()))); - $purpurBreakInfo = new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD(), 30.0)); + $purpurBreakInfo = new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD, 30.0)); self::register("purpur", new Opaque(new BID(Ids::PURPUR), "Purpur Block", $purpurBreakInfo)); self::register("purpur_pillar", new SimplePillar(new BID(Ids::PURPUR_PILLAR), "Purpur Pillar", $purpurBreakInfo)); self::register("purpur_stairs", new Stair(new BID(Ids::PURPUR_STAIRS), "Purpur Stairs", $purpurBreakInfo)); - $quartzBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD())); + $quartzBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD)); self::register("quartz", new Opaque(new BID(Ids::QUARTZ), "Quartz Block", $quartzBreakInfo)); self::register("chiseled_quartz", new SimplePillar(new BID(Ids::CHISELED_QUARTZ), "Chiseled Quartz Block", $quartzBreakInfo)); self::register("quartz_pillar", new SimplePillar(new BID(Ids::QUARTZ_PILLAR), "Quartz Pillar", $quartzBreakInfo)); @@ -989,7 +990,7 @@ public function getBreakTime(Item $item) : float{ self::register("rail", new Rail(new BID(Ids::RAIL), "Rail", $railBreakInfo)); self::register("red_mushroom", new RedMushroom(new BID(Ids::RED_MUSHROOM), "Red Mushroom", new Info(BreakInfo::instant(), [Tags::POTTABLE_PLANTS]))); - self::register("redstone", new Redstone(new BID(Ids::REDSTONE), "Redstone Block", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD(), 30.0)))); + self::register("redstone", new Redstone(new BID(Ids::REDSTONE), "Redstone Block", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD, 30.0)))); self::register("redstone_comparator", new RedstoneComparator(new BID(Ids::REDSTONE_COMPARATOR, TileComparator::class), "Redstone Comparator", new Info(BreakInfo::instant()))); self::register("redstone_lamp", new RedstoneLamp(new BID(Ids::REDSTONE_LAMP), "Redstone Lamp", new Info(new BreakInfo(0.3)))); self::register("redstone_repeater", new RedstoneRepeater(new BID(Ids::REDSTONE_REPEATER), "Redstone Repeater", new Info(BreakInfo::instant()))); @@ -1005,14 +1006,14 @@ public function getBreakTime(Item $item) : float{ self::register("sea_pickle", new SeaPickle(new BID(Ids::SEA_PICKLE), "Sea Pickle", new Info(BreakInfo::instant()))); self::register("mob_head", new MobHead(new BID(Ids::MOB_HEAD, TileMobHead::class), "Mob Head", new Info(new BreakInfo(1.0), enchantmentTags: [EnchantmentTags::MASK]))); self::register("slime", new Slime(new BID(Ids::SLIME), "Slime Block", new Info(BreakInfo::instant()))); - self::register("snow", new Snow(new BID(Ids::SNOW), "Snow Block", new Info(BreakInfo::shovel(0.2, ToolTier::WOOD())))); - self::register("snow_layer", new SnowLayer(new BID(Ids::SNOW_LAYER), "Snow Layer", new Info(BreakInfo::shovel(0.1, ToolTier::WOOD())))); + self::register("snow", new Snow(new BID(Ids::SNOW), "Snow Block", new Info(BreakInfo::shovel(0.2, ToolTier::WOOD)))); + self::register("snow_layer", new SnowLayer(new BID(Ids::SNOW_LAYER), "Snow Layer", new Info(BreakInfo::shovel(0.1, ToolTier::WOOD)))); self::register("soul_sand", new SoulSand(new BID(Ids::SOUL_SAND), "Soul Sand", new Info(BreakInfo::shovel(0.5)))); self::register("sponge", new Sponge(new BID(Ids::SPONGE), "Sponge", new Info(new BreakInfo(0.6, ToolType::HOE)))); $shulkerBoxBreakInfo = new Info(BreakInfo::pickaxe(2)); self::register("shulker_box", new ShulkerBox(new BID(Ids::SHULKER_BOX, TileShulkerBox::class), "Shulker Box", $shulkerBoxBreakInfo)); - $stoneBreakInfo = new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD(), 30.0)); + $stoneBreakInfo = new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD, 30.0)); self::register( "stone", $stone = new class(new BID(Ids::STONE), "Stone", $stoneBreakInfo) extends Opaque{ @@ -1057,10 +1058,10 @@ public function isAffectedBySilkTouch() : bool{ self::register("mossy_stone_brick_stairs", new Stair(new BID(Ids::MOSSY_STONE_BRICK_STAIRS), "Mossy Stone Brick Stairs", $stoneBreakInfo)); self::register("stone_button", new StoneButton(new BID(Ids::STONE_BUTTON), "Stone Button", new Info(BreakInfo::pickaxe(0.5)))); self::register("stonecutter", new Stonecutter(new BID(Ids::STONECUTTER), "Stonecutter", new Info(BreakInfo::pickaxe(3.5)))); - self::register("stone_pressure_plate", new StonePressurePlate(new BID(Ids::STONE_PRESSURE_PLATE), "Stone Pressure Plate", new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD())))); + self::register("stone_pressure_plate", new StonePressurePlate(new BID(Ids::STONE_PRESSURE_PLATE), "Stone Pressure Plate", new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD)))); //TODO: in the future this won't be the same for all the types - $stoneSlabBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD(), 30.0)); + $stoneSlabBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0)); self::register("brick_slab", new Slab(new BID(Ids::BRICK_SLAB), "Brick", $stoneSlabBreakInfo)); self::register("cobblestone_slab", new Slab(new BID(Ids::COBBLESTONE_SLAB), "Cobblestone", $stoneSlabBreakInfo)); @@ -1092,7 +1093,7 @@ public function isAffectedBySilkTouch() : bool{ self::register("smooth_quartz_slab", new Slab(new BID(Ids::SMOOTH_QUARTZ_SLAB), "Smooth Quartz", $stoneSlabBreakInfo)); self::register("stone_slab", new Slab(new BID(Ids::STONE_SLAB), "Stone", $stoneSlabBreakInfo)); - self::register("legacy_stonecutter", new Opaque(new BID(Ids::LEGACY_STONECUTTER), "Legacy Stonecutter", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD())))); + self::register("legacy_stonecutter", new Opaque(new BID(Ids::LEGACY_STONECUTTER), "Legacy Stonecutter", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD)))); self::register("sugarcane", new Sugarcane(new BID(Ids::SUGARCANE), "Sugarcane", new Info(BreakInfo::instant()))); self::register("sweet_berry_bush", new SweetBerryBush(new BID(Ids::SWEET_BERRY_BUSH), "Sweet Berry Bush", new Info(BreakInfo::instant()))); self::register("tnt", new TNT(new BID(Ids::TNT), "TNT", new Info(BreakInfo::instant()))); @@ -1113,7 +1114,7 @@ public function isAffectedBySilkTouch() : bool{ self::register("water", new Water(new BID(Ids::WATER), "Water", new Info(BreakInfo::indestructible(500.0)))); self::register("lily_pad", new WaterLily(new BID(Ids::LILY_PAD), "Lily Pad", new Info(BreakInfo::instant()))); - $weightedPressurePlateBreakInfo = new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD())); + $weightedPressurePlateBreakInfo = new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD)); self::register("weighted_pressure_plate_heavy", new WeightedPressurePlateHeavy( new BID(Ids::WEIGHTED_PRESSURE_PLATE_HEAVY), "Weighted Pressure Plate Heavy", @@ -1140,16 +1141,16 @@ public function getBreakTime(Item $item) : float{ }); $saplingTypeInfo = new Info(BreakInfo::instant(), [Tags::POTTABLE_PLANTS]); - foreach(SaplingType::getAll() as $saplingType){ + foreach(SaplingType::cases() as $saplingType){ $name = $saplingType->getDisplayName(); - self::register($saplingType->name() . "_sapling", new Sapling(WoodLikeBlockIdHelper::getSaplingIdentifier($saplingType), $name . " Sapling", $saplingTypeInfo, $saplingType)); + self::register(strtolower($saplingType->name) . "_sapling", new Sapling(WoodLikeBlockIdHelper::getSaplingIdentifier($saplingType), $name . " Sapling", $saplingTypeInfo, $saplingType)); } - foreach(LeavesType::getAll() as $leavesType){ + foreach(LeavesType::cases() as $leavesType){ $name = $leavesType->getDisplayName(); - self::register($leavesType->name() . "_leaves", new Leaves(WoodLikeBlockIdHelper::getLeavesIdentifier($leavesType), $name . " Leaves", $leavesBreakInfo, $leavesType)); + self::register(strtolower($leavesType->name) . "_leaves", new Leaves(WoodLikeBlockIdHelper::getLeavesIdentifier($leavesType), $name . " Leaves", $leavesBreakInfo, $leavesType)); } - $sandstoneBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD())); + $sandstoneBreakInfo = new Info(BreakInfo::pickaxe(0.8, ToolTier::WOOD)); self::register("red_sandstone_stairs", new Stair(new BID(Ids::RED_SANDSTONE_STAIRS), "Red Sandstone Stairs", $sandstoneBreakInfo)); self::register("smooth_red_sandstone_stairs", new Stair(new BID(Ids::SMOOTH_RED_SANDSTONE_STAIRS), "Smooth Red Sandstone Stairs", $sandstoneBreakInfo)); self::register("red_sandstone", new Opaque(new BID(Ids::RED_SANDSTONE), "Red Sandstone", $sandstoneBreakInfo)); @@ -1164,7 +1165,7 @@ public function getBreakTime(Item $item) : float{ self::register("cut_sandstone", new Opaque(new BID(Ids::CUT_SANDSTONE), "Cut Sandstone", $sandstoneBreakInfo)); self::register("smooth_sandstone", new Opaque(new BID(Ids::SMOOTH_SANDSTONE), "Smooth Sandstone", $sandstoneBreakInfo)); - self::register("glazed_terracotta", new GlazedTerracotta(new BID(Ids::GLAZED_TERRACOTTA), "Glazed Terracotta", new Info(BreakInfo::pickaxe(1.4, ToolTier::WOOD())))); + self::register("glazed_terracotta", new GlazedTerracotta(new BID(Ids::GLAZED_TERRACOTTA), "Glazed Terracotta", new Info(BreakInfo::pickaxe(1.4, ToolTier::WOOD)))); self::register("dyed_shulker_box", new DyedShulkerBox(new BID(Ids::DYED_SHULKER_BOX, TileShulkerBox::class), "Dyed Shulker Box", $shulkerBoxBreakInfo)); self::register("stained_glass", new StainedGlass(new BID(Ids::STAINED_GLASS), "Stained Glass", $glassBreakInfo)); self::register("stained_glass_pane", new StainedGlassPane(new BID(Ids::STAINED_GLASS_PANE), "Stained Glass Pane", $glassBreakInfo)); @@ -1172,7 +1173,7 @@ public function getBreakTime(Item $item) : float{ self::register("stained_hardened_glass", new StainedHardenedGlass(new BID(Ids::STAINED_HARDENED_GLASS), "Stained Hardened Glass", $hardenedGlassBreakInfo)); self::register("stained_hardened_glass_pane", new StainedHardenedGlassPane(new BID(Ids::STAINED_HARDENED_GLASS_PANE), "Stained Hardened Glass Pane", $hardenedGlassBreakInfo)); self::register("carpet", new Carpet(new BID(Ids::CARPET), "Carpet", new Info(new BreakInfo(0.1)))); - self::register("concrete", new Concrete(new BID(Ids::CONCRETE), "Concrete", new Info(BreakInfo::pickaxe(1.8, ToolTier::WOOD())))); + self::register("concrete", new Concrete(new BID(Ids::CONCRETE), "Concrete", new Info(BreakInfo::pickaxe(1.8, ToolTier::WOOD)))); self::register("concrete_powder", new ConcretePowder(new BID(Ids::CONCRETE_POWDER), "Concrete Powder", new Info(BreakInfo::shovel(0.5)))); self::register("wool", new Wool(new BID(Ids::WOOL), "Wool", new Info(new class(0.8, ToolType::SHEARS) extends BreakInfo{ public function getBreakTime(Item $item) : float{ @@ -1186,7 +1187,7 @@ public function getBreakTime(Item $item) : float{ }))); //TODO: in the future these won't all have the same hardness; they only do now because of the old metadata crap - $wallBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD(), 30.0)); + $wallBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0)); self::register("cobblestone_wall", new Wall(new BID(Ids::COBBLESTONE_WALL), "Cobblestone Wall", $wallBreakInfo)); self::register("andesite_wall", new Wall(new BID(Ids::ANDESITE_WALL), "Andesite Wall", $wallBreakInfo)); self::register("brick_wall", new Wall(new BID(Ids::BRICK_WALL), "Brick Wall", $wallBreakInfo)); @@ -1204,7 +1205,7 @@ public function getBreakTime(Item $item) : float{ self::registerElements(); - $chemistryTableBreakInfo = new Info(BreakInfo::pickaxe(2.5, ToolTier::WOOD())); + $chemistryTableBreakInfo = new Info(BreakInfo::pickaxe(2.5, ToolTier::WOOD)); self::register("compound_creator", new ChemistryTable(new BID(Ids::COMPOUND_CREATOR), "Compound Creator", $chemistryTableBreakInfo)); self::register("element_constructor", new ChemistryTable(new BID(Ids::ELEMENT_CONSTRUCTOR), "Element Constructor", $chemistryTableBreakInfo)); self::register("lab_table", new ChemistryTable(new BID(Ids::LAB_TABLE), "Lab Table", $chemistryTableBreakInfo)); @@ -1262,9 +1263,9 @@ private static function registerWoodenBlocks() : void{ $woodenButtonBreakInfo = new Info(BreakInfo::axe(0.5)); $woodenPressurePlateBreakInfo = new Info(BreakInfo::axe(0.5)); - foreach(WoodType::getAll() as $woodType){ + foreach(WoodType::cases() as $woodType){ $name = $woodType->getDisplayName(); - $idName = fn(string $suffix) => $woodType->name() . "_" . $suffix; + $idName = fn(string $suffix) => strtolower($woodType->name) . "_" . $suffix; self::register($idName(mb_strtolower($woodType->getStandardLogSuffix() ?? "log", 'US-ASCII')), new Wood(WoodLikeBlockIdHelper::getLogIdentifier($woodType), $name . " " . ($woodType->getStandardLogSuffix() ?? "Log"), $logBreakInfo, $woodType)); self::register($idName(mb_strtolower($woodType->getAllSidedLogSuffix() ?? "wood", 'US-ASCII')), new Wood(WoodLikeBlockIdHelper::getAllSidedLogIdentifier($woodType), $name . " " . ($woodType->getAllSidedLogSuffix() ?? "Wood"), $logBreakInfo, $woodType)); @@ -1427,26 +1428,26 @@ private static function registerElements() : void{ private static function registerOres() : void{ $stoneOreBreakInfo = fn(ToolTier $toolTier) => new Info(BreakInfo::pickaxe(3.0, $toolTier)); - self::register("coal_ore", new CoalOre(new BID(Ids::COAL_ORE), "Coal Ore", $stoneOreBreakInfo(ToolTier::WOOD()))); - self::register("copper_ore", new CopperOre(new BID(Ids::COPPER_ORE), "Copper Ore", $stoneOreBreakInfo(ToolTier::STONE()))); - self::register("diamond_ore", new DiamondOre(new BID(Ids::DIAMOND_ORE), "Diamond Ore", $stoneOreBreakInfo(ToolTier::IRON()))); - self::register("emerald_ore", new EmeraldOre(new BID(Ids::EMERALD_ORE), "Emerald Ore", $stoneOreBreakInfo(ToolTier::IRON()))); - self::register("gold_ore", new GoldOre(new BID(Ids::GOLD_ORE), "Gold Ore", $stoneOreBreakInfo(ToolTier::IRON()))); - self::register("iron_ore", new IronOre(new BID(Ids::IRON_ORE), "Iron Ore", $stoneOreBreakInfo(ToolTier::STONE()))); - self::register("lapis_lazuli_ore", new LapisOre(new BID(Ids::LAPIS_LAZULI_ORE), "Lapis Lazuli Ore", $stoneOreBreakInfo(ToolTier::STONE()))); - self::register("redstone_ore", new RedstoneOre(new BID(Ids::REDSTONE_ORE), "Redstone Ore", $stoneOreBreakInfo(ToolTier::IRON()))); + self::register("coal_ore", new CoalOre(new BID(Ids::COAL_ORE), "Coal Ore", $stoneOreBreakInfo(ToolTier::WOOD))); + self::register("copper_ore", new CopperOre(new BID(Ids::COPPER_ORE), "Copper Ore", $stoneOreBreakInfo(ToolTier::STONE))); + self::register("diamond_ore", new DiamondOre(new BID(Ids::DIAMOND_ORE), "Diamond Ore", $stoneOreBreakInfo(ToolTier::IRON))); + self::register("emerald_ore", new EmeraldOre(new BID(Ids::EMERALD_ORE), "Emerald Ore", $stoneOreBreakInfo(ToolTier::IRON))); + self::register("gold_ore", new GoldOre(new BID(Ids::GOLD_ORE), "Gold Ore", $stoneOreBreakInfo(ToolTier::IRON))); + self::register("iron_ore", new IronOre(new BID(Ids::IRON_ORE), "Iron Ore", $stoneOreBreakInfo(ToolTier::STONE))); + self::register("lapis_lazuli_ore", new LapisOre(new BID(Ids::LAPIS_LAZULI_ORE), "Lapis Lazuli Ore", $stoneOreBreakInfo(ToolTier::STONE))); + self::register("redstone_ore", new RedstoneOre(new BID(Ids::REDSTONE_ORE), "Redstone Ore", $stoneOreBreakInfo(ToolTier::IRON))); $deepslateOreBreakInfo = fn(ToolTier $toolTier) => new Info(BreakInfo::pickaxe(4.5, $toolTier)); - self::register("deepslate_coal_ore", new CoalOre(new BID(Ids::DEEPSLATE_COAL_ORE), "Deepslate Coal Ore", $deepslateOreBreakInfo(ToolTier::WOOD()))); - self::register("deepslate_copper_ore", new CopperOre(new BID(Ids::DEEPSLATE_COPPER_ORE), "Deepslate Copper Ore", $deepslateOreBreakInfo(ToolTier::STONE()))); - self::register("deepslate_diamond_ore", new DiamondOre(new BID(Ids::DEEPSLATE_DIAMOND_ORE), "Deepslate Diamond Ore", $deepslateOreBreakInfo(ToolTier::IRON()))); - self::register("deepslate_emerald_ore", new EmeraldOre(new BID(Ids::DEEPSLATE_EMERALD_ORE), "Deepslate Emerald Ore", $deepslateOreBreakInfo(ToolTier::IRON()))); - self::register("deepslate_gold_ore", new GoldOre(new BID(Ids::DEEPSLATE_GOLD_ORE), "Deepslate Gold Ore", $deepslateOreBreakInfo(ToolTier::IRON()))); - self::register("deepslate_iron_ore", new IronOre(new BID(Ids::DEEPSLATE_IRON_ORE), "Deepslate Iron Ore", $deepslateOreBreakInfo(ToolTier::STONE()))); - self::register("deepslate_lapis_lazuli_ore", new LapisOre(new BID(Ids::DEEPSLATE_LAPIS_LAZULI_ORE), "Deepslate Lapis Lazuli Ore", $deepslateOreBreakInfo(ToolTier::STONE()))); - self::register("deepslate_redstone_ore", new RedstoneOre(new BID(Ids::DEEPSLATE_REDSTONE_ORE), "Deepslate Redstone Ore", $deepslateOreBreakInfo(ToolTier::IRON()))); - - $netherrackOreBreakInfo = new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD())); + self::register("deepslate_coal_ore", new CoalOre(new BID(Ids::DEEPSLATE_COAL_ORE), "Deepslate Coal Ore", $deepslateOreBreakInfo(ToolTier::WOOD))); + self::register("deepslate_copper_ore", new CopperOre(new BID(Ids::DEEPSLATE_COPPER_ORE), "Deepslate Copper Ore", $deepslateOreBreakInfo(ToolTier::STONE))); + self::register("deepslate_diamond_ore", new DiamondOre(new BID(Ids::DEEPSLATE_DIAMOND_ORE), "Deepslate Diamond Ore", $deepslateOreBreakInfo(ToolTier::IRON))); + self::register("deepslate_emerald_ore", new EmeraldOre(new BID(Ids::DEEPSLATE_EMERALD_ORE), "Deepslate Emerald Ore", $deepslateOreBreakInfo(ToolTier::IRON))); + self::register("deepslate_gold_ore", new GoldOre(new BID(Ids::DEEPSLATE_GOLD_ORE), "Deepslate Gold Ore", $deepslateOreBreakInfo(ToolTier::IRON))); + self::register("deepslate_iron_ore", new IronOre(new BID(Ids::DEEPSLATE_IRON_ORE), "Deepslate Iron Ore", $deepslateOreBreakInfo(ToolTier::STONE))); + self::register("deepslate_lapis_lazuli_ore", new LapisOre(new BID(Ids::DEEPSLATE_LAPIS_LAZULI_ORE), "Deepslate Lapis Lazuli Ore", $deepslateOreBreakInfo(ToolTier::STONE))); + self::register("deepslate_redstone_ore", new RedstoneOre(new BID(Ids::DEEPSLATE_REDSTONE_ORE), "Deepslate Redstone Ore", $deepslateOreBreakInfo(ToolTier::IRON))); + + $netherrackOreBreakInfo = new Info(BreakInfo::pickaxe(3.0, ToolTier::WOOD)); self::register("nether_quartz_ore", new NetherQuartzOre(new BID(Ids::NETHER_QUARTZ_ORE), "Nether Quartz Ore", $netherrackOreBreakInfo)); self::register("nether_gold_ore", new NetherGoldOre(new BID(Ids::NETHER_GOLD_ORE), "Nether Gold Ore", $netherrackOreBreakInfo)); } @@ -1478,20 +1479,20 @@ private static function registerBlocksR14() : void{ private static function registerBlocksR16() : void{ //for some reason, slabs have weird hardness like the legacy ones - $slabBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD(), 30.0)); + $slabBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0)); - self::register("ancient_debris", new Opaque(new BID(Ids::ANCIENT_DEBRIS), "Ancient Debris", new Info(BreakInfo::pickaxe(30, ToolTier::DIAMOND(), 3600.0)))); - $netheriteBreakInfo = new Info(BreakInfo::pickaxe(50, ToolTier::DIAMOND(), 3600.0)); + self::register("ancient_debris", new Opaque(new BID(Ids::ANCIENT_DEBRIS), "Ancient Debris", new Info(BreakInfo::pickaxe(30, ToolTier::DIAMOND, 3600.0)))); + $netheriteBreakInfo = new Info(BreakInfo::pickaxe(50, ToolTier::DIAMOND, 3600.0)); self::register("netherite", new class(new BID(Ids::NETHERITE), "Netherite Block", $netheriteBreakInfo) extends Opaque{ public function isFireProofAsItem() : bool{ return true; } }); - $basaltBreakInfo = new Info(BreakInfo::pickaxe(1.25, ToolTier::WOOD(), 21.0)); + $basaltBreakInfo = new Info(BreakInfo::pickaxe(1.25, ToolTier::WOOD, 21.0)); self::register("basalt", new SimplePillar(new BID(Ids::BASALT), "Basalt", $basaltBreakInfo)); self::register("polished_basalt", new SimplePillar(new BID(Ids::POLISHED_BASALT), "Polished Basalt", $basaltBreakInfo)); self::register("smooth_basalt", new Opaque(new BID(Ids::SMOOTH_BASALT), "Smooth Basalt", $basaltBreakInfo)); - $blackstoneBreakInfo = new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD(), 30.0)); + $blackstoneBreakInfo = new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD, 30.0)); self::register("blackstone", new Opaque(new BID(Ids::BLACKSTONE), "Blackstone", $blackstoneBreakInfo)); self::register("blackstone_slab", new Slab(new BID(Ids::BLACKSTONE_SLAB), "Blackstone", $slabBreakInfo)); self::register("blackstone_stairs", new Stair(new BID(Ids::BLACKSTONE_STAIRS), "Blackstone Stairs", $blackstoneBreakInfo)); @@ -1503,7 +1504,7 @@ public function isFireProofAsItem() : bool{ return true; } $prefix = fn(string $thing) => "Polished Blackstone" . ($thing !== "" ? " $thing" : ""); self::register("polished_blackstone", new Opaque(new BID(Ids::POLISHED_BLACKSTONE), $prefix(""), $blackstoneBreakInfo)); self::register("polished_blackstone_button", new StoneButton(new BID(Ids::POLISHED_BLACKSTONE_BUTTON), $prefix("Button"), new Info(BreakInfo::pickaxe(0.5)))); - self::register("polished_blackstone_pressure_plate", new StonePressurePlate(new BID(Ids::POLISHED_BLACKSTONE_PRESSURE_PLATE), $prefix("Pressure Plate"), new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD())), 20)); + self::register("polished_blackstone_pressure_plate", new StonePressurePlate(new BID(Ids::POLISHED_BLACKSTONE_PRESSURE_PLATE), $prefix("Pressure Plate"), new Info(BreakInfo::pickaxe(0.5, ToolTier::WOOD)), 20)); self::register("polished_blackstone_slab", new Slab(new BID(Ids::POLISHED_BLACKSTONE_SLAB), $prefix(""), $slabBreakInfo)); self::register("polished_blackstone_stairs", new Stair(new BID(Ids::POLISHED_BLACKSTONE_STAIRS), $prefix("Stairs"), $blackstoneBreakInfo)); self::register("polished_blackstone_wall", new Wall(new BID(Ids::POLISHED_BLACKSTONE_WALL), $prefix("Wall"), $blackstoneBreakInfo)); @@ -1527,33 +1528,33 @@ public function getLightLevel() : int{ return 15; } }); self::register("warped_wart_block", new Opaque(new BID(Ids::WARPED_WART_BLOCK), "Warped Wart Block", new Info(new BreakInfo(1.0, ToolType::HOE)))); - self::register("crying_obsidian", new class(new BID(Ids::CRYING_OBSIDIAN), "Crying Obsidian", new Info(BreakInfo::pickaxe(35.0 /* 50 in Java */, ToolTier::DIAMOND(), 6000.0))) extends Opaque{ + self::register("crying_obsidian", new class(new BID(Ids::CRYING_OBSIDIAN), "Crying Obsidian", new Info(BreakInfo::pickaxe(35.0 /* 50 in Java */, ToolTier::DIAMOND, 6000.0))) extends Opaque{ public function getLightLevel() : int{ return 10;} }); self::register("twisting_vines", new NetherVines(new BID(Ids::TWISTING_VINES), "Twisting Vines", new Info(BreakInfo::instant()), Facing::UP)); self::register("weeping_vines", new NetherVines(new BID(Ids::WEEPING_VINES), "Weeping Vines", new Info(BreakInfo::instant()), Facing::DOWN)); - self::register("chain", new Chain(new BID(Ids::CHAIN), "Chain", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD())))); + self::register("chain", new Chain(new BID(Ids::CHAIN), "Chain", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD)))); } private static function registerBlocksR17() : void{ //in java this can be acquired using any tool - seems to be a parity issue in bedrock - self::register("amethyst", new class(new BID(Ids::AMETHYST), "Amethyst", new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD()))) extends Opaque{ + self::register("amethyst", new class(new BID(Ids::AMETHYST), "Amethyst", new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD))) extends Opaque{ public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{ $this->position->getWorld()->addSound($this->position, new AmethystBlockChimeSound()); $this->position->getWorld()->addSound($this->position, new BlockPunchSound($this)); } }); - self::register("calcite", new Opaque(new BID(Ids::CALCITE), "Calcite", new Info(BreakInfo::pickaxe(0.75, ToolTier::WOOD())))); - self::register("tuff", new Opaque(new BID(Ids::TUFF), "Tuff", new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD(), 30.0)))); + self::register("calcite", new Opaque(new BID(Ids::CALCITE), "Calcite", new Info(BreakInfo::pickaxe(0.75, ToolTier::WOOD)))); + self::register("tuff", new Opaque(new BID(Ids::TUFF), "Tuff", new Info(BreakInfo::pickaxe(1.5, ToolTier::WOOD, 30.0)))); - self::register("raw_copper", new Opaque(new BID(Ids::RAW_COPPER), "Raw Copper Block", new Info(BreakInfo::pickaxe(5, ToolTier::STONE(), 30.0)))); - self::register("raw_gold", new Opaque(new BID(Ids::RAW_GOLD), "Raw Gold Block", new Info(BreakInfo::pickaxe(5, ToolTier::IRON(), 30.0)))); - self::register("raw_iron", new Opaque(new BID(Ids::RAW_IRON), "Raw Iron Block", new Info(BreakInfo::pickaxe(5, ToolTier::STONE(), 30.0)))); + self::register("raw_copper", new Opaque(new BID(Ids::RAW_COPPER), "Raw Copper Block", new Info(BreakInfo::pickaxe(5, ToolTier::STONE, 30.0)))); + self::register("raw_gold", new Opaque(new BID(Ids::RAW_GOLD), "Raw Gold Block", new Info(BreakInfo::pickaxe(5, ToolTier::IRON, 30.0)))); + self::register("raw_iron", new Opaque(new BID(Ids::RAW_IRON), "Raw Iron Block", new Info(BreakInfo::pickaxe(5, ToolTier::STONE, 30.0)))); - $deepslateBreakInfo = new Info(BreakInfo::pickaxe(3, ToolTier::WOOD(), 18.0)); + $deepslateBreakInfo = new Info(BreakInfo::pickaxe(3, ToolTier::WOOD, 18.0)); self::register("deepslate", new class(new BID(Ids::DEEPSLATE), "Deepslate", $deepslateBreakInfo) extends SimplePillar{ public function getDropsForCompatibleTool(Item $item) : array{ return [VanillaBlocks::COBBLED_DEEPSLATE()->asItem()]; @@ -1565,29 +1566,29 @@ public function isAffectedBySilkTouch() : bool{ }); //TODO: parity issue here - in Java this has a hardness of 3.0, but in bedrock it's 3.5 - self::register("chiseled_deepslate", new Opaque(new BID(Ids::CHISELED_DEEPSLATE), "Chiseled Deepslate", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD(), 18.0)))); + self::register("chiseled_deepslate", new Opaque(new BID(Ids::CHISELED_DEEPSLATE), "Chiseled Deepslate", new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD, 18.0)))); - $deepslateBrickBreakInfo = new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD(), 18.0)); + $deepslateBrickBreakInfo = new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD, 18.0)); self::register("deepslate_bricks", new Opaque(new BID(Ids::DEEPSLATE_BRICKS), "Deepslate Bricks", $deepslateBrickBreakInfo)); self::register("deepslate_brick_slab", new Slab(new BID(Ids::DEEPSLATE_BRICK_SLAB), "Deepslate Brick", $deepslateBrickBreakInfo)); self::register("deepslate_brick_stairs", new Stair(new BID(Ids::DEEPSLATE_BRICK_STAIRS), "Deepslate Brick Stairs", $deepslateBrickBreakInfo)); self::register("deepslate_brick_wall", new Wall(new BID(Ids::DEEPSLATE_BRICK_WALL), "Deepslate Brick Wall", $deepslateBrickBreakInfo)); self::register("cracked_deepslate_bricks", new Opaque(new BID(Ids::CRACKED_DEEPSLATE_BRICKS), "Cracked Deepslate Bricks", $deepslateBrickBreakInfo)); - $deepslateTilesBreakInfo = new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD(), 18.0)); + $deepslateTilesBreakInfo = new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD, 18.0)); self::register("deepslate_tiles", new Opaque(new BID(Ids::DEEPSLATE_TILES), "Deepslate Tiles", $deepslateTilesBreakInfo)); self::register("deepslate_tile_slab", new Slab(new BID(Ids::DEEPSLATE_TILE_SLAB), "Deepslate Tile", $deepslateTilesBreakInfo)); self::register("deepslate_tile_stairs", new Stair(new BID(Ids::DEEPSLATE_TILE_STAIRS), "Deepslate Tile Stairs", $deepslateTilesBreakInfo)); self::register("deepslate_tile_wall", new Wall(new BID(Ids::DEEPSLATE_TILE_WALL), "Deepslate Tile Wall", $deepslateTilesBreakInfo)); self::register("cracked_deepslate_tiles", new Opaque(new BID(Ids::CRACKED_DEEPSLATE_TILES), "Cracked Deepslate Tiles", $deepslateTilesBreakInfo)); - $cobbledDeepslateBreakInfo = new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD(), 18.0)); + $cobbledDeepslateBreakInfo = new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD, 18.0)); self::register("cobbled_deepslate", new Opaque(new BID(Ids::COBBLED_DEEPSLATE), "Cobbled Deepslate", $cobbledDeepslateBreakInfo)); self::register("cobbled_deepslate_slab", new Slab(new BID(Ids::COBBLED_DEEPSLATE_SLAB), "Cobbled Deepslate", $cobbledDeepslateBreakInfo)); self::register("cobbled_deepslate_stairs", new Stair(new BID(Ids::COBBLED_DEEPSLATE_STAIRS), "Cobbled Deepslate Stairs", $cobbledDeepslateBreakInfo)); self::register("cobbled_deepslate_wall", new Wall(new BID(Ids::COBBLED_DEEPSLATE_WALL), "Cobbled Deepslate Wall", $cobbledDeepslateBreakInfo)); - $polishedDeepslateBreakInfo = new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD(), 18.0)); + $polishedDeepslateBreakInfo = new Info(BreakInfo::pickaxe(3.5, ToolTier::WOOD, 18.0)); self::register("polished_deepslate", new Opaque(new BID(Ids::POLISHED_DEEPSLATE), "Polished Deepslate", $polishedDeepslateBreakInfo)); self::register("polished_deepslate_slab", new Slab(new BID(Ids::POLISHED_DEEPSLATE_SLAB), "Polished Deepslate", $polishedDeepslateBreakInfo)); self::register("polished_deepslate_stairs", new Stair(new BID(Ids::POLISHED_DEEPSLATE_STAIRS), "Polished Deepslate Stairs", $polishedDeepslateBreakInfo)); @@ -1596,7 +1597,7 @@ public function isAffectedBySilkTouch() : bool{ self::register("tinted_glass", new TintedGlass(new BID(Ids::TINTED_GLASS), "Tinted Glass", new Info(new BreakInfo(0.3)))); //blast resistance should be 30 if we were matched with java :( - $copperBreakInfo = new Info(BreakInfo::pickaxe(3.0, ToolTier::STONE(), 18.0)); + $copperBreakInfo = new Info(BreakInfo::pickaxe(3.0, ToolTier::STONE, 18.0)); self::register("lightning_rod", new LightningRod(new BID(Ids::LIGHTNING_ROD), "Lightning Rod", $copperBreakInfo)); self::register("copper", new Copper(new BID(Ids::COPPER), "Copper Block", $copperBreakInfo)); @@ -1630,7 +1631,7 @@ private static function registerMudBlocks() : void{ self::register("mud", new Opaque(new BID(Ids::MUD), "Mud", new Info(BreakInfo::shovel(0.5), [Tags::MUD]))); self::register("packed_mud", new Opaque(new BID(Ids::PACKED_MUD), "Packed Mud", new Info(BreakInfo::pickaxe(1.0, null, 15.0)))); - $mudBricksBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD(), 30.0)); + $mudBricksBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0)); self::register("mud_bricks", new Opaque(new BID(Ids::MUD_BRICKS), "Mud Bricks", $mudBricksBreakInfo)); self::register("mud_brick_slab", new Slab(new BID(Ids::MUD_BRICK_SLAB), "Mud Brick", $mudBricksBreakInfo)); @@ -1639,7 +1640,7 @@ private static function registerMudBlocks() : void{ } private static function registerCauldronBlocks() : void{ - $cauldronBreakInfo = new Info(BreakInfo::pickaxe(2, ToolTier::WOOD())); + $cauldronBreakInfo = new Info(BreakInfo::pickaxe(2, ToolTier::WOOD)); self::register("cauldron", new Cauldron(new BID(Ids::CAULDRON, TileCauldron::class), "Cauldron", $cauldronBreakInfo)); self::register("water_cauldron", new WaterCauldron(new BID(Ids::WATER_CAULDRON, TileCauldron::class), "Water Cauldron", $cauldronBreakInfo)); diff --git a/src/block/Wall.php b/src/block/Wall.php index 5a60c0314b..ae2204d7f7 100644 --- a/src/block/Wall.php +++ b/src/block/Wall.php @@ -101,9 +101,9 @@ protected function recalculateConnections() : bool{ foreach(Facing::HORIZONTAL as $facing){ $block = $this->getSide($facing); - if($block instanceof static || $block instanceof FenceGate || $block instanceof Thin || ($block->isSolid() && !$block->isTransparent())){ + if($block instanceof static || $block instanceof FenceGate || $block instanceof Thin || $block->getSupportType(Facing::opposite($facing)) === SupportType::FULL){ if(!isset($this->connections[$facing])){ - $this->connections[$facing] = WallConnectionType::SHORT(); + $this->connections[$facing] = WallConnectionType::SHORT; $changed++; } }elseif(isset($this->connections[$facing])){ @@ -156,6 +156,6 @@ public function getWaterloggingLevel() : int{ } public function getSupportType(int $facing) : SupportType{ - return Facing::axis($facing) === Axis::Y ? SupportType::CENTER() : SupportType::NONE(); + return Facing::axis($facing) === Axis::Y ? SupportType::CENTER : SupportType::NONE; } } diff --git a/src/block/WaterCauldron.php b/src/block/WaterCauldron.php index 6a3c95048f..e470aa6cb8 100644 --- a/src/block/WaterCauldron.php +++ b/src/block/WaterCauldron.php @@ -110,10 +110,10 @@ public function getEmptySound() : Sound{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ $world = $this->position->getWorld(); if(($dyeColor = match($item->getTypeId()){ - ItemTypeIds::LAPIS_LAZULI => DyeColor::BLUE(), - ItemTypeIds::INK_SAC => DyeColor::BLACK(), - ItemTypeIds::COCOA_BEANS => DyeColor::BROWN(), - ItemTypeIds::BONE_MEAL => DyeColor::WHITE(), + ItemTypeIds::LAPIS_LAZULI => DyeColor::BLUE, + ItemTypeIds::INK_SAC => DyeColor::BLACK, + ItemTypeIds::COCOA_BEANS => DyeColor::BROWN, + ItemTypeIds::BONE_MEAL => DyeColor::WHITE, ItemTypeIds::DYE => $item instanceof Dye ? $item->getColor() : null, default => null }) !== null && ($newColor = $dyeColor->getRgbValue())->toRGBA() !== $this->customWaterColor?->toRGBA() @@ -123,7 +123,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $item->pop(); }elseif($item instanceof Potion || $item instanceof SplashPotion){ //TODO: lingering potion - if($item->getType()->equals(PotionType::WATER())){ + if($item->getType() === PotionType::WATER){ $this->setCustomWaterColor(null)->addFillLevels(self::WATER_BOTTLE_FILL_AMOUNT, $item, VanillaItems::GLASS_BOTTLE(), $returnedItems); }else{ $this->mix($item, VanillaItems::GLASS_BOTTLE(), $returnedItems); @@ -170,7 +170,7 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player match($item->getTypeId()){ ItemTypeIds::WATER_BUCKET => $this->setCustomWaterColor(null)->addFillLevels(self::MAX_FILL_LEVEL, $item, VanillaItems::BUCKET(), $returnedItems), ItemTypeIds::BUCKET => $this->removeFillLevels(self::MAX_FILL_LEVEL, $item, VanillaItems::WATER_BUCKET(), $returnedItems), - ItemTypeIds::GLASS_BOTTLE => $this->removeFillLevels(self::WATER_BOTTLE_FILL_AMOUNT, $item, VanillaItems::POTION()->setType(PotionType::WATER()), $returnedItems), + ItemTypeIds::GLASS_BOTTLE => $this->removeFillLevels(self::WATER_BOTTLE_FILL_AMOUNT, $item, VanillaItems::POTION()->setType(PotionType::WATER), $returnedItems), ItemTypeIds::LAVA_BUCKET, ItemTypeIds::POWDER_SNOW_BUCKET => $this->mix($item, VanillaItems::BUCKET(), $returnedItems), default => null }; diff --git a/src/block/WaterLily.php b/src/block/WaterLily.php index 8263330f64..5dfb0d74a1 100644 --- a/src/block/WaterLily.php +++ b/src/block/WaterLily.php @@ -23,14 +23,15 @@ namespace pocketmine\block; -use pocketmine\item\Item; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; class WaterLily extends Flowable{ + use StaticSupportTrait { + canBePlacedAt as supportedWhenPlacedAt; + } /** * @return AxisAlignedBB[] @@ -40,23 +41,10 @@ protected function recalculateCollisionBoxes() : array{ } public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ - return !$blockReplace instanceof Water && parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); - } - - private function canBeSupportedBy(Block $block) : bool{ - return $block instanceof Water; - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){ - return false; - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); + return !$blockReplace instanceof Water && $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){ - $this->position->getWorld()->useBreakOn($this->position); - } + private function canBeSupportedAt(Block $block) : bool{ + return $block->getSide(Facing::DOWN) instanceof Water; } } diff --git a/src/block/WitherRose.php b/src/block/WitherRose.php index 696b261150..8c0977b375 100644 --- a/src/block/WitherRose.php +++ b/src/block/WitherRose.php @@ -23,23 +23,22 @@ namespace pocketmine\block; +use pocketmine\block\utils\StaticSupportTrait; use pocketmine\entity\effect\EffectInstance; use pocketmine\entity\effect\VanillaEffects; use pocketmine\entity\Entity; use pocketmine\entity\Living; -use pocketmine\item\Item; use pocketmine\math\Facing; -use pocketmine\math\Vector3; -use pocketmine\player\Player; -use pocketmine\world\BlockTransaction; class WitherRose extends Flowable{ + use StaticSupportTrait; - private function canBeSupportedBy(Block $block) : bool{ + private function canBeSupportedAt(Block $block) : bool{ + $supportBlock = $block->getSide(Facing::DOWN); return - $block->hasTypeTag(BlockTypeTags::DIRT) || - $block->hasTypeTag(BlockTypeTags::MUD) || - match($block->getTypeId()){ + $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || + $supportBlock->hasTypeTag(BlockTypeTags::MUD) || + match($supportBlock->getTypeId()){ BlockTypeIds::NETHERRACK, BlockTypeIds::SOUL_SAND, BlockTypeIds::SOUL_SOIL => true, @@ -47,19 +46,6 @@ private function canBeSupportedBy(Block $block) : bool{ }; } - public function onNearbyBlockChange() : void{ - if(!$this->canBeSupportedBy($this->getSide(Facing::DOWN))){ - $this->position->getWorld()->useBreakOn($this->position); - } - } - - public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){ - return false; - } - return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); - } - public function hasEntityCollision() : bool{ return true; } public function onEntityInside(Entity $entity) : bool{ diff --git a/src/block/WoodLikeBlockIdHelper.php b/src/block/WoodLikeBlockIdHelper.php index f4cddb53b8..5f668608a8 100644 --- a/src/block/WoodLikeBlockIdHelper.php +++ b/src/block/WoodLikeBlockIdHelper.php @@ -30,7 +30,6 @@ use pocketmine\block\utils\SaplingType; use pocketmine\block\utils\WoodType; use pocketmine\item\VanillaItems; -use pocketmine\utils\AssumptionFailedError; /** * All wood-like blocks have different IDs for different wood types. @@ -48,110 +47,103 @@ final class WoodLikeBlockIdHelper{ public static function getPlanksIdentifier(WoodType $type) : BID{ - return new BID(match($type->id()){ - WoodType::OAK()->id() => Ids::OAK_PLANKS, - WoodType::SPRUCE()->id() => Ids::SPRUCE_PLANKS, - WoodType::BIRCH()->id() => Ids::BIRCH_PLANKS, - WoodType::JUNGLE()->id() => Ids::JUNGLE_PLANKS, - WoodType::ACACIA()->id() => Ids::ACACIA_PLANKS, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_PLANKS, - WoodType::MANGROVE()->id() => Ids::MANGROVE_PLANKS, - WoodType::CRIMSON()->id() => Ids::CRIMSON_PLANKS, - WoodType::WARPED()->id() => Ids::WARPED_PLANKS, - WoodType::CHERRY()->id() => Ids::CHERRY_PLANKS, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($type){ + WoodType::OAK => Ids::OAK_PLANKS, + WoodType::SPRUCE => Ids::SPRUCE_PLANKS, + WoodType::BIRCH => Ids::BIRCH_PLANKS, + WoodType::JUNGLE => Ids::JUNGLE_PLANKS, + WoodType::ACACIA => Ids::ACACIA_PLANKS, + WoodType::DARK_OAK => Ids::DARK_OAK_PLANKS, + WoodType::MANGROVE => Ids::MANGROVE_PLANKS, + WoodType::CRIMSON => Ids::CRIMSON_PLANKS, + WoodType::WARPED => Ids::WARPED_PLANKS, + WoodType::CHERRY => Ids::CHERRY_PLANKS, }); } public static function getFenceIdentifier(WoodType $type) : BID{ - return new BID(match($type->id()){ - WoodType::OAK()->id() => Ids::OAK_FENCE, - WoodType::SPRUCE()->id() => Ids::SPRUCE_FENCE, - WoodType::BIRCH()->id() => Ids::BIRCH_FENCE, - WoodType::JUNGLE()->id() => Ids::JUNGLE_FENCE, - WoodType::ACACIA()->id() => Ids::ACACIA_FENCE, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_FENCE, - WoodType::MANGROVE()->id() => Ids::MANGROVE_FENCE, - WoodType::CRIMSON()->id() => Ids::CRIMSON_FENCE, - WoodType::WARPED()->id() => Ids::WARPED_FENCE, - WoodType::CHERRY()->id() => Ids::CHERRY_FENCE, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($type){ + WoodType::OAK => Ids::OAK_FENCE, + WoodType::SPRUCE => Ids::SPRUCE_FENCE, + WoodType::BIRCH => Ids::BIRCH_FENCE, + WoodType::JUNGLE => Ids::JUNGLE_FENCE, + WoodType::ACACIA => Ids::ACACIA_FENCE, + WoodType::DARK_OAK => Ids::DARK_OAK_FENCE, + WoodType::MANGROVE => Ids::MANGROVE_FENCE, + WoodType::CRIMSON => Ids::CRIMSON_FENCE, + WoodType::WARPED => Ids::WARPED_FENCE, + WoodType::CHERRY => Ids::CHERRY_FENCE, }); } public static function getSlabIdentifier(WoodType $type) : BID{ - return new BID(match($type->id()){ - WoodType::OAK()->id() => Ids::OAK_SLAB, - WoodType::SPRUCE()->id() => Ids::SPRUCE_SLAB, - WoodType::BIRCH()->id() => Ids::BIRCH_SLAB, - WoodType::JUNGLE()->id() => Ids::JUNGLE_SLAB, - WoodType::ACACIA()->id() => Ids::ACACIA_SLAB, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_SLAB, - WoodType::MANGROVE()->id() => Ids::MANGROVE_SLAB, - WoodType::CRIMSON()->id() => Ids::CRIMSON_SLAB, - WoodType::WARPED()->id() => Ids::WARPED_SLAB, - WoodType::CHERRY()->id() => Ids::CHERRY_SLAB, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($type){ + WoodType::OAK => Ids::OAK_SLAB, + WoodType::SPRUCE => Ids::SPRUCE_SLAB, + WoodType::BIRCH => Ids::BIRCH_SLAB, + WoodType::JUNGLE => Ids::JUNGLE_SLAB, + WoodType::ACACIA => Ids::ACACIA_SLAB, + WoodType::DARK_OAK => Ids::DARK_OAK_SLAB, + WoodType::MANGROVE => Ids::MANGROVE_SLAB, + WoodType::CRIMSON => Ids::CRIMSON_SLAB, + WoodType::WARPED => Ids::WARPED_SLAB, + WoodType::CHERRY => Ids::CHERRY_SLAB, }); } public static function getLogIdentifier(WoodType $treeType) : BID{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_LOG, - WoodType::SPRUCE()->id() => Ids::SPRUCE_LOG, - WoodType::BIRCH()->id() => Ids::BIRCH_LOG, - WoodType::JUNGLE()->id() => Ids::JUNGLE_LOG, - WoodType::ACACIA()->id() => Ids::ACACIA_LOG, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_LOG, - WoodType::MANGROVE()->id() => Ids::MANGROVE_LOG, - WoodType::CRIMSON()->id() => Ids::CRIMSON_STEM, - WoodType::WARPED()->id() => Ids::WARPED_STEM, - WoodType::CHERRY()->id() => Ids::CHERRY_LOG, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_LOG, + WoodType::SPRUCE => Ids::SPRUCE_LOG, + WoodType::BIRCH => Ids::BIRCH_LOG, + WoodType::JUNGLE => Ids::JUNGLE_LOG, + WoodType::ACACIA => Ids::ACACIA_LOG, + WoodType::DARK_OAK => Ids::DARK_OAK_LOG, + WoodType::MANGROVE => Ids::MANGROVE_LOG, + WoodType::CRIMSON => Ids::CRIMSON_STEM, + WoodType::WARPED => Ids::WARPED_STEM, + WoodType::CHERRY => Ids::CHERRY_LOG, }); } public static function getAllSidedLogIdentifier(WoodType $treeType) : BID{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_WOOD, - WoodType::SPRUCE()->id() => Ids::SPRUCE_WOOD, - WoodType::BIRCH()->id() => Ids::BIRCH_WOOD, - WoodType::JUNGLE()->id() => Ids::JUNGLE_WOOD, - WoodType::ACACIA()->id() => Ids::ACACIA_WOOD, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_WOOD, - WoodType::MANGROVE()->id() => Ids::MANGROVE_WOOD, - WoodType::CRIMSON()->id() => Ids::CRIMSON_HYPHAE, - WoodType::WARPED()->id() => Ids::WARPED_HYPHAE, - WoodType::CHERRY()->id() => Ids::CHERRY_WOOD, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_WOOD, + WoodType::SPRUCE => Ids::SPRUCE_WOOD, + WoodType::BIRCH => Ids::BIRCH_WOOD, + WoodType::JUNGLE => Ids::JUNGLE_WOOD, + WoodType::ACACIA => Ids::ACACIA_WOOD, + WoodType::DARK_OAK => Ids::DARK_OAK_WOOD, + WoodType::MANGROVE => Ids::MANGROVE_WOOD, + WoodType::CRIMSON => Ids::CRIMSON_HYPHAE, + WoodType::WARPED => Ids::WARPED_HYPHAE, + WoodType::CHERRY => Ids::CHERRY_WOOD, }); } public static function getLeavesIdentifier(LeavesType $leavesType) : BID{ - return new BID(match($leavesType->id()){ - LeavesType::OAK()->id() => Ids::OAK_LEAVES, - LeavesType::SPRUCE()->id() => Ids::SPRUCE_LEAVES, - LeavesType::BIRCH()->id() => Ids::BIRCH_LEAVES, - LeavesType::JUNGLE()->id() => Ids::JUNGLE_LEAVES, - LeavesType::ACACIA()->id() => Ids::ACACIA_LEAVES, - LeavesType::DARK_OAK()->id() => Ids::DARK_OAK_LEAVES, - LeavesType::MANGROVE()->id() => Ids::MANGROVE_LEAVES, - LeavesType::AZALEA()->id() => Ids::AZALEA_LEAVES, - LeavesType::FLOWERING_AZALEA()->id() => Ids::FLOWERING_AZALEA_LEAVES, - LeavesType::CHERRY()->id() => Ids::CHERRY_LEAVES, - default => throw new AssumptionFailedError("All leaves types should be covered") + return new BID(match($leavesType){ + LeavesType::OAK => Ids::OAK_LEAVES, + LeavesType::SPRUCE => Ids::SPRUCE_LEAVES, + LeavesType::BIRCH => Ids::BIRCH_LEAVES, + LeavesType::JUNGLE => Ids::JUNGLE_LEAVES, + LeavesType::ACACIA => Ids::ACACIA_LEAVES, + LeavesType::DARK_OAK => Ids::DARK_OAK_LEAVES, + LeavesType::MANGROVE => Ids::MANGROVE_LEAVES, + LeavesType::AZALEA => Ids::AZALEA_LEAVES, + LeavesType::FLOWERING_AZALEA => Ids::FLOWERING_AZALEA_LEAVES, + LeavesType::CHERRY => Ids::CHERRY_LEAVES, }); } public static function getSaplingIdentifier(SaplingType $treeType) : BID{ - return new BID(match($treeType->id()){ - SaplingType::OAK()->id() => Ids::OAK_SAPLING, - SaplingType::SPRUCE()->id() => Ids::SPRUCE_SAPLING, - SaplingType::BIRCH()->id() => Ids::BIRCH_SAPLING, - SaplingType::JUNGLE()->id() => Ids::JUNGLE_SAPLING, - SaplingType::ACACIA()->id() => Ids::ACACIA_SAPLING, - SaplingType::DARK_OAK()->id() => Ids::DARK_OAK_SAPLING, - default => throw new AssumptionFailedError("All tree types should be covered") + return new BID(match($treeType){ + SaplingType::OAK => Ids::OAK_SAPLING, + SaplingType::SPRUCE => Ids::SPRUCE_SAPLING, + SaplingType::BIRCH => Ids::BIRCH_SAPLING, + SaplingType::JUNGLE => Ids::JUNGLE_SAPLING, + SaplingType::ACACIA => Ids::ACACIA_SAPLING, + SaplingType::DARK_OAK => Ids::DARK_OAK_SAPLING, }); } @@ -160,164 +152,112 @@ public static function getSaplingIdentifier(SaplingType $treeType) : BID{ * @phpstan-return array{BID, BID, \Closure() : \pocketmine\item\Item} */ public static function getSignInfo(WoodType $treeType) : array{ - switch($treeType->id()){ - case WoodType::OAK()->id(): - return [ - new BID(Ids::OAK_SIGN, TileSign::class), - new BID(Ids::OAK_WALL_SIGN, TileSign::class), - fn() => VanillaItems::OAK_SIGN() - ]; - case WoodType::SPRUCE()->id(): - return [ - new BID(Ids::SPRUCE_SIGN, TileSign::class), - new BID(Ids::SPRUCE_WALL_SIGN, TileSign::class), - fn() => VanillaItems::SPRUCE_SIGN() - ]; - case WoodType::BIRCH()->id(): - return [ - new BID(Ids::BIRCH_SIGN, TileSign::class), - new BID(Ids::BIRCH_WALL_SIGN, TileSign::class), - fn() => VanillaItems::BIRCH_SIGN() - ]; - case WoodType::JUNGLE()->id(): - return [ - new BID(Ids::JUNGLE_SIGN, TileSign::class), - new BID(Ids::JUNGLE_WALL_SIGN, TileSign::class), - fn() => VanillaItems::JUNGLE_SIGN() - ]; - case WoodType::ACACIA()->id(): - return [ - new BID(Ids::ACACIA_SIGN, TileSign::class), - new BID(Ids::ACACIA_WALL_SIGN, TileSign::class), - fn() => VanillaItems::ACACIA_SIGN() - ]; - case WoodType::DARK_OAK()->id(): - return [ - new BID(Ids::DARK_OAK_SIGN, TileSign::class), - new BID(Ids::DARK_OAK_WALL_SIGN, TileSign::class), - fn() => VanillaItems::DARK_OAK_SIGN() - ]; - case WoodType::MANGROVE()->id(): - return [ - new BID(Ids::MANGROVE_SIGN, TileSign::class), - new BID(Ids::MANGROVE_WALL_SIGN, TileSign::class), - fn() => VanillaItems::MANGROVE_SIGN() - ]; - case WoodType::CRIMSON()->id(): - return [ - new BID(Ids::CRIMSON_SIGN, TileSign::class), - new BID(Ids::CRIMSON_WALL_SIGN, TileSign::class), - fn() => VanillaItems::CRIMSON_SIGN() - ]; - case WoodType::WARPED()->id(): - return [ - new BID(Ids::WARPED_SIGN, TileSign::class), - new BID(Ids::WARPED_WALL_SIGN, TileSign::class), - fn() => VanillaItems::WARPED_SIGN() - ]; - case WoodType::CHERRY()->id(): - return [ - new BID(Ids::CHERRY_SIGN, TileSign::class), - new BID(Ids::CHERRY_WALL_SIGN, TileSign::class), - fn() => VanillaItems::CHERRY_SIGN() - ]; - } - throw new AssumptionFailedError("Switch should cover all wood types"); + $make = fn(int $floorId, int $wallId, \Closure $getItem) => [ + new BID($floorId, TileSign::class), + new BID($wallId, TileSign::class), + $getItem + ]; + return match($treeType){ + WoodType::OAK => $make(Ids::OAK_SIGN, Ids::OAK_WALL_SIGN, fn() => VanillaItems::OAK_SIGN()), + WoodType::SPRUCE => $make(Ids::SPRUCE_SIGN, Ids::SPRUCE_WALL_SIGN, fn() => VanillaItems::SPRUCE_SIGN()), + WoodType::BIRCH => $make(Ids::BIRCH_SIGN, Ids::BIRCH_WALL_SIGN, fn() => VanillaItems::BIRCH_SIGN()), + WoodType::JUNGLE => $make(Ids::JUNGLE_SIGN, Ids::JUNGLE_WALL_SIGN, fn() => VanillaItems::JUNGLE_SIGN()), + WoodType::ACACIA => $make(Ids::ACACIA_SIGN, Ids::ACACIA_WALL_SIGN, fn() => VanillaItems::ACACIA_SIGN()), + WoodType::DARK_OAK => $make(Ids::DARK_OAK_SIGN, Ids::DARK_OAK_WALL_SIGN, fn() => VanillaItems::DARK_OAK_SIGN()), + WoodType::MANGROVE => $make(Ids::MANGROVE_SIGN, Ids::MANGROVE_WALL_SIGN, fn() => VanillaItems::MANGROVE_SIGN()), + WoodType::CRIMSON => $make(Ids::CRIMSON_SIGN, Ids::CRIMSON_WALL_SIGN, fn() => VanillaItems::CRIMSON_SIGN()), + WoodType::WARPED => $make(Ids::WARPED_SIGN, Ids::WARPED_WALL_SIGN, fn() => VanillaItems::WARPED_SIGN()), + WoodType::CHERRY => $make(Ids::CHERRY_SIGN, Ids::CHERRY_WALL_SIGN, fn() => VanillaItems::CHERRY_SIGN()), + }; } public static function getTrapdoorIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_TRAPDOOR, - WoodType::SPRUCE()->id() => Ids::SPRUCE_TRAPDOOR, - WoodType::BIRCH()->id() => Ids::BIRCH_TRAPDOOR, - WoodType::JUNGLE()->id() => Ids::JUNGLE_TRAPDOOR, - WoodType::ACACIA()->id() => Ids::ACACIA_TRAPDOOR, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_TRAPDOOR, - WoodType::MANGROVE()->id() => Ids::MANGROVE_TRAPDOOR, - WoodType::CRIMSON()->id() => Ids::CRIMSON_TRAPDOOR, - WoodType::WARPED()->id() => Ids::WARPED_TRAPDOOR, - WoodType::CHERRY()->id() => Ids::CHERRY_TRAPDOOR, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_TRAPDOOR, + WoodType::SPRUCE => Ids::SPRUCE_TRAPDOOR, + WoodType::BIRCH => Ids::BIRCH_TRAPDOOR, + WoodType::JUNGLE => Ids::JUNGLE_TRAPDOOR, + WoodType::ACACIA => Ids::ACACIA_TRAPDOOR, + WoodType::DARK_OAK => Ids::DARK_OAK_TRAPDOOR, + WoodType::MANGROVE => Ids::MANGROVE_TRAPDOOR, + WoodType::CRIMSON => Ids::CRIMSON_TRAPDOOR, + WoodType::WARPED => Ids::WARPED_TRAPDOOR, + WoodType::CHERRY => Ids::CHERRY_TRAPDOOR, }); } public static function getButtonIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_BUTTON, - WoodType::SPRUCE()->id() => Ids::SPRUCE_BUTTON, - WoodType::BIRCH()->id() => Ids::BIRCH_BUTTON, - WoodType::JUNGLE()->id() => Ids::JUNGLE_BUTTON, - WoodType::ACACIA()->id() => Ids::ACACIA_BUTTON, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_BUTTON, - WoodType::MANGROVE()->id() => Ids::MANGROVE_BUTTON, - WoodType::CRIMSON()->id() => Ids::CRIMSON_BUTTON, - WoodType::WARPED()->id() => Ids::WARPED_BUTTON, - WoodType::CHERRY()->id() => Ids::CHERRY_BUTTON, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_BUTTON, + WoodType::SPRUCE => Ids::SPRUCE_BUTTON, + WoodType::BIRCH => Ids::BIRCH_BUTTON, + WoodType::JUNGLE => Ids::JUNGLE_BUTTON, + WoodType::ACACIA => Ids::ACACIA_BUTTON, + WoodType::DARK_OAK => Ids::DARK_OAK_BUTTON, + WoodType::MANGROVE => Ids::MANGROVE_BUTTON, + WoodType::CRIMSON => Ids::CRIMSON_BUTTON, + WoodType::WARPED => Ids::WARPED_BUTTON, + WoodType::CHERRY => Ids::CHERRY_BUTTON, }); } public static function getPressurePlateIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_PRESSURE_PLATE, - WoodType::SPRUCE()->id() => Ids::SPRUCE_PRESSURE_PLATE, - WoodType::BIRCH()->id() => Ids::BIRCH_PRESSURE_PLATE, - WoodType::JUNGLE()->id() => Ids::JUNGLE_PRESSURE_PLATE, - WoodType::ACACIA()->id() => Ids::ACACIA_PRESSURE_PLATE, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_PRESSURE_PLATE, - WoodType::MANGROVE()->id() => Ids::MANGROVE_PRESSURE_PLATE, - WoodType::CRIMSON()->id() => Ids::CRIMSON_PRESSURE_PLATE, - WoodType::WARPED()->id() => Ids::WARPED_PRESSURE_PLATE, - WoodType::CHERRY()->id() => Ids::CHERRY_PRESSURE_PLATE, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_PRESSURE_PLATE, + WoodType::SPRUCE => Ids::SPRUCE_PRESSURE_PLATE, + WoodType::BIRCH => Ids::BIRCH_PRESSURE_PLATE, + WoodType::JUNGLE => Ids::JUNGLE_PRESSURE_PLATE, + WoodType::ACACIA => Ids::ACACIA_PRESSURE_PLATE, + WoodType::DARK_OAK => Ids::DARK_OAK_PRESSURE_PLATE, + WoodType::MANGROVE => Ids::MANGROVE_PRESSURE_PLATE, + WoodType::CRIMSON => Ids::CRIMSON_PRESSURE_PLATE, + WoodType::WARPED => Ids::WARPED_PRESSURE_PLATE, + WoodType::CHERRY => Ids::CHERRY_PRESSURE_PLATE, }); } public static function getDoorIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_DOOR, - WoodType::SPRUCE()->id() => Ids::SPRUCE_DOOR, - WoodType::BIRCH()->id() => Ids::BIRCH_DOOR, - WoodType::JUNGLE()->id() => Ids::JUNGLE_DOOR, - WoodType::ACACIA()->id() => Ids::ACACIA_DOOR, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_DOOR, - WoodType::MANGROVE()->id() => Ids::MANGROVE_DOOR, - WoodType::CRIMSON()->id() => Ids::CRIMSON_DOOR, - WoodType::WARPED()->id() => Ids::WARPED_DOOR, - WoodType::CHERRY()->id() => Ids::CHERRY_DOOR, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_DOOR, + WoodType::SPRUCE => Ids::SPRUCE_DOOR, + WoodType::BIRCH => Ids::BIRCH_DOOR, + WoodType::JUNGLE => Ids::JUNGLE_DOOR, + WoodType::ACACIA => Ids::ACACIA_DOOR, + WoodType::DARK_OAK => Ids::DARK_OAK_DOOR, + WoodType::MANGROVE => Ids::MANGROVE_DOOR, + WoodType::CRIMSON => Ids::CRIMSON_DOOR, + WoodType::WARPED => Ids::WARPED_DOOR, + WoodType::CHERRY => Ids::CHERRY_DOOR, }); } public static function getFenceGateIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_FENCE_GATE, - WoodType::SPRUCE()->id() => Ids::SPRUCE_FENCE_GATE, - WoodType::BIRCH()->id() => Ids::BIRCH_FENCE_GATE, - WoodType::JUNGLE()->id() => Ids::JUNGLE_FENCE_GATE, - WoodType::ACACIA()->id() => Ids::ACACIA_FENCE_GATE, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_FENCE_GATE, - WoodType::MANGROVE()->id() => Ids::MANGROVE_FENCE_GATE, - WoodType::CRIMSON()->id() => Ids::CRIMSON_FENCE_GATE, - WoodType::WARPED()->id() => Ids::WARPED_FENCE_GATE, - WoodType::CHERRY()->id() => Ids::CHERRY_FENCE_GATE, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_FENCE_GATE, + WoodType::SPRUCE => Ids::SPRUCE_FENCE_GATE, + WoodType::BIRCH => Ids::BIRCH_FENCE_GATE, + WoodType::JUNGLE => Ids::JUNGLE_FENCE_GATE, + WoodType::ACACIA => Ids::ACACIA_FENCE_GATE, + WoodType::DARK_OAK => Ids::DARK_OAK_FENCE_GATE, + WoodType::MANGROVE => Ids::MANGROVE_FENCE_GATE, + WoodType::CRIMSON => Ids::CRIMSON_FENCE_GATE, + WoodType::WARPED => Ids::WARPED_FENCE_GATE, + WoodType::CHERRY => Ids::CHERRY_FENCE_GATE, }); } public static function getStairsIdentifier(WoodType $treeType) : BlockIdentifier{ - return new BID(match($treeType->id()){ - WoodType::OAK()->id() => Ids::OAK_STAIRS, - WoodType::SPRUCE()->id() => Ids::SPRUCE_STAIRS, - WoodType::BIRCH()->id() => Ids::BIRCH_STAIRS, - WoodType::JUNGLE()->id() => Ids::JUNGLE_STAIRS, - WoodType::ACACIA()->id() => Ids::ACACIA_STAIRS, - WoodType::DARK_OAK()->id() => Ids::DARK_OAK_STAIRS, - WoodType::MANGROVE()->id() => Ids::MANGROVE_STAIRS, - WoodType::CRIMSON()->id() => Ids::CRIMSON_STAIRS, - WoodType::WARPED()->id() => Ids::WARPED_STAIRS, - WoodType::CHERRY()->id() => Ids::CHERRY_STAIRS, - default => throw new AssumptionFailedError("All wood types should be covered") + return new BID(match($treeType){ + WoodType::OAK => Ids::OAK_STAIRS, + WoodType::SPRUCE => Ids::SPRUCE_STAIRS, + WoodType::BIRCH => Ids::BIRCH_STAIRS, + WoodType::JUNGLE => Ids::JUNGLE_STAIRS, + WoodType::ACACIA => Ids::ACACIA_STAIRS, + WoodType::DARK_OAK => Ids::DARK_OAK_STAIRS, + WoodType::MANGROVE => Ids::MANGROVE_STAIRS, + WoodType::CRIMSON => Ids::CRIMSON_STAIRS, + WoodType::WARPED => Ids::WARPED_STAIRS, + WoodType::CHERRY => Ids::CHERRY_STAIRS, }); } } diff --git a/src/block/Wool.php b/src/block/Wool.php index 2cc2b75358..0b008ac042 100644 --- a/src/block/Wool.php +++ b/src/block/Wool.php @@ -24,16 +24,10 @@ namespace pocketmine\block; use pocketmine\block\utils\ColoredTrait; -use pocketmine\block\utils\DyeColor; class Wool extends Opaque{ use ColoredTrait; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ - $this->color = DyeColor::WHITE(); - parent::__construct($idInfo, $name, $typeInfo); - } - public function getFlameEncouragement() : int{ return 30; } diff --git a/src/block/inventory/EnchantInventory.php b/src/block/inventory/EnchantInventory.php index 5d7e452595..b726dbedf3 100644 --- a/src/block/inventory/EnchantInventory.php +++ b/src/block/inventory/EnchantInventory.php @@ -23,11 +23,11 @@ namespace pocketmine\block\inventory; -use pocketmine\event\player\PlayerEnchantOptionsRequestEvent; +use pocketmine\event\player\PlayerEnchantingOptionsRequestEvent; use pocketmine\inventory\SimpleInventory; use pocketmine\inventory\TemporaryInventory; -use pocketmine\item\enchantment\EnchantmentHelper as Helper; -use pocketmine\item\enchantment\EnchantOption; +use pocketmine\item\enchantment\EnchantingHelper as Helper; +use pocketmine\item\enchantment\EnchantingOption; use pocketmine\item\Item; use pocketmine\world\Position; use function array_values; @@ -39,7 +39,7 @@ class EnchantInventory extends SimpleInventory implements BlockInventory, Tempor public const SLOT_INPUT = 0; public const SLOT_LAPIS = 1; - /** @var EnchantOption[] $options */ + /** @var EnchantingOption[] $options */ private array $options = []; public function __construct(Position $holder){ @@ -52,9 +52,9 @@ protected function onSlotChange(int $index, Item $before) : void{ foreach($this->viewers as $viewer){ $this->options = []; $item = $this->getInput(); - $options = Helper::getEnchantOptions($this->holder, $item, $viewer->getEnchantmentSeed()); + $options = Helper::generateOptions($this->holder, $item, $viewer->getEnchantmentSeed()); - $event = new PlayerEnchantOptionsRequestEvent($viewer, $this, $options); + $event = new PlayerEnchantingOptionsRequestEvent($viewer, $this, $options); $event->call(); if(!$event->isCancelled() && count($event->getOptions()) > 0){ $this->options = array_values($event->getOptions()); @@ -79,7 +79,7 @@ public function getOutput(int $optionId) : ?Item{ return $option === null ? null : Helper::enchantItem($this->getInput(), $option->getEnchantments()); } - public function getOption(int $optionId) : ?EnchantOption{ + public function getOption(int $optionId) : ?EnchantingOption{ return $this->options[$optionId] ?? null; } } diff --git a/src/block/inventory/SmithingTableInventory.php b/src/block/inventory/SmithingTableInventory.php index a01b80cad0..2f67ac9d2d 100644 --- a/src/block/inventory/SmithingTableInventory.php +++ b/src/block/inventory/SmithingTableInventory.php @@ -32,6 +32,6 @@ final class SmithingTableInventory extends SimpleInventory implements BlockInven public function __construct(Position $holder){ $this->holder = $holder; - parent::__construct(2); + parent::__construct(3); } } diff --git a/src/block/tile/Banner.php b/src/block/tile/Banner.php index c1af68b1d0..c9904a3dbf 100644 --- a/src/block/tile/Banner.php +++ b/src/block/tile/Banner.php @@ -27,7 +27,6 @@ use pocketmine\block\utils\DyeColor; use pocketmine\data\bedrock\BannerPatternTypeIdMap; use pocketmine\data\bedrock\DyeColorIdMap; -use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; @@ -45,7 +44,7 @@ class Banner extends Spawnable{ public const TAG_PATTERN_COLOR = "Color"; public const TAG_PATTERN_NAME = "Pattern"; - private DyeColor $baseColor; + private DyeColor $baseColor = DyeColor::BLACK; /** * @var BannerPatternLayer[] @@ -53,11 +52,6 @@ class Banner extends Spawnable{ */ private array $patterns = []; - public function __construct(World $world, Vector3 $pos){ - $this->baseColor = DyeColor::BLACK(); - parent::__construct($world, $pos); - } - public function readSaveData(CompoundTag $nbt) : void{ $colorIdMap = DyeColorIdMap::getInstance(); if( @@ -66,7 +60,7 @@ public function readSaveData(CompoundTag $nbt) : void{ ){ $this->baseColor = $baseColor; }else{ - $this->baseColor = DyeColor::BLACK(); //TODO: this should be an error + $this->baseColor = DyeColor::BLACK; //TODO: this should be an error } $patternTypeIdMap = BannerPatternTypeIdMap::getInstance(); @@ -75,7 +69,7 @@ public function readSaveData(CompoundTag $nbt) : void{ if($patterns !== null){ /** @var CompoundTag $pattern */ foreach($patterns as $pattern){ - $patternColor = $colorIdMap->fromInvertedId($pattern->getInt(self::TAG_PATTERN_COLOR)) ?? DyeColor::BLACK(); //TODO: missing pattern colour should be an error + $patternColor = $colorIdMap->fromInvertedId($pattern->getInt(self::TAG_PATTERN_COLOR)) ?? DyeColor::BLACK; //TODO: missing pattern colour should be an error $patternType = $patternTypeIdMap->fromId($pattern->getString(self::TAG_PATTERN_NAME)); if($patternType === null){ continue; //TODO: this should be an error, but right now we don't have the setup to deal with it diff --git a/src/block/tile/Bed.php b/src/block/tile/Bed.php index 17b3e7324c..b4804980d2 100644 --- a/src/block/tile/Bed.php +++ b/src/block/tile/Bed.php @@ -25,21 +25,14 @@ use pocketmine\block\utils\DyeColor; use pocketmine\data\bedrock\DyeColorIdMap; -use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\convert\TypeConverter; -use pocketmine\world\World; class Bed extends Spawnable{ public const TAG_COLOR = "color"; - private DyeColor $color; - - public function __construct(World $world, Vector3 $pos){ - $this->color = DyeColor::RED(); - parent::__construct($world, $pos); - } + private DyeColor $color = DyeColor::RED; public function getColor() : DyeColor{ return $this->color; @@ -56,7 +49,7 @@ public function readSaveData(CompoundTag $nbt) : void{ ){ $this->color = $color; }else{ - $this->color = DyeColor::RED(); //TODO: this should be an error, but we don't have the systems to handle it yet + $this->color = DyeColor::RED; //TODO: this should be an error, but we don't have the systems to handle it yet } } diff --git a/src/block/tile/BlastFurnace.php b/src/block/tile/BlastFurnace.php index e6e23c88c3..1356e32bf4 100644 --- a/src/block/tile/BlastFurnace.php +++ b/src/block/tile/BlastFurnace.php @@ -27,6 +27,6 @@ class BlastFurnace extends Furnace{ public function getFurnaceType() : FurnaceType{ - return FurnaceType::BLAST_FURNACE(); + return FurnaceType::BLAST_FURNACE; } } diff --git a/src/block/tile/MobHead.php b/src/block/tile/MobHead.php index 94788e8104..f5fc3f9a2a 100644 --- a/src/block/tile/MobHead.php +++ b/src/block/tile/MobHead.php @@ -26,11 +26,9 @@ use pocketmine\block\utils\MobHeadType; use pocketmine\data\bedrock\MobHeadTypeIdMap; use pocketmine\data\SavedDataLoadingException; -use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\convert\TypeConverter; -use pocketmine\world\World; /** * @deprecated @@ -43,14 +41,9 @@ class MobHead extends Spawnable{ private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int - private MobHeadType $mobHeadType; + private MobHeadType $mobHeadType = MobHeadType::SKELETON; private int $rotation = 0; - public function __construct(World $world, Vector3 $pos){ - $this->mobHeadType = MobHeadType::SKELETON(); - parent::__construct($world, $pos); - } - public function readSaveData(CompoundTag $nbt) : void{ if(($skullTypeTag = $nbt->getTag(self::TAG_SKULL_TYPE)) instanceof ByteTag){ $mobHeadType = MobHeadTypeIdMap::getInstance()->fromId($skullTypeTag->getValue()); diff --git a/src/block/tile/NormalFurnace.php b/src/block/tile/NormalFurnace.php index 9580920e20..6aa61b8ce7 100644 --- a/src/block/tile/NormalFurnace.php +++ b/src/block/tile/NormalFurnace.php @@ -27,6 +27,6 @@ class NormalFurnace extends Furnace{ public function getFurnaceType() : FurnaceType{ - return FurnaceType::FURNACE(); + return FurnaceType::FURNACE; } } diff --git a/src/block/tile/Sign.php b/src/block/tile/Sign.php index 0a2619d0f7..64199c7f3b 100644 --- a/src/block/tile/Sign.php +++ b/src/block/tile/Sign.php @@ -31,7 +31,6 @@ use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\mcpe\convert\TypeConverter; -use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\utils\Binary; use pocketmine\world\World; use function array_pad; @@ -70,6 +69,8 @@ public static function fixTextBlob(string $blob) : array{ } protected SignText $text; + private bool $waxed = false; + protected ?int $editorEntityRuntimeId = null; public function __construct(World $world, Vector3 $pos){ @@ -103,6 +104,7 @@ public function readSaveData(CompoundTag $nbt) : void{ } $this->text = new SignText($text); } + $this->waxed = $nbt->getByte(self::TAG_WAXED, 0) !== 0; } protected function writeSaveData(CompoundTag $nbt) : void{ @@ -115,6 +117,7 @@ protected function writeSaveData(CompoundTag $nbt) : void{ $nbt->setInt(self::TAG_TEXT_COLOR, Binary::signInt($this->text->getBaseColor()->toARGB())); $nbt->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0); $nbt->setByte(self::TAG_LEGACY_BUG_RESOLVE, 1); + $nbt->setByte(self::TAG_WAXED, $this->waxed ? 1 : 0); } public function getText() : SignText{ @@ -125,6 +128,10 @@ public function setText(SignText $text) : void{ $this->text = $text; } + public function isWaxed() : bool{ return $this->waxed; } + + public function setWaxed(bool $waxed) : void{ $this->waxed = $waxed; } + /** * Returns the entity runtime ID of the player who placed this sign. Only the player whose entity ID matches this * one may edit the sign text. @@ -142,30 +149,20 @@ public function setEditorEntityRuntimeId(?int $editorEntityRuntimeId) : void{ } protected function addAdditionalSpawnData(CompoundTag $nbt, TypeConverter $typeConverter) : void{ - if($typeConverter->getProtocolId() >= ProtocolInfo::PROTOCOL_1_19_80){ - $nbt->setTag(self::TAG_FRONT_TEXT, CompoundTag::create() - ->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines())) - ->setInt(self::TAG_TEXT_COLOR, Binary::signInt($this->text->getBaseColor()->toARGB())) - ->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0) - ->setByte(self::TAG_PERSIST_FORMATTING, 1) //TODO: not sure what this is used for - ); - //TODO: this is not yet used by the server, but needed to rollback any client-side changes to the back text - $nbt->setTag(self::TAG_BACK_TEXT, CompoundTag::create() - ->setString(self::TAG_TEXT_BLOB, "") - ->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00)) - ->setByte(self::TAG_GLOWING_TEXT, 0) - ->setByte(self::TAG_PERSIST_FORMATTING, 1) - ); - $nbt->setByte(self::TAG_WAXED, 0); - $nbt->setLong(self::TAG_LOCKED_FOR_EDITING_BY, $this->editorEntityRuntimeId ?? -1); - }else{ - $nbt->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines())); - - //the following are not yet used by the server, but needed to roll back any changes to glowing state or colour - //if the client uses dye on the sign - $nbt->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00)); - $nbt->setByte(self::TAG_GLOWING_TEXT, 0); - $nbt->setByte(self::TAG_LEGACY_BUG_RESOLVE, 1); - } + $nbt->setTag(self::TAG_FRONT_TEXT, CompoundTag::create() + ->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines())) + ->setInt(self::TAG_TEXT_COLOR, Binary::signInt($this->text->getBaseColor()->toARGB())) + ->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0) + ->setByte(self::TAG_PERSIST_FORMATTING, 1) //TODO: not sure what this is used for + ); + //TODO: this is not yet used by the server, but needed to rollback any client-side changes to the back text + $nbt->setTag(self::TAG_BACK_TEXT, CompoundTag::create() + ->setString(self::TAG_TEXT_BLOB, "") + ->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00)) + ->setByte(self::TAG_GLOWING_TEXT, 0) + ->setByte(self::TAG_PERSIST_FORMATTING, 1) + ); + $nbt->setByte(self::TAG_WAXED, $this->waxed ? 1 : 0); + $nbt->setLong(self::TAG_LOCKED_FOR_EDITING_BY, $this->editorEntityRuntimeId ?? -1); } } diff --git a/src/block/tile/Smoker.php b/src/block/tile/Smoker.php index 4b5a017336..824eeedd28 100644 --- a/src/block/tile/Smoker.php +++ b/src/block/tile/Smoker.php @@ -27,6 +27,6 @@ class Smoker extends Furnace{ public function getFurnaceType() : FurnaceType{ - return FurnaceType::SMOKER(); + return FurnaceType::SMOKER; } } diff --git a/src/block/utils/AgeableTrait.php b/src/block/utils/AgeableTrait.php new file mode 100644 index 0000000000..6ef1ce826e --- /dev/null +++ b/src/block/utils/AgeableTrait.php @@ -0,0 +1,53 @@ +boundedInt((int) ceil(log(self::MAX_AGE, 2)), 0, self::MAX_AGE, $this->age); + } + + public function getAge() : int{ return $this->age; } + + /** + * @return $this + */ + public function setAge(int $age) : self{ + if($age < 0 || $age > self::MAX_AGE){ + throw new \InvalidArgumentException("Age must be in range 0 ... " . self::MAX_AGE); + } + $this->age = $age; + return $this; + } +} diff --git a/src/block/utils/BannerPatternType.php b/src/block/utils/BannerPatternType.php index 85b0640591..083fada1b3 100644 --- a/src/block/utils/BannerPatternType.php +++ b/src/block/utils/BannerPatternType.php @@ -23,13 +23,11 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static BannerPatternType BORDER() * @method static BannerPatternType BRICKS() @@ -70,49 +68,45 @@ * @method static BannerPatternType TRIANGLE_BOTTOM() * @method static BannerPatternType TRIANGLE_TOP() */ -final class BannerPatternType{ - use EnumTrait; +enum BannerPatternType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("border"), - new self("bricks"), - new self("circle"), - new self("creeper"), - new self("cross"), - new self("curly_border"), - new self("diagonal_left"), - new self("diagonal_right"), - new self("diagonal_up_left"), - new self("diagonal_up_right"), - new self("flower"), - new self("gradient"), - new self("gradient_up"), - new self("half_horizontal"), - new self("half_horizontal_bottom"), - new self("half_vertical"), - new self("half_vertical_right"), - new self("mojang"), - new self("rhombus"), - new self("skull"), - new self("small_stripes"), - new self("square_bottom_left"), - new self("square_bottom_right"), - new self("square_top_left"), - new self("square_top_right"), - new self("straight_cross"), - new self("stripe_bottom"), - new self("stripe_center"), - new self("stripe_downleft"), - new self("stripe_downright"), - new self("stripe_left"), - new self("stripe_middle"), - new self("stripe_right"), - new self("stripe_top"), - new self("triangle_bottom"), - new self("triangle_top"), - new self("triangles_bottom"), - new self("triangles_top") - ); - } + case BORDER; + case BRICKS; + case CIRCLE; + case CREEPER; + case CROSS; + case CURLY_BORDER; + case DIAGONAL_LEFT; + case DIAGONAL_RIGHT; + case DIAGONAL_UP_LEFT; + case DIAGONAL_UP_RIGHT; + case FLOWER; + case GRADIENT; + case GRADIENT_UP; + case HALF_HORIZONTAL; + case HALF_HORIZONTAL_BOTTOM; + case HALF_VERTICAL; + case HALF_VERTICAL_RIGHT; + case MOJANG; + case RHOMBUS; + case SKULL; + case SMALL_STRIPES; + case SQUARE_BOTTOM_LEFT; + case SQUARE_BOTTOM_RIGHT; + case SQUARE_TOP_LEFT; + case SQUARE_TOP_RIGHT; + case STRAIGHT_CROSS; + case STRIPE_BOTTOM; + case STRIPE_CENTER; + case STRIPE_DOWNLEFT; + case STRIPE_DOWNRIGHT; + case STRIPE_LEFT; + case STRIPE_MIDDLE; + case STRIPE_RIGHT; + case STRIPE_TOP; + case TRIANGLE_BOTTOM; + case TRIANGLE_TOP; + case TRIANGLES_BOTTOM; + case TRIANGLES_TOP; } diff --git a/src/block/utils/BellAttachmentType.php b/src/block/utils/BellAttachmentType.php index 963257031b..29b88a2c40 100644 --- a/src/block/utils/BellAttachmentType.php +++ b/src/block/utils/BellAttachmentType.php @@ -23,28 +23,22 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static BellAttachmentType CEILING() * @method static BellAttachmentType FLOOR() * @method static BellAttachmentType ONE_WALL() * @method static BellAttachmentType TWO_WALLS() */ -final class BellAttachmentType{ - use EnumTrait; +enum BellAttachmentType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("ceiling"), - new self("floor"), - new self("one_wall"), - new self("two_walls") - ); - } + case CEILING; + case FLOOR; + case ONE_WALL; + case TWO_WALLS; } diff --git a/src/block/utils/BrewingStandSlot.php b/src/block/utils/BrewingStandSlot.php index faeeaa7c4a..21500b1c97 100644 --- a/src/block/utils/BrewingStandSlot.php +++ b/src/block/utils/BrewingStandSlot.php @@ -24,37 +24,31 @@ namespace pocketmine\block\utils; use pocketmine\block\inventory\BrewingStandInventory; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static BrewingStandSlot EAST() * @method static BrewingStandSlot NORTHWEST() * @method static BrewingStandSlot SOUTHWEST() */ -final class BrewingStandSlot{ - use EnumTrait { - __construct as Enum___construct; - } +enum BrewingStandSlot{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("east", BrewingStandInventory::SLOT_BOTTLE_LEFT), - new self("northwest", BrewingStandInventory::SLOT_BOTTLE_MIDDLE), - new self("southwest", BrewingStandInventory::SLOT_BOTTLE_RIGHT) - ); - } - - private function __construct(string $enumName, private int $slotNumber){ - $this->Enum___construct($enumName); - } + case EAST; + case NORTHWEST; + case SOUTHWEST; /** * Returns the brewing stand inventory slot number associated with this visual slot. */ - public function getSlotNumber() : int{ return $this->slotNumber; } + public function getSlotNumber() : int{ + return match($this){ + self::EAST => BrewingStandInventory::SLOT_BOTTLE_LEFT, + self::NORTHWEST => BrewingStandInventory::SLOT_BOTTLE_MIDDLE, + self::SOUTHWEST => BrewingStandInventory::SLOT_BOTTLE_RIGHT + }; + } } diff --git a/src/block/utils/ColoredTrait.php b/src/block/utils/ColoredTrait.php index dab86fb663..2ecd58e203 100644 --- a/src/block/utils/ColoredTrait.php +++ b/src/block/utils/ColoredTrait.php @@ -28,11 +28,11 @@ trait ColoredTrait{ /** @var DyeColor */ - private $color; + private $color = DyeColor::WHITE; /** @see Block::describeBlockItemState() */ public function describeBlockItemState(RuntimeDataDescriber $w) : void{ - $w->dyeColor($this->color); + $w->enum($this->color); } public function getColor() : DyeColor{ return $this->color; } diff --git a/src/block/utils/CopperOxidation.php b/src/block/utils/CopperOxidation.php index 8278819a79..ba9abeaed3 100644 --- a/src/block/utils/CopperOxidation.php +++ b/src/block/utils/CopperOxidation.php @@ -23,57 +23,30 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static CopperOxidation EXPOSED() * @method static CopperOxidation NONE() * @method static CopperOxidation OXIDIZED() * @method static CopperOxidation WEATHERED() */ -final class CopperOxidation{ - use EnumTrait { - __construct as Enum___construct; - register as Enum_register; - } - - protected static function setup() : void{ - self::registerAll( - new self("none", 0), - new self("exposed", 1), - new self("weathered", 2), - new self("oxidized", 3) - ); - } +enum CopperOxidation : int{ + use LegacyEnumShimTrait; - protected static function register(self $member) : void{ - self::Enum_register($member); - self::$levelMap[$member->value] = $member; - } - - /** - * @var self[] - * @phpstan-var array - */ - private static array $levelMap = []; - - private function __construct( - string $name, - private int $value - ){ - $this->Enum___construct($name); - } + case NONE = 0; + case EXPOSED = 1; + case WEATHERED = 2; + case OXIDIZED = 3; public function getPrevious() : ?self{ - return self::$levelMap[$this->value - 1] ?? null; + return self::tryFrom($this->value - 1); } public function getNext() : ?self{ - return self::$levelMap[$this->value + 1] ?? null; + return self::tryFrom($this->value + 1); } } diff --git a/src/block/utils/CopperTrait.php b/src/block/utils/CopperTrait.php index 5fede94ddd..5ad8aa82d1 100644 --- a/src/block/utils/CopperTrait.php +++ b/src/block/utils/CopperTrait.php @@ -23,8 +23,6 @@ namespace pocketmine\block\utils; -use pocketmine\block\BlockIdentifier; -use pocketmine\block\BlockTypeInfo; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Axe; use pocketmine\item\Item; @@ -36,16 +34,11 @@ use pocketmine\world\sound\ScrapeSound; trait CopperTrait{ - private CopperOxidation $oxidation; + private CopperOxidation $oxidation = CopperOxidation::NONE; private bool $waxed = false; - public function __construct(BlockIdentifier $identifier, string $name, BlockTypeInfo $typeInfo){ - $this->oxidation = CopperOxidation::NONE(); - parent::__construct($identifier, $name, $typeInfo); - } - public function describeBlockItemState(RuntimeDataDescriber $w) : void{ - $w->copperOxidation($this->oxidation); + $w->enum($this->oxidation); $w->bool($this->waxed); } diff --git a/src/block/utils/CoralType.php b/src/block/utils/CoralType.php index 5a4d88fa9c..cba3e8ddee 100644 --- a/src/block/utils/CoralType.php +++ b/src/block/utils/CoralType.php @@ -23,13 +23,11 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static CoralType BRAIN() * @method static CoralType BUBBLE() @@ -37,27 +35,22 @@ * @method static CoralType HORN() * @method static CoralType TUBE() */ -final class CoralType{ - use EnumTrait { - __construct as Enum___construct; +enum CoralType{ + use LegacyEnumShimTrait; + + case TUBE; + case BRAIN; + case BUBBLE; + case FIRE; + case HORN; + + public function getDisplayName() : string{ + return match($this){ + self::TUBE => "Tube", + self::BRAIN => "Brain", + self::BUBBLE => "Bubble", + self::FIRE => "Fire", + self::HORN => "Horn", + }; } - - protected static function setup() : void{ - self::registerAll( - new self("tube", "Tube"), - new self("brain", "Brain"), - new self("bubble", "Bubble"), - new self("fire", "Fire"), - new self("horn", "Horn"), - ); - } - - private function __construct( - string $name, - private string $displayName - ){ - $this->Enum___construct($name); - } - - public function getDisplayName() : string{ return $this->displayName; } } diff --git a/src/block/utils/CoralTypeTrait.php b/src/block/utils/CoralTypeTrait.php index 5dcd539d43..a335bf9ecc 100644 --- a/src/block/utils/CoralTypeTrait.php +++ b/src/block/utils/CoralTypeTrait.php @@ -27,12 +27,12 @@ use pocketmine\data\runtime\RuntimeDataDescriber; trait CoralTypeTrait{ - protected CoralType $coralType; + protected CoralType $coralType = CoralType::TUBE; protected bool $dead = false; /** @see Block::describeBlockItemState() */ public function describeBlockItemState(RuntimeDataDescriber $w) : void{ - $w->coralType($this->coralType); + $w->enum($this->coralType); $w->bool($this->dead); } diff --git a/src/block/utils/DirtType.php b/src/block/utils/DirtType.php index 536268676d..9bed30d1c5 100644 --- a/src/block/utils/DirtType.php +++ b/src/block/utils/DirtType.php @@ -23,26 +23,20 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static DirtType COARSE() * @method static DirtType NORMAL() * @method static DirtType ROOTED() */ -final class DirtType{ - use EnumTrait; +enum DirtType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("normal"), - new self("coarse"), - new self("rooted") - ); - } + case NORMAL; + case COARSE; + case ROOTED; } diff --git a/src/block/utils/DripleafState.php b/src/block/utils/DripleafState.php index 3c2e20a13e..4b0cedce7e 100644 --- a/src/block/utils/DripleafState.php +++ b/src/block/utils/DripleafState.php @@ -23,43 +23,30 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static DripleafState FULL_TILT() * @method static DripleafState PARTIAL_TILT() * @method static DripleafState STABLE() * @method static DripleafState UNSTABLE() */ -final class DripleafState{ - use EnumTrait { - register as Enum_register; - __construct as Enum___construct; - } +enum DripleafState{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("stable", null), - new self("unstable", 10), - new self("partial_tilt", 10), - new self("full_tilt", 100) - ); - } - - private function __construct( - string $enumName, - private ?int $scheduledUpdateDelayTicks - ){ - $this->Enum___construct($enumName); - } + case STABLE; + case UNSTABLE; + case PARTIAL_TILT; + case FULL_TILT; public function getScheduledUpdateDelayTicks() : ?int{ - return $this->scheduledUpdateDelayTicks; + return match($this){ + self::STABLE => null, + self::UNSTABLE, self::PARTIAL_TILT => 10, + self::FULL_TILT => 100, + }; } - } diff --git a/src/block/utils/DyeColor.php b/src/block/utils/DyeColor.php index 81c51618a0..5b205eda5e 100644 --- a/src/block/utils/DyeColor.php +++ b/src/block/utils/DyeColor.php @@ -24,13 +24,12 @@ namespace pocketmine\block\utils; use pocketmine\color\Color; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; +use function spl_object_id; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static DyeColor BLACK() * @method static DyeColor BLUE() @@ -48,46 +47,70 @@ * @method static DyeColor RED() * @method static DyeColor WHITE() * @method static DyeColor YELLOW() + * + * @phpstan-type TMetadata array{0: string, 1: Color} */ -final class DyeColor{ - use EnumTrait { - __construct as Enum___construct; - } +enum DyeColor{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new DyeColor("white", "White", new Color(0xf0, 0xf0, 0xf0)), - new DyeColor("orange", "Orange", new Color(0xf9, 0x80, 0x1d)), - new DyeColor("magenta", "Magenta", new Color(0xc7, 0x4e, 0xbd)), - new DyeColor("light_blue", "Light Blue", new Color(0x3a, 0xb3, 0xda)), - new DyeColor("yellow", "Yellow", new Color(0xfe, 0xd8, 0x3d)), - new DyeColor("lime", "Lime", new Color(0x80, 0xc7, 0x1f)), - new DyeColor("pink", "Pink", new Color(0xf3, 0x8b, 0xaa)), - new DyeColor("gray", "Gray", new Color(0x47, 0x4f, 0x52)), - new DyeColor("light_gray", "Light Gray", new Color(0x9d, 0x9d, 0x97)), - new DyeColor("cyan", "Cyan", new Color(0x16, 0x9c, 0x9c)), - new DyeColor("purple", "Purple", new Color(0x89, 0x32, 0xb8)), - new DyeColor("blue", "Blue", new Color(0x3c, 0x44, 0xaa)), - new DyeColor("brown", "Brown", new Color(0x83, 0x54, 0x32)), - new DyeColor("green", "Green", new Color(0x5e, 0x7c, 0x16)), - new DyeColor("red", "Red", new Color(0xb0, 0x2e, 0x26)), - new DyeColor("black", "Black", new Color(0x1d, 0x1d, 0x21)) - ); + case WHITE; + case ORANGE; + case MAGENTA; + case LIGHT_BLUE; + case YELLOW; + case LIME; + case PINK; + case GRAY; + case LIGHT_GRAY; + case CYAN; + case PURPLE; + case BLUE; + case BROWN; + case GREEN; + case RED; + case BLACK; + + /** + * This function exists only to permit the use of named arguments and to make the code easier to read in PhpStorm. + * + * @phpstan-return TMetadata + */ + private static function meta(string $displayName, Color $rgbValue) : array{ + return [$displayName, $rgbValue]; } - private function __construct( - string $enumName, - private string $displayName, - private Color $rgbValue - ){ - $this->Enum___construct($enumName); + /** + * @phpstan-return TMetadata + */ + private function getMetadata() : array{ + /** @phpstan-var array $cache */ + static $cache = []; + + return $cache[spl_object_id($this)] ??= match($this){ + self::WHITE => self::meta("White", new Color(0xf0, 0xf0, 0xf0)), + self::ORANGE => self::meta("Orange", new Color(0xf9, 0x80, 0x1d)), + self::MAGENTA => self::meta("Magenta", new Color(0xc7, 0x4e, 0xbd)), + self::LIGHT_BLUE => self::meta("Light Blue", new Color(0x3a, 0xb3, 0xda)), + self::YELLOW => self::meta("Yellow", new Color(0xfe, 0xd8, 0x3d)), + self::LIME => self::meta("Lime", new Color(0x80, 0xc7, 0x1f)), + self::PINK => self::meta("Pink", new Color(0xf3, 0x8b, 0xaa)), + self::GRAY => self::meta("Gray", new Color(0x47, 0x4f, 0x52)), + self::LIGHT_GRAY => self::meta("Light Gray", new Color(0x9d, 0x9d, 0x97)), + self::CYAN => self::meta("Cyan", new Color(0x16, 0x9c, 0x9c)), + self::PURPLE => self::meta("Purple", new Color(0x89, 0x32, 0xb8)), + self::BLUE => self::meta("Blue", new Color(0x3c, 0x44, 0xaa)), + self::BROWN => self::meta("Brown", new Color(0x83, 0x54, 0x32)), + self::GREEN => self::meta("Green", new Color(0x5e, 0x7c, 0x16)), + self::RED => self::meta("Red", new Color(0xb0, 0x2e, 0x26)), + self::BLACK => self::meta("Black", new Color(0x1d, 0x1d, 0x21)), + }; } public function getDisplayName() : string{ - return $this->displayName; + return $this->getMetadata()[0]; } public function getRgbValue() : Color{ - return $this->rgbValue; + return $this->getMetadata()[1]; } } diff --git a/src/block/utils/FroglightType.php b/src/block/utils/FroglightType.php index f6b9c1d13f..ab20d31ac5 100644 --- a/src/block/utils/FroglightType.php +++ b/src/block/utils/FroglightType.php @@ -23,26 +23,20 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static FroglightType OCHRE() * @method static FroglightType PEARLESCENT() * @method static FroglightType VERDANT() */ -final class FroglightType{ - use EnumTrait; +enum FroglightType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("ochre"), - new self("pearlescent"), - new self("verdant") - ); - } + case OCHRE; + case PEARLESCENT; + case VERDANT; } diff --git a/src/block/utils/LeavesType.php b/src/block/utils/LeavesType.php index ecb2a1fd94..975551ad6d 100644 --- a/src/block/utils/LeavesType.php +++ b/src/block/utils/LeavesType.php @@ -23,13 +23,11 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static LeavesType ACACIA() * @method static LeavesType AZALEA() @@ -42,35 +40,32 @@ * @method static LeavesType OAK() * @method static LeavesType SPRUCE() */ -final class LeavesType{ - use EnumTrait { - register as Enum_register; - __construct as Enum___construct; - } - - protected static function setup() : void{ - self::registerAll( - new self("oak", "Oak"), - new self("spruce", "Spruce"), - new self("birch", "Birch"), - new self("jungle", "Jungle"), - new self("acacia", "Acacia"), - new self("dark_oak", "Dark Oak"), - new self("mangrove", "Mangrove"), - new self("azalea", "Azalea"), - new self("flowering_azalea", "Flowering Azalea"), - new self("cherry", "Cherry") - ); - } +enum LeavesType{ + use LegacyEnumShimTrait; - private function __construct( - string $enumName, - private string $displayName - ){ - $this->Enum___construct($enumName); - } + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + case MANGROVE; + case AZALEA; + case FLOWERING_AZALEA; + case CHERRY; public function getDisplayName() : string{ - return $this->displayName; + return match($this){ + self::OAK => "Oak", + self::SPRUCE => "Spruce", + self::BIRCH => "Birch", + self::JUNGLE => "Jungle", + self::ACACIA => "Acacia", + self::DARK_OAK => "Dark Oak", + self::MANGROVE => "Mangrove", + self::AZALEA => "Azalea", + self::FLOWERING_AZALEA => "Flowering Azalea", + self::CHERRY => "Cherry" + }; } } diff --git a/src/block/utils/LeverFacing.php b/src/block/utils/LeverFacing.php index 99eeb88d30..1af92d6c4c 100644 --- a/src/block/utils/LeverFacing.php +++ b/src/block/utils/LeverFacing.php @@ -24,13 +24,11 @@ namespace pocketmine\block\utils; use pocketmine\math\Facing; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static LeverFacing DOWN_AXIS_X() * @method static LeverFacing DOWN_AXIS_Z() @@ -41,27 +39,26 @@ * @method static LeverFacing UP_AXIS_Z() * @method static LeverFacing WEST() */ -final class LeverFacing{ - use EnumTrait { - __construct as Enum___construct; - } +enum LeverFacing{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("up_axis_x", Facing::UP), - new self("up_axis_z", Facing::UP), - new self("down_axis_x", Facing::DOWN), - new self("down_axis_z", Facing::DOWN), - new self("north", Facing::NORTH), - new self("east", Facing::EAST), - new self("south", Facing::SOUTH), - new self("west", Facing::WEST), - ); - } + case UP_AXIS_X; + case UP_AXIS_Z; + case DOWN_AXIS_X; + case DOWN_AXIS_Z; + case NORTH; + case EAST; + case SOUTH; + case WEST; - private function __construct(string $enumName, private int $facing){ - $this->Enum___construct($enumName); + public function getFacing() : int{ + return match($this){ + self::UP_AXIS_X, self::UP_AXIS_Z => Facing::UP, + self::DOWN_AXIS_X, self::DOWN_AXIS_Z => Facing::DOWN, + self::NORTH => Facing::NORTH, + self::EAST => Facing::EAST, + self::SOUTH => Facing::SOUTH, + self::WEST => Facing::WEST, + }; } - - public function getFacing() : int{ return $this->facing; } } diff --git a/src/block/utils/MobHeadType.php b/src/block/utils/MobHeadType.php index 391b668209..af1fe1c4c2 100644 --- a/src/block/utils/MobHeadType.php +++ b/src/block/utils/MobHeadType.php @@ -23,13 +23,11 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static MobHeadType CREEPER() * @method static MobHeadType DRAGON() @@ -39,31 +37,26 @@ * @method static MobHeadType WITHER_SKELETON() * @method static MobHeadType ZOMBIE() */ -final class MobHeadType{ - use EnumTrait { - __construct as Enum___construct; - } - - protected static function setup() : void{ - self::registerAll( - new MobHeadType("skeleton", "Skeleton Skull"), - new MobHeadType("wither_skeleton", "Wither Skeleton Skull"), - new MobHeadType("zombie", "Zombie Head"), - new MobHeadType("player", "Player Head"), - new MobHeadType("creeper", "Creeper Head"), - new MobHeadType("dragon", "Dragon Head"), - new MobHeadType("piglin", "Piglin Head") - ); - } +enum MobHeadType{ + use LegacyEnumShimTrait; - private function __construct( - string $enumName, - private string $displayName - ){ - $this->Enum___construct($enumName); - } + case SKELETON; + case WITHER_SKELETON; + case ZOMBIE; + case PLAYER; + case CREEPER; + case DRAGON; + case PIGLIN; public function getDisplayName() : string{ - return $this->displayName; + return match($this){ + self::SKELETON => "Skeleton Skull", + self::WITHER_SKELETON => "Wither Skeleton Skull", + self::ZOMBIE => "Zombie Head", + self::PLAYER => "Player Head", + self::CREEPER => "Creeper Head", + self::DRAGON => "Dragon Head", + self::PIGLIN => "Piglin Head" + }; } } diff --git a/src/block/utils/MushroomBlockType.php b/src/block/utils/MushroomBlockType.php index 7f001d13da..6bc499b236 100644 --- a/src/block/utils/MushroomBlockType.php +++ b/src/block/utils/MushroomBlockType.php @@ -23,13 +23,11 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static MushroomBlockType ALL_CAP() * @method static MushroomBlockType CAP_EAST() @@ -43,22 +41,18 @@ * @method static MushroomBlockType CAP_WEST() * @method static MushroomBlockType PORES() */ -final class MushroomBlockType{ - use EnumTrait; +enum MushroomBlockType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("PORES"), - new self("CAP_NORTHWEST"), - new self("CAP_NORTH"), - new self("CAP_NORTHEAST"), - new self("CAP_WEST"), - new self("CAP_MIDDLE"), - new self("CAP_EAST"), - new self("CAP_SOUTHWEST"), - new self("CAP_SOUTH"), - new self("CAP_SOUTHEAST"), - new self("ALL_CAP") - ); - } + case PORES; + case CAP_NORTHWEST; + case CAP_NORTH; + case CAP_NORTHEAST; + case CAP_WEST; + case CAP_MIDDLE; + case CAP_EAST; + case CAP_SOUTHWEST; + case CAP_SOUTH; + case CAP_SOUTHEAST; + case ALL_CAP; } diff --git a/src/block/utils/RecordType.php b/src/block/utils/RecordType.php index 9b0ab580fc..e63cee9204 100644 --- a/src/block/utils/RecordType.php +++ b/src/block/utils/RecordType.php @@ -26,13 +26,12 @@ use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\Translatable; use pocketmine\network\mcpe\protocol\types\LevelSoundEvent; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; +use function spl_object_id; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static RecordType DISK_11() * @method static RecordType DISK_13() @@ -49,48 +48,63 @@ * @method static RecordType DISK_STRAD() * @method static RecordType DISK_WAIT() * @method static RecordType DISK_WARD() + * + * @phpstan-type TMetadata array{0: string, 1: LevelSoundEvent::*, 2: Translatable} */ -final class RecordType{ - use EnumTrait { - __construct as Enum___construct; - } +enum RecordType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new RecordType("disk_13", "C418 - 13", LevelSoundEvent::RECORD_13, KnownTranslationFactory::item_record_13_desc()), - new RecordType("disk_5", "Samuel Åberg - 5", LevelSoundEvent::RECORD_5, KnownTranslationFactory::item_record_5_desc()), - new RecordType("disk_cat", "C418 - cat", LevelSoundEvent::RECORD_CAT, KnownTranslationFactory::item_record_cat_desc()), - new RecordType("disk_blocks", "C418 - blocks", LevelSoundEvent::RECORD_BLOCKS, KnownTranslationFactory::item_record_blocks_desc()), - new RecordType("disk_chirp", "C418 - chirp", LevelSoundEvent::RECORD_CHIRP, KnownTranslationFactory::item_record_chirp_desc()), - new RecordType("disk_far", "C418 - far", LevelSoundEvent::RECORD_FAR, KnownTranslationFactory::item_record_far_desc()), - new RecordType("disk_mall", "C418 - mall", LevelSoundEvent::RECORD_MALL, KnownTranslationFactory::item_record_mall_desc()), - new RecordType("disk_mellohi", "C418 - mellohi", LevelSoundEvent::RECORD_MELLOHI, KnownTranslationFactory::item_record_mellohi_desc()), - new RecordType("disk_otherside", "Lena Raine - otherside", LevelSoundEvent::RECORD_OTHERSIDE, KnownTranslationFactory::item_record_otherside_desc()), - new RecordType("disk_pigstep", "Lena Raine - Pigstep", LevelSoundEvent::RECORD_PIGSTEP, KnownTranslationFactory::item_record_pigstep_desc()), - new RecordType("disk_stal", "C418 - stal", LevelSoundEvent::RECORD_STAL, KnownTranslationFactory::item_record_stal_desc()), - new RecordType("disk_strad", "C418 - strad", LevelSoundEvent::RECORD_STRAD, KnownTranslationFactory::item_record_strad_desc()), - new RecordType("disk_ward", "C418 - ward", LevelSoundEvent::RECORD_WARD, KnownTranslationFactory::item_record_ward_desc()), - new RecordType("disk_11", "C418 - 11", LevelSoundEvent::RECORD_11, KnownTranslationFactory::item_record_11_desc()), - new RecordType("disk_wait", "C418 - wait", LevelSoundEvent::RECORD_WAIT, KnownTranslationFactory::item_record_wait_desc()) - ); - } + case DISK_13; + case DISK_5; + case DISK_CAT; + case DISK_BLOCKS; + case DISK_CHIRP; + case DISK_FAR; + case DISK_MALL; + case DISK_MELLOHI; + case DISK_OTHERSIDE; + case DISK_PIGSTEP; + case DISK_STAL; + case DISK_STRAD; + case DISK_WARD; + case DISK_11; + case DISK_WAIT; - private function __construct( - string $enumName, - private string $soundName, - private int $soundId, - private Translatable $translatableName - ){ - $this->Enum___construct($enumName); + /** + * @phpstan-return TMetadata + */ + private function getMetadata() : array{ + /** @phpstan-var array $cache */ + static $cache = []; + + return $cache[spl_object_id($this)] ??= match($this){ + self::DISK_13 => ["C418 - 13", LevelSoundEvent::RECORD_13, KnownTranslationFactory::item_record_13_desc()], + self::DISK_5 => ["Samuel Åberg - 5", LevelSoundEvent::RECORD_5, KnownTranslationFactory::item_record_5_desc()], + self::DISK_CAT => ["C418 - cat", LevelSoundEvent::RECORD_CAT, KnownTranslationFactory::item_record_cat_desc()], + self::DISK_BLOCKS => ["C418 - blocks", LevelSoundEvent::RECORD_BLOCKS, KnownTranslationFactory::item_record_blocks_desc()], + self::DISK_CHIRP => ["C418 - chirp", LevelSoundEvent::RECORD_CHIRP, KnownTranslationFactory::item_record_chirp_desc()], + self::DISK_FAR => ["C418 - far", LevelSoundEvent::RECORD_FAR, KnownTranslationFactory::item_record_far_desc()], + self::DISK_MALL => ["C418 - mall", LevelSoundEvent::RECORD_MALL, KnownTranslationFactory::item_record_mall_desc()], + self::DISK_MELLOHI => ["C418 - mellohi", LevelSoundEvent::RECORD_MELLOHI, KnownTranslationFactory::item_record_mellohi_desc()], + self::DISK_OTHERSIDE => ["Lena Raine - otherside", LevelSoundEvent::RECORD_OTHERSIDE, KnownTranslationFactory::item_record_otherside_desc()], + self::DISK_PIGSTEP => ["Lena Raine - Pigstep", LevelSoundEvent::RECORD_PIGSTEP, KnownTranslationFactory::item_record_pigstep_desc()], + self::DISK_STAL => ["C418 - stal", LevelSoundEvent::RECORD_STAL, KnownTranslationFactory::item_record_stal_desc()], + self::DISK_STRAD => ["C418 - strad", LevelSoundEvent::RECORD_STRAD, KnownTranslationFactory::item_record_strad_desc()], + self::DISK_WARD => ["C418 - ward", LevelSoundEvent::RECORD_WARD, KnownTranslationFactory::item_record_ward_desc()], + self::DISK_11 => ["C418 - 11", LevelSoundEvent::RECORD_11, KnownTranslationFactory::item_record_11_desc()], + self::DISK_WAIT => ["C418 - wait", LevelSoundEvent::RECORD_WAIT, KnownTranslationFactory::item_record_wait_desc()] + }; } public function getSoundName() : string{ - return $this->soundName; + return $this->getMetadata()[0]; } public function getSoundId() : int{ - return $this->soundId; + return $this->getMetadata()[1]; } - public function getTranslatableName() : Translatable{ return $this->translatableName; } + public function getTranslatableName() : Translatable{ + return $this->getMetadata()[2]; + } } diff --git a/src/block/utils/SaplingType.php b/src/block/utils/SaplingType.php index 516ee1516b..9fe87936cd 100644 --- a/src/block/utils/SaplingType.php +++ b/src/block/utils/SaplingType.php @@ -23,14 +23,12 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; use pocketmine\world\generator\object\TreeType; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static SaplingType ACACIA() * @method static SaplingType BIRCH() @@ -39,33 +37,29 @@ * @method static SaplingType OAK() * @method static SaplingType SPRUCE() */ -final class SaplingType{ - use EnumTrait { - __construct as Enum___construct; - } +enum SaplingType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("oak", TreeType::OAK()), - new self("spruce", TreeType::SPRUCE()), - new self("birch", TreeType::BIRCH()), - new self("jungle", TreeType::JUNGLE()), - new self("acacia", TreeType::ACACIA()), - new self("dark_oak", TreeType::DARK_OAK()), - //TODO: cherry - ); - } + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + //TODO: cherry - private function __construct( - string $enumName, - private TreeType $treeType, - ){ - $this->Enum___construct($enumName); + public function getTreeType() : TreeType{ + return match($this){ + self::OAK => TreeType::OAK, + self::SPRUCE => TreeType::SPRUCE, + self::BIRCH => TreeType::BIRCH, + self::JUNGLE => TreeType::JUNGLE, + self::ACACIA => TreeType::ACACIA, + self::DARK_OAK => TreeType::DARK_OAK, + }; } - public function getTreeType() : TreeType{ return $this->treeType; } - public function getDisplayName() : string{ - return $this->treeType->getDisplayName(); + return $this->getTreeType()->getDisplayName(); } } diff --git a/src/block/utils/SlabType.php b/src/block/utils/SlabType.php index 1da1b3e5a3..90f3e09535 100644 --- a/src/block/utils/SlabType.php +++ b/src/block/utils/SlabType.php @@ -23,26 +23,20 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static SlabType BOTTOM() * @method static SlabType DOUBLE() * @method static SlabType TOP() */ -final class SlabType{ - use EnumTrait; +enum SlabType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("bottom"), - new self("top"), - new self("double") - ); - } + case BOTTOM; + case TOP; + case DOUBLE; } diff --git a/src/block/utils/StairShape.php b/src/block/utils/StairShape.php index c98aec8fba..b89b9adbb2 100644 --- a/src/block/utils/StairShape.php +++ b/src/block/utils/StairShape.php @@ -23,13 +23,11 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static StairShape INNER_LEFT() * @method static StairShape INNER_RIGHT() @@ -37,16 +35,12 @@ * @method static StairShape OUTER_RIGHT() * @method static StairShape STRAIGHT() */ -final class StairShape{ - use EnumTrait; +enum StairShape{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("straight"), - new self("inner_left"), - new self("inner_right"), - new self("outer_left"), - new self("outer_right") - ); - } + case STRAIGHT; + case INNER_LEFT; + case INNER_RIGHT; + case OUTER_LEFT; + case OUTER_RIGHT; } diff --git a/src/block/utils/StaticSupportTrait.php b/src/block/utils/StaticSupportTrait.php new file mode 100644 index 0000000000..0e40230cc6 --- /dev/null +++ b/src/block/utils/StaticSupportTrait.php @@ -0,0 +1,57 @@ +canBeSupportedAt($blockReplace) && parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); + } + + /** + * @see Block::onNearbyBlockChange() + */ + public function onNearbyBlockChange() : void{ + if(!$this->canBeSupportedAt($this)){ + $this->position->getWorld()->useBreakOn($this->position); + }else{ + parent::onNearbyBlockChange(); + } + } +} diff --git a/src/block/utils/SupportType.php b/src/block/utils/SupportType.php index b4480bf57f..9513d86401 100644 --- a/src/block/utils/SupportType.php +++ b/src/block/utils/SupportType.php @@ -23,36 +23,30 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static SupportType CENTER() * @method static SupportType EDGE() * @method static SupportType FULL() * @method static SupportType NONE() */ -final class SupportType{ - use EnumTrait; - - protected static function setup() : void{ - self::registerAll( - new self("full"), - new self("center"), - new self("edge"), - new self("none") - ); - } +enum SupportType{ + use LegacyEnumShimTrait; + + case FULL; + case CENTER; + case EDGE; + case NONE; public function hasEdgeSupport() : bool{ - return $this->equals(self::EDGE()) || $this->equals(self::FULL()); + return $this === self::EDGE || $this === self::FULL; } public function hasCenterSupport() : bool{ - return $this->equals(self::CENTER()) || $this->equals(self::FULL()); + return $this === self::CENTER || $this === self::FULL; } } diff --git a/src/block/utils/WallConnectionType.php b/src/block/utils/WallConnectionType.php index 11765ab33c..1d4c8d1524 100644 --- a/src/block/utils/WallConnectionType.php +++ b/src/block/utils/WallConnectionType.php @@ -23,24 +23,18 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static WallConnectionType SHORT() * @method static WallConnectionType TALL() */ -final class WallConnectionType{ - use EnumTrait; +enum WallConnectionType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("short"), - new self("tall") - ); - } + case SHORT; + case TALL; } diff --git a/src/block/utils/WoodType.php b/src/block/utils/WoodType.php index b9d96561b9..f6195b9f90 100644 --- a/src/block/utils/WoodType.php +++ b/src/block/utils/WoodType.php @@ -23,13 +23,11 @@ namespace pocketmine\block\utils; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static WoodType ACACIA() * @method static WoodType BIRCH() @@ -42,41 +40,44 @@ * @method static WoodType SPRUCE() * @method static WoodType WARPED() */ -final class WoodType{ - use EnumTrait { - __construct as private Enum___construct; - } +enum WoodType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("oak", "Oak", true), - new self("spruce", "Spruce", true), - new self("birch", "Birch", true), - new self("jungle", "Jungle", true), - new self("acacia", "Acacia", true), - new self("dark_oak", "Dark Oak", true), - new self("mangrove", "Mangrove", true), - new self("crimson", "Crimson", false, "Stem", "Hyphae"), - new self("warped", "Warped", false, "Stem", "Hyphae"), - new self("cherry", "Cherry", true), - ); - } + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + case MANGROVE; + case CRIMSON; + case WARPED; + case CHERRY; - private function __construct( - string $enumName, - private string $displayName, - private bool $flammable, - private ?string $standardLogSuffix = null, - private ?string $allSidedLogSuffix = null, - ){ - $this->Enum___construct($enumName); + public function getDisplayName() : string{ + return match($this){ + self::OAK => "Oak", + self::SPRUCE => "Spruce", + self::BIRCH => "Birch", + self::JUNGLE => "Jungle", + self::ACACIA => "Acacia", + self::DARK_OAK => "Dark Oak", + self::MANGROVE => "Mangrove", + self::CRIMSON => "Crimson", + self::WARPED => "Warped", + self::CHERRY => "Cherry", + }; } - public function getDisplayName() : string{ return $this->displayName; } - - public function isFlammable() : bool{ return $this->flammable; } + public function isFlammable() : bool{ + return $this !== self::CRIMSON && $this !== self::WARPED; + } - public function getStandardLogSuffix() : ?string{ return $this->standardLogSuffix; } + public function getStandardLogSuffix() : ?string{ + return $this === self::CRIMSON || $this === self::WARPED ? "Stem" : null; + } - public function getAllSidedLogSuffix() : ?string{ return $this->allSidedLogSuffix; } + public function getAllSidedLogSuffix() : ?string{ + return $this === self::CRIMSON || $this === self::WARPED ? "Hyphae" : null; + } } diff --git a/src/command/defaults/DefaultGamemodeCommand.php b/src/command/defaults/DefaultGamemodeCommand.php index 3860b9e34e..d3030eb27b 100644 --- a/src/command/defaults/DefaultGamemodeCommand.php +++ b/src/command/defaults/DefaultGamemodeCommand.php @@ -28,6 +28,7 @@ use pocketmine\lang\KnownTranslationFactory; use pocketmine\permission\DefaultPermissionNames; use pocketmine\player\GameMode; +use pocketmine\ServerProperties; use function count; class DefaultGamemodeCommand extends VanillaCommand{ @@ -52,7 +53,8 @@ public function execute(CommandSender $sender, string $commandLabel, array $args return true; } - $sender->getServer()->getConfigGroup()->setConfigString("gamemode", $gameMode->name()); + //TODO: this probably shouldn't use the enum name directly + $sender->getServer()->getConfigGroup()->setConfigString(ServerProperties::GAME_MODE, $gameMode->name); $sender->sendMessage(KnownTranslationFactory::commands_defaultgamemode_success($gameMode->getTranslatableName())); return true; } diff --git a/src/command/defaults/DifficultyCommand.php b/src/command/defaults/DifficultyCommand.php index 98eb3be3bc..dee75e025e 100644 --- a/src/command/defaults/DifficultyCommand.php +++ b/src/command/defaults/DifficultyCommand.php @@ -28,6 +28,7 @@ use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\lang\KnownTranslationFactory; use pocketmine\permission\DefaultPermissionNames; +use pocketmine\ServerProperties; use pocketmine\world\World; use function count; @@ -54,7 +55,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args } if($difficulty !== -1){ - $sender->getServer()->getConfigGroup()->setConfigInt("difficulty", $difficulty); + $sender->getServer()->getConfigGroup()->setConfigInt(ServerProperties::DIFFICULTY, $difficulty); //TODO: add per-world support foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){ diff --git a/src/command/defaults/EnchantCommand.php b/src/command/defaults/EnchantCommand.php index 189931b99b..191a146b03 100644 --- a/src/command/defaults/EnchantCommand.php +++ b/src/command/defaults/EnchantCommand.php @@ -25,7 +25,7 @@ use pocketmine\command\CommandSender; use pocketmine\command\utils\InvalidCommandSyntaxException; -use pocketmine\item\enchantment\EnchantmentHelper; +use pocketmine\item\enchantment\EnchantingHelper; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\enchantment\StringToEnchantmentParser; use pocketmine\lang\KnownTranslationFactory; @@ -78,7 +78,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args } //this is necessary to deal with enchanted books, which are a different item type than regular books - $enchantedItem = EnchantmentHelper::enchantItem($item, [new EnchantmentInstance($enchantment, $level)]); + $enchantedItem = EnchantingHelper::enchantItem($item, [new EnchantmentInstance($enchantment, $level)]); $player->getInventory()->setItemInHand($enchantedItem); self::broadcastCommandMessage($sender, KnownTranslationFactory::commands_enchant_success($player->getName())); diff --git a/src/command/defaults/GamemodeCommand.php b/src/command/defaults/GamemodeCommand.php index 86ca8e9df6..666626a692 100644 --- a/src/command/defaults/GamemodeCommand.php +++ b/src/command/defaults/GamemodeCommand.php @@ -61,13 +61,13 @@ public function execute(CommandSender $sender, string $commandLabel, array $args return true; } - if($target->getGamemode()->equals($gameMode)){ + if($target->getGamemode() === $gameMode){ $sender->sendMessage(KnownTranslationFactory::pocketmine_command_gamemode_failure($target->getName())); return true; } $target->setGamemode($gameMode); - if(!$gameMode->equals($target->getGamemode())){ + if($gameMode !== $target->getGamemode()){ $sender->sendMessage(KnownTranslationFactory::pocketmine_command_gamemode_failure($target->getName())); }else{ if($target === $sender){ diff --git a/src/command/defaults/TimingsCommand.php b/src/command/defaults/TimingsCommand.php index b5ca18628a..3c0701ea42 100644 --- a/src/command/defaults/TimingsCommand.php +++ b/src/command/defaults/TimingsCommand.php @@ -35,6 +35,7 @@ use pocketmine\utils\InternetException; use pocketmine\utils\InternetRequestResult; use pocketmine\utils\Utils; +use pocketmine\YmlServerProperties; use Symfony\Component\Filesystem\Path; use function count; use function fclose; @@ -130,7 +131,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args ]; fclose($fileTimings); - $host = $sender->getServer()->getConfigGroup()->getPropertyString("timings.host", "timings.pmmp.io"); + $host = $sender->getServer()->getConfigGroup()->getPropertyString(YmlServerProperties::TIMINGS_HOST, "timings.pmmp.io"); $sender->getServer()->getAsyncPool()->submitTask(new BulkCurlTask( [new BulkCurlTaskOperation( diff --git a/src/command/defaults/WhitelistCommand.php b/src/command/defaults/WhitelistCommand.php index 65860aefae..fdf01ff562 100644 --- a/src/command/defaults/WhitelistCommand.php +++ b/src/command/defaults/WhitelistCommand.php @@ -30,6 +30,7 @@ use pocketmine\permission\DefaultPermissionNames; use pocketmine\player\Player; use pocketmine\Server; +use pocketmine\ServerProperties; use function count; use function implode; use function sort; @@ -71,7 +72,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args case "on": if($this->testPermission($sender, DefaultPermissionNames::COMMAND_WHITELIST_ENABLE)){ $server = $sender->getServer(); - $server->getConfigGroup()->setConfigBool("white-list", true); + $server->getConfigGroup()->setConfigBool(ServerProperties::WHITELIST, true); $this->kickNonWhitelistedPlayers($server); Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_whitelist_enabled()); } @@ -79,7 +80,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args return true; case "off": if($this->testPermission($sender, DefaultPermissionNames::COMMAND_WHITELIST_DISABLE)){ - $sender->getServer()->getConfigGroup()->setConfigBool("white-list", false); + $sender->getServer()->getConfigGroup()->setConfigBool(ServerProperties::WHITELIST, false); Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_whitelist_disabled()); } diff --git a/src/crafting/CraftingManager.php b/src/crafting/CraftingManager.php index 74bc2ba102..c7c0b10c64 100644 --- a/src/crafting/CraftingManager.php +++ b/src/crafting/CraftingManager.php @@ -29,6 +29,7 @@ use pocketmine\utils\BinaryStream; use pocketmine\utils\DestructorCallbackTrait; use pocketmine\utils\ObjectSet; +use function spl_object_id; use function usort; class CraftingManager{ @@ -80,8 +81,8 @@ class CraftingManager{ public function __construct(){ $this->recipeRegisteredCallbacks = new ObjectSet(); - foreach(FurnaceType::getAll() as $furnaceType){ - $this->furnaceRecipeManagers[$furnaceType->id()] = new FurnaceRecipeManager(); + foreach(FurnaceType::cases() as $furnaceType){ + $this->furnaceRecipeManagers[spl_object_id($furnaceType)] = new FurnaceRecipeManager(); } $recipeRegisteredCallbacks = $this->recipeRegisteredCallbacks; @@ -177,7 +178,7 @@ public function getCraftingRecipeFromIndex(int $index) : ?CraftingRecipe{ } public function getFurnaceRecipeManager(FurnaceType $furnaceType) : FurnaceRecipeManager{ - return $this->furnaceRecipeManagers[$furnaceType->id()]; + return $this->furnaceRecipeManagers[spl_object_id($furnaceType)]; } /** diff --git a/src/crafting/CraftingManagerFromDataHelper.php b/src/crafting/CraftingManagerFromDataHelper.php index ae0bfdab6c..3924e5ef63 100644 --- a/src/crafting/CraftingManagerFromDataHelper.php +++ b/src/crafting/CraftingManagerFromDataHelper.php @@ -211,10 +211,10 @@ public static function make(string $directoryPath) : CraftingManager{ foreach(self::loadJsonArrayOfObjectsFile(Path::join($directoryPath, 'shapeless_crafting.json'), ShapelessRecipeData::class) as $recipe){ $recipeType = match($recipe->block){ - "crafting_table" => ShapelessRecipeType::CRAFTING(), - "stonecutter" => ShapelessRecipeType::STONECUTTER(), - "smithing_table" => ShapelessRecipeType::SMITHING(), - "cartography_table" => ShapelessRecipeType::CARTOGRAPHY(), + "crafting_table" => ShapelessRecipeType::CRAFTING, + "stonecutter" => ShapelessRecipeType::STONECUTTER, + "smithing_table" => ShapelessRecipeType::SMITHING, + "cartography_table" => ShapelessRecipeType::CARTOGRAPHY, default => null }; if($recipeType === null){ @@ -270,9 +270,9 @@ public static function make(string $directoryPath) : CraftingManager{ } foreach(self::loadJsonArrayOfObjectsFile(Path::join($directoryPath, 'smelting.json'), FurnaceRecipeData::class) as $recipe){ $furnaceType = match ($recipe->block){ - "furnace" => FurnaceType::FURNACE(), - "blast_furnace" => FurnaceType::BLAST_FURNACE(), - "smoker" => FurnaceType::SMOKER(), + "furnace" => FurnaceType::FURNACE, + "blast_furnace" => FurnaceType::BLAST_FURNACE, + "smoker" => FurnaceType::SMOKER, //TODO: campfire default => null }; diff --git a/src/crafting/FurnaceType.php b/src/crafting/FurnaceType.php index 649ff4484d..0ce5b72cea 100644 --- a/src/crafting/FurnaceType.php +++ b/src/crafting/FurnaceType.php @@ -23,40 +23,45 @@ namespace pocketmine\crafting; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; use pocketmine\world\sound\BlastFurnaceSound; use pocketmine\world\sound\FurnaceSound; use pocketmine\world\sound\SmokerSound; use pocketmine\world\sound\Sound; +use function spl_object_id; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static FurnaceType BLAST_FURNACE() * @method static FurnaceType FURNACE() * @method static FurnaceType SMOKER() + * + * @phpstan-type TMetadata array{0: int, 1: Sound} */ -final class FurnaceType{ - use EnumTrait { - __construct as Enum___construct; - } +enum FurnaceType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("furnace", 200, new FurnaceSound()), - new self("blast_furnace", 100, new BlastFurnaceSound()), - new self("smoker", 100, new SmokerSound()), - ); - } + case FURNACE; + case BLAST_FURNACE; + case SMOKER; + + /** + * @phpstan-return TMetadata + */ + private function getMetadata() : array{ + /** @phpstan-var array $cache */ + static $cache = []; - private function __construct(string $enumName, private int $cookDurationTicks, private Sound $cookSound){ - $this->Enum___construct($enumName); + return $cache[spl_object_id($this)] ??= match($this){ + self::FURNACE => [200, new FurnaceSound()], + self::BLAST_FURNACE => [100, new BlastFurnaceSound()], + self::SMOKER => [100, new SmokerSound()], + }; } - public function getCookDurationTicks() : int{ return $this->cookDurationTicks; } + public function getCookDurationTicks() : int{ return $this->getMetadata()[0]; } - public function getCookSound() : Sound{ return $this->cookSound; } + public function getCookSound() : Sound{ return $this->getMetadata()[1]; } } diff --git a/src/crafting/ShapelessRecipeType.php b/src/crafting/ShapelessRecipeType.php index b115c22f49..4f4624a4bf 100644 --- a/src/crafting/ShapelessRecipeType.php +++ b/src/crafting/ShapelessRecipeType.php @@ -23,28 +23,22 @@ namespace pocketmine\crafting; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static ShapelessRecipeType CARTOGRAPHY() * @method static ShapelessRecipeType CRAFTING() * @method static ShapelessRecipeType SMITHING() * @method static ShapelessRecipeType STONECUTTER() */ -final class ShapelessRecipeType{ - use EnumTrait; +enum ShapelessRecipeType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("crafting"), - new self("stonecutter"), - new self("smithing"), - new self("cartography") - ); - } + case CRAFTING; + case STONECUTTER; + case SMITHING; + case CARTOGRAPHY; } diff --git a/src/crash/CrashDump.php b/src/crash/CrashDump.php index 40af53fd02..1a558b499d 100644 --- a/src/crash/CrashDump.php +++ b/src/crash/CrashDump.php @@ -34,6 +34,7 @@ use pocketmine\utils\Filesystem; use pocketmine\utils\Utils; use pocketmine\VersionInfo; +use pocketmine\YmlServerProperties; use Symfony\Component\Filesystem\Path; use function array_map; use function base64_encode; @@ -142,7 +143,7 @@ private function pluginsData() : void{ depends: $d->getDepend(), softDepends: $d->getSoftDepend(), main: $d->getMain(), - load: mb_strtoupper($d->getOrder()->name()), + load: mb_strtoupper($d->getOrder()->name), website: $d->getWebsite() ); } @@ -152,7 +153,7 @@ private function pluginsData() : void{ private function extraData() : void{ global $argv; - if($this->server->getConfigGroup()->getPropertyBool("auto-report.send-settings", true)){ + if($this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_REPORT_SEND_SETTINGS, true)){ $this->data->parameters = (array) $argv; if(($serverDotProperties = @file_get_contents(Path::join($this->server->getDataPath(), "server.properties"))) !== false){ $this->data->serverDotProperties = preg_replace("#^rcon\\.password=(.*)$#m", "rcon.password=******", $serverDotProperties) ?? throw new AssumptionFailedError("Pattern is valid"); @@ -170,7 +171,7 @@ private function extraData() : void{ $this->data->jit_mode = Utils::getOpcacheJitMode(); - if($this->server->getConfigGroup()->getPropertyBool("auto-report.send-phpinfo", true)){ + if($this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_REPORT_SEND_PHPINFO, true)){ ob_start(); phpinfo(); $this->data->phpinfo = ob_get_contents(); // @phpstan-ignore-line @@ -199,12 +200,14 @@ private function baseCrash() : void{ if(($pos = strpos($error["message"], "\n")) !== false){ $error["message"] = substr($error["message"], 0, $pos); } + $error["thread"] = "Main"; } $error["message"] = mb_scrub($error["message"], 'UTF-8'); if(isset($lastError)){ $this->data->lastError = $lastError; $this->data->lastError["message"] = mb_scrub($this->data->lastError["message"], 'UTF-8'); + $this->data->lastError["trace"] = array_map(array: $lastError["trace"], callback: fn(ThreadCrashInfoFrame $frame) => $frame->getPrintableFrame()); } $this->data->error = $error; @@ -224,7 +227,7 @@ private function baseCrash() : void{ } } - if($this->server->getConfigGroup()->getPropertyBool("auto-report.send-code", true) && file_exists($error["fullFile"])){ + if($this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_REPORT_SEND_CODE, true) && file_exists($error["fullFile"])){ $file = @file($error["fullFile"], FILE_IGNORE_NEW_LINES); if($file !== false){ for($l = max(0, $error["line"] - 10); $l < $error["line"] + 10 && isset($file[$l]); ++$l){ diff --git a/src/data/bedrock/BannerPatternTypeIdMap.php b/src/data/bedrock/BannerPatternTypeIdMap.php index 293f8ec387..064844e199 100644 --- a/src/data/bedrock/BannerPatternTypeIdMap.php +++ b/src/data/bedrock/BannerPatternTypeIdMap.php @@ -26,6 +26,7 @@ use pocketmine\block\utils\BannerPatternType; use pocketmine\utils\SingletonTrait; use function array_key_exists; +use function spl_object_id; final class BannerPatternTypeIdMap{ use SingletonTrait; @@ -42,49 +43,49 @@ final class BannerPatternTypeIdMap{ private array $enumToId = []; public function __construct(){ - $this->register("bo", BannerPatternType::BORDER()); - $this->register("bri", BannerPatternType::BRICKS()); - $this->register("mc", BannerPatternType::CIRCLE()); - $this->register("cre", BannerPatternType::CREEPER()); - $this->register("cr", BannerPatternType::CROSS()); - $this->register("cbo", BannerPatternType::CURLY_BORDER()); - $this->register("lud", BannerPatternType::DIAGONAL_LEFT()); - $this->register("rd", BannerPatternType::DIAGONAL_RIGHT()); - $this->register("ld", BannerPatternType::DIAGONAL_UP_LEFT()); - $this->register("rud", BannerPatternType::DIAGONAL_UP_RIGHT()); - $this->register("flo", BannerPatternType::FLOWER()); - $this->register("gra", BannerPatternType::GRADIENT()); - $this->register("gru", BannerPatternType::GRADIENT_UP()); - $this->register("hh", BannerPatternType::HALF_HORIZONTAL()); - $this->register("hhb", BannerPatternType::HALF_HORIZONTAL_BOTTOM()); - $this->register("vh", BannerPatternType::HALF_VERTICAL()); - $this->register("vhr", BannerPatternType::HALF_VERTICAL_RIGHT()); - $this->register("moj", BannerPatternType::MOJANG()); - $this->register("mr", BannerPatternType::RHOMBUS()); - $this->register("sku", BannerPatternType::SKULL()); - $this->register("ss", BannerPatternType::SMALL_STRIPES()); - $this->register("bl", BannerPatternType::SQUARE_BOTTOM_LEFT()); - $this->register("br", BannerPatternType::SQUARE_BOTTOM_RIGHT()); - $this->register("tl", BannerPatternType::SQUARE_TOP_LEFT()); - $this->register("tr", BannerPatternType::SQUARE_TOP_RIGHT()); - $this->register("sc", BannerPatternType::STRAIGHT_CROSS()); - $this->register("bs", BannerPatternType::STRIPE_BOTTOM()); - $this->register("cs", BannerPatternType::STRIPE_CENTER()); - $this->register("dls", BannerPatternType::STRIPE_DOWNLEFT()); - $this->register("drs", BannerPatternType::STRIPE_DOWNRIGHT()); - $this->register("ls", BannerPatternType::STRIPE_LEFT()); - $this->register("ms", BannerPatternType::STRIPE_MIDDLE()); - $this->register("rs", BannerPatternType::STRIPE_RIGHT()); - $this->register("ts", BannerPatternType::STRIPE_TOP()); - $this->register("bt", BannerPatternType::TRIANGLE_BOTTOM()); - $this->register("tt", BannerPatternType::TRIANGLE_TOP()); - $this->register("bts", BannerPatternType::TRIANGLES_BOTTOM()); - $this->register("tts", BannerPatternType::TRIANGLES_TOP()); + $this->register("bo", BannerPatternType::BORDER); + $this->register("bri", BannerPatternType::BRICKS); + $this->register("mc", BannerPatternType::CIRCLE); + $this->register("cre", BannerPatternType::CREEPER); + $this->register("cr", BannerPatternType::CROSS); + $this->register("cbo", BannerPatternType::CURLY_BORDER); + $this->register("lud", BannerPatternType::DIAGONAL_LEFT); + $this->register("rd", BannerPatternType::DIAGONAL_RIGHT); + $this->register("ld", BannerPatternType::DIAGONAL_UP_LEFT); + $this->register("rud", BannerPatternType::DIAGONAL_UP_RIGHT); + $this->register("flo", BannerPatternType::FLOWER); + $this->register("gra", BannerPatternType::GRADIENT); + $this->register("gru", BannerPatternType::GRADIENT_UP); + $this->register("hh", BannerPatternType::HALF_HORIZONTAL); + $this->register("hhb", BannerPatternType::HALF_HORIZONTAL_BOTTOM); + $this->register("vh", BannerPatternType::HALF_VERTICAL); + $this->register("vhr", BannerPatternType::HALF_VERTICAL_RIGHT); + $this->register("moj", BannerPatternType::MOJANG); + $this->register("mr", BannerPatternType::RHOMBUS); + $this->register("sku", BannerPatternType::SKULL); + $this->register("ss", BannerPatternType::SMALL_STRIPES); + $this->register("bl", BannerPatternType::SQUARE_BOTTOM_LEFT); + $this->register("br", BannerPatternType::SQUARE_BOTTOM_RIGHT); + $this->register("tl", BannerPatternType::SQUARE_TOP_LEFT); + $this->register("tr", BannerPatternType::SQUARE_TOP_RIGHT); + $this->register("sc", BannerPatternType::STRAIGHT_CROSS); + $this->register("bs", BannerPatternType::STRIPE_BOTTOM); + $this->register("cs", BannerPatternType::STRIPE_CENTER); + $this->register("dls", BannerPatternType::STRIPE_DOWNLEFT); + $this->register("drs", BannerPatternType::STRIPE_DOWNRIGHT); + $this->register("ls", BannerPatternType::STRIPE_LEFT); + $this->register("ms", BannerPatternType::STRIPE_MIDDLE); + $this->register("rs", BannerPatternType::STRIPE_RIGHT); + $this->register("ts", BannerPatternType::STRIPE_TOP); + $this->register("bt", BannerPatternType::TRIANGLE_BOTTOM); + $this->register("tt", BannerPatternType::TRIANGLE_TOP); + $this->register("bts", BannerPatternType::TRIANGLES_BOTTOM); + $this->register("tts", BannerPatternType::TRIANGLES_TOP); } public function register(string $stringId, BannerPatternType $type) : void{ $this->idToEnum[$stringId] = $type; - $this->enumToId[$type->id()] = $stringId; + $this->enumToId[spl_object_id($type)] = $stringId; } public function fromId(string $id) : ?BannerPatternType{ @@ -92,9 +93,10 @@ public function fromId(string $id) : ?BannerPatternType{ } public function toId(BannerPatternType $type) : string{ - if(!array_key_exists($type->id(), $this->enumToId)){ - throw new \InvalidArgumentException("Missing mapping for banner pattern type " . $type->name()); + $k = spl_object_id($type); + if(!array_key_exists($k, $this->enumToId)){ + throw new \InvalidArgumentException("Missing mapping for banner pattern type " . $type->name); } - return $this->enumToId[$type->id()]; + return $this->enumToId[$k]; } } diff --git a/src/data/bedrock/DyeColorIdMap.php b/src/data/bedrock/DyeColorIdMap.php index 35db72c3e7..a360e4f910 100644 --- a/src/data/bedrock/DyeColorIdMap.php +++ b/src/data/bedrock/DyeColorIdMap.php @@ -26,21 +26,14 @@ use pocketmine\block\utils\DyeColor; use pocketmine\data\bedrock\item\ItemTypeNames; use pocketmine\utils\SingletonTrait; +use function spl_object_id; final class DyeColorIdMap{ use SingletonTrait; - - /** - * @var DyeColor[] - * @phpstan-var array - */ - private array $idToEnum = []; - - /** - * @var int[] - * @phpstan-var array - */ - private array $enumToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait { + register as registerInt; + } /** * @var DyeColor[] @@ -55,33 +48,28 @@ final class DyeColorIdMap{ private array $enumToItemId = []; private function __construct(){ - $this->register(0, ItemTypeNames::WHITE_DYE, DyeColor::WHITE()); - $this->register(1, ItemTypeNames::ORANGE_DYE, DyeColor::ORANGE()); - $this->register(2, ItemTypeNames::MAGENTA_DYE, DyeColor::MAGENTA()); - $this->register(3, ItemTypeNames::LIGHT_BLUE_DYE, DyeColor::LIGHT_BLUE()); - $this->register(4, ItemTypeNames::YELLOW_DYE, DyeColor::YELLOW()); - $this->register(5, ItemTypeNames::LIME_DYE, DyeColor::LIME()); - $this->register(6, ItemTypeNames::PINK_DYE, DyeColor::PINK()); - $this->register(7, ItemTypeNames::GRAY_DYE, DyeColor::GRAY()); - $this->register(8, ItemTypeNames::LIGHT_GRAY_DYE, DyeColor::LIGHT_GRAY()); - $this->register(9, ItemTypeNames::CYAN_DYE, DyeColor::CYAN()); - $this->register(10, ItemTypeNames::PURPLE_DYE, DyeColor::PURPLE()); - $this->register(11, ItemTypeNames::BLUE_DYE, DyeColor::BLUE()); - $this->register(12, ItemTypeNames::BROWN_DYE, DyeColor::BROWN()); - $this->register(13, ItemTypeNames::GREEN_DYE, DyeColor::GREEN()); - $this->register(14, ItemTypeNames::RED_DYE, DyeColor::RED()); - $this->register(15, ItemTypeNames::BLACK_DYE, DyeColor::BLACK()); + $this->register(0, ItemTypeNames::WHITE_DYE, DyeColor::WHITE); + $this->register(1, ItemTypeNames::ORANGE_DYE, DyeColor::ORANGE); + $this->register(2, ItemTypeNames::MAGENTA_DYE, DyeColor::MAGENTA); + $this->register(3, ItemTypeNames::LIGHT_BLUE_DYE, DyeColor::LIGHT_BLUE); + $this->register(4, ItemTypeNames::YELLOW_DYE, DyeColor::YELLOW); + $this->register(5, ItemTypeNames::LIME_DYE, DyeColor::LIME); + $this->register(6, ItemTypeNames::PINK_DYE, DyeColor::PINK); + $this->register(7, ItemTypeNames::GRAY_DYE, DyeColor::GRAY); + $this->register(8, ItemTypeNames::LIGHT_GRAY_DYE, DyeColor::LIGHT_GRAY); + $this->register(9, ItemTypeNames::CYAN_DYE, DyeColor::CYAN); + $this->register(10, ItemTypeNames::PURPLE_DYE, DyeColor::PURPLE); + $this->register(11, ItemTypeNames::BLUE_DYE, DyeColor::BLUE); + $this->register(12, ItemTypeNames::BROWN_DYE, DyeColor::BROWN); + $this->register(13, ItemTypeNames::GREEN_DYE, DyeColor::GREEN); + $this->register(14, ItemTypeNames::RED_DYE, DyeColor::RED); + $this->register(15, ItemTypeNames::BLACK_DYE, DyeColor::BLACK); } private function register(int $id, string $itemId, DyeColor $color) : void{ - $this->idToEnum[$id] = $color; - $this->enumToId[$color->id()] = $id; + $this->registerInt($id, $color); $this->itemIdToEnum[$itemId] = $color; - $this->enumToItemId[$color->id()] = $itemId; - } - - public function toId(DyeColor $color) : int{ - return $this->enumToId[$color->id()]; //TODO: is it possible for this to be missing? + $this->enumToItemId[spl_object_id($color)] = $itemId; } public function toInvertedId(DyeColor $color) : int{ @@ -89,11 +77,7 @@ public function toInvertedId(DyeColor $color) : int{ } public function toItemId(DyeColor $color) : string{ - return $this->enumToItemId[$color->id()]; - } - - public function fromId(int $id) : ?DyeColor{ - return $this->idToEnum[$id] ?? null; + return $this->enumToItemId[spl_object_id($color)]; } public function fromInvertedId(int $id) : ?DyeColor{ diff --git a/src/data/bedrock/EffectIdMap.php b/src/data/bedrock/EffectIdMap.php index 6dce86d9b9..cadd8c397c 100644 --- a/src/data/bedrock/EffectIdMap.php +++ b/src/data/bedrock/EffectIdMap.php @@ -26,23 +26,11 @@ use pocketmine\entity\effect\Effect; use pocketmine\entity\effect\VanillaEffects; use pocketmine\utils\SingletonTrait; -use function array_key_exists; -use function spl_object_id; final class EffectIdMap{ use SingletonTrait; - - /** - * @var Effect[] - * @phpstan-var array - */ - private array $idToEffect = []; - - /** - * @var int[] - * @phpstan-var array - */ - private array $effectToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait; private function __construct(){ $this->register(EffectIds::SPEED, VanillaEffects::SPEED()); @@ -76,24 +64,4 @@ private function __construct(){ //TODO: VILLAGE_HERO $this->register(EffectIds::DARKNESS, VanillaEffects::DARKNESS()); } - - //TODO: not a big fan of the code duplication here :( - - public function register(int $mcpeId, Effect $effect) : void{ - $this->idToEffect[$mcpeId] = $effect; - $this->effectToId[spl_object_id($effect)] = $mcpeId; - } - - public function fromId(int $id) : ?Effect{ - //we might not have all the effect IDs registered - return $this->idToEffect[$id] ?? null; - } - - public function toId(Effect $effect) : int{ - if(!array_key_exists(spl_object_id($effect), $this->effectToId)){ - //this should never happen, so we treat it as an exceptional condition - throw new \InvalidArgumentException("Effect does not have a mapped ID"); - } - return $this->effectToId[spl_object_id($effect)]; - } } diff --git a/src/data/bedrock/EnchantmentIdMap.php b/src/data/bedrock/EnchantmentIdMap.php index 1d974ed6e9..ae2460cfeb 100644 --- a/src/data/bedrock/EnchantmentIdMap.php +++ b/src/data/bedrock/EnchantmentIdMap.php @@ -26,25 +26,14 @@ use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\utils\SingletonTrait; -use function array_key_exists; -use function spl_object_id; /** * Handles translation of internal enchantment types to and from Minecraft: Bedrock IDs. */ final class EnchantmentIdMap{ use SingletonTrait; - - /** - * @var Enchantment[] - * @phpstan-var array - */ - private array $idToEnch = []; - /** - * @var int[] - * @phpstan-var array - */ - private array $enchToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait; private function __construct(){ $this->register(EnchantmentIds::PROTECTION, VanillaEnchantments::PROTECTION()); @@ -77,22 +66,4 @@ private function __construct(){ $this->register(EnchantmentIds::SWIFT_SNEAK, VanillaEnchantments::SWIFT_SNEAK()); } - - public function register(int $mcpeId, Enchantment $enchantment) : void{ - $this->idToEnch[$mcpeId] = $enchantment; - $this->enchToId[spl_object_id($enchantment)] = $mcpeId; - } - - public function fromId(int $id) : ?Enchantment{ - //we might not have all the enchantment IDs registered - return $this->idToEnch[$id] ?? null; - } - - public function toId(Enchantment $enchantment) : int{ - if(!array_key_exists(spl_object_id($enchantment), $this->enchToId)){ - //this should never happen, so we treat it as an exceptional condition - throw new \InvalidArgumentException("Enchantment does not have a mapped ID"); - } - return $this->enchToId[spl_object_id($enchantment)]; - } } diff --git a/src/data/bedrock/IntSaveIdMapTrait.php b/src/data/bedrock/IntSaveIdMapTrait.php new file mode 100644 index 0000000000..cf1631fd5f --- /dev/null +++ b/src/data/bedrock/IntSaveIdMapTrait.php @@ -0,0 +1,81 @@ + + */ + private array $idToEnum = []; + + /** + * @var int[] + * @phpstan-var array + */ + private array $enumToId = []; + + /** + * @phpstan-param TObject $enum + */ + protected function getRuntimeId(object $enum) : int{ + //this is fine for enums and non-cloning object registries + return spl_object_id($enum); + } + + /** + * @phpstan-param TObject $enum + */ + public function register(int $saveId, object $enum) : void{ + $this->idToEnum[$saveId] = $enum; + $this->enumToId[$this->getRuntimeId($enum)] = $saveId; + } + + /** + * @phpstan-return TObject|null + */ + public function fromId(int $id) : ?object{ + //we might not have all the effect IDs registered + return $this->idToEnum[$id] ?? null; + } + + /** + * @phpstan-param TObject $enum + */ + public function toId(object $enum) : int{ + $runtimeId = $this->getRuntimeId($enum); + if(!array_key_exists($runtimeId, $this->enumToId)){ + //this should never happen, so we treat it as an exceptional condition + throw new \InvalidArgumentException("Object does not have a mapped save ID"); + } + return $this->enumToId[$runtimeId]; + } +} diff --git a/src/data/bedrock/MedicineTypeIdMap.php b/src/data/bedrock/MedicineTypeIdMap.php index a85dbb7a8e..00d1f27a86 100644 --- a/src/data/bedrock/MedicineTypeIdMap.php +++ b/src/data/bedrock/MedicineTypeIdMap.php @@ -28,39 +28,13 @@ final class MedicineTypeIdMap{ use SingletonTrait; - - /** - * @var MedicineType[] - * @phpstan-var array - */ - private array $idToEnum = []; - - /** - * @var int[] - * @phpstan-var array - */ - private array $enumToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait; private function __construct(){ - $this->register(MedicineTypeIds::ANTIDOTE, MedicineType::ANTIDOTE()); - $this->register(MedicineTypeIds::ELIXIR, MedicineType::ELIXIR()); - $this->register(MedicineTypeIds::EYE_DROPS, MedicineType::EYE_DROPS()); - $this->register(MedicineTypeIds::TONIC, MedicineType::TONIC()); - } - - private function register(int $id, MedicineType $type) : void{ - $this->idToEnum[$id] = $type; - $this->enumToId[$type->id()] = $id; - } - - public function fromId(int $id) : ?MedicineType{ - return $this->idToEnum[$id] ?? null; - } - - public function toId(MedicineType $type) : int{ - if(!isset($this->enumToId[$type->id()])){ - throw new \InvalidArgumentException("Type does not have a mapped ID"); - } - return $this->enumToId[$type->id()]; + $this->register(MedicineTypeIds::ANTIDOTE, MedicineType::ANTIDOTE); + $this->register(MedicineTypeIds::ELIXIR, MedicineType::ELIXIR); + $this->register(MedicineTypeIds::EYE_DROPS, MedicineType::EYE_DROPS); + $this->register(MedicineTypeIds::TONIC, MedicineType::TONIC); } } diff --git a/src/data/bedrock/MobHeadTypeIdMap.php b/src/data/bedrock/MobHeadTypeIdMap.php index 99213fa46c..ec678b1924 100644 --- a/src/data/bedrock/MobHeadTypeIdMap.php +++ b/src/data/bedrock/MobHeadTypeIdMap.php @@ -28,42 +28,16 @@ final class MobHeadTypeIdMap{ use SingletonTrait; - - /** - * @var MobHeadType[] - * @phpstan-var array - */ - private array $idToEnum = []; - - /** - * @var int[] - * @phpstan-var array - */ - private array $enumToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait; private function __construct(){ - $this->register(0, MobHeadType::SKELETON()); - $this->register(1, MobHeadType::WITHER_SKELETON()); - $this->register(2, MobHeadType::ZOMBIE()); - $this->register(3, MobHeadType::PLAYER()); - $this->register(4, MobHeadType::CREEPER()); - $this->register(5, MobHeadType::DRAGON()); - $this->register(6, MobHeadType::PIGLIN()); - } - - private function register(int $id, MobHeadType $type) : void{ - $this->idToEnum[$id] = $type; - $this->enumToId[$type->id()] = $id; - } - - public function fromId(int $id) : ?MobHeadType{ - return $this->idToEnum[$id] ?? null; - } - - public function toId(MobHeadType $type) : int{ - if(!isset($this->enumToId[$type->id()])){ - throw new \InvalidArgumentException("Type does not have a mapped ID"); - } - return $this->enumToId[$type->id()]; + $this->register(0, MobHeadType::SKELETON); + $this->register(1, MobHeadType::WITHER_SKELETON); + $this->register(2, MobHeadType::ZOMBIE); + $this->register(3, MobHeadType::PLAYER); + $this->register(4, MobHeadType::CREEPER); + $this->register(5, MobHeadType::DRAGON); + $this->register(6, MobHeadType::PIGLIN); } } diff --git a/src/data/bedrock/MushroomBlockTypeIdMap.php b/src/data/bedrock/MushroomBlockTypeIdMap.php index 2eec175499..92edef4b23 100644 --- a/src/data/bedrock/MushroomBlockTypeIdMap.php +++ b/src/data/bedrock/MushroomBlockTypeIdMap.php @@ -26,49 +26,23 @@ use pocketmine\block\utils\MushroomBlockType; use pocketmine\data\bedrock\block\BlockLegacyMetadata as LegacyMeta; use pocketmine\utils\SingletonTrait; -use function array_key_exists; final class MushroomBlockTypeIdMap{ use SingletonTrait; - - /** - * @var MushroomBlockType[] - * @phpstan-var array - */ - private array $idToEnum = []; - /** - * @var int[] - * @phpstan-var array - */ - private array $enumToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait; public function __construct(){ - $this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_PORES, MushroomBlockType::PORES()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER, MushroomBlockType::CAP_NORTHWEST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE, MushroomBlockType::CAP_NORTH()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER, MushroomBlockType::CAP_NORTHEAST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE, MushroomBlockType::CAP_WEST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY, MushroomBlockType::CAP_MIDDLE()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE, MushroomBlockType::CAP_EAST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER, MushroomBlockType::CAP_SOUTHWEST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTH_SIDE, MushroomBlockType::CAP_SOUTH()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHEAST_CORNER, MushroomBlockType::CAP_SOUTHEAST()); - $this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_CAP, MushroomBlockType::ALL_CAP()); - } - - public function register(int $id, MushroomBlockType $type) : void{ - $this->idToEnum[$id] = $type; - $this->enumToId[$type->id()] = $id; - } - - public function fromId(int $id) : ?MushroomBlockType{ - return $this->idToEnum[$id] ?? null; - } - - public function toId(MushroomBlockType $type) : int{ - if(!array_key_exists($type->id(), $this->enumToId)){ - throw new \InvalidArgumentException("Mushroom block type does not have a mapped ID"); //this should never happen - } - return $this->enumToId[$type->id()]; + $this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_PORES, MushroomBlockType::PORES); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER, MushroomBlockType::CAP_NORTHWEST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE, MushroomBlockType::CAP_NORTH); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER, MushroomBlockType::CAP_NORTHEAST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE, MushroomBlockType::CAP_WEST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY, MushroomBlockType::CAP_MIDDLE); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE, MushroomBlockType::CAP_EAST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER, MushroomBlockType::CAP_SOUTHWEST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTH_SIDE, MushroomBlockType::CAP_SOUTH); + $this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHEAST_CORNER, MushroomBlockType::CAP_SOUTHEAST); + $this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_CAP, MushroomBlockType::ALL_CAP); } } diff --git a/src/data/bedrock/NoteInstrumentIdMap.php b/src/data/bedrock/NoteInstrumentIdMap.php index 0b8a437357..e721b881d2 100644 --- a/src/data/bedrock/NoteInstrumentIdMap.php +++ b/src/data/bedrock/NoteInstrumentIdMap.php @@ -28,51 +28,25 @@ final class NoteInstrumentIdMap{ use SingletonTrait; - - /** - * @var NoteInstrument[] - * @phpstan-var array - */ - private array $idToEnum = []; - - /** - * @var int[] - * @phpstan-var array - */ - private array $enumToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait; private function __construct(){ - $this->register(0, NoteInstrument::PIANO()); - $this->register(1, NoteInstrument::BASS_DRUM()); - $this->register(2, NoteInstrument::SNARE()); - $this->register(3, NoteInstrument::CLICKS_AND_STICKS()); - $this->register(4, NoteInstrument::DOUBLE_BASS()); - $this->register(5, NoteInstrument::BELL()); - $this->register(6, NoteInstrument::FLUTE()); - $this->register(7, NoteInstrument::CHIME()); - $this->register(8, NoteInstrument::GUITAR()); - $this->register(9, NoteInstrument::XYLOPHONE()); - $this->register(10, NoteInstrument::IRON_XYLOPHONE()); - $this->register(11, NoteInstrument::COW_BELL()); - $this->register(12, NoteInstrument::DIDGERIDOO()); - $this->register(13, NoteInstrument::BIT()); - $this->register(14, NoteInstrument::BANJO()); - $this->register(15, NoteInstrument::PLING()); - } - - private function register(int $id, NoteInstrument $instrument) : void{ - $this->idToEnum[$id] = $instrument; - $this->enumToId[$instrument->id()] = $id; - } - - public function fromId(int $id) : ?NoteInstrument{ - return $this->idToEnum[$id] ?? null; - } - - public function toId(NoteInstrument $instrument) : int{ - if(!isset($this->enumToId[$instrument->id()])){ - throw new \InvalidArgumentException("Type does not have a mapped ID"); - } - return $this->enumToId[$instrument->id()]; + $this->register(0, NoteInstrument::PIANO); + $this->register(1, NoteInstrument::BASS_DRUM); + $this->register(2, NoteInstrument::SNARE); + $this->register(3, NoteInstrument::CLICKS_AND_STICKS); + $this->register(4, NoteInstrument::DOUBLE_BASS); + $this->register(5, NoteInstrument::BELL); + $this->register(6, NoteInstrument::FLUTE); + $this->register(7, NoteInstrument::CHIME); + $this->register(8, NoteInstrument::GUITAR); + $this->register(9, NoteInstrument::XYLOPHONE); + $this->register(10, NoteInstrument::IRON_XYLOPHONE); + $this->register(11, NoteInstrument::COW_BELL); + $this->register(12, NoteInstrument::DIDGERIDOO); + $this->register(13, NoteInstrument::BIT); + $this->register(14, NoteInstrument::BANJO); + $this->register(15, NoteInstrument::PLING); } } diff --git a/src/data/bedrock/PotionTypeIdMap.php b/src/data/bedrock/PotionTypeIdMap.php index 8194f24a26..3fef20f68c 100644 --- a/src/data/bedrock/PotionTypeIdMap.php +++ b/src/data/bedrock/PotionTypeIdMap.php @@ -28,78 +28,52 @@ final class PotionTypeIdMap{ use SingletonTrait; - - /** - * @var PotionType[] - * @phpstan-var array - */ - private array $idToEnum = []; - - /** - * @var int[] - * @phpstan-var array - */ - private array $enumToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait; private function __construct(){ - $this->register(PotionTypeIds::WATER, PotionType::WATER()); - $this->register(PotionTypeIds::MUNDANE, PotionType::MUNDANE()); - $this->register(PotionTypeIds::LONG_MUNDANE, PotionType::LONG_MUNDANE()); - $this->register(PotionTypeIds::THICK, PotionType::THICK()); - $this->register(PotionTypeIds::AWKWARD, PotionType::AWKWARD()); - $this->register(PotionTypeIds::NIGHT_VISION, PotionType::NIGHT_VISION()); - $this->register(PotionTypeIds::LONG_NIGHT_VISION, PotionType::LONG_NIGHT_VISION()); - $this->register(PotionTypeIds::INVISIBILITY, PotionType::INVISIBILITY()); - $this->register(PotionTypeIds::LONG_INVISIBILITY, PotionType::LONG_INVISIBILITY()); - $this->register(PotionTypeIds::LEAPING, PotionType::LEAPING()); - $this->register(PotionTypeIds::LONG_LEAPING, PotionType::LONG_LEAPING()); - $this->register(PotionTypeIds::STRONG_LEAPING, PotionType::STRONG_LEAPING()); - $this->register(PotionTypeIds::FIRE_RESISTANCE, PotionType::FIRE_RESISTANCE()); - $this->register(PotionTypeIds::LONG_FIRE_RESISTANCE, PotionType::LONG_FIRE_RESISTANCE()); - $this->register(PotionTypeIds::SWIFTNESS, PotionType::SWIFTNESS()); - $this->register(PotionTypeIds::LONG_SWIFTNESS, PotionType::LONG_SWIFTNESS()); - $this->register(PotionTypeIds::STRONG_SWIFTNESS, PotionType::STRONG_SWIFTNESS()); - $this->register(PotionTypeIds::SLOWNESS, PotionType::SLOWNESS()); - $this->register(PotionTypeIds::LONG_SLOWNESS, PotionType::LONG_SLOWNESS()); - $this->register(PotionTypeIds::WATER_BREATHING, PotionType::WATER_BREATHING()); - $this->register(PotionTypeIds::LONG_WATER_BREATHING, PotionType::LONG_WATER_BREATHING()); - $this->register(PotionTypeIds::HEALING, PotionType::HEALING()); - $this->register(PotionTypeIds::STRONG_HEALING, PotionType::STRONG_HEALING()); - $this->register(PotionTypeIds::HARMING, PotionType::HARMING()); - $this->register(PotionTypeIds::STRONG_HARMING, PotionType::STRONG_HARMING()); - $this->register(PotionTypeIds::POISON, PotionType::POISON()); - $this->register(PotionTypeIds::LONG_POISON, PotionType::LONG_POISON()); - $this->register(PotionTypeIds::STRONG_POISON, PotionType::STRONG_POISON()); - $this->register(PotionTypeIds::REGENERATION, PotionType::REGENERATION()); - $this->register(PotionTypeIds::LONG_REGENERATION, PotionType::LONG_REGENERATION()); - $this->register(PotionTypeIds::STRONG_REGENERATION, PotionType::STRONG_REGENERATION()); - $this->register(PotionTypeIds::STRENGTH, PotionType::STRENGTH()); - $this->register(PotionTypeIds::LONG_STRENGTH, PotionType::LONG_STRENGTH()); - $this->register(PotionTypeIds::STRONG_STRENGTH, PotionType::STRONG_STRENGTH()); - $this->register(PotionTypeIds::WEAKNESS, PotionType::WEAKNESS()); - $this->register(PotionTypeIds::LONG_WEAKNESS, PotionType::LONG_WEAKNESS()); - $this->register(PotionTypeIds::WITHER, PotionType::WITHER()); - $this->register(PotionTypeIds::TURTLE_MASTER, PotionType::TURTLE_MASTER()); - $this->register(PotionTypeIds::LONG_TURTLE_MASTER, PotionType::LONG_TURTLE_MASTER()); - $this->register(PotionTypeIds::STRONG_TURTLE_MASTER, PotionType::STRONG_TURTLE_MASTER()); - $this->register(PotionTypeIds::SLOW_FALLING, PotionType::SLOW_FALLING()); - $this->register(PotionTypeIds::LONG_SLOW_FALLING, PotionType::LONG_SLOW_FALLING()); - $this->register(PotionTypeIds::STRONG_SLOWNESS, PotionType::STRONG_SLOWNESS()); - } - - private function register(int $id, PotionType $type) : void{ - $this->idToEnum[$id] = $type; - $this->enumToId[$type->id()] = $id; - } - - public function fromId(int $id) : ?PotionType{ - return $this->idToEnum[$id] ?? null; - } - - public function toId(PotionType $type) : int{ - if(!isset($this->enumToId[$type->id()])){ - throw new \InvalidArgumentException("Type does not have a mapped ID"); - } - return $this->enumToId[$type->id()]; + $this->register(PotionTypeIds::WATER, PotionType::WATER); + $this->register(PotionTypeIds::MUNDANE, PotionType::MUNDANE); + $this->register(PotionTypeIds::LONG_MUNDANE, PotionType::LONG_MUNDANE); + $this->register(PotionTypeIds::THICK, PotionType::THICK); + $this->register(PotionTypeIds::AWKWARD, PotionType::AWKWARD); + $this->register(PotionTypeIds::NIGHT_VISION, PotionType::NIGHT_VISION); + $this->register(PotionTypeIds::LONG_NIGHT_VISION, PotionType::LONG_NIGHT_VISION); + $this->register(PotionTypeIds::INVISIBILITY, PotionType::INVISIBILITY); + $this->register(PotionTypeIds::LONG_INVISIBILITY, PotionType::LONG_INVISIBILITY); + $this->register(PotionTypeIds::LEAPING, PotionType::LEAPING); + $this->register(PotionTypeIds::LONG_LEAPING, PotionType::LONG_LEAPING); + $this->register(PotionTypeIds::STRONG_LEAPING, PotionType::STRONG_LEAPING); + $this->register(PotionTypeIds::FIRE_RESISTANCE, PotionType::FIRE_RESISTANCE); + $this->register(PotionTypeIds::LONG_FIRE_RESISTANCE, PotionType::LONG_FIRE_RESISTANCE); + $this->register(PotionTypeIds::SWIFTNESS, PotionType::SWIFTNESS); + $this->register(PotionTypeIds::LONG_SWIFTNESS, PotionType::LONG_SWIFTNESS); + $this->register(PotionTypeIds::STRONG_SWIFTNESS, PotionType::STRONG_SWIFTNESS); + $this->register(PotionTypeIds::SLOWNESS, PotionType::SLOWNESS); + $this->register(PotionTypeIds::LONG_SLOWNESS, PotionType::LONG_SLOWNESS); + $this->register(PotionTypeIds::WATER_BREATHING, PotionType::WATER_BREATHING); + $this->register(PotionTypeIds::LONG_WATER_BREATHING, PotionType::LONG_WATER_BREATHING); + $this->register(PotionTypeIds::HEALING, PotionType::HEALING); + $this->register(PotionTypeIds::STRONG_HEALING, PotionType::STRONG_HEALING); + $this->register(PotionTypeIds::HARMING, PotionType::HARMING); + $this->register(PotionTypeIds::STRONG_HARMING, PotionType::STRONG_HARMING); + $this->register(PotionTypeIds::POISON, PotionType::POISON); + $this->register(PotionTypeIds::LONG_POISON, PotionType::LONG_POISON); + $this->register(PotionTypeIds::STRONG_POISON, PotionType::STRONG_POISON); + $this->register(PotionTypeIds::REGENERATION, PotionType::REGENERATION); + $this->register(PotionTypeIds::LONG_REGENERATION, PotionType::LONG_REGENERATION); + $this->register(PotionTypeIds::STRONG_REGENERATION, PotionType::STRONG_REGENERATION); + $this->register(PotionTypeIds::STRENGTH, PotionType::STRENGTH); + $this->register(PotionTypeIds::LONG_STRENGTH, PotionType::LONG_STRENGTH); + $this->register(PotionTypeIds::STRONG_STRENGTH, PotionType::STRONG_STRENGTH); + $this->register(PotionTypeIds::WEAKNESS, PotionType::WEAKNESS); + $this->register(PotionTypeIds::LONG_WEAKNESS, PotionType::LONG_WEAKNESS); + $this->register(PotionTypeIds::WITHER, PotionType::WITHER); + $this->register(PotionTypeIds::TURTLE_MASTER, PotionType::TURTLE_MASTER); + $this->register(PotionTypeIds::LONG_TURTLE_MASTER, PotionType::LONG_TURTLE_MASTER); + $this->register(PotionTypeIds::STRONG_TURTLE_MASTER, PotionType::STRONG_TURTLE_MASTER); + $this->register(PotionTypeIds::SLOW_FALLING, PotionType::SLOW_FALLING); + $this->register(PotionTypeIds::LONG_SLOW_FALLING, PotionType::LONG_SLOW_FALLING); + $this->register(PotionTypeIds::STRONG_SLOWNESS, PotionType::STRONG_SLOWNESS); } } diff --git a/src/data/bedrock/SuspiciousStewTypeIdMap.php b/src/data/bedrock/SuspiciousStewTypeIdMap.php index 1dc86abf19..c4de4b742d 100644 --- a/src/data/bedrock/SuspiciousStewTypeIdMap.php +++ b/src/data/bedrock/SuspiciousStewTypeIdMap.php @@ -28,45 +28,19 @@ final class SuspiciousStewTypeIdMap{ use SingletonTrait; - - /** - * @var SuspiciousStewType[] - * @phpstan-var array - */ - private array $idToEnum = []; - - /** - * @var int[] - * @phpstan-var array - */ - private array $enumToId = []; + /** @phpstan-use IntSaveIdMapTrait */ + use IntSaveIdMapTrait; private function __construct(){ - $this->register(SuspiciousStewTypeIds::POPPY, SuspiciousStewType::POPPY()); - $this->register(SuspiciousStewTypeIds::CORNFLOWER, SuspiciousStewType::CORNFLOWER()); - $this->register(SuspiciousStewTypeIds::TULIP, SuspiciousStewType::TULIP()); - $this->register(SuspiciousStewTypeIds::AZURE_BLUET, SuspiciousStewType::AZURE_BLUET()); - $this->register(SuspiciousStewTypeIds::LILY_OF_THE_VALLEY, SuspiciousStewType::LILY_OF_THE_VALLEY()); - $this->register(SuspiciousStewTypeIds::DANDELION, SuspiciousStewType::DANDELION()); - $this->register(SuspiciousStewTypeIds::BLUE_ORCHID, SuspiciousStewType::BLUE_ORCHID()); - $this->register(SuspiciousStewTypeIds::ALLIUM, SuspiciousStewType::ALLIUM()); - $this->register(SuspiciousStewTypeIds::OXEYE_DAISY, SuspiciousStewType::OXEYE_DAISY()); - $this->register(SuspiciousStewTypeIds::WITHER_ROSE, SuspiciousStewType::WITHER_ROSE()); - } - - private function register(int $id, SuspiciousStewType $type) : void{ - $this->idToEnum[$id] = $type; - $this->enumToId[$type->id()] = $id; - } - - public function fromId(int $id) : ?SuspiciousStewType{ - return $this->idToEnum[$id] ?? null; - } - - public function toId(SuspiciousStewType $type) : int{ - if(!isset($this->enumToId[$type->id()])){ - throw new \InvalidArgumentException("Type does not have a mapped ID"); - } - return $this->enumToId[$type->id()]; + $this->register(SuspiciousStewTypeIds::POPPY, SuspiciousStewType::POPPY); + $this->register(SuspiciousStewTypeIds::CORNFLOWER, SuspiciousStewType::CORNFLOWER); + $this->register(SuspiciousStewTypeIds::TULIP, SuspiciousStewType::TULIP); + $this->register(SuspiciousStewTypeIds::AZURE_BLUET, SuspiciousStewType::AZURE_BLUET); + $this->register(SuspiciousStewTypeIds::LILY_OF_THE_VALLEY, SuspiciousStewType::LILY_OF_THE_VALLEY); + $this->register(SuspiciousStewTypeIds::DANDELION, SuspiciousStewType::DANDELION); + $this->register(SuspiciousStewTypeIds::BLUE_ORCHID, SuspiciousStewType::BLUE_ORCHID); + $this->register(SuspiciousStewTypeIds::ALLIUM, SuspiciousStewType::ALLIUM); + $this->register(SuspiciousStewTypeIds::OXEYE_DAISY, SuspiciousStewType::OXEYE_DAISY); + $this->register(SuspiciousStewTypeIds::WITHER_ROSE, SuspiciousStewType::WITHER_ROSE); } } diff --git a/src/data/bedrock/block/BlockStateData.php b/src/data/bedrock/block/BlockStateData.php index f7b7612509..c5712cf6c7 100644 --- a/src/data/bedrock/block/BlockStateData.php +++ b/src/data/bedrock/block/BlockStateData.php @@ -42,8 +42,8 @@ final class BlockStateData{ public const CURRENT_VERSION = (1 << 24) | //major (20 << 16) | //minor - (10 << 8) | //patch - (32); //revision + (30 << 8) | //patch + (50); //revision public const TAG_NAME = "name"; public const TAG_STATES = "states"; diff --git a/src/data/bedrock/block/BlockStateNames.php b/src/data/bedrock/block/BlockStateNames.php index f38ba78e99..0e1b29e272 100644 --- a/src/data/bedrock/block/BlockStateNames.php +++ b/src/data/bedrock/block/BlockStateNames.php @@ -98,8 +98,10 @@ private function __construct(){ public const LEVER_DIRECTION = "lever_direction"; public const LIQUID_DEPTH = "liquid_depth"; public const LIT = "lit"; + public const MC_BLOCK_FACE = "minecraft:block_face"; public const MC_CARDINAL_DIRECTION = "minecraft:cardinal_direction"; public const MC_FACING_DIRECTION = "minecraft:facing_direction"; + public const MC_VERTICAL_HALF = "minecraft:vertical_half"; public const MOISTURIZED_AMOUNT = "moisturized_amount"; public const MONSTER_EGG_STONE_TYPE = "monster_egg_stone_type"; public const MULTI_FACE_DIRECTION_BITS = "multi_face_direction_bits"; @@ -141,7 +143,6 @@ private function __construct(){ public const SUSPENDED_BIT = "suspended_bit"; public const TALL_GRASS_TYPE = "tall_grass_type"; public const TOGGLE_BIT = "toggle_bit"; - public const TOP_SLOT_BIT = "top_slot_bit"; public const TORCH_FACING_DIRECTION = "torch_facing_direction"; public const TRIGGERED_BIT = "triggered_bit"; public const TURTLE_EGG_COUNT = "turtle_egg_count"; diff --git a/src/data/bedrock/block/BlockStateStringValues.php b/src/data/bedrock/block/BlockStateStringValues.php index 5834b2df49..712ff70797 100644 --- a/src/data/bedrock/block/BlockStateStringValues.php +++ b/src/data/bedrock/block/BlockStateStringValues.php @@ -131,6 +131,13 @@ private function __construct(){ public const LEVER_DIRECTION_UP_NORTH_SOUTH = "up_north_south"; public const LEVER_DIRECTION_WEST = "west"; + public const MC_BLOCK_FACE_DOWN = "down"; + public const MC_BLOCK_FACE_EAST = "east"; + public const MC_BLOCK_FACE_NORTH = "north"; + public const MC_BLOCK_FACE_SOUTH = "south"; + public const MC_BLOCK_FACE_UP = "up"; + public const MC_BLOCK_FACE_WEST = "west"; + public const MC_CARDINAL_DIRECTION_EAST = "east"; public const MC_CARDINAL_DIRECTION_NORTH = "north"; public const MC_CARDINAL_DIRECTION_SOUTH = "south"; @@ -143,6 +150,9 @@ private function __construct(){ public const MC_FACING_DIRECTION_UP = "up"; public const MC_FACING_DIRECTION_WEST = "west"; + public const MC_VERTICAL_HALF_BOTTOM = "bottom"; + public const MC_VERTICAL_HALF_TOP = "top"; + public const MONSTER_EGG_STONE_TYPE_CHISELED_STONE_BRICK = "chiseled_stone_brick"; public const MONSTER_EGG_STONE_TYPE_COBBLESTONE = "cobblestone"; public const MONSTER_EGG_STONE_TYPE_CRACKED_STONE_BRICK = "cracked_stone_brick"; diff --git a/src/data/bedrock/block/BlockTypeNames.php b/src/data/bedrock/block/BlockTypeNames.php index 48b1c29f0f..0fa1060492 100644 --- a/src/data/bedrock/block/BlockTypeNames.php +++ b/src/data/bedrock/block/BlockTypeNames.php @@ -99,8 +99,12 @@ private function __construct(){ public const BLACK_CANDLE_CAKE = "minecraft:black_candle_cake"; public const BLACK_CARPET = "minecraft:black_carpet"; public const BLACK_CONCRETE = "minecraft:black_concrete"; + public const BLACK_CONCRETE_POWDER = "minecraft:black_concrete_powder"; public const BLACK_GLAZED_TERRACOTTA = "minecraft:black_glazed_terracotta"; public const BLACK_SHULKER_BOX = "minecraft:black_shulker_box"; + public const BLACK_STAINED_GLASS = "minecraft:black_stained_glass"; + public const BLACK_STAINED_GLASS_PANE = "minecraft:black_stained_glass_pane"; + public const BLACK_TERRACOTTA = "minecraft:black_terracotta"; public const BLACK_WOOL = "minecraft:black_wool"; public const BLACKSTONE = "minecraft:blackstone"; public const BLACKSTONE_DOUBLE_SLAB = "minecraft:blackstone_double_slab"; @@ -112,9 +116,13 @@ private function __construct(){ public const BLUE_CANDLE_CAKE = "minecraft:blue_candle_cake"; public const BLUE_CARPET = "minecraft:blue_carpet"; public const BLUE_CONCRETE = "minecraft:blue_concrete"; + public const BLUE_CONCRETE_POWDER = "minecraft:blue_concrete_powder"; public const BLUE_GLAZED_TERRACOTTA = "minecraft:blue_glazed_terracotta"; public const BLUE_ICE = "minecraft:blue_ice"; public const BLUE_SHULKER_BOX = "minecraft:blue_shulker_box"; + public const BLUE_STAINED_GLASS = "minecraft:blue_stained_glass"; + public const BLUE_STAINED_GLASS_PANE = "minecraft:blue_stained_glass_pane"; + public const BLUE_TERRACOTTA = "minecraft:blue_terracotta"; public const BLUE_WOOL = "minecraft:blue_wool"; public const BONE_BLOCK = "minecraft:bone_block"; public const BOOKSHELF = "minecraft:bookshelf"; @@ -127,10 +135,14 @@ private function __construct(){ public const BROWN_CANDLE_CAKE = "minecraft:brown_candle_cake"; public const BROWN_CARPET = "minecraft:brown_carpet"; public const BROWN_CONCRETE = "minecraft:brown_concrete"; + public const BROWN_CONCRETE_POWDER = "minecraft:brown_concrete_powder"; public const BROWN_GLAZED_TERRACOTTA = "minecraft:brown_glazed_terracotta"; public const BROWN_MUSHROOM = "minecraft:brown_mushroom"; public const BROWN_MUSHROOM_BLOCK = "minecraft:brown_mushroom_block"; public const BROWN_SHULKER_BOX = "minecraft:brown_shulker_box"; + public const BROWN_STAINED_GLASS = "minecraft:brown_stained_glass"; + public const BROWN_STAINED_GLASS_PANE = "minecraft:brown_stained_glass_pane"; + public const BROWN_TERRACOTTA = "minecraft:brown_terracotta"; public const BROWN_WOOL = "minecraft:brown_wool"; public const BUBBLE_COLUMN = "minecraft:bubble_column"; public const BUBBLE_CORAL = "minecraft:bubble_coral"; @@ -194,7 +206,6 @@ private function __construct(){ public const COLORED_TORCH_RG = "minecraft:colored_torch_rg"; public const COMMAND_BLOCK = "minecraft:command_block"; public const COMPOSTER = "minecraft:composter"; - public const CONCRETE_POWDER = "minecraft:concrete_powder"; public const CONDUIT = "minecraft:conduit"; public const COPPER_BLOCK = "minecraft:copper_block"; public const COPPER_ORE = "minecraft:copper_ore"; @@ -235,8 +246,12 @@ private function __construct(){ public const CYAN_CANDLE_CAKE = "minecraft:cyan_candle_cake"; public const CYAN_CARPET = "minecraft:cyan_carpet"; public const CYAN_CONCRETE = "minecraft:cyan_concrete"; + public const CYAN_CONCRETE_POWDER = "minecraft:cyan_concrete_powder"; public const CYAN_GLAZED_TERRACOTTA = "minecraft:cyan_glazed_terracotta"; public const CYAN_SHULKER_BOX = "minecraft:cyan_shulker_box"; + public const CYAN_STAINED_GLASS = "minecraft:cyan_stained_glass"; + public const CYAN_STAINED_GLASS_PANE = "minecraft:cyan_stained_glass_pane"; + public const CYAN_TERRACOTTA = "minecraft:cyan_terracotta"; public const CYAN_WOOL = "minecraft:cyan_wool"; public const DARK_OAK_BUTTON = "minecraft:dark_oak_button"; public const DARK_OAK_DOOR = "minecraft:dark_oak_door"; @@ -463,15 +478,23 @@ private function __construct(){ public const GRAY_CANDLE_CAKE = "minecraft:gray_candle_cake"; public const GRAY_CARPET = "minecraft:gray_carpet"; public const GRAY_CONCRETE = "minecraft:gray_concrete"; + public const GRAY_CONCRETE_POWDER = "minecraft:gray_concrete_powder"; public const GRAY_GLAZED_TERRACOTTA = "minecraft:gray_glazed_terracotta"; public const GRAY_SHULKER_BOX = "minecraft:gray_shulker_box"; + public const GRAY_STAINED_GLASS = "minecraft:gray_stained_glass"; + public const GRAY_STAINED_GLASS_PANE = "minecraft:gray_stained_glass_pane"; + public const GRAY_TERRACOTTA = "minecraft:gray_terracotta"; public const GRAY_WOOL = "minecraft:gray_wool"; public const GREEN_CANDLE = "minecraft:green_candle"; public const GREEN_CANDLE_CAKE = "minecraft:green_candle_cake"; public const GREEN_CARPET = "minecraft:green_carpet"; public const GREEN_CONCRETE = "minecraft:green_concrete"; + public const GREEN_CONCRETE_POWDER = "minecraft:green_concrete_powder"; public const GREEN_GLAZED_TERRACOTTA = "minecraft:green_glazed_terracotta"; public const GREEN_SHULKER_BOX = "minecraft:green_shulker_box"; + public const GREEN_STAINED_GLASS = "minecraft:green_stained_glass"; + public const GREEN_STAINED_GLASS_PANE = "minecraft:green_stained_glass_pane"; + public const GREEN_TERRACOTTA = "minecraft:green_terracotta"; public const GREEN_WOOL = "minecraft:green_wool"; public const GRINDSTONE = "minecraft:grindstone"; public const HANGING_ROOTS = "minecraft:hanging_roots"; @@ -525,14 +548,22 @@ private function __construct(){ public const LIGHT_BLUE_CANDLE_CAKE = "minecraft:light_blue_candle_cake"; public const LIGHT_BLUE_CARPET = "minecraft:light_blue_carpet"; public const LIGHT_BLUE_CONCRETE = "minecraft:light_blue_concrete"; + public const LIGHT_BLUE_CONCRETE_POWDER = "minecraft:light_blue_concrete_powder"; public const LIGHT_BLUE_GLAZED_TERRACOTTA = "minecraft:light_blue_glazed_terracotta"; public const LIGHT_BLUE_SHULKER_BOX = "minecraft:light_blue_shulker_box"; + public const LIGHT_BLUE_STAINED_GLASS = "minecraft:light_blue_stained_glass"; + public const LIGHT_BLUE_STAINED_GLASS_PANE = "minecraft:light_blue_stained_glass_pane"; + public const LIGHT_BLUE_TERRACOTTA = "minecraft:light_blue_terracotta"; public const LIGHT_BLUE_WOOL = "minecraft:light_blue_wool"; public const LIGHT_GRAY_CANDLE = "minecraft:light_gray_candle"; public const LIGHT_GRAY_CANDLE_CAKE = "minecraft:light_gray_candle_cake"; public const LIGHT_GRAY_CARPET = "minecraft:light_gray_carpet"; public const LIGHT_GRAY_CONCRETE = "minecraft:light_gray_concrete"; + public const LIGHT_GRAY_CONCRETE_POWDER = "minecraft:light_gray_concrete_powder"; public const LIGHT_GRAY_SHULKER_BOX = "minecraft:light_gray_shulker_box"; + public const LIGHT_GRAY_STAINED_GLASS = "minecraft:light_gray_stained_glass"; + public const LIGHT_GRAY_STAINED_GLASS_PANE = "minecraft:light_gray_stained_glass_pane"; + public const LIGHT_GRAY_TERRACOTTA = "minecraft:light_gray_terracotta"; public const LIGHT_GRAY_WOOL = "minecraft:light_gray_wool"; public const LIGHT_WEIGHTED_PRESSURE_PLATE = "minecraft:light_weighted_pressure_plate"; public const LIGHTNING_ROD = "minecraft:lightning_rod"; @@ -540,8 +571,12 @@ private function __construct(){ public const LIME_CANDLE_CAKE = "minecraft:lime_candle_cake"; public const LIME_CARPET = "minecraft:lime_carpet"; public const LIME_CONCRETE = "minecraft:lime_concrete"; + public const LIME_CONCRETE_POWDER = "minecraft:lime_concrete_powder"; public const LIME_GLAZED_TERRACOTTA = "minecraft:lime_glazed_terracotta"; public const LIME_SHULKER_BOX = "minecraft:lime_shulker_box"; + public const LIME_STAINED_GLASS = "minecraft:lime_stained_glass"; + public const LIME_STAINED_GLASS_PANE = "minecraft:lime_stained_glass_pane"; + public const LIME_TERRACOTTA = "minecraft:lime_terracotta"; public const LIME_WOOL = "minecraft:lime_wool"; public const LIT_BLAST_FURNACE = "minecraft:lit_blast_furnace"; public const LIT_DEEPSLATE_REDSTONE_ORE = "minecraft:lit_deepslate_redstone_ore"; @@ -556,8 +591,12 @@ private function __construct(){ public const MAGENTA_CANDLE_CAKE = "minecraft:magenta_candle_cake"; public const MAGENTA_CARPET = "minecraft:magenta_carpet"; public const MAGENTA_CONCRETE = "minecraft:magenta_concrete"; + public const MAGENTA_CONCRETE_POWDER = "minecraft:magenta_concrete_powder"; public const MAGENTA_GLAZED_TERRACOTTA = "minecraft:magenta_glazed_terracotta"; public const MAGENTA_SHULKER_BOX = "minecraft:magenta_shulker_box"; + public const MAGENTA_STAINED_GLASS = "minecraft:magenta_stained_glass"; + public const MAGENTA_STAINED_GLASS_PANE = "minecraft:magenta_stained_glass_pane"; + public const MAGENTA_TERRACOTTA = "minecraft:magenta_terracotta"; public const MAGENTA_WOOL = "minecraft:magenta_wool"; public const MAGMA = "minecraft:magma"; public const MANGROVE_BUTTON = "minecraft:mangrove_button"; @@ -620,8 +659,12 @@ private function __construct(){ public const ORANGE_CANDLE_CAKE = "minecraft:orange_candle_cake"; public const ORANGE_CARPET = "minecraft:orange_carpet"; public const ORANGE_CONCRETE = "minecraft:orange_concrete"; + public const ORANGE_CONCRETE_POWDER = "minecraft:orange_concrete_powder"; public const ORANGE_GLAZED_TERRACOTTA = "minecraft:orange_glazed_terracotta"; public const ORANGE_SHULKER_BOX = "minecraft:orange_shulker_box"; + public const ORANGE_STAINED_GLASS = "minecraft:orange_stained_glass"; + public const ORANGE_STAINED_GLASS_PANE = "minecraft:orange_stained_glass_pane"; + public const ORANGE_TERRACOTTA = "minecraft:orange_terracotta"; public const ORANGE_WOOL = "minecraft:orange_wool"; public const OXIDIZED_COPPER = "minecraft:oxidized_copper"; public const OXIDIZED_CUT_COPPER = "minecraft:oxidized_cut_copper"; @@ -635,9 +678,13 @@ private function __construct(){ public const PINK_CANDLE_CAKE = "minecraft:pink_candle_cake"; public const PINK_CARPET = "minecraft:pink_carpet"; public const PINK_CONCRETE = "minecraft:pink_concrete"; + public const PINK_CONCRETE_POWDER = "minecraft:pink_concrete_powder"; public const PINK_GLAZED_TERRACOTTA = "minecraft:pink_glazed_terracotta"; public const PINK_PETALS = "minecraft:pink_petals"; public const PINK_SHULKER_BOX = "minecraft:pink_shulker_box"; + public const PINK_STAINED_GLASS = "minecraft:pink_stained_glass"; + public const PINK_STAINED_GLASS_PANE = "minecraft:pink_stained_glass_pane"; + public const PINK_TERRACOTTA = "minecraft:pink_terracotta"; public const PINK_WOOL = "minecraft:pink_wool"; public const PISTON = "minecraft:piston"; public const PISTON_ARM_COLLISION = "minecraft:piston_arm_collision"; @@ -681,8 +728,12 @@ private function __construct(){ public const PURPLE_CANDLE_CAKE = "minecraft:purple_candle_cake"; public const PURPLE_CARPET = "minecraft:purple_carpet"; public const PURPLE_CONCRETE = "minecraft:purple_concrete"; + public const PURPLE_CONCRETE_POWDER = "minecraft:purple_concrete_powder"; public const PURPLE_GLAZED_TERRACOTTA = "minecraft:purple_glazed_terracotta"; public const PURPLE_SHULKER_BOX = "minecraft:purple_shulker_box"; + public const PURPLE_STAINED_GLASS = "minecraft:purple_stained_glass"; + public const PURPLE_STAINED_GLASS_PANE = "minecraft:purple_stained_glass_pane"; + public const PURPLE_TERRACOTTA = "minecraft:purple_terracotta"; public const PURPLE_WOOL = "minecraft:purple_wool"; public const PURPUR_BLOCK = "minecraft:purpur_block"; public const PURPUR_STAIRS = "minecraft:purpur_stairs"; @@ -698,6 +749,7 @@ private function __construct(){ public const RED_CANDLE_CAKE = "minecraft:red_candle_cake"; public const RED_CARPET = "minecraft:red_carpet"; public const RED_CONCRETE = "minecraft:red_concrete"; + public const RED_CONCRETE_POWDER = "minecraft:red_concrete_powder"; public const RED_FLOWER = "minecraft:red_flower"; public const RED_GLAZED_TERRACOTTA = "minecraft:red_glazed_terracotta"; public const RED_MUSHROOM = "minecraft:red_mushroom"; @@ -707,6 +759,9 @@ private function __construct(){ public const RED_SANDSTONE = "minecraft:red_sandstone"; public const RED_SANDSTONE_STAIRS = "minecraft:red_sandstone_stairs"; public const RED_SHULKER_BOX = "minecraft:red_shulker_box"; + public const RED_STAINED_GLASS = "minecraft:red_stained_glass"; + public const RED_STAINED_GLASS_PANE = "minecraft:red_stained_glass_pane"; + public const RED_TERRACOTTA = "minecraft:red_terracotta"; public const RED_WOOL = "minecraft:red_wool"; public const REDSTONE_BLOCK = "minecraft:redstone_block"; public const REDSTONE_LAMP = "minecraft:redstone_lamp"; @@ -766,9 +821,6 @@ private function __construct(){ public const SPRUCE_STANDING_SIGN = "minecraft:spruce_standing_sign"; public const SPRUCE_TRAPDOOR = "minecraft:spruce_trapdoor"; public const SPRUCE_WALL_SIGN = "minecraft:spruce_wall_sign"; - public const STAINED_GLASS = "minecraft:stained_glass"; - public const STAINED_GLASS_PANE = "minecraft:stained_glass_pane"; - public const STAINED_HARDENED_CLAY = "minecraft:stained_hardened_clay"; public const STANDING_BANNER = "minecraft:standing_banner"; public const STANDING_SIGN = "minecraft:standing_sign"; public const STICKY_PISTON = "minecraft:sticky_piston"; @@ -883,8 +935,12 @@ private function __construct(){ public const WHITE_CANDLE_CAKE = "minecraft:white_candle_cake"; public const WHITE_CARPET = "minecraft:white_carpet"; public const WHITE_CONCRETE = "minecraft:white_concrete"; + public const WHITE_CONCRETE_POWDER = "minecraft:white_concrete_powder"; public const WHITE_GLAZED_TERRACOTTA = "minecraft:white_glazed_terracotta"; public const WHITE_SHULKER_BOX = "minecraft:white_shulker_box"; + public const WHITE_STAINED_GLASS = "minecraft:white_stained_glass"; + public const WHITE_STAINED_GLASS_PANE = "minecraft:white_stained_glass_pane"; + public const WHITE_TERRACOTTA = "minecraft:white_terracotta"; public const WHITE_WOOL = "minecraft:white_wool"; public const WITHER_ROSE = "minecraft:wither_rose"; public const WOOD = "minecraft:wood"; @@ -896,8 +952,12 @@ private function __construct(){ public const YELLOW_CANDLE_CAKE = "minecraft:yellow_candle_cake"; public const YELLOW_CARPET = "minecraft:yellow_carpet"; public const YELLOW_CONCRETE = "minecraft:yellow_concrete"; + public const YELLOW_CONCRETE_POWDER = "minecraft:yellow_concrete_powder"; public const YELLOW_FLOWER = "minecraft:yellow_flower"; public const YELLOW_GLAZED_TERRACOTTA = "minecraft:yellow_glazed_terracotta"; public const YELLOW_SHULKER_BOX = "minecraft:yellow_shulker_box"; + public const YELLOW_STAINED_GLASS = "minecraft:yellow_stained_glass"; + public const YELLOW_STAINED_GLASS_PANE = "minecraft:yellow_stained_glass_pane"; + public const YELLOW_TERRACOTTA = "minecraft:yellow_terracotta"; public const YELLOW_WOOL = "minecraft:yellow_wool"; } diff --git a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php index 6ffc1c55df..08753ded1d 100644 --- a/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php +++ b/src/data/bedrock/block/convert/BlockObjectToStateSerializer.php @@ -174,7 +174,6 @@ use pocketmine\data\bedrock\block\convert\BlockStateWriter as Writer; use pocketmine\math\Axis; use pocketmine\math\Facing; -use pocketmine\utils\AssumptionFailedError; use function get_class; final class BlockObjectToStateSerializer implements BlockStateSerializer{ @@ -271,161 +270,229 @@ public function serializeBlock(Block $blockState) : BlockStateData{ private function registerCandleSerializers() : void{ $this->map(Blocks::CANDLE(), fn(Candle $block) => Helper::encodeCandle($block, new Writer(Ids::CANDLE))); $this->map(Blocks::DYED_CANDLE(), fn(DyedCandle $block) => Helper::encodeCandle($block, new Writer(match($block->getColor()){ - DyeColor::BLACK() => Ids::BLACK_CANDLE, - DyeColor::BLUE() => Ids::BLUE_CANDLE, - DyeColor::BROWN() => Ids::BROWN_CANDLE, - DyeColor::CYAN() => Ids::CYAN_CANDLE, - DyeColor::GRAY() => Ids::GRAY_CANDLE, - DyeColor::GREEN() => Ids::GREEN_CANDLE, - DyeColor::LIGHT_BLUE() => Ids::LIGHT_BLUE_CANDLE, - DyeColor::LIGHT_GRAY() => Ids::LIGHT_GRAY_CANDLE, - DyeColor::LIME() => Ids::LIME_CANDLE, - DyeColor::MAGENTA() => Ids::MAGENTA_CANDLE, - DyeColor::ORANGE() => Ids::ORANGE_CANDLE, - DyeColor::PINK() => Ids::PINK_CANDLE, - DyeColor::PURPLE() => Ids::PURPLE_CANDLE, - DyeColor::RED() => Ids::RED_CANDLE, - DyeColor::WHITE() => Ids::WHITE_CANDLE, - DyeColor::YELLOW() => Ids::YELLOW_CANDLE, - default => throw new AssumptionFailedError("Unhandled DyeColor " . $block->getColor()->name()) + DyeColor::BLACK => Ids::BLACK_CANDLE, + DyeColor::BLUE => Ids::BLUE_CANDLE, + DyeColor::BROWN => Ids::BROWN_CANDLE, + DyeColor::CYAN => Ids::CYAN_CANDLE, + DyeColor::GRAY => Ids::GRAY_CANDLE, + DyeColor::GREEN => Ids::GREEN_CANDLE, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CANDLE, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CANDLE, + DyeColor::LIME => Ids::LIME_CANDLE, + DyeColor::MAGENTA => Ids::MAGENTA_CANDLE, + DyeColor::ORANGE => Ids::ORANGE_CANDLE, + DyeColor::PINK => Ids::PINK_CANDLE, + DyeColor::PURPLE => Ids::PURPLE_CANDLE, + DyeColor::RED => Ids::RED_CANDLE, + DyeColor::WHITE => Ids::WHITE_CANDLE, + DyeColor::YELLOW => Ids::YELLOW_CANDLE, }))); $this->map(Blocks::CAKE_WITH_CANDLE(), fn(CakeWithCandle $block) => Writer::create(Ids::CANDLE_CAKE) ->writeBool(StateNames::LIT, $block->isLit())); $this->map(Blocks::CAKE_WITH_DYED_CANDLE(), fn(CakeWithDyedCandle $block) => Writer::create(match($block->getColor()){ - DyeColor::BLACK() => Ids::BLACK_CANDLE_CAKE, - DyeColor::BLUE() => Ids::BLUE_CANDLE_CAKE, - DyeColor::BROWN() => Ids::BROWN_CANDLE_CAKE, - DyeColor::CYAN() => Ids::CYAN_CANDLE_CAKE, - DyeColor::GRAY() => Ids::GRAY_CANDLE_CAKE, - DyeColor::GREEN() => Ids::GREEN_CANDLE_CAKE, - DyeColor::LIGHT_BLUE() => Ids::LIGHT_BLUE_CANDLE_CAKE, - DyeColor::LIGHT_GRAY() => Ids::LIGHT_GRAY_CANDLE_CAKE, - DyeColor::LIME() => Ids::LIME_CANDLE_CAKE, - DyeColor::MAGENTA() => Ids::MAGENTA_CANDLE_CAKE, - DyeColor::ORANGE() => Ids::ORANGE_CANDLE_CAKE, - DyeColor::PINK() => Ids::PINK_CANDLE_CAKE, - DyeColor::PURPLE() => Ids::PURPLE_CANDLE_CAKE, - DyeColor::RED() => Ids::RED_CANDLE_CAKE, - DyeColor::WHITE() => Ids::WHITE_CANDLE_CAKE, - DyeColor::YELLOW() => Ids::YELLOW_CANDLE_CAKE, - default => throw new AssumptionFailedError("Unhandled DyeColor " . $block->getColor()->name()) + DyeColor::BLACK => Ids::BLACK_CANDLE_CAKE, + DyeColor::BLUE => Ids::BLUE_CANDLE_CAKE, + DyeColor::BROWN => Ids::BROWN_CANDLE_CAKE, + DyeColor::CYAN => Ids::CYAN_CANDLE_CAKE, + DyeColor::GRAY => Ids::GRAY_CANDLE_CAKE, + DyeColor::GREEN => Ids::GREEN_CANDLE_CAKE, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CANDLE_CAKE, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CANDLE_CAKE, + DyeColor::LIME => Ids::LIME_CANDLE_CAKE, + DyeColor::MAGENTA => Ids::MAGENTA_CANDLE_CAKE, + DyeColor::ORANGE => Ids::ORANGE_CANDLE_CAKE, + DyeColor::PINK => Ids::PINK_CANDLE_CAKE, + DyeColor::PURPLE => Ids::PURPLE_CANDLE_CAKE, + DyeColor::RED => Ids::RED_CANDLE_CAKE, + DyeColor::WHITE => Ids::WHITE_CANDLE_CAKE, + DyeColor::YELLOW => Ids::YELLOW_CANDLE_CAKE, })->writeBool(StateNames::LIT, $block->isLit())); } public function registerFlatColorBlockSerializers() : void{ $this->map(Blocks::GLAZED_TERRACOTTA(), function(GlazedTerracotta $block) : Writer{ - return Writer::create(match($color = $block->getColor()){ - DyeColor::BLACK() => Ids::BLACK_GLAZED_TERRACOTTA, - DyeColor::BLUE() => Ids::BLUE_GLAZED_TERRACOTTA, - DyeColor::BROWN() => Ids::BROWN_GLAZED_TERRACOTTA, - DyeColor::CYAN() => Ids::CYAN_GLAZED_TERRACOTTA, - DyeColor::GRAY() => Ids::GRAY_GLAZED_TERRACOTTA, - DyeColor::GREEN() => Ids::GREEN_GLAZED_TERRACOTTA, - DyeColor::LIGHT_BLUE() => Ids::LIGHT_BLUE_GLAZED_TERRACOTTA, - DyeColor::LIGHT_GRAY() => Ids::SILVER_GLAZED_TERRACOTTA, - DyeColor::LIME() => Ids::LIME_GLAZED_TERRACOTTA, - DyeColor::MAGENTA() => Ids::MAGENTA_GLAZED_TERRACOTTA, - DyeColor::ORANGE() => Ids::ORANGE_GLAZED_TERRACOTTA, - DyeColor::PINK() => Ids::PINK_GLAZED_TERRACOTTA, - DyeColor::PURPLE() => Ids::PURPLE_GLAZED_TERRACOTTA, - DyeColor::RED() => Ids::RED_GLAZED_TERRACOTTA, - DyeColor::WHITE() => Ids::WHITE_GLAZED_TERRACOTTA, - DyeColor::YELLOW() => Ids::YELLOW_GLAZED_TERRACOTTA, - default => throw new AssumptionFailedError("Unhandled dye colour " . $color->name()) + return Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_GLAZED_TERRACOTTA, + DyeColor::BLUE => Ids::BLUE_GLAZED_TERRACOTTA, + DyeColor::BROWN => Ids::BROWN_GLAZED_TERRACOTTA, + DyeColor::CYAN => Ids::CYAN_GLAZED_TERRACOTTA, + DyeColor::GRAY => Ids::GRAY_GLAZED_TERRACOTTA, + DyeColor::GREEN => Ids::GREEN_GLAZED_TERRACOTTA, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_GLAZED_TERRACOTTA, + DyeColor::LIGHT_GRAY => Ids::SILVER_GLAZED_TERRACOTTA, + DyeColor::LIME => Ids::LIME_GLAZED_TERRACOTTA, + DyeColor::MAGENTA => Ids::MAGENTA_GLAZED_TERRACOTTA, + DyeColor::ORANGE => Ids::ORANGE_GLAZED_TERRACOTTA, + DyeColor::PINK => Ids::PINK_GLAZED_TERRACOTTA, + DyeColor::PURPLE => Ids::PURPLE_GLAZED_TERRACOTTA, + DyeColor::RED => Ids::RED_GLAZED_TERRACOTTA, + DyeColor::WHITE => Ids::WHITE_GLAZED_TERRACOTTA, + DyeColor::YELLOW => Ids::YELLOW_GLAZED_TERRACOTTA, }) ->writeHorizontalFacing($block->getFacing()); }); - $this->map(Blocks::WOOL(), fn(Wool $block) => Writer::create(match($color = $block->getColor()){ - DyeColor::BLACK() => Ids::BLACK_WOOL, - DyeColor::BLUE() => Ids::BLUE_WOOL, - DyeColor::BROWN() => Ids::BROWN_WOOL, - DyeColor::CYAN() => Ids::CYAN_WOOL, - DyeColor::GRAY() => Ids::GRAY_WOOL, - DyeColor::GREEN() => Ids::GREEN_WOOL, - DyeColor::LIGHT_BLUE() => Ids::LIGHT_BLUE_WOOL, - DyeColor::LIGHT_GRAY() => Ids::LIGHT_GRAY_WOOL, - DyeColor::LIME() => Ids::LIME_WOOL, - DyeColor::MAGENTA() => Ids::MAGENTA_WOOL, - DyeColor::ORANGE() => Ids::ORANGE_WOOL, - DyeColor::PINK() => Ids::PINK_WOOL, - DyeColor::PURPLE() => Ids::PURPLE_WOOL, - DyeColor::RED() => Ids::RED_WOOL, - DyeColor::WHITE() => Ids::WHITE_WOOL, - DyeColor::YELLOW() => Ids::YELLOW_WOOL, - default => throw new AssumptionFailedError("Unhandled dye colour " . $color->name()) + $this->map(Blocks::WOOL(), fn(Wool $block) => Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_WOOL, + DyeColor::BLUE => Ids::BLUE_WOOL, + DyeColor::BROWN => Ids::BROWN_WOOL, + DyeColor::CYAN => Ids::CYAN_WOOL, + DyeColor::GRAY => Ids::GRAY_WOOL, + DyeColor::GREEN => Ids::GREEN_WOOL, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_WOOL, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_WOOL, + DyeColor::LIME => Ids::LIME_WOOL, + DyeColor::MAGENTA => Ids::MAGENTA_WOOL, + DyeColor::ORANGE => Ids::ORANGE_WOOL, + DyeColor::PINK => Ids::PINK_WOOL, + DyeColor::PURPLE => Ids::PURPLE_WOOL, + DyeColor::RED => Ids::RED_WOOL, + DyeColor::WHITE => Ids::WHITE_WOOL, + DyeColor::YELLOW => Ids::YELLOW_WOOL, })); - $this->map(Blocks::CARPET(), fn(Carpet $block) => Writer::create(match($color = $block->getColor()){ - DyeColor::BLACK() => Ids::BLACK_CARPET, - DyeColor::BLUE() => Ids::BLUE_CARPET, - DyeColor::BROWN() => Ids::BROWN_CARPET, - DyeColor::CYAN() => Ids::CYAN_CARPET, - DyeColor::GRAY() => Ids::GRAY_CARPET, - DyeColor::GREEN() => Ids::GREEN_CARPET, - DyeColor::LIGHT_BLUE() => Ids::LIGHT_BLUE_CARPET, - DyeColor::LIGHT_GRAY() => Ids::LIGHT_GRAY_CARPET, - DyeColor::LIME() => Ids::LIME_CARPET, - DyeColor::MAGENTA() => Ids::MAGENTA_CARPET, - DyeColor::ORANGE() => Ids::ORANGE_CARPET, - DyeColor::PINK() => Ids::PINK_CARPET, - DyeColor::PURPLE() => Ids::PURPLE_CARPET, - DyeColor::RED() => Ids::RED_CARPET, - DyeColor::WHITE() => Ids::WHITE_CARPET, - DyeColor::YELLOW() => Ids::YELLOW_CARPET, - default => throw new AssumptionFailedError("Unhandled dye colour " . $color->name()) + $this->map(Blocks::CARPET(), fn(Carpet $block) => Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_CARPET, + DyeColor::BLUE => Ids::BLUE_CARPET, + DyeColor::BROWN => Ids::BROWN_CARPET, + DyeColor::CYAN => Ids::CYAN_CARPET, + DyeColor::GRAY => Ids::GRAY_CARPET, + DyeColor::GREEN => Ids::GREEN_CARPET, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CARPET, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CARPET, + DyeColor::LIME => Ids::LIME_CARPET, + DyeColor::MAGENTA => Ids::MAGENTA_CARPET, + DyeColor::ORANGE => Ids::ORANGE_CARPET, + DyeColor::PINK => Ids::PINK_CARPET, + DyeColor::PURPLE => Ids::PURPLE_CARPET, + DyeColor::RED => Ids::RED_CARPET, + DyeColor::WHITE => Ids::WHITE_CARPET, + DyeColor::YELLOW => Ids::YELLOW_CARPET, })); - $this->map(Blocks::DYED_SHULKER_BOX(), fn(DyedShulkerBox $block) => Writer::create(match($color = $block->getColor()){ - DyeColor::BLACK() => Ids::BLACK_SHULKER_BOX, - DyeColor::BLUE() => Ids::BLUE_SHULKER_BOX, - DyeColor::BROWN() => Ids::BROWN_SHULKER_BOX, - DyeColor::CYAN() => Ids::CYAN_SHULKER_BOX, - DyeColor::GRAY() => Ids::GRAY_SHULKER_BOX, - DyeColor::GREEN() => Ids::GREEN_SHULKER_BOX, - DyeColor::LIGHT_BLUE() => Ids::LIGHT_BLUE_SHULKER_BOX, - DyeColor::LIGHT_GRAY() => Ids::LIGHT_GRAY_SHULKER_BOX, - DyeColor::LIME() => Ids::LIME_SHULKER_BOX, - DyeColor::MAGENTA() => Ids::MAGENTA_SHULKER_BOX, - DyeColor::ORANGE() => Ids::ORANGE_SHULKER_BOX, - DyeColor::PINK() => Ids::PINK_SHULKER_BOX, - DyeColor::PURPLE() => Ids::PURPLE_SHULKER_BOX, - DyeColor::RED() => Ids::RED_SHULKER_BOX, - DyeColor::WHITE() => Ids::WHITE_SHULKER_BOX, - DyeColor::YELLOW() => Ids::YELLOW_SHULKER_BOX, - default => throw new AssumptionFailedError("Unhandled dye colour " . $color->name()) + $this->map(Blocks::DYED_SHULKER_BOX(), fn(DyedShulkerBox $block) => Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_SHULKER_BOX, + DyeColor::BLUE => Ids::BLUE_SHULKER_BOX, + DyeColor::BROWN => Ids::BROWN_SHULKER_BOX, + DyeColor::CYAN => Ids::CYAN_SHULKER_BOX, + DyeColor::GRAY => Ids::GRAY_SHULKER_BOX, + DyeColor::GREEN => Ids::GREEN_SHULKER_BOX, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_SHULKER_BOX, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_SHULKER_BOX, + DyeColor::LIME => Ids::LIME_SHULKER_BOX, + DyeColor::MAGENTA => Ids::MAGENTA_SHULKER_BOX, + DyeColor::ORANGE => Ids::ORANGE_SHULKER_BOX, + DyeColor::PINK => Ids::PINK_SHULKER_BOX, + DyeColor::PURPLE => Ids::PURPLE_SHULKER_BOX, + DyeColor::RED => Ids::RED_SHULKER_BOX, + DyeColor::WHITE => Ids::WHITE_SHULKER_BOX, + DyeColor::YELLOW => Ids::YELLOW_SHULKER_BOX, })); - $this->map(Blocks::CONCRETE(), fn(Concrete $block) => Writer::create(match($color = $block->getColor()){ - DyeColor::BLACK() => Ids::BLACK_CONCRETE, - DyeColor::BLUE() => Ids::BLUE_CONCRETE, - DyeColor::BROWN() => Ids::BROWN_CONCRETE, - DyeColor::CYAN() => Ids::CYAN_CONCRETE, - DyeColor::GRAY() => Ids::GRAY_CONCRETE, - DyeColor::GREEN() => Ids::GREEN_CONCRETE, - DyeColor::LIGHT_BLUE() => Ids::LIGHT_BLUE_CONCRETE, - DyeColor::LIGHT_GRAY() => Ids::LIGHT_GRAY_CONCRETE, - DyeColor::LIME() => Ids::LIME_CONCRETE, - DyeColor::MAGENTA() => Ids::MAGENTA_CONCRETE, - DyeColor::ORANGE() => Ids::ORANGE_CONCRETE, - DyeColor::PINK() => Ids::PINK_CONCRETE, - DyeColor::PURPLE() => Ids::PURPLE_CONCRETE, - DyeColor::RED() => Ids::RED_CONCRETE, - DyeColor::WHITE() => Ids::WHITE_CONCRETE, - DyeColor::YELLOW() => Ids::YELLOW_CONCRETE, - default => throw new AssumptionFailedError("Unhandled dye colour " . $color->name()) + $this->map(Blocks::CONCRETE(), fn(Concrete $block) => Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_CONCRETE, + DyeColor::BLUE => Ids::BLUE_CONCRETE, + DyeColor::BROWN => Ids::BROWN_CONCRETE, + DyeColor::CYAN => Ids::CYAN_CONCRETE, + DyeColor::GRAY => Ids::GRAY_CONCRETE, + DyeColor::GREEN => Ids::GREEN_CONCRETE, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CONCRETE, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CONCRETE, + DyeColor::LIME => Ids::LIME_CONCRETE, + DyeColor::MAGENTA => Ids::MAGENTA_CONCRETE, + DyeColor::ORANGE => Ids::ORANGE_CONCRETE, + DyeColor::PINK => Ids::PINK_CONCRETE, + DyeColor::PURPLE => Ids::PURPLE_CONCRETE, + DyeColor::RED => Ids::RED_CONCRETE, + DyeColor::WHITE => Ids::WHITE_CONCRETE, + DyeColor::YELLOW => Ids::YELLOW_CONCRETE, + })); + + $this->map(Blocks::CONCRETE_POWDER(), fn(ConcretePowder $block) => Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_CONCRETE_POWDER, + DyeColor::BLUE => Ids::BLUE_CONCRETE_POWDER, + DyeColor::BROWN => Ids::BROWN_CONCRETE_POWDER, + DyeColor::CYAN => Ids::CYAN_CONCRETE_POWDER, + DyeColor::GRAY => Ids::GRAY_CONCRETE_POWDER, + DyeColor::GREEN => Ids::GREEN_CONCRETE_POWDER, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_CONCRETE_POWDER, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_CONCRETE_POWDER, + DyeColor::LIME => Ids::LIME_CONCRETE_POWDER, + DyeColor::MAGENTA => Ids::MAGENTA_CONCRETE_POWDER, + DyeColor::ORANGE => Ids::ORANGE_CONCRETE_POWDER, + DyeColor::PINK => Ids::PINK_CONCRETE_POWDER, + DyeColor::PURPLE => Ids::PURPLE_CONCRETE_POWDER, + DyeColor::RED => Ids::RED_CONCRETE_POWDER, + DyeColor::WHITE => Ids::WHITE_CONCRETE_POWDER, + DyeColor::YELLOW => Ids::YELLOW_CONCRETE_POWDER, + })); + + $this->map(Blocks::STAINED_CLAY(), fn(StainedHardenedClay $block) => Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_TERRACOTTA, + DyeColor::BLUE => Ids::BLUE_TERRACOTTA, + DyeColor::BROWN => Ids::BROWN_TERRACOTTA, + DyeColor::CYAN => Ids::CYAN_TERRACOTTA, + DyeColor::GRAY => Ids::GRAY_TERRACOTTA, + DyeColor::GREEN => Ids::GREEN_TERRACOTTA, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_TERRACOTTA, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_TERRACOTTA, + DyeColor::LIME => Ids::LIME_TERRACOTTA, + DyeColor::MAGENTA => Ids::MAGENTA_TERRACOTTA, + DyeColor::ORANGE => Ids::ORANGE_TERRACOTTA, + DyeColor::PINK => Ids::PINK_TERRACOTTA, + DyeColor::PURPLE => Ids::PURPLE_TERRACOTTA, + DyeColor::RED => Ids::RED_TERRACOTTA, + DyeColor::WHITE => Ids::WHITE_TERRACOTTA, + DyeColor::YELLOW => Ids::YELLOW_TERRACOTTA, + })); + + $this->map(Blocks::STAINED_GLASS(), fn(StainedGlass $block) => Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_STAINED_GLASS, + DyeColor::BLUE => Ids::BLUE_STAINED_GLASS, + DyeColor::BROWN => Ids::BROWN_STAINED_GLASS, + DyeColor::CYAN => Ids::CYAN_STAINED_GLASS, + DyeColor::GRAY => Ids::GRAY_STAINED_GLASS, + DyeColor::GREEN => Ids::GREEN_STAINED_GLASS, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_STAINED_GLASS, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_STAINED_GLASS, + DyeColor::LIME => Ids::LIME_STAINED_GLASS, + DyeColor::MAGENTA => Ids::MAGENTA_STAINED_GLASS, + DyeColor::ORANGE => Ids::ORANGE_STAINED_GLASS, + DyeColor::PINK => Ids::PINK_STAINED_GLASS, + DyeColor::PURPLE => Ids::PURPLE_STAINED_GLASS, + DyeColor::RED => Ids::RED_STAINED_GLASS, + DyeColor::WHITE => Ids::WHITE_STAINED_GLASS, + DyeColor::YELLOW => Ids::YELLOW_STAINED_GLASS, + })); + + $this->map(Blocks::STAINED_GLASS_PANE(), fn(StainedGlassPane $block) => Writer::create(match($block->getColor()){ + DyeColor::BLACK => Ids::BLACK_STAINED_GLASS_PANE, + DyeColor::BLUE => Ids::BLUE_STAINED_GLASS_PANE, + DyeColor::BROWN => Ids::BROWN_STAINED_GLASS_PANE, + DyeColor::CYAN => Ids::CYAN_STAINED_GLASS_PANE, + DyeColor::GRAY => Ids::GRAY_STAINED_GLASS_PANE, + DyeColor::GREEN => Ids::GREEN_STAINED_GLASS_PANE, + DyeColor::LIGHT_BLUE => Ids::LIGHT_BLUE_STAINED_GLASS_PANE, + DyeColor::LIGHT_GRAY => Ids::LIGHT_GRAY_STAINED_GLASS_PANE, + DyeColor::LIME => Ids::LIME_STAINED_GLASS_PANE, + DyeColor::MAGENTA => Ids::MAGENTA_STAINED_GLASS_PANE, + DyeColor::ORANGE => Ids::ORANGE_STAINED_GLASS_PANE, + DyeColor::PINK => Ids::PINK_STAINED_GLASS_PANE, + DyeColor::PURPLE => Ids::PURPLE_STAINED_GLASS_PANE, + DyeColor::RED => Ids::RED_STAINED_GLASS_PANE, + DyeColor::WHITE => Ids::WHITE_STAINED_GLASS_PANE, + DyeColor::YELLOW => Ids::YELLOW_STAINED_GLASS_PANE, })); } private function registerFlatCoralSerializers() : void{ $this->map(Blocks::CORAL(), fn(Coral $block) => Writer::create( - match($coralType = $block->getCoralType()){ - CoralType::BRAIN() => $block->isDead() ? Ids::DEAD_BRAIN_CORAL : Ids::BRAIN_CORAL, - CoralType::BUBBLE() => $block->isDead() ? Ids::DEAD_BUBBLE_CORAL : Ids::BUBBLE_CORAL, - CoralType::FIRE() => $block->isDead() ? Ids::DEAD_FIRE_CORAL : Ids::FIRE_CORAL, - CoralType::HORN() => $block->isDead() ? Ids::DEAD_HORN_CORAL : Ids::HORN_CORAL, - CoralType::TUBE() => $block->isDead() ? Ids::DEAD_TUBE_CORAL : Ids::TUBE_CORAL, - default => throw new AssumptionFailedError("Unhandled coral type " . $coralType->name()) + match($block->getCoralType()){ + CoralType::BRAIN => $block->isDead() ? Ids::DEAD_BRAIN_CORAL : Ids::BRAIN_CORAL, + CoralType::BUBBLE => $block->isDead() ? Ids::DEAD_BUBBLE_CORAL : Ids::BUBBLE_CORAL, + CoralType::FIRE => $block->isDead() ? Ids::DEAD_FIRE_CORAL : Ids::FIRE_CORAL, + CoralType::HORN => $block->isDead() ? Ids::DEAD_HORN_CORAL : Ids::HORN_CORAL, + CoralType::TUBE => $block->isDead() ? Ids::DEAD_TUBE_CORAL : Ids::TUBE_CORAL, } )); } @@ -905,7 +972,7 @@ private function registerSerializers() : void{ $this->map(Blocks::ANDESITE_WALL(), fn(Wall $block) => Helper::encodeLegacyWall($block, StringValues::WALL_BLOCK_TYPE_ANDESITE)); $this->map(Blocks::ANVIL(), function(Anvil $block) : Writer{ return Writer::create(Ids::ANVIL) - ->writeLegacyHorizontalFacing($block->getFacing()) + ->writeCardinalHorizontalFacing($block->getFacing()) ->writeString(StateNames::DAMAGE, match($damage = $block->getDamage()){ 0 => StringValues::DAMAGE_UNDAMAGED, 1 => StringValues::DAMAGE_SLIGHTLY_DAMAGED, @@ -965,19 +1032,18 @@ private function registerSerializers() : void{ }); $this->map(Blocks::BIG_DRIPLEAF_HEAD(), function(BigDripleafHead $block) : Writer{ return Writer::create(Ids::BIG_DRIPLEAF) - ->writeLegacyHorizontalFacing($block->getFacing()) - ->writeString(StateNames::BIG_DRIPLEAF_TILT, match($block->getLeafState()->id()){ - DripleafState::STABLE()->id() => StringValues::BIG_DRIPLEAF_TILT_NONE, - DripleafState::UNSTABLE()->id() => StringValues::BIG_DRIPLEAF_TILT_UNSTABLE, - DripleafState::PARTIAL_TILT()->id() => StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT, - DripleafState::FULL_TILT()->id() => StringValues::BIG_DRIPLEAF_TILT_FULL_TILT, - default => throw new BlockStateSerializeException("Invalid Dripleaf tilt type " . $block->getLeafState()->name()) + ->writeCardinalHorizontalFacing($block->getFacing()) + ->writeString(StateNames::BIG_DRIPLEAF_TILT, match($block->getLeafState()){ + DripleafState::STABLE => StringValues::BIG_DRIPLEAF_TILT_NONE, + DripleafState::UNSTABLE => StringValues::BIG_DRIPLEAF_TILT_UNSTABLE, + DripleafState::PARTIAL_TILT => StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT, + DripleafState::FULL_TILT => StringValues::BIG_DRIPLEAF_TILT_FULL_TILT, }) ->writeBool(StateNames::BIG_DRIPLEAF_HEAD, true); }); $this->map(Blocks::BIG_DRIPLEAF_STEM(), function(BigDripleafStem $block) : Writer{ return Writer::create(Ids::BIG_DRIPLEAF) - ->writeLegacyHorizontalFacing($block->getFacing()) + ->writeCardinalHorizontalFacing($block->getFacing()) ->writeString(StateNames::BIG_DRIPLEAF_TILT, StringValues::BIG_DRIPLEAF_TILT_NONE) ->writeBool(StateNames::BIG_DRIPLEAF_HEAD, false); }); @@ -995,9 +1061,9 @@ private function registerSerializers() : void{ }); $this->map(Blocks::BREWING_STAND(), function(BrewingStand $block) : Writer{ return Writer::create(Ids::BREWING_STAND) - ->writeBool(StateNames::BREWING_STAND_SLOT_A_BIT, $block->hasSlot(BrewingStandSlot::EAST())) - ->writeBool(StateNames::BREWING_STAND_SLOT_B_BIT, $block->hasSlot(BrewingStandSlot::SOUTHWEST())) - ->writeBool(StateNames::BREWING_STAND_SLOT_C_BIT, $block->hasSlot(BrewingStandSlot::NORTHWEST())); + ->writeBool(StateNames::BREWING_STAND_SLOT_A_BIT, $block->hasSlot(BrewingStandSlot::EAST)) + ->writeBool(StateNames::BREWING_STAND_SLOT_B_BIT, $block->hasSlot(BrewingStandSlot::SOUTHWEST)) + ->writeBool(StateNames::BREWING_STAND_SLOT_C_BIT, $block->hasSlot(BrewingStandSlot::NORTHWEST)); }); $this->map(Blocks::BRICK_SLAB(), fn(Slab $block) => Helper::encodeStoneSlab1($block, StringValues::STONE_SLAB_TYPE_BRICK)); $this->mapStairs(Blocks::BRICK_STAIRS(), Ids::BRICK_STAIRS); @@ -1129,10 +1195,6 @@ private function registerSerializers() : void{ ->writeLegacyHorizontalFacing(Facing::opposite($block->getFacing())); }); $this->map(Blocks::COMPOUND_CREATOR(), fn(ChemistryTable $block) => Helper::encodeChemistryTable($block, StringValues::CHEMISTRY_TABLE_TYPE_COMPOUND_CREATOR, new Writer(Ids::CHEMISTRY_TABLE))); - $this->map(Blocks::CONCRETE_POWDER(), function(ConcretePowder $block) : Writer{ - return Writer::create(Ids::CONCRETE_POWDER) - ->writeColor($block->getColor()); - }); $this->map(Blocks::CORAL_BLOCK(), function(CoralBlock $block) : Writer{ return Writer::create(Ids::CORAL_BLOCK) ->writeBool(StateNames::DEAD_BIT, $block->isDead()) @@ -1184,14 +1246,14 @@ private function registerSerializers() : void{ $this->map(Blocks::DIORITE_WALL(), fn(Wall $block) => Helper::encodeLegacyWall($block, StringValues::WALL_BLOCK_TYPE_DIORITE)); $this->map(Blocks::DIRT(), function(Dirt $block) : Writer{ $dirtType = $block->getDirtType(); - if($dirtType->equals(DirtType::ROOTED())){ + if($dirtType === DirtType::ROOTED){ return new Writer(Ids::DIRT_WITH_ROOTS); } return Writer::create(Ids::DIRT) ->writeString(StateNames::DIRT_TYPE, match($dirtType){ - DirtType::COARSE() => StringValues::DIRT_TYPE_COARSE, - DirtType::NORMAL() => StringValues::DIRT_TYPE_NORMAL, - default => throw new AssumptionFailedError("Unhandled dirt type " . $dirtType->name()) + DirtType::COARSE => StringValues::DIRT_TYPE_COARSE, + DirtType::NORMAL => StringValues::DIRT_TYPE_NORMAL, + //ROOTED was already checked above }); }); $this->map(Blocks::DOUBLE_TALLGRASS(), fn(DoubleTallGrass $block) => Helper::encodeDoublePlant($block, StringValues::DOUBLE_PLANT_TYPE_GRASS, Writer::create(Ids::DOUBLE_PLANT))); @@ -1203,7 +1265,7 @@ private function registerSerializers() : void{ $this->map(Blocks::END_PORTAL_FRAME(), function(EndPortalFrame $block) : Writer{ return Writer::create(Ids::END_PORTAL_FRAME) ->writeBool(StateNames::END_PORTAL_EYE_BIT, $block->hasEye()) - ->writeLegacyHorizontalFacing($block->getFacing()); + ->writeCardinalHorizontalFacing($block->getFacing()); }); $this->map(Blocks::END_ROD(), function(EndRod $block) : Writer{ return Writer::create(Ids::END_ROD) @@ -1229,10 +1291,9 @@ private function registerSerializers() : void{ }); $this->map(Blocks::FROGLIGHT(), function(Froglight $block){ return Writer::create(match($block->getFroglightType()){ - FroglightType::OCHRE() => Ids::OCHRE_FROGLIGHT, - FroglightType::PEARLESCENT() => Ids::PEARLESCENT_FROGLIGHT, - FroglightType::VERDANT() => Ids::VERDANT_FROGLIGHT, - default => throw new AssumptionFailedError("Unhandled froglight type " . $block->getFroglightType()->name()) + FroglightType::OCHRE => Ids::OCHRE_FROGLIGHT, + FroglightType::PEARLESCENT => Ids::PEARLESCENT_FROGLIGHT, + FroglightType::VERDANT => Ids::VERDANT_FROGLIGHT, }) ->writePillarAxis($block->getAxis()); }); @@ -1291,21 +1352,20 @@ private function registerSerializers() : void{ $this->map(Blocks::LECTERN(), function(Lectern $block) : Writer{ return Writer::create(Ids::LECTERN) ->writeBool(StateNames::POWERED_BIT, $block->isProducingSignal()) - ->writeLegacyHorizontalFacing($block->getFacing()); + ->writeCardinalHorizontalFacing($block->getFacing()); }); $this->map(Blocks::LEVER(), function(Lever $block) : Writer{ return Writer::create(Ids::LEVER) ->writeBool(StateNames::OPEN_BIT, $block->isActivated()) - ->writeString(StateNames::LEVER_DIRECTION, match($block->getFacing()->id()){ - LeverFacing::DOWN_AXIS_Z()->id() => StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH, - LeverFacing::DOWN_AXIS_X()->id() => StringValues::LEVER_DIRECTION_DOWN_EAST_WEST, - LeverFacing::UP_AXIS_Z()->id() => StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH, - LeverFacing::UP_AXIS_X()->id() => StringValues::LEVER_DIRECTION_UP_EAST_WEST, - LeverFacing::NORTH()->id() => StringValues::LEVER_DIRECTION_NORTH, - LeverFacing::SOUTH()->id() => StringValues::LEVER_DIRECTION_SOUTH, - LeverFacing::WEST()->id() => StringValues::LEVER_DIRECTION_WEST, - LeverFacing::EAST()->id() => StringValues::LEVER_DIRECTION_EAST, - default => throw new BlockStateSerializeException("Invalid Lever facing " . $block->getFacing()->name()), + ->writeString(StateNames::LEVER_DIRECTION, match($block->getFacing()){ + LeverFacing::DOWN_AXIS_Z => StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH, + LeverFacing::DOWN_AXIS_X => StringValues::LEVER_DIRECTION_DOWN_EAST_WEST, + LeverFacing::UP_AXIS_Z => StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH, + LeverFacing::UP_AXIS_X => StringValues::LEVER_DIRECTION_UP_EAST_WEST, + LeverFacing::NORTH => StringValues::LEVER_DIRECTION_NORTH, + LeverFacing::SOUTH => StringValues::LEVER_DIRECTION_SOUTH, + LeverFacing::WEST => StringValues::LEVER_DIRECTION_WEST, + LeverFacing::EAST => StringValues::LEVER_DIRECTION_EAST, }); }); $this->map(Blocks::LIGHT(), function(Light $block) : Writer{ @@ -1367,7 +1427,7 @@ private function registerSerializers() : void{ $this->map(Blocks::PEONY(), fn(DoublePlant $block) => Helper::encodeDoublePlant($block, StringValues::DOUBLE_PLANT_TYPE_PAEONIA, Writer::create(Ids::DOUBLE_PLANT))); $this->map(Blocks::PINK_PETALS(), function(PinkPetals $block) : Writer{ return Writer::create(Ids::PINK_PETALS) - ->writeLegacyHorizontalFacing($block->getFacing()) + ->writeCardinalHorizontalFacing($block->getFacing()) ->writeInt(StateNames::GROWTH, $block->getCount() - 1); }); $this->map(Blocks::PINK_TULIP(), fn() => Helper::encodeRedFlower(StringValues::FLOWER_TYPE_TULIP_PINK)); @@ -1441,13 +1501,13 @@ private function registerSerializers() : void{ return Writer::create($block->isPowered() ? Ids::POWERED_COMPARATOR : Ids::UNPOWERED_COMPARATOR) ->writeBool(StateNames::OUTPUT_LIT_BIT, $block->isPowered()) ->writeBool(StateNames::OUTPUT_SUBTRACT_BIT, $block->isSubtractMode()) - ->writeLegacyHorizontalFacing($block->getFacing()); + ->writeCardinalHorizontalFacing($block->getFacing()); }); $this->map(Blocks::REDSTONE_LAMP(), fn(RedstoneLamp $block) => new Writer($block->isPowered() ? Ids::LIT_REDSTONE_LAMP : Ids::REDSTONE_LAMP)); $this->map(Blocks::REDSTONE_ORE(), fn(RedstoneOre $block) => new Writer($block->isLit() ? Ids::LIT_REDSTONE_ORE : Ids::REDSTONE_ORE)); $this->map(Blocks::REDSTONE_REPEATER(), function(RedstoneRepeater $block) : Writer{ return Writer::create($block->isPowered() ? Ids::POWERED_REPEATER : Ids::UNPOWERED_REPEATER) - ->writeLegacyHorizontalFacing($block->getFacing()) + ->writeCardinalHorizontalFacing($block->getFacing()) ->writeInt(StateNames::REPEATER_DELAY, $block->getDelay() - 1); }); $this->map(Blocks::REDSTONE_TORCH(), function(RedstoneTorch $block) : Writer{ @@ -1484,7 +1544,7 @@ private function registerSerializers() : void{ }); $this->map(Blocks::SMALL_DRIPLEAF(), function(SmallDripleaf $block) : Writer{ return Writer::create(Ids::SMALL_DRIPLEAF_BLOCK) - ->writeLegacyHorizontalFacing($block->getFacing()) + ->writeCardinalHorizontalFacing($block->getFacing()) ->writeBool(StateNames::UPPER_BLOCK_BIT, $block->isTop()); }); $this->map(Blocks::SMOKER(), fn(Furnace $block) => Helper::encodeFurnace($block, Ids::SMOKER, Ids::LIT_SMOKER)); @@ -1520,18 +1580,6 @@ private function registerSerializers() : void{ ->writeString(StateNames::SPONGE_TYPE, $block->isWet() ? StringValues::SPONGE_TYPE_WET : StringValues::SPONGE_TYPE_DRY); }); $this->map(Blocks::SPRUCE_SAPLING(), fn(Sapling $block) => Helper::encodeSapling($block, StringValues::SAPLING_TYPE_SPRUCE)); - $this->map(Blocks::STAINED_CLAY(), function(StainedHardenedClay $block) : Writer{ - return Writer::create(Ids::STAINED_HARDENED_CLAY) - ->writeColor($block->getColor()); - }); - $this->map(Blocks::STAINED_GLASS(), function(StainedGlass $block) : Writer{ - return Writer::create(Ids::STAINED_GLASS) - ->writeColor($block->getColor()); - }); - $this->map(Blocks::STAINED_GLASS_PANE(), function(StainedGlassPane $block) : Writer{ - return Writer::create(Ids::STAINED_GLASS_PANE) - ->writeColor($block->getColor()); - }); $this->map(Blocks::STAINED_HARDENED_GLASS(), function(StainedHardenedGlass $block) : Writer{ return Writer::create(Ids::HARD_STAINED_GLASS) ->writeColor($block->getColor()); @@ -1606,13 +1654,12 @@ private function registerSerializers() : void{ }); $this->map(Blocks::WALL_CORAL_FAN(), function(WallCoralFan $block) : Writer{ $coralType = $block->getCoralType(); - return Writer::create(match($coralType->id()){ - CoralType::TUBE()->id(), CoralType::BRAIN()->id() => Ids::CORAL_FAN_HANG, - CoralType::BUBBLE()->id(), CoralType::FIRE()->id() => Ids::CORAL_FAN_HANG2, - CoralType::HORN()->id() => Ids::CORAL_FAN_HANG3, - default => throw new BlockStateSerializeException("Invalid Coral type " . $coralType->name()), + return Writer::create(match($coralType){ + CoralType::TUBE, CoralType::BRAIN => Ids::CORAL_FAN_HANG, + CoralType::BUBBLE, CoralType::FIRE => Ids::CORAL_FAN_HANG2, + CoralType::HORN => Ids::CORAL_FAN_HANG3, }) - ->writeBool(StateNames::CORAL_HANG_TYPE_BIT, $coralType->equals(CoralType::BRAIN()) || $coralType->equals(CoralType::FIRE())) + ->writeBool(StateNames::CORAL_HANG_TYPE_BIT, $coralType === CoralType::BRAIN || $coralType === CoralType::FIRE) ->writeBool(StateNames::DEAD_BIT, $block->isDead()) ->writeCoralFacing($block->getFacing()); }); diff --git a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php index 8018d71b89..b929f68005 100644 --- a/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php +++ b/src/data/bedrock/block/convert/BlockStateDeserializerHelper.php @@ -93,7 +93,7 @@ public static function decodeCrops(Crops $block, BlockStateReader $in) : Crops{ /** @throws BlockStateDeserializeException */ public static function decodeComparator(RedstoneComparator $block, BlockStateReader $in) : RedstoneComparator{ return $block - ->setFacing($in->readLegacyHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setPowered($in->readBool(BlockStateNames::OUTPUT_LIT_BIT)) ->setSubtractMode($in->readBool(BlockStateNames::OUTPUT_SUBTRACT_BIT)); } @@ -216,7 +216,7 @@ public static function decodeMushroomBlock(RedMushroomBlock $block, BlockStateRe /** @throws BlockStateDeserializeException */ public static function decodeRepeater(RedstoneRepeater $block, BlockStateReader $in) : RedstoneRepeater{ return $block - ->setFacing($in->readLegacyHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setDelay($in->readBoundedInt(BlockStateNames::REPEATER_DELAY, 0, 3) + 1); } diff --git a/src/data/bedrock/block/convert/BlockStateReader.php b/src/data/bedrock/block/convert/BlockStateReader.php index 09dab0f2c6..ebfe1c50ed 100644 --- a/src/data/bedrock/block/convert/BlockStateReader.php +++ b/src/data/bedrock/block/convert/BlockStateReader.php @@ -227,22 +227,22 @@ public function readCardinalHorizontalFacing() : int{ public function readColor() : DyeColor{ // * color (StringTag) = black, blue, brown, cyan, gray, green, light_blue, lime, magenta, orange, pink, purple, red, silver, white, yellow return match($color = $this->readString(BlockStateNames::COLOR)){ - StringValues::COLOR_BLACK => DyeColor::BLACK(), - StringValues::COLOR_BLUE => DyeColor::BLUE(), - StringValues::COLOR_BROWN => DyeColor::BROWN(), - StringValues::COLOR_CYAN => DyeColor::CYAN(), - StringValues::COLOR_GRAY => DyeColor::GRAY(), - StringValues::COLOR_GREEN => DyeColor::GREEN(), - StringValues::COLOR_LIGHT_BLUE => DyeColor::LIGHT_BLUE(), - StringValues::COLOR_LIME => DyeColor::LIME(), - StringValues::COLOR_MAGENTA => DyeColor::MAGENTA(), - StringValues::COLOR_ORANGE => DyeColor::ORANGE(), - StringValues::COLOR_PINK => DyeColor::PINK(), - StringValues::COLOR_PURPLE => DyeColor::PURPLE(), - StringValues::COLOR_RED => DyeColor::RED(), - StringValues::COLOR_SILVER => DyeColor::LIGHT_GRAY(), - StringValues::COLOR_WHITE => DyeColor::WHITE(), - StringValues::COLOR_YELLOW => DyeColor::YELLOW(), + StringValues::COLOR_BLACK => DyeColor::BLACK, + StringValues::COLOR_BLUE => DyeColor::BLUE, + StringValues::COLOR_BROWN => DyeColor::BROWN, + StringValues::COLOR_CYAN => DyeColor::CYAN, + StringValues::COLOR_GRAY => DyeColor::GRAY, + StringValues::COLOR_GREEN => DyeColor::GREEN, + StringValues::COLOR_LIGHT_BLUE => DyeColor::LIGHT_BLUE, + StringValues::COLOR_LIME => DyeColor::LIME, + StringValues::COLOR_MAGENTA => DyeColor::MAGENTA, + StringValues::COLOR_ORANGE => DyeColor::ORANGE, + StringValues::COLOR_PINK => DyeColor::PINK, + StringValues::COLOR_PURPLE => DyeColor::PURPLE, + StringValues::COLOR_RED => DyeColor::RED, + StringValues::COLOR_SILVER => DyeColor::LIGHT_GRAY, + StringValues::COLOR_WHITE => DyeColor::WHITE, + StringValues::COLOR_YELLOW => DyeColor::YELLOW, default => throw $this->badValueException(BlockStateNames::COLOR, $color), }; } @@ -293,7 +293,11 @@ public function readPillarAxis() : int{ /** @throws BlockStateDeserializeException */ public function readSlabPosition() : SlabType{ - return $this->readBool(BlockStateNames::TOP_SLOT_BIT) ? SlabType::TOP() : SlabType::BOTTOM(); + return match($rawValue = $this->readString(BlockStateNames::MC_VERTICAL_HALF)){ + StringValues::MC_VERTICAL_HALF_BOTTOM => SlabType::BOTTOM, + StringValues::MC_VERTICAL_HALF_TOP => SlabType::TOP, + default => throw $this->badValueException(BlockStateNames::MC_VERTICAL_HALF, $rawValue, "Invalid slab position"), + }; } /** @@ -316,11 +320,11 @@ public function readTorchFacing() : int{ /** @throws BlockStateDeserializeException */ public function readCoralType() : CoralType{ return match($type = $this->readString(BlockStateNames::CORAL_COLOR)){ - StringValues::CORAL_COLOR_BLUE => CoralType::TUBE(), - StringValues::CORAL_COLOR_PINK => CoralType::BRAIN(), - StringValues::CORAL_COLOR_PURPLE => CoralType::BUBBLE(), - StringValues::CORAL_COLOR_RED => CoralType::FIRE(), - StringValues::CORAL_COLOR_YELLOW => CoralType::HORN(), + StringValues::CORAL_COLOR_BLUE => CoralType::TUBE, + StringValues::CORAL_COLOR_PINK => CoralType::BRAIN, + StringValues::CORAL_COLOR_PURPLE => CoralType::BUBBLE, + StringValues::CORAL_COLOR_RED => CoralType::FIRE, + StringValues::CORAL_COLOR_YELLOW => CoralType::HORN, default => throw $this->badValueException(BlockStateNames::CORAL_COLOR, $type), }; } @@ -328,10 +332,10 @@ public function readCoralType() : CoralType{ /** @throws BlockStateDeserializeException */ public function readBellAttachmentType() : BellAttachmentType{ return match($type = $this->readString(BlockStateNames::ATTACHMENT)){ - StringValues::ATTACHMENT_HANGING => BellAttachmentType::CEILING(), - StringValues::ATTACHMENT_STANDING => BellAttachmentType::FLOOR(), - StringValues::ATTACHMENT_SIDE => BellAttachmentType::ONE_WALL(), - StringValues::ATTACHMENT_MULTIPLE => BellAttachmentType::TWO_WALLS(), + StringValues::ATTACHMENT_HANGING => BellAttachmentType::CEILING, + StringValues::ATTACHMENT_STANDING => BellAttachmentType::FLOOR, + StringValues::ATTACHMENT_SIDE => BellAttachmentType::ONE_WALL, + StringValues::ATTACHMENT_MULTIPLE => BellAttachmentType::TWO_WALLS, default => throw $this->badValueException(BlockStateNames::ATTACHMENT, $type), }; } @@ -343,8 +347,8 @@ public function readWallConnectionType(string $name) : ?WallConnectionType{ //we need to find a better way to auto-generate the constant names when they are reused //for now, using these constants is better than nothing since it still gives static analysability StringValues::WALL_CONNECTION_TYPE_EAST_NONE => null, - StringValues::WALL_CONNECTION_TYPE_EAST_SHORT => WallConnectionType::SHORT(), - StringValues::WALL_CONNECTION_TYPE_EAST_TALL => WallConnectionType::TALL(), + StringValues::WALL_CONNECTION_TYPE_EAST_SHORT => WallConnectionType::SHORT, + StringValues::WALL_CONNECTION_TYPE_EAST_TALL => WallConnectionType::TALL, default => throw $this->badValueException($name, $type), }; } diff --git a/src/data/bedrock/block/convert/BlockStateSerializerHelper.php b/src/data/bedrock/block/convert/BlockStateSerializerHelper.php index 97fa5532fb..2822324e5c 100644 --- a/src/data/bedrock/block/convert/BlockStateSerializerHelper.php +++ b/src/data/bedrock/block/convert/BlockStateSerializerHelper.php @@ -54,7 +54,6 @@ use pocketmine\data\bedrock\block\convert\BlockStateWriter as Writer; use pocketmine\data\bedrock\MushroomBlockTypeIdMap; use pocketmine\math\Facing; -use pocketmine\utils\AssumptionFailedError; final class BlockStateSerializerHelper{ @@ -101,11 +100,10 @@ public static function encodeCauldron(string $liquid, int $fillLevel) : BlockSta public static function selectCopperId(CopperOxidation $oxidation, string $noneId, string $exposedId, string $weatheredId, string $oxidizedId) : string{ return match($oxidation){ - CopperOxidation::NONE() => $noneId, - CopperOxidation::EXPOSED() => $exposedId, - CopperOxidation::WEATHERED() => $weatheredId, - CopperOxidation::OXIDIZED() => $oxidizedId, - default => throw new AssumptionFailedError("Unhandled copper oxidation " . $oxidation->name()) + CopperOxidation::NONE => $noneId, + CopperOxidation::EXPOSED => $exposedId, + CopperOxidation::WEATHERED => $weatheredId, + CopperOxidation::OXIDIZED => $oxidizedId, }; } @@ -137,7 +135,7 @@ public static function encodeFloorSign(FloorSign $block, BlockStateWriter $out) public static function encodeFurnace(Furnace $block, string $unlitId, string $litId) : BlockStateWriter{ return BlockStateWriter::create($block->isLit() ? $litId : $unlitId) - ->writeHorizontalFacing($block->getFacing()); + ->writeCardinalHorizontalFacing($block->getFacing()); } public static function encodeItemFrame(ItemFrame $block, string $id) : BlockStateWriter{ @@ -210,10 +208,9 @@ public static function encodeSimplePressurePlate(SimplePressurePlate $block, Blo public static function encodeSlab(Slab $block, string $singleId, string $doubleId) : BlockStateWriter{ $slabType = $block->getSlabType(); - return BlockStateWriter::create($slabType->equals(SlabType::DOUBLE()) ? $doubleId : $singleId) - + return BlockStateWriter::create($slabType === SlabType::DOUBLE ? $doubleId : $singleId) //this is (intentionally) also written for double slabs (as zero) to maintain bug parity with MCPE - ->writeBool(BlockStateNames::TOP_SLOT_BIT, $slabType->equals(SlabType::TOP())); + ->writeSlabPosition($slabType === SlabType::DOUBLE ? SlabType::BOTTOM : $slabType); } public static function encodeStairs(Stair $block, BlockStateWriter $out) : BlockStateWriter{ diff --git a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php index f6b8699a94..c26fe4986f 100644 --- a/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php +++ b/src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php @@ -113,8 +113,8 @@ public function mapSimple(string $id, \Closure $getBlock) : void{ public function mapSlab(string $singleId, string $doubleId, \Closure $getBlock) : void{ $this->map($singleId, fn(Reader $in) : Slab => $getBlock($in)->setSlabType($in->readSlabPosition())); $this->map($doubleId, function(Reader $in) use ($getBlock) : Slab{ - $in->ignored(StateNames::TOP_SLOT_BIT); - return $getBlock($in)->setSlabType(SlabType::DOUBLE()); + $in->ignored(StateNames::MC_VERTICAL_HALF); + return $getBlock($in)->setSlabType(SlabType::DOUBLE); }); } @@ -134,44 +134,44 @@ public function mapLog(string $unstrippedId, string $strippedId, \Closure $getBl private function registerCandleDeserializers() : void{ $this->map(Ids::CANDLE, fn(Reader $in) => Helper::decodeCandle(Blocks::CANDLE(), $in)); foreach([ - Ids::BLACK_CANDLE => DyeColor::BLACK(), - Ids::BLUE_CANDLE => DyeColor::BLUE(), - Ids::BROWN_CANDLE => DyeColor::BROWN(), - Ids::CYAN_CANDLE => DyeColor::CYAN(), - Ids::GRAY_CANDLE => DyeColor::GRAY(), - Ids::GREEN_CANDLE => DyeColor::GREEN(), - Ids::LIGHT_BLUE_CANDLE => DyeColor::LIGHT_BLUE(), - Ids::LIGHT_GRAY_CANDLE => DyeColor::LIGHT_GRAY(), - Ids::LIME_CANDLE => DyeColor::LIME(), - Ids::MAGENTA_CANDLE => DyeColor::MAGENTA(), - Ids::ORANGE_CANDLE => DyeColor::ORANGE(), - Ids::PINK_CANDLE => DyeColor::PINK(), - Ids::PURPLE_CANDLE => DyeColor::PURPLE(), - Ids::RED_CANDLE => DyeColor::RED(), - Ids::WHITE_CANDLE => DyeColor::WHITE(), - Ids::YELLOW_CANDLE => DyeColor::YELLOW(), + Ids::BLACK_CANDLE => DyeColor::BLACK, + Ids::BLUE_CANDLE => DyeColor::BLUE, + Ids::BROWN_CANDLE => DyeColor::BROWN, + Ids::CYAN_CANDLE => DyeColor::CYAN, + Ids::GRAY_CANDLE => DyeColor::GRAY, + Ids::GREEN_CANDLE => DyeColor::GREEN, + Ids::LIGHT_BLUE_CANDLE => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_CANDLE => DyeColor::LIGHT_GRAY, + Ids::LIME_CANDLE => DyeColor::LIME, + Ids::MAGENTA_CANDLE => DyeColor::MAGENTA, + Ids::ORANGE_CANDLE => DyeColor::ORANGE, + Ids::PINK_CANDLE => DyeColor::PINK, + Ids::PURPLE_CANDLE => DyeColor::PURPLE, + Ids::RED_CANDLE => DyeColor::RED, + Ids::WHITE_CANDLE => DyeColor::WHITE, + Ids::YELLOW_CANDLE => DyeColor::YELLOW, ] as $id => $color){ $this->map($id, fn(Reader $in) => Helper::decodeCandle(Blocks::DYED_CANDLE()->setColor($color), $in)); } $this->map(Ids::CANDLE_CAKE, fn(Reader $in) => Blocks::CAKE_WITH_CANDLE()->setLit($in->readBool(StateNames::LIT))); foreach([ - Ids::BLACK_CANDLE_CAKE => DyeColor::BLACK(), - Ids::BLUE_CANDLE_CAKE => DyeColor::BLUE(), - Ids::BROWN_CANDLE_CAKE => DyeColor::BROWN(), - Ids::CYAN_CANDLE_CAKE => DyeColor::CYAN(), - Ids::GRAY_CANDLE_CAKE => DyeColor::GRAY(), - Ids::GREEN_CANDLE_CAKE => DyeColor::GREEN(), - Ids::LIGHT_BLUE_CANDLE_CAKE => DyeColor::LIGHT_BLUE(), - Ids::LIGHT_GRAY_CANDLE_CAKE => DyeColor::LIGHT_GRAY(), - Ids::LIME_CANDLE_CAKE => DyeColor::LIME(), - Ids::MAGENTA_CANDLE_CAKE => DyeColor::MAGENTA(), - Ids::ORANGE_CANDLE_CAKE => DyeColor::ORANGE(), - Ids::PINK_CANDLE_CAKE => DyeColor::PINK(), - Ids::PURPLE_CANDLE_CAKE => DyeColor::PURPLE(), - Ids::RED_CANDLE_CAKE => DyeColor::RED(), - Ids::WHITE_CANDLE_CAKE => DyeColor::WHITE(), - Ids::YELLOW_CANDLE_CAKE => DyeColor::YELLOW(), + Ids::BLACK_CANDLE_CAKE => DyeColor::BLACK, + Ids::BLUE_CANDLE_CAKE => DyeColor::BLUE, + Ids::BROWN_CANDLE_CAKE => DyeColor::BROWN, + Ids::CYAN_CANDLE_CAKE => DyeColor::CYAN, + Ids::GRAY_CANDLE_CAKE => DyeColor::GRAY, + Ids::GREEN_CANDLE_CAKE => DyeColor::GREEN, + Ids::LIGHT_BLUE_CANDLE_CAKE => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_CANDLE_CAKE => DyeColor::LIGHT_GRAY, + Ids::LIME_CANDLE_CAKE => DyeColor::LIME, + Ids::MAGENTA_CANDLE_CAKE => DyeColor::MAGENTA, + Ids::ORANGE_CANDLE_CAKE => DyeColor::ORANGE, + Ids::PINK_CANDLE_CAKE => DyeColor::PINK, + Ids::PURPLE_CANDLE_CAKE => DyeColor::PURPLE, + Ids::RED_CANDLE_CAKE => DyeColor::RED, + Ids::WHITE_CANDLE_CAKE => DyeColor::WHITE, + Ids::YELLOW_CANDLE_CAKE => DyeColor::YELLOW, ] as $id => $color){ $this->map($id, fn(Reader $in) => Blocks::CAKE_WITH_DYED_CANDLE() ->setColor($color) @@ -182,22 +182,22 @@ private function registerCandleDeserializers() : void{ private function registerFlatColorBlockDeserializers() : void{ foreach([ - Ids::BLACK_GLAZED_TERRACOTTA => DyeColor::BLACK(), - Ids::BLUE_GLAZED_TERRACOTTA => DyeColor::BLUE(), - Ids::BROWN_GLAZED_TERRACOTTA => DyeColor::BROWN(), - Ids::CYAN_GLAZED_TERRACOTTA => DyeColor::CYAN(), - Ids::GRAY_GLAZED_TERRACOTTA => DyeColor::GRAY(), - Ids::GREEN_GLAZED_TERRACOTTA => DyeColor::GREEN(), - Ids::LIGHT_BLUE_GLAZED_TERRACOTTA => DyeColor::LIGHT_BLUE(), - Ids::SILVER_GLAZED_TERRACOTTA => DyeColor::LIGHT_GRAY(), - Ids::LIME_GLAZED_TERRACOTTA => DyeColor::LIME(), - Ids::MAGENTA_GLAZED_TERRACOTTA => DyeColor::MAGENTA(), - Ids::ORANGE_GLAZED_TERRACOTTA => DyeColor::ORANGE(), - Ids::PINK_GLAZED_TERRACOTTA => DyeColor::PINK(), - Ids::PURPLE_GLAZED_TERRACOTTA => DyeColor::PURPLE(), - Ids::RED_GLAZED_TERRACOTTA => DyeColor::RED(), - Ids::WHITE_GLAZED_TERRACOTTA => DyeColor::WHITE(), - Ids::YELLOW_GLAZED_TERRACOTTA => DyeColor::YELLOW(), + Ids::BLACK_GLAZED_TERRACOTTA => DyeColor::BLACK, + Ids::BLUE_GLAZED_TERRACOTTA => DyeColor::BLUE, + Ids::BROWN_GLAZED_TERRACOTTA => DyeColor::BROWN, + Ids::CYAN_GLAZED_TERRACOTTA => DyeColor::CYAN, + Ids::GRAY_GLAZED_TERRACOTTA => DyeColor::GRAY, + Ids::GREEN_GLAZED_TERRACOTTA => DyeColor::GREEN, + Ids::LIGHT_BLUE_GLAZED_TERRACOTTA => DyeColor::LIGHT_BLUE, + Ids::SILVER_GLAZED_TERRACOTTA => DyeColor::LIGHT_GRAY, + Ids::LIME_GLAZED_TERRACOTTA => DyeColor::LIME, + Ids::MAGENTA_GLAZED_TERRACOTTA => DyeColor::MAGENTA, + Ids::ORANGE_GLAZED_TERRACOTTA => DyeColor::ORANGE, + Ids::PINK_GLAZED_TERRACOTTA => DyeColor::PINK, + Ids::PURPLE_GLAZED_TERRACOTTA => DyeColor::PURPLE, + Ids::RED_GLAZED_TERRACOTTA => DyeColor::RED, + Ids::WHITE_GLAZED_TERRACOTTA => DyeColor::WHITE, + Ids::YELLOW_GLAZED_TERRACOTTA => DyeColor::YELLOW, ] as $id => $color){ $this->map($id, fn(Reader $in) => Blocks::GLAZED_TERRACOTTA() ->setColor($color) @@ -206,106 +206,190 @@ private function registerFlatColorBlockDeserializers() : void{ } foreach([ - Ids::BLACK_WOOL => DyeColor::BLACK(), - Ids::BLUE_WOOL => DyeColor::BLUE(), - Ids::BROWN_WOOL => DyeColor::BROWN(), - Ids::CYAN_WOOL => DyeColor::CYAN(), - Ids::GRAY_WOOL => DyeColor::GRAY(), - Ids::GREEN_WOOL => DyeColor::GREEN(), - Ids::LIGHT_BLUE_WOOL => DyeColor::LIGHT_BLUE(), - Ids::LIGHT_GRAY_WOOL => DyeColor::LIGHT_GRAY(), - Ids::LIME_WOOL => DyeColor::LIME(), - Ids::MAGENTA_WOOL => DyeColor::MAGENTA(), - Ids::ORANGE_WOOL => DyeColor::ORANGE(), - Ids::PINK_WOOL => DyeColor::PINK(), - Ids::PURPLE_WOOL => DyeColor::PURPLE(), - Ids::RED_WOOL => DyeColor::RED(), - Ids::WHITE_WOOL => DyeColor::WHITE(), - Ids::YELLOW_WOOL => DyeColor::YELLOW(), + Ids::BLACK_WOOL => DyeColor::BLACK, + Ids::BLUE_WOOL => DyeColor::BLUE, + Ids::BROWN_WOOL => DyeColor::BROWN, + Ids::CYAN_WOOL => DyeColor::CYAN, + Ids::GRAY_WOOL => DyeColor::GRAY, + Ids::GREEN_WOOL => DyeColor::GREEN, + Ids::LIGHT_BLUE_WOOL => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_WOOL => DyeColor::LIGHT_GRAY, + Ids::LIME_WOOL => DyeColor::LIME, + Ids::MAGENTA_WOOL => DyeColor::MAGENTA, + Ids::ORANGE_WOOL => DyeColor::ORANGE, + Ids::PINK_WOOL => DyeColor::PINK, + Ids::PURPLE_WOOL => DyeColor::PURPLE, + Ids::RED_WOOL => DyeColor::RED, + Ids::WHITE_WOOL => DyeColor::WHITE, + Ids::YELLOW_WOOL => DyeColor::YELLOW, ] as $id => $color){ $this->mapSimple($id, fn() => Blocks::WOOL()->setColor($color)); } foreach([ - Ids::BLACK_CARPET => DyeColor::BLACK(), - Ids::BLUE_CARPET => DyeColor::BLUE(), - Ids::BROWN_CARPET => DyeColor::BROWN(), - Ids::CYAN_CARPET => DyeColor::CYAN(), - Ids::GRAY_CARPET => DyeColor::GRAY(), - Ids::GREEN_CARPET => DyeColor::GREEN(), - Ids::LIGHT_BLUE_CARPET => DyeColor::LIGHT_BLUE(), - Ids::LIGHT_GRAY_CARPET => DyeColor::LIGHT_GRAY(), - Ids::LIME_CARPET => DyeColor::LIME(), - Ids::MAGENTA_CARPET => DyeColor::MAGENTA(), - Ids::ORANGE_CARPET => DyeColor::ORANGE(), - Ids::PINK_CARPET => DyeColor::PINK(), - Ids::PURPLE_CARPET => DyeColor::PURPLE(), - Ids::RED_CARPET => DyeColor::RED(), - Ids::WHITE_CARPET => DyeColor::WHITE(), - Ids::YELLOW_CARPET => DyeColor::YELLOW(), + Ids::BLACK_CARPET => DyeColor::BLACK, + Ids::BLUE_CARPET => DyeColor::BLUE, + Ids::BROWN_CARPET => DyeColor::BROWN, + Ids::CYAN_CARPET => DyeColor::CYAN, + Ids::GRAY_CARPET => DyeColor::GRAY, + Ids::GREEN_CARPET => DyeColor::GREEN, + Ids::LIGHT_BLUE_CARPET => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_CARPET => DyeColor::LIGHT_GRAY, + Ids::LIME_CARPET => DyeColor::LIME, + Ids::MAGENTA_CARPET => DyeColor::MAGENTA, + Ids::ORANGE_CARPET => DyeColor::ORANGE, + Ids::PINK_CARPET => DyeColor::PINK, + Ids::PURPLE_CARPET => DyeColor::PURPLE, + Ids::RED_CARPET => DyeColor::RED, + Ids::WHITE_CARPET => DyeColor::WHITE, + Ids::YELLOW_CARPET => DyeColor::YELLOW, ] as $id => $color){ $this->mapSimple($id, fn() => Blocks::CARPET()->setColor($color)); } foreach([ - Ids::BLACK_SHULKER_BOX => DyeColor::BLACK(), - Ids::BLUE_SHULKER_BOX => DyeColor::BLUE(), - Ids::BROWN_SHULKER_BOX => DyeColor::BROWN(), - Ids::CYAN_SHULKER_BOX => DyeColor::CYAN(), - Ids::GRAY_SHULKER_BOX => DyeColor::GRAY(), - Ids::GREEN_SHULKER_BOX => DyeColor::GREEN(), - Ids::LIGHT_BLUE_SHULKER_BOX => DyeColor::LIGHT_BLUE(), - Ids::LIGHT_GRAY_SHULKER_BOX => DyeColor::LIGHT_GRAY(), - Ids::LIME_SHULKER_BOX => DyeColor::LIME(), - Ids::MAGENTA_SHULKER_BOX => DyeColor::MAGENTA(), - Ids::ORANGE_SHULKER_BOX => DyeColor::ORANGE(), - Ids::PINK_SHULKER_BOX => DyeColor::PINK(), - Ids::PURPLE_SHULKER_BOX => DyeColor::PURPLE(), - Ids::RED_SHULKER_BOX => DyeColor::RED(), - Ids::WHITE_SHULKER_BOX => DyeColor::WHITE(), - Ids::YELLOW_SHULKER_BOX => DyeColor::YELLOW(), + Ids::BLACK_SHULKER_BOX => DyeColor::BLACK, + Ids::BLUE_SHULKER_BOX => DyeColor::BLUE, + Ids::BROWN_SHULKER_BOX => DyeColor::BROWN, + Ids::CYAN_SHULKER_BOX => DyeColor::CYAN, + Ids::GRAY_SHULKER_BOX => DyeColor::GRAY, + Ids::GREEN_SHULKER_BOX => DyeColor::GREEN, + Ids::LIGHT_BLUE_SHULKER_BOX => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_SHULKER_BOX => DyeColor::LIGHT_GRAY, + Ids::LIME_SHULKER_BOX => DyeColor::LIME, + Ids::MAGENTA_SHULKER_BOX => DyeColor::MAGENTA, + Ids::ORANGE_SHULKER_BOX => DyeColor::ORANGE, + Ids::PINK_SHULKER_BOX => DyeColor::PINK, + Ids::PURPLE_SHULKER_BOX => DyeColor::PURPLE, + Ids::RED_SHULKER_BOX => DyeColor::RED, + Ids::WHITE_SHULKER_BOX => DyeColor::WHITE, + Ids::YELLOW_SHULKER_BOX => DyeColor::YELLOW, ] as $id => $color){ $this->mapSimple($id, fn() => Blocks::DYED_SHULKER_BOX()->setColor($color)); } foreach([ - Ids::BLACK_CONCRETE => DyeColor::BLACK(), - Ids::BLUE_CONCRETE => DyeColor::BLUE(), - Ids::BROWN_CONCRETE => DyeColor::BROWN(), - Ids::CYAN_CONCRETE => DyeColor::CYAN(), - Ids::GRAY_CONCRETE => DyeColor::GRAY(), - Ids::GREEN_CONCRETE => DyeColor::GREEN(), - Ids::LIGHT_BLUE_CONCRETE => DyeColor::LIGHT_BLUE(), - Ids::LIGHT_GRAY_CONCRETE => DyeColor::LIGHT_GRAY(), - Ids::LIME_CONCRETE => DyeColor::LIME(), - Ids::MAGENTA_CONCRETE => DyeColor::MAGENTA(), - Ids::ORANGE_CONCRETE => DyeColor::ORANGE(), - Ids::PINK_CONCRETE => DyeColor::PINK(), - Ids::PURPLE_CONCRETE => DyeColor::PURPLE(), - Ids::RED_CONCRETE => DyeColor::RED(), - Ids::WHITE_CONCRETE => DyeColor::WHITE(), - Ids::YELLOW_CONCRETE => DyeColor::YELLOW(), + Ids::BLACK_CONCRETE => DyeColor::BLACK, + Ids::BLUE_CONCRETE => DyeColor::BLUE, + Ids::BROWN_CONCRETE => DyeColor::BROWN, + Ids::CYAN_CONCRETE => DyeColor::CYAN, + Ids::GRAY_CONCRETE => DyeColor::GRAY, + Ids::GREEN_CONCRETE => DyeColor::GREEN, + Ids::LIGHT_BLUE_CONCRETE => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_CONCRETE => DyeColor::LIGHT_GRAY, + Ids::LIME_CONCRETE => DyeColor::LIME, + Ids::MAGENTA_CONCRETE => DyeColor::MAGENTA, + Ids::ORANGE_CONCRETE => DyeColor::ORANGE, + Ids::PINK_CONCRETE => DyeColor::PINK, + Ids::PURPLE_CONCRETE => DyeColor::PURPLE, + Ids::RED_CONCRETE => DyeColor::RED, + Ids::WHITE_CONCRETE => DyeColor::WHITE, + Ids::YELLOW_CONCRETE => DyeColor::YELLOW, ] as $id => $color){ $this->mapSimple($id, fn() => Blocks::CONCRETE()->setColor($color)); } + + foreach([ + Ids::BLACK_CONCRETE_POWDER => DyeColor::BLACK, + Ids::BLUE_CONCRETE_POWDER => DyeColor::BLUE, + Ids::BROWN_CONCRETE_POWDER => DyeColor::BROWN, + Ids::CYAN_CONCRETE_POWDER => DyeColor::CYAN, + Ids::GRAY_CONCRETE_POWDER => DyeColor::GRAY, + Ids::GREEN_CONCRETE_POWDER => DyeColor::GREEN, + Ids::LIGHT_BLUE_CONCRETE_POWDER => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_CONCRETE_POWDER => DyeColor::LIGHT_GRAY, + Ids::LIME_CONCRETE_POWDER => DyeColor::LIME, + Ids::MAGENTA_CONCRETE_POWDER => DyeColor::MAGENTA, + Ids::ORANGE_CONCRETE_POWDER => DyeColor::ORANGE, + Ids::PINK_CONCRETE_POWDER => DyeColor::PINK, + Ids::PURPLE_CONCRETE_POWDER => DyeColor::PURPLE, + Ids::RED_CONCRETE_POWDER => DyeColor::RED, + Ids::WHITE_CONCRETE_POWDER => DyeColor::WHITE, + Ids::YELLOW_CONCRETE_POWDER => DyeColor::YELLOW, + ] as $id => $color){ + $this->mapSimple($id, fn() => Blocks::CONCRETE_POWDER()->setColor($color)); + } + + foreach([ + Ids::BLACK_TERRACOTTA => DyeColor::BLACK, + Ids::BLUE_TERRACOTTA => DyeColor::BLUE, + Ids::BROWN_TERRACOTTA => DyeColor::BROWN, + Ids::CYAN_TERRACOTTA => DyeColor::CYAN, + Ids::GRAY_TERRACOTTA => DyeColor::GRAY, + Ids::GREEN_TERRACOTTA => DyeColor::GREEN, + Ids::LIGHT_BLUE_TERRACOTTA => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_TERRACOTTA => DyeColor::LIGHT_GRAY, + Ids::LIME_TERRACOTTA => DyeColor::LIME, + Ids::MAGENTA_TERRACOTTA => DyeColor::MAGENTA, + Ids::ORANGE_TERRACOTTA => DyeColor::ORANGE, + Ids::PINK_TERRACOTTA => DyeColor::PINK, + Ids::PURPLE_TERRACOTTA => DyeColor::PURPLE, + Ids::RED_TERRACOTTA => DyeColor::RED, + Ids::WHITE_TERRACOTTA => DyeColor::WHITE, + Ids::YELLOW_TERRACOTTA => DyeColor::YELLOW, + ] as $id => $color){ + $this->mapSimple($id, fn() => Blocks::STAINED_CLAY()->setColor($color)); + } + + foreach([ + Ids::BLACK_STAINED_GLASS => DyeColor::BLACK, + Ids::BLUE_STAINED_GLASS => DyeColor::BLUE, + Ids::BROWN_STAINED_GLASS => DyeColor::BROWN, + Ids::CYAN_STAINED_GLASS => DyeColor::CYAN, + Ids::GRAY_STAINED_GLASS => DyeColor::GRAY, + Ids::GREEN_STAINED_GLASS => DyeColor::GREEN, + Ids::LIGHT_BLUE_STAINED_GLASS => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_STAINED_GLASS => DyeColor::LIGHT_GRAY, + Ids::LIME_STAINED_GLASS => DyeColor::LIME, + Ids::MAGENTA_STAINED_GLASS => DyeColor::MAGENTA, + Ids::ORANGE_STAINED_GLASS => DyeColor::ORANGE, + Ids::PINK_STAINED_GLASS => DyeColor::PINK, + Ids::PURPLE_STAINED_GLASS => DyeColor::PURPLE, + Ids::RED_STAINED_GLASS => DyeColor::RED, + Ids::WHITE_STAINED_GLASS => DyeColor::WHITE, + Ids::YELLOW_STAINED_GLASS => DyeColor::YELLOW, + ] as $id => $color){ + $this->mapSimple($id, fn() => Blocks::STAINED_GLASS()->setColor($color)); + } + + foreach([ + Ids::BLACK_STAINED_GLASS_PANE => DyeColor::BLACK, + Ids::BLUE_STAINED_GLASS_PANE => DyeColor::BLUE, + Ids::BROWN_STAINED_GLASS_PANE => DyeColor::BROWN, + Ids::CYAN_STAINED_GLASS_PANE => DyeColor::CYAN, + Ids::GRAY_STAINED_GLASS_PANE => DyeColor::GRAY, + Ids::GREEN_STAINED_GLASS_PANE => DyeColor::GREEN, + Ids::LIGHT_BLUE_STAINED_GLASS_PANE => DyeColor::LIGHT_BLUE, + Ids::LIGHT_GRAY_STAINED_GLASS_PANE => DyeColor::LIGHT_GRAY, + Ids::LIME_STAINED_GLASS_PANE => DyeColor::LIME, + Ids::MAGENTA_STAINED_GLASS_PANE => DyeColor::MAGENTA, + Ids::ORANGE_STAINED_GLASS_PANE => DyeColor::ORANGE, + Ids::PINK_STAINED_GLASS_PANE => DyeColor::PINK, + Ids::PURPLE_STAINED_GLASS_PANE => DyeColor::PURPLE, + Ids::RED_STAINED_GLASS_PANE => DyeColor::RED, + Ids::WHITE_STAINED_GLASS_PANE => DyeColor::WHITE, + Ids::YELLOW_STAINED_GLASS_PANE => DyeColor::YELLOW, + ] as $id => $color){ + $this->mapSimple($id, fn() => Blocks::STAINED_GLASS_PANE()->setColor($color)); + } } private function registerFlatCoralDeserializers() : void{ foreach([ - Ids::BRAIN_CORAL => CoralType::BRAIN(), - Ids::BUBBLE_CORAL => CoralType::BUBBLE(), - Ids::FIRE_CORAL => CoralType::FIRE(), - Ids::HORN_CORAL => CoralType::HORN(), - Ids::TUBE_CORAL => CoralType::TUBE(), + Ids::BRAIN_CORAL => CoralType::BRAIN, + Ids::BUBBLE_CORAL => CoralType::BUBBLE, + Ids::FIRE_CORAL => CoralType::FIRE, + Ids::HORN_CORAL => CoralType::HORN, + Ids::TUBE_CORAL => CoralType::TUBE, ] as $id => $coralType){ $this->mapSimple($id, fn() => Blocks::CORAL()->setCoralType($coralType)->setDead(false)); } foreach([ - Ids::DEAD_BRAIN_CORAL => CoralType::BRAIN(), - Ids::DEAD_BUBBLE_CORAL => CoralType::BUBBLE(), - Ids::DEAD_FIRE_CORAL => CoralType::FIRE(), - Ids::DEAD_HORN_CORAL => CoralType::HORN(), - Ids::DEAD_TUBE_CORAL => CoralType::TUBE(), + Ids::DEAD_BRAIN_CORAL => CoralType::BRAIN, + Ids::DEAD_BUBBLE_CORAL => CoralType::BUBBLE, + Ids::DEAD_FIRE_CORAL => CoralType::FIRE, + Ids::DEAD_HORN_CORAL => CoralType::HORN, + Ids::DEAD_TUBE_CORAL => CoralType::TUBE, ] as $id => $coralType){ $this->mapSimple($id, fn() => Blocks::CORAL()->setCoralType($coralType)->setDead(true)); } @@ -781,7 +865,7 @@ private function registerDeserializers() : void{ StringValues::DAMAGE_BROKEN => 0, default => throw $in->badValueException(StateNames::DAMAGE, $value), }) - ->setFacing($in->readLegacyHorizontalFacing()); + ->setFacing($in->readCardinalHorizontalFacing()); }); $this->map(Ids::BAMBOO, function(Reader $in) : Block{ return Blocks::BAMBOO() @@ -831,17 +915,17 @@ private function registerDeserializers() : void{ $this->map(Ids::BIG_DRIPLEAF, function(Reader $in) : Block{ if($in->readBool(StateNames::BIG_DRIPLEAF_HEAD)){ return Blocks::BIG_DRIPLEAF_HEAD() - ->setFacing($in->readLegacyHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setLeafState(match($type = $in->readString(StateNames::BIG_DRIPLEAF_TILT)){ - StringValues::BIG_DRIPLEAF_TILT_NONE => DripleafState::STABLE(), - StringValues::BIG_DRIPLEAF_TILT_UNSTABLE => DripleafState::UNSTABLE(), - StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT => DripleafState::PARTIAL_TILT(), - StringValues::BIG_DRIPLEAF_TILT_FULL_TILT => DripleafState::FULL_TILT(), + StringValues::BIG_DRIPLEAF_TILT_NONE => DripleafState::STABLE, + StringValues::BIG_DRIPLEAF_TILT_UNSTABLE => DripleafState::UNSTABLE, + StringValues::BIG_DRIPLEAF_TILT_PARTIAL_TILT => DripleafState::PARTIAL_TILT, + StringValues::BIG_DRIPLEAF_TILT_FULL_TILT => DripleafState::FULL_TILT, default => throw $in->badValueException(StateNames::BIG_DRIPLEAF_TILT, $type), }); }else{ $in->ignored(StateNames::BIG_DRIPLEAF_TILT); - return Blocks::BIG_DRIPLEAF_STEM()->setFacing($in->readLegacyHorizontalFacing()); + return Blocks::BIG_DRIPLEAF_STEM()->setFacing($in->readCardinalHorizontalFacing()); } }); $this->mapSlab(Ids::BLACKSTONE_SLAB, Ids::BLACKSTONE_DOUBLE_SLAB, fn() => Blocks::BLACKSTONE_SLAB()); @@ -849,7 +933,7 @@ private function registerDeserializers() : void{ $this->map(Ids::BLACKSTONE_WALL, fn(Reader $in) => Helper::decodeWall(Blocks::BLACKSTONE_WALL(), $in)); $this->map(Ids::BLAST_FURNACE, function(Reader $in) : Block{ return Blocks::BLAST_FURNACE() - ->setFacing($in->readHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setLit(false); }); $this->map(Ids::BONE_BLOCK, function(Reader $in) : Block{ @@ -858,9 +942,9 @@ private function registerDeserializers() : void{ }); $this->map(Ids::BREWING_STAND, function(Reader $in) : Block{ return Blocks::BREWING_STAND() - ->setSlot(BrewingStandSlot::EAST(), $in->readBool(StateNames::BREWING_STAND_SLOT_A_BIT)) - ->setSlot(BrewingStandSlot::SOUTHWEST(), $in->readBool(StateNames::BREWING_STAND_SLOT_B_BIT)) - ->setSlot(BrewingStandSlot::NORTHWEST(), $in->readBool(StateNames::BREWING_STAND_SLOT_C_BIT)); + ->setSlot(BrewingStandSlot::EAST, $in->readBool(StateNames::BREWING_STAND_SLOT_A_BIT)) + ->setSlot(BrewingStandSlot::SOUTHWEST, $in->readBool(StateNames::BREWING_STAND_SLOT_B_BIT)) + ->setSlot(BrewingStandSlot::NORTHWEST, $in->readBool(StateNames::BREWING_STAND_SLOT_C_BIT)); }); $this->mapStairs(Ids::BRICK_STAIRS, fn() => Blocks::BRICK_STAIRS()); $this->map(Ids::BROWN_MUSHROOM_BLOCK, fn(Reader $in) => Helper::decodeMushroomBlock(Blocks::BROWN_MUSHROOM_BLOCK(), $in)); @@ -935,14 +1019,10 @@ private function registerDeserializers() : void{ Blocks::GREEN_TORCH()->setFacing($in->readTorchFacing()) : Blocks::RED_TORCH()->setFacing($in->readTorchFacing()); }); - $this->map(Ids::CONCRETE_POWDER, function(Reader $in) : Block{ - return Blocks::CONCRETE_POWDER() - ->setColor($in->readColor()); - }); - $this->map(Ids::COPPER_BLOCK, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::NONE())); - $this->map(Ids::CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE())); - $this->mapSlab(Ids::CUT_COPPER_SLAB, Ids::DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE())); - $this->mapStairs(Ids::CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE())); + $this->map(Ids::COPPER_BLOCK, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::NONE)); + $this->map(Ids::CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); + $this->mapSlab(Ids::CUT_COPPER_SLAB, Ids::DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); + $this->mapStairs(Ids::CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); $this->map(Ids::CORAL_BLOCK, function(Reader $in) : Block{ return Blocks::CORAL_BLOCK() ->setCoralType($in->readCoralType()) @@ -953,13 +1033,13 @@ private function registerDeserializers() : void{ $this->map(Ids::CORAL_FAN_DEAD, fn(Reader $in) => Helper::decodeFloorCoralFan(Blocks::CORAL_FAN(), $in) ->setDead(true)); $this->map(Ids::CORAL_FAN_HANG, fn(Reader $in) => Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) - ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::BRAIN() : CoralType::TUBE())); + ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::BRAIN : CoralType::TUBE)); $this->map(Ids::CORAL_FAN_HANG2, fn(Reader $in) => Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) - ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::FIRE() : CoralType::BUBBLE())); + ->setCoralType($in->readBool(StateNames::CORAL_HANG_TYPE_BIT) ? CoralType::FIRE : CoralType::BUBBLE)); $this->map(Ids::CORAL_FAN_HANG3, function(Reader $in) : Block{ $in->ignored(StateNames::CORAL_HANG_TYPE_BIT); //the game always writes this, even though it's not used return Helper::decodeWallCoralFan(Blocks::WALL_CORAL_FAN(), $in) - ->setCoralType(CoralType::HORN()); + ->setCoralType(CoralType::HORN); }); $this->mapStairs(Ids::DARK_PRISMARINE_STAIRS, fn() => Blocks::DARK_PRISMARINE_STAIRS()); $this->map(Ids::DAYLIGHT_DETECTOR, fn(Reader $in) => Helper::decodeDaylightSensor(Blocks::DAYLIGHT_SENSOR(), $in) @@ -986,12 +1066,12 @@ private function registerDeserializers() : void{ $this->map(Ids::DIRT, function(Reader $in) : Block{ return Blocks::DIRT() ->setDirtType(match($value = $in->readString(StateNames::DIRT_TYPE)){ - StringValues::DIRT_TYPE_NORMAL => DirtType::NORMAL(), - StringValues::DIRT_TYPE_COARSE => DirtType::COARSE(), + StringValues::DIRT_TYPE_NORMAL => DirtType::NORMAL, + StringValues::DIRT_TYPE_COARSE => DirtType::COARSE, default => throw $in->badValueException(StateNames::DIRT_TYPE, $value), }); }); - $this->map(Ids::DIRT_WITH_ROOTS, fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED())); + $this->map(Ids::DIRT_WITH_ROOTS, fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED)); $this->map(Ids::DOUBLE_PLANT, function(Reader $in) : Block{ return (match($type = $in->readString(StateNames::DOUBLE_PLANT_TYPE)){ StringValues::DOUBLE_PLANT_TYPE_FERN => Blocks::LARGE_FERN(), @@ -1007,7 +1087,7 @@ private function registerDeserializers() : void{ $this->map(Ids::END_PORTAL_FRAME, function(Reader $in) : Block{ return Blocks::END_PORTAL_FRAME() ->setEye($in->readBool(StateNames::END_PORTAL_EYE_BIT)) - ->setFacing($in->readLegacyHorizontalFacing()); + ->setFacing($in->readCardinalHorizontalFacing()); }); $this->map(Ids::END_ROD, function(Reader $in) : Block{ return Blocks::END_ROD() @@ -1017,10 +1097,10 @@ private function registerDeserializers() : void{ return Blocks::ENDER_CHEST() ->setFacing($in->readHorizontalFacing()); }); - $this->map(Ids::EXPOSED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::EXPOSED())); - $this->map(Ids::EXPOSED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED())); - $this->mapSlab(Ids::EXPOSED_CUT_COPPER_SLAB, Ids::EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED())); - $this->mapStairs(Ids::EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED())); + $this->map(Ids::EXPOSED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); + $this->map(Ids::EXPOSED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); + $this->mapSlab(Ids::EXPOSED_CUT_COPPER_SLAB, Ids::EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); + $this->mapStairs(Ids::EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); $this->map(Ids::FARMLAND, function(Reader $in) : Block{ return Blocks::FARMLAND() ->setWetness($in->readBoundedInt(StateNames::MOISTURIZED_AMOUNT, 0, 7)); @@ -1042,7 +1122,7 @@ private function registerDeserializers() : void{ }); $this->map(Ids::FURNACE, function(Reader $in) : Block{ return Blocks::FURNACE() - ->setFacing($in->readHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setLit(false); }); $this->map(Ids::GLOW_LICHEN, fn(Reader $in) => Blocks::GLOW_LICHEN()->setFaces($in->readFacingFlags())); @@ -1084,21 +1164,21 @@ private function registerDeserializers() : void{ $this->map(Ids::LAVA, fn(Reader $in) => Helper::decodeStillLiquid(Blocks::LAVA(), $in)); $this->map(Ids::LECTERN, function(Reader $in) : Block{ return Blocks::LECTERN() - ->setFacing($in->readLegacyHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setProducingSignal($in->readBool(StateNames::POWERED_BIT)); }); $this->map(Ids::LEVER, function(Reader $in) : Block{ return Blocks::LEVER() ->setActivated($in->readBool(StateNames::OPEN_BIT)) ->setFacing(match($value = $in->readString(StateNames::LEVER_DIRECTION)){ - StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH => LeverFacing::DOWN_AXIS_Z(), - StringValues::LEVER_DIRECTION_DOWN_EAST_WEST => LeverFacing::DOWN_AXIS_X(), - StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH => LeverFacing::UP_AXIS_Z(), - StringValues::LEVER_DIRECTION_UP_EAST_WEST => LeverFacing::UP_AXIS_X(), - StringValues::LEVER_DIRECTION_NORTH => LeverFacing::NORTH(), - StringValues::LEVER_DIRECTION_SOUTH => LeverFacing::SOUTH(), - StringValues::LEVER_DIRECTION_WEST => LeverFacing::WEST(), - StringValues::LEVER_DIRECTION_EAST => LeverFacing::EAST(), + StringValues::LEVER_DIRECTION_DOWN_NORTH_SOUTH => LeverFacing::DOWN_AXIS_Z, + StringValues::LEVER_DIRECTION_DOWN_EAST_WEST => LeverFacing::DOWN_AXIS_X, + StringValues::LEVER_DIRECTION_UP_NORTH_SOUTH => LeverFacing::UP_AXIS_Z, + StringValues::LEVER_DIRECTION_UP_EAST_WEST => LeverFacing::UP_AXIS_X, + StringValues::LEVER_DIRECTION_NORTH => LeverFacing::NORTH, + StringValues::LEVER_DIRECTION_SOUTH => LeverFacing::SOUTH, + StringValues::LEVER_DIRECTION_WEST => LeverFacing::WEST, + StringValues::LEVER_DIRECTION_EAST => LeverFacing::EAST, default => throw $in->badValueException(StateNames::LEVER_DIRECTION, $value), }); }); @@ -1113,13 +1193,13 @@ private function registerDeserializers() : void{ $this->map(Ids::LIGHT_WEIGHTED_PRESSURE_PLATE, fn(Reader $in) => Helper::decodeWeightedPressurePlate(Blocks::WEIGHTED_PRESSURE_PLATE_LIGHT(), $in)); $this->map(Ids::LIT_BLAST_FURNACE, function(Reader $in) : Block{ return Blocks::BLAST_FURNACE() - ->setFacing($in->readHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setLit(true); }); $this->map(Ids::LIT_DEEPSLATE_REDSTONE_ORE, fn() => Blocks::DEEPSLATE_REDSTONE_ORE()->setLit(true)); $this->map(Ids::LIT_FURNACE, function(Reader $in) : Block{ return Blocks::FURNACE() - ->setFacing($in->readHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setLit(true); }); $this->map(Ids::LIT_PUMPKIN, function(Reader $in) : Block{ @@ -1136,7 +1216,7 @@ private function registerDeserializers() : void{ }); $this->map(Ids::LIT_SMOKER, function(Reader $in) : Block{ return Blocks::SMOKER() - ->setFacing($in->readHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setLit(true); }); $this->map(Ids::LOOM, function(Reader $in) : Block{ @@ -1170,17 +1250,17 @@ private function registerDeserializers() : void{ ->setAge($in->readBoundedInt(StateNames::AGE, 0, 3)); }); $this->mapStairs(Ids::NORMAL_STONE_STAIRS, fn() => Blocks::STONE_STAIRS()); - $this->map(Ids::OCHRE_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::OCHRE())->setAxis($in->readPillarAxis())); - $this->map(Ids::OXIDIZED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED())); - $this->map(Ids::OXIDIZED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED())); - $this->mapSlab(Ids::OXIDIZED_CUT_COPPER_SLAB, Ids::OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED())); - $this->mapStairs(Ids::OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED())); - $this->map(Ids::PEARLESCENT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::PEARLESCENT())->setAxis($in->readPillarAxis())); + $this->map(Ids::OCHRE_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::OCHRE)->setAxis($in->readPillarAxis())); + $this->map(Ids::OXIDIZED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); + $this->map(Ids::OXIDIZED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); + $this->mapSlab(Ids::OXIDIZED_CUT_COPPER_SLAB, Ids::OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); + $this->mapStairs(Ids::OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); + $this->map(Ids::PEARLESCENT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::PEARLESCENT)->setAxis($in->readPillarAxis())); $this->map(Ids::PINK_PETALS, function(Reader $in) : Block{ //Pink petals only uses 0-3, but GROWTH state can go up to 7 $growth = $in->readBoundedInt(StateNames::GROWTH, 0, 7); return Blocks::PINK_PETALS() - ->setFacing($in->readLegacyHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setCount(min($growth + 1, PinkPetals::MAX_COUNT)); }); $this->mapStairs(Ids::POLISHED_ANDESITE_STAIRS, fn() => Blocks::POLISHED_ANDESITE_STAIRS()); @@ -1354,12 +1434,12 @@ private function registerDeserializers() : void{ }); $this->map(Ids::SMOKER, function(Reader $in) : Block{ return Blocks::SMOKER() - ->setFacing($in->readHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setLit(false); }); $this->map(Ids::SMALL_DRIPLEAF_BLOCK, function(Reader $in) : Block{ return Blocks::SMALL_DRIPLEAF() - ->setFacing($in->readLegacyHorizontalFacing()) + ->setFacing($in->readCardinalHorizontalFacing()) ->setTop($in->readBool(StateNames::UPPER_BLOCK_BIT)); }); $this->mapStairs(Ids::SMOOTH_QUARTZ_STAIRS, fn() => Blocks::SMOOTH_QUARTZ_STAIRS()); @@ -1388,18 +1468,6 @@ private function registerDeserializers() : void{ default => throw $in->badValueException(StateNames::SPONGE_TYPE, $type), }); }); - $this->map(Ids::STAINED_GLASS, function(Reader $in) : Block{ - return Blocks::STAINED_GLASS() - ->setColor($in->readColor()); - }); - $this->map(Ids::STAINED_GLASS_PANE, function(Reader $in) : Block{ - return Blocks::STAINED_GLASS_PANE() - ->setColor($in->readColor()); - }); - $this->map(Ids::STAINED_HARDENED_CLAY, function(Reader $in) : Block{ - return Blocks::STAINED_CLAY() - ->setColor($in->readColor()); - }); $this->map(Ids::STANDING_BANNER, function(Reader $in) : Block{ return Blocks::BANNER() ->setRotation($in->readBoundedInt(StateNames::GROUND_SIGN_DIRECTION, 0, 15)); @@ -1493,7 +1561,7 @@ private function registerDeserializers() : void{ $this->map(Ids::UNPOWERED_COMPARATOR, fn(Reader $in) => Helper::decodeComparator(Blocks::REDSTONE_COMPARATOR(), $in)); $this->map(Ids::UNPOWERED_REPEATER, fn(Reader $in) => Helper::decodeRepeater(Blocks::REDSTONE_REPEATER(), $in) ->setPowered(false)); - $this->map(Ids::VERDANT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::VERDANT())->setAxis($in->readPillarAxis())); + $this->map(Ids::VERDANT_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::VERDANT)->setAxis($in->readPillarAxis())); $this->map(Ids::VINE, function(Reader $in) : Block{ $vineDirectionFlags = $in->readBoundedInt(StateNames::VINE_DIRECTION_BITS, 0, 15); return Blocks::VINES() @@ -1507,26 +1575,26 @@ private function registerDeserializers() : void{ ->setFacing($in->readHorizontalFacing()); }); $this->map(Ids::WATER, fn(Reader $in) => Helper::decodeStillLiquid(Blocks::WATER(), $in)); - $this->map(Ids::WAXED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::NONE())); - $this->map(Ids::WAXED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE())); - $this->mapSlab(Ids::WAXED_CUT_COPPER_SLAB, Ids::WAXED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE())); - $this->mapStairs(Ids::WAXED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE())); - $this->map(Ids::WAXED_EXPOSED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::EXPOSED())); - $this->map(Ids::WAXED_EXPOSED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED())); - $this->mapSlab(Ids::WAXED_EXPOSED_CUT_COPPER_SLAB, Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED())); - $this->mapStairs(Ids::WAXED_EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED())); - $this->map(Ids::WAXED_OXIDIZED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED())); - $this->map(Ids::WAXED_OXIDIZED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED())); - $this->mapSlab(Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB, Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED())); - $this->mapStairs(Ids::WAXED_OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED())); - $this->map(Ids::WAXED_WEATHERED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::WEATHERED())); - $this->map(Ids::WAXED_WEATHERED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED())); - $this->mapSlab(Ids::WAXED_WEATHERED_CUT_COPPER_SLAB, Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED())); - $this->mapStairs(Ids::WAXED_WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED())); - $this->map(Ids::WEATHERED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::WEATHERED())); - $this->map(Ids::WEATHERED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED())); - $this->mapSlab(Ids::WEATHERED_CUT_COPPER_SLAB, Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED())); - $this->mapStairs(Ids::WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED())); + $this->map(Ids::WAXED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::NONE)); + $this->map(Ids::WAXED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::NONE)); + $this->mapSlab(Ids::WAXED_CUT_COPPER_SLAB, Ids::WAXED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::NONE)); + $this->mapStairs(Ids::WAXED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::NONE)); + $this->map(Ids::WAXED_EXPOSED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::EXPOSED)); + $this->map(Ids::WAXED_EXPOSED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::EXPOSED)); + $this->mapSlab(Ids::WAXED_EXPOSED_CUT_COPPER_SLAB, Ids::WAXED_EXPOSED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::EXPOSED)); + $this->mapStairs(Ids::WAXED_EXPOSED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::EXPOSED)); + $this->map(Ids::WAXED_OXIDIZED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED)); + $this->map(Ids::WAXED_OXIDIZED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED)); + $this->mapSlab(Ids::WAXED_OXIDIZED_CUT_COPPER_SLAB, Ids::WAXED_OXIDIZED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::OXIDIZED)); + $this->mapStairs(Ids::WAXED_OXIDIZED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::OXIDIZED)); + $this->map(Ids::WAXED_WEATHERED_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); + $this->map(Ids::WAXED_WEATHERED_CUT_COPPER, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); + $this->mapSlab(Ids::WAXED_WEATHERED_CUT_COPPER_SLAB, Ids::WAXED_WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); + $this->mapStairs(Ids::WAXED_WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeWaxedCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); + $this->map(Ids::WEATHERED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::WEATHERED)); + $this->map(Ids::WEATHERED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::WEATHERED)); + $this->mapSlab(Ids::WEATHERED_CUT_COPPER_SLAB, Ids::WEATHERED_DOUBLE_CUT_COPPER_SLAB, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_SLAB(), CopperOxidation::WEATHERED)); + $this->mapStairs(Ids::WEATHERED_CUT_COPPER_STAIRS, fn() => Helper::decodeCopper(Blocks::CUT_COPPER_STAIRS(), CopperOxidation::WEATHERED)); $this->map(Ids::WEEPING_VINES, function(Reader $in) : Block{ return Blocks::WEEPING_VINES() ->setAge($in->readBoundedInt(StateNames::WEEPING_VINES_AGE, 0, 25)); diff --git a/src/data/bedrock/block/convert/BlockStateWriter.php b/src/data/bedrock/block/convert/BlockStateWriter.php index 2e2d8daae4..f7884a7f04 100644 --- a/src/data/bedrock/block/convert/BlockStateWriter.php +++ b/src/data/bedrock/block/convert/BlockStateWriter.php @@ -181,24 +181,23 @@ public function writeCardinalHorizontalFacing(int $value) : self{ /** @return $this */ public function writeColor(DyeColor $color) : self{ - $this->writeString(BlockStateNames::COLOR, match($color->id()){ - DyeColor::BLACK()->id() => StringValues::COLOR_BLACK, - DyeColor::BLUE()->id() => StringValues::COLOR_BLUE, - DyeColor::BROWN()->id() => StringValues::COLOR_BROWN, - DyeColor::CYAN()->id() => StringValues::COLOR_CYAN, - DyeColor::GRAY()->id() => StringValues::COLOR_GRAY, - DyeColor::GREEN()->id() => StringValues::COLOR_GREEN, - DyeColor::LIGHT_BLUE()->id() => StringValues::COLOR_LIGHT_BLUE, - DyeColor::LIGHT_GRAY()->id() => StringValues::COLOR_SILVER, - DyeColor::LIME()->id() => StringValues::COLOR_LIME, - DyeColor::MAGENTA()->id() => StringValues::COLOR_MAGENTA, - DyeColor::ORANGE()->id() => StringValues::COLOR_ORANGE, - DyeColor::PINK()->id() => StringValues::COLOR_PINK, - DyeColor::PURPLE()->id() => StringValues::COLOR_PURPLE, - DyeColor::RED()->id() => StringValues::COLOR_RED, - DyeColor::WHITE()->id() => StringValues::COLOR_WHITE, - DyeColor::YELLOW()->id() => StringValues::COLOR_YELLOW, - default => throw new BlockStateSerializeException("Invalid Color " . $color->name()) + $this->writeString(BlockStateNames::COLOR, match($color){ + DyeColor::BLACK => StringValues::COLOR_BLACK, + DyeColor::BLUE => StringValues::COLOR_BLUE, + DyeColor::BROWN => StringValues::COLOR_BROWN, + DyeColor::CYAN => StringValues::COLOR_CYAN, + DyeColor::GRAY => StringValues::COLOR_GRAY, + DyeColor::GREEN => StringValues::COLOR_GREEN, + DyeColor::LIGHT_BLUE => StringValues::COLOR_LIGHT_BLUE, + DyeColor::LIGHT_GRAY => StringValues::COLOR_SILVER, + DyeColor::LIME => StringValues::COLOR_LIME, + DyeColor::MAGENTA => StringValues::COLOR_MAGENTA, + DyeColor::ORANGE => StringValues::COLOR_ORANGE, + DyeColor::PINK => StringValues::COLOR_PINK, + DyeColor::PURPLE => StringValues::COLOR_PURPLE, + DyeColor::RED => StringValues::COLOR_RED, + DyeColor::WHITE => StringValues::COLOR_WHITE, + DyeColor::YELLOW => StringValues::COLOR_YELLOW, }); return $this; } @@ -246,10 +245,10 @@ public function writePillarAxis(int $axis) : self{ /** @return $this */ public function writeSlabPosition(SlabType $slabType) : self{ - $this->writeBool(BlockStateNames::TOP_SLOT_BIT, match($slabType->id()){ - SlabType::TOP()->id() => true, - SlabType::BOTTOM()->id() => false, - default => throw new BlockStateSerializeException("Invalid slab type " . $slabType->name()) + $this->writeString(BlockStateNames::MC_VERTICAL_HALF, match($slabType){ + SlabType::TOP => StringValues::MC_VERTICAL_HALF_TOP, + SlabType::BOTTOM => StringValues::MC_VERTICAL_HALF_BOTTOM, + default => throw new BlockStateSerializeException("Invalid slab type " . $slabType->name) }); return $this; } @@ -270,39 +269,37 @@ public function writeTorchFacing(int $facing) : self{ /** @return $this */ public function writeLegacyWoodType(WoodType $treeType) : self{ - $this->writeString(BlockStateNames::WOOD_TYPE, match($treeType->id()){ - WoodType::OAK()->id() => StringValues::WOOD_TYPE_OAK, - WoodType::SPRUCE()->id() => StringValues::WOOD_TYPE_SPRUCE, - WoodType::BIRCH()->id() => StringValues::WOOD_TYPE_BIRCH, - WoodType::JUNGLE()->id() => StringValues::WOOD_TYPE_JUNGLE, - WoodType::ACACIA()->id() => StringValues::WOOD_TYPE_ACACIA, - WoodType::DARK_OAK()->id() => StringValues::WOOD_TYPE_DARK_OAK, - default => throw new BlockStateSerializeException("Invalid Wood type " . $treeType->name()) + $this->writeString(BlockStateNames::WOOD_TYPE, match($treeType){ + WoodType::OAK => StringValues::WOOD_TYPE_OAK, + WoodType::SPRUCE => StringValues::WOOD_TYPE_SPRUCE, + WoodType::BIRCH => StringValues::WOOD_TYPE_BIRCH, + WoodType::JUNGLE => StringValues::WOOD_TYPE_JUNGLE, + WoodType::ACACIA => StringValues::WOOD_TYPE_ACACIA, + WoodType::DARK_OAK => StringValues::WOOD_TYPE_DARK_OAK, + default => throw new BlockStateSerializeException("Invalid legacy wood type " . $treeType->name) }); return $this; } /** @return $this */ public function writeCoralType(CoralType $coralType) : self{ - $this->writeString(BlockStateNames::CORAL_COLOR, match($coralType->id()){ - CoralType::TUBE()->id() => StringValues::CORAL_COLOR_BLUE, - CoralType::BRAIN()->id() => StringValues::CORAL_COLOR_PINK, - CoralType::BUBBLE()->id() => StringValues::CORAL_COLOR_PURPLE, - CoralType::FIRE()->id() => StringValues::CORAL_COLOR_RED, - CoralType::HORN()->id() => StringValues::CORAL_COLOR_YELLOW, - default => throw new BlockStateSerializeException("Invalid Coral type " . $coralType->name()) + $this->writeString(BlockStateNames::CORAL_COLOR, match($coralType){ + CoralType::TUBE => StringValues::CORAL_COLOR_BLUE, + CoralType::BRAIN => StringValues::CORAL_COLOR_PINK, + CoralType::BUBBLE => StringValues::CORAL_COLOR_PURPLE, + CoralType::FIRE => StringValues::CORAL_COLOR_RED, + CoralType::HORN => StringValues::CORAL_COLOR_YELLOW, }); return $this; } /** @return $this */ public function writeBellAttachmentType(BellAttachmentType $attachmentType) : self{ - $this->writeString(BlockStateNames::ATTACHMENT, match($attachmentType->id()){ - BellAttachmentType::FLOOR()->id() => StringValues::ATTACHMENT_STANDING, - BellAttachmentType::CEILING()->id() => StringValues::ATTACHMENT_HANGING, - BellAttachmentType::ONE_WALL()->id() => StringValues::ATTACHMENT_SIDE, - BellAttachmentType::TWO_WALLS()->id() => StringValues::ATTACHMENT_MULTIPLE, - default => throw new BlockStateSerializeException("Invalid Bell attachment type " . $attachmentType->name()) + $this->writeString(BlockStateNames::ATTACHMENT, match($attachmentType){ + BellAttachmentType::FLOOR => StringValues::ATTACHMENT_STANDING, + BellAttachmentType::CEILING => StringValues::ATTACHMENT_HANGING, + BellAttachmentType::ONE_WALL => StringValues::ATTACHMENT_SIDE, + BellAttachmentType::TWO_WALLS => StringValues::ATTACHMENT_MULTIPLE, }); return $this; } @@ -311,9 +308,8 @@ public function writeBellAttachmentType(BellAttachmentType $attachmentType) : se public function writeWallConnectionType(string $name, ?WallConnectionType $wallConnectionType) : self{ $this->writeString($name, match($wallConnectionType){ null => StringValues::WALL_CONNECTION_TYPE_EAST_NONE, - WallConnectionType::SHORT() => StringValues::WALL_CONNECTION_TYPE_EAST_SHORT, - WallConnectionType::TALL() => StringValues::WALL_CONNECTION_TYPE_EAST_TALL, - default => throw new BlockStateSerializeException("Invalid Wall connection type " . $wallConnectionType->name()) + WallConnectionType::SHORT => StringValues::WALL_CONNECTION_TYPE_EAST_SHORT, + WallConnectionType::TALL => StringValues::WALL_CONNECTION_TYPE_EAST_TALL, }); return $this; } diff --git a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php index bac0fddb6e..928b6d656f 100644 --- a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php +++ b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php @@ -520,7 +520,7 @@ function(SuspiciousStew $item, int $meta) : void{ * complex to implement in a generic way. */ private function registerMiscItemMappings() : void{ - foreach(DyeColor::getAll() as $color){ + foreach(DyeColor::cases() as $color){ $id = DyeColorIdMap::getInstance()->toItemId($color); $this->deserializer?->map($id, fn() => Items::DYE()->setColor($color)); } diff --git a/src/data/bedrock/item/ItemTypeNames.php b/src/data/bedrock/item/ItemTypeNames.php index e0e3820e4c..85f01106a6 100644 --- a/src/data/bedrock/item/ItemTypeNames.php +++ b/src/data/bedrock/item/ItemTypeNames.php @@ -125,6 +125,7 @@ final class ItemTypeNames{ public const COMPASS = "minecraft:compass"; public const COMPOUND = "minecraft:compound"; public const CONCRETE = "minecraft:concrete"; + public const CONCRETE_POWDER = "minecraft:concrete_powder"; public const COOKED_BEEF = "minecraft:cooked_beef"; public const COOKED_CHICKEN = "minecraft:cooked_chicken"; public const COOKED_COD = "minecraft:cooked_cod"; @@ -437,6 +438,9 @@ final class ItemTypeNames{ public const SPRUCE_SIGN = "minecraft:spruce_sign"; public const SPYGLASS = "minecraft:spyglass"; public const SQUID_SPAWN_EGG = "minecraft:squid_spawn_egg"; + public const STAINED_GLASS = "minecraft:stained_glass"; + public const STAINED_GLASS_PANE = "minecraft:stained_glass_pane"; + public const STAINED_HARDENED_CLAY = "minecraft:stained_hardened_clay"; public const STICK = "minecraft:stick"; public const STONE_AXE = "minecraft:stone_axe"; public const STONE_HOE = "minecraft:stone_hoe"; diff --git a/src/data/java/GameModeIdMap.php b/src/data/java/GameModeIdMap.php index 348749b51f..41258dd66e 100644 --- a/src/data/java/GameModeIdMap.php +++ b/src/data/java/GameModeIdMap.php @@ -26,6 +26,7 @@ use pocketmine\player\GameMode; use pocketmine\utils\SingletonTrait; use function array_key_exists; +use function spl_object_id; final class GameModeIdMap{ use SingletonTrait; @@ -43,15 +44,15 @@ final class GameModeIdMap{ private array $enumToId = []; public function __construct(){ - $this->register(0, GameMode::SURVIVAL()); - $this->register(1, GameMode::CREATIVE()); - $this->register(2, GameMode::ADVENTURE()); - $this->register(3, GameMode::SPECTATOR()); + $this->register(0, GameMode::SURVIVAL); + $this->register(1, GameMode::CREATIVE); + $this->register(2, GameMode::ADVENTURE); + $this->register(3, GameMode::SPECTATOR); } private function register(int $id, GameMode $type) : void{ $this->idToEnum[$id] = $type; - $this->enumToId[$type->id()] = $id; + $this->enumToId[spl_object_id($type)] = $id; } public function fromId(int $id) : ?GameMode{ @@ -59,9 +60,10 @@ public function fromId(int $id) : ?GameMode{ } public function toId(GameMode $type) : int{ - if(!array_key_exists($type->id(), $this->enumToId)){ - throw new \InvalidArgumentException("Game mode does not have a mapped ID"); //this should never happen + $k = spl_object_id($type); + if(!array_key_exists($k, $this->enumToId)){ + throw new \InvalidArgumentException("Game mode $type->name does not have a mapped ID"); //this should never happen } - return $this->enumToId[$type->id()]; + return $this->enumToId[$k]; } } diff --git a/src/data/runtime/RuntimeEnumSizeCalculatorTrait.php b/src/data/runtime/LegacyRuntimeEnumDescriberTrait.php similarity index 74% rename from src/data/runtime/RuntimeEnumSizeCalculatorTrait.php rename to src/data/runtime/LegacyRuntimeEnumDescriberTrait.php index 2ab62f03e6..dd35fabfbf 100644 --- a/src/data/runtime/RuntimeEnumSizeCalculatorTrait.php +++ b/src/data/runtime/LegacyRuntimeEnumDescriberTrait.php @@ -24,67 +24,71 @@ namespace pocketmine\data\runtime; /** - * This class is auto-generated. Do not edit it manually. - * @see build/generate-runtime-enum-serializers.php + * Provides backwards-compatible shims for the old codegen'd enum describer methods. + * This is kept for plugin backwards compatibility, but these functions should not be used in new code. + * @deprecated */ -trait RuntimeEnumSizeCalculatorTrait{ +trait LegacyRuntimeEnumDescriberTrait{ - abstract protected function addBits(int $bits) : void; + /** + * @phpstan-template T of \UnitEnum + * @phpstan-param T $case + */ + abstract protected function enum(\UnitEnum &$case) : void; public function bellAttachmentType(\pocketmine\block\utils\BellAttachmentType &$value) : void{ - $this->addBits(2); + $this->enum($value); } public function copperOxidation(\pocketmine\block\utils\CopperOxidation &$value) : void{ - $this->addBits(2); + $this->enum($value); } public function coralType(\pocketmine\block\utils\CoralType &$value) : void{ - $this->addBits(3); + $this->enum($value); } public function dirtType(\pocketmine\block\utils\DirtType &$value) : void{ - $this->addBits(2); + $this->enum($value); } public function dripleafState(\pocketmine\block\utils\DripleafState &$value) : void{ - $this->addBits(2); + $this->enum($value); } public function dyeColor(\pocketmine\block\utils\DyeColor &$value) : void{ - $this->addBits(4); + $this->enum($value); } public function froglightType(\pocketmine\block\utils\FroglightType &$value) : void{ - $this->addBits(2); + $this->enum($value); } public function leverFacing(\pocketmine\block\utils\LeverFacing &$value) : void{ - $this->addBits(3); + $this->enum($value); } public function medicineType(\pocketmine\item\MedicineType &$value) : void{ - $this->addBits(2); + $this->enum($value); } public function mobHeadType(\pocketmine\block\utils\MobHeadType &$value) : void{ - $this->addBits(3); + $this->enum($value); } public function mushroomBlockType(\pocketmine\block\utils\MushroomBlockType &$value) : void{ - $this->addBits(4); + $this->enum($value); } public function potionType(\pocketmine\item\PotionType &$value) : void{ - $this->addBits(6); + $this->enum($value); } public function slabType(\pocketmine\block\utils\SlabType &$value) : void{ - $this->addBits(2); + $this->enum($value); } public function suspiciousStewType(\pocketmine\item\SuspiciousStewType &$value) : void{ - $this->addBits(4); + $this->enum($value); } - } diff --git a/src/data/runtime/RuntimeDataDescriber.php b/src/data/runtime/RuntimeDataDescriber.php index 36822a6f39..2d8c52ec29 100644 --- a/src/data/runtime/RuntimeDataDescriber.php +++ b/src/data/runtime/RuntimeDataDescriber.php @@ -77,4 +77,10 @@ public function brewingStandSlots(array &$slots) : void; public function railShape(int &$railShape) : void; public function straightOnlyRailShape(int &$railShape) : void; + + /** + * @phpstan-template T of \UnitEnum + * @phpstan-param T $case + */ + public function enum(\UnitEnum &$case) : void; } diff --git a/src/data/runtime/RuntimeDataReader.php b/src/data/runtime/RuntimeDataReader.php index 8b0a4b30cd..9b64450733 100644 --- a/src/data/runtime/RuntimeDataReader.php +++ b/src/data/runtime/RuntimeDataReader.php @@ -29,10 +29,12 @@ use pocketmine\math\Axis; use pocketmine\math\Facing; use pocketmine\utils\AssumptionFailedError; +use function get_class; use function intdiv; +use function spl_object_id; final class RuntimeDataReader implements RuntimeDataDescriber{ - use RuntimeEnumDeserializerTrait; + use LegacyRuntimeEnumDescriberTrait; private int $offset = 0; @@ -165,8 +167,8 @@ public function wallConnections(array &$connections) : void{ $type = intdiv($packed, (3 ** $offset)) % 3; if($type !== 0){ $result[$facing] = match($type){ - 1 => WallConnectionType::SHORT(), - 2 => WallConnectionType::TALL(), + 1 => WallConnectionType::SHORT, + 2 => WallConnectionType::TALL, default => throw new AssumptionFailedError("Unreachable") }; } @@ -182,13 +184,9 @@ public function wallConnections(array &$connections) : void{ */ public function brewingStandSlots(array &$slots) : void{ $result = []; - foreach([ - BrewingStandSlot::EAST(), - BrewingStandSlot::NORTHWEST(), - BrewingStandSlot::SOUTHWEST(), - ] as $member){ + foreach(BrewingStandSlot::cases() as $member){ if($this->readBool()){ - $result[$member->id()] = $member; + $result[spl_object_id($member)] = $member; } } @@ -213,5 +211,16 @@ public function straightOnlyRailShape(int &$railShape) : void{ $railShape = $result; } + public function enum(\UnitEnum &$case) : void{ + $metadata = RuntimeEnumMetadata::from($case); + $raw = $this->readInt($metadata->bits); + $result = $metadata->intToEnum($raw); + if($result === null){ + throw new InvalidSerializedRuntimeDataException("Invalid serialized value $raw for " . get_class($case)); + } + + $case = $result; + } + public function getOffset() : int{ return $this->offset; } } diff --git a/src/data/runtime/RuntimeDataSizeCalculator.php b/src/data/runtime/RuntimeDataSizeCalculator.php index 87eec2ba84..82e3602135 100644 --- a/src/data/runtime/RuntimeDataSizeCalculator.php +++ b/src/data/runtime/RuntimeDataSizeCalculator.php @@ -28,7 +28,7 @@ use function count; final class RuntimeDataSizeCalculator implements RuntimeDataDescriber{ - use RuntimeEnumSizeCalculatorTrait; + use LegacyRuntimeEnumDescriberTrait; private int $bits = 0; @@ -85,7 +85,7 @@ public function wallConnections(array &$connections) : void{ } public function brewingStandSlots(array &$slots) : void{ - $this->addBits(count(BrewingStandSlot::getAll())); + $this->addBits(count(BrewingStandSlot::cases())); } public function railShape(int &$railShape) : void{ @@ -95,4 +95,9 @@ public function railShape(int &$railShape) : void{ public function straightOnlyRailShape(int &$railShape) : void{ $this->addBits(3); } + + public function enum(\UnitEnum &$case) : void{ + $metadata = RuntimeEnumMetadata::from($case); + $this->addBits($metadata->bits); + } } diff --git a/src/data/runtime/RuntimeDataWriter.php b/src/data/runtime/RuntimeDataWriter.php index e302967383..9e78875ea0 100644 --- a/src/data/runtime/RuntimeDataWriter.php +++ b/src/data/runtime/RuntimeDataWriter.php @@ -27,11 +27,11 @@ use pocketmine\block\utils\WallConnectionType; use pocketmine\math\Axis; use pocketmine\math\Facing; -use pocketmine\utils\AssumptionFailedError; use function array_flip; +use function spl_object_id; final class RuntimeDataWriter implements RuntimeDataDescriber{ - use RuntimeEnumSerializerTrait; + use LegacyRuntimeEnumDescriberTrait; private int $value = 0; private int $offset = 0; @@ -148,9 +148,8 @@ public function wallConnections(array &$connections) : void{ foreach(Facing::HORIZONTAL as $facing){ $packed += match($connections[$facing] ?? null){ null => 0, - WallConnectionType::SHORT() => 1, - WallConnectionType::TALL() => 2, - default => throw new AssumptionFailedError("Unreachable") + WallConnectionType::SHORT => 1, + WallConnectionType::TALL => 2, } * (3 ** $offset); $offset++; } @@ -162,12 +161,8 @@ public function wallConnections(array &$connections) : void{ * @phpstan-param array $slots */ public function brewingStandSlots(array &$slots) : void{ - foreach([ - BrewingStandSlot::EAST(), - BrewingStandSlot::NORTHWEST(), - BrewingStandSlot::SOUTHWEST(), - ] as $member){ - $this->writeBool(isset($slots[$member->id()])); + foreach(BrewingStandSlot::cases() as $member){ + $this->writeBool(isset($slots[spl_object_id($member)])); } } @@ -179,6 +174,11 @@ public function straightOnlyRailShape(int &$railShape) : void{ $this->int(3, $railShape); } + public function enum(\UnitEnum &$case) : void{ + $metadata = RuntimeEnumMetadata::from($case); + $this->writeInt($metadata->bits, $metadata->enumToInt($case)); + } + public function getValue() : int{ return $this->value; } public function getOffset() : int{ return $this->offset; } diff --git a/src/data/runtime/RuntimeEnumDescriber.php b/src/data/runtime/RuntimeEnumDescriber.php index 7103017f75..79550d041b 100644 --- a/src/data/runtime/RuntimeEnumDescriber.php +++ b/src/data/runtime/RuntimeEnumDescriber.php @@ -24,8 +24,9 @@ namespace pocketmine\data\runtime; /** - * This class is auto-generated. Do not edit it manually. - * @see build/generate-runtime-enum-serializers.php + * Provides backwards-compatible shims for the old codegen'd enum describer methods. + * This is kept for plugin backwards compatibility, but these functions should not be used in new code. + * @deprecated */ interface RuntimeEnumDescriber{ diff --git a/src/data/runtime/RuntimeEnumDeserializerTrait.php b/src/data/runtime/RuntimeEnumDeserializerTrait.php deleted file mode 100644 index 7d80a6f547..0000000000 --- a/src/data/runtime/RuntimeEnumDeserializerTrait.php +++ /dev/null @@ -1,243 +0,0 @@ -readInt(2)){ - 0 => \pocketmine\block\utils\BellAttachmentType::CEILING(), - 1 => \pocketmine\block\utils\BellAttachmentType::FLOOR(), - 2 => \pocketmine\block\utils\BellAttachmentType::ONE_WALL(), - 3 => \pocketmine\block\utils\BellAttachmentType::TWO_WALLS(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for BellAttachmentType") - }; - } - - public function copperOxidation(\pocketmine\block\utils\CopperOxidation &$value) : void{ - $value = match($this->readInt(2)){ - 0 => \pocketmine\block\utils\CopperOxidation::EXPOSED(), - 1 => \pocketmine\block\utils\CopperOxidation::NONE(), - 2 => \pocketmine\block\utils\CopperOxidation::OXIDIZED(), - 3 => \pocketmine\block\utils\CopperOxidation::WEATHERED(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for CopperOxidation") - }; - } - - public function coralType(\pocketmine\block\utils\CoralType &$value) : void{ - $value = match($this->readInt(3)){ - 0 => \pocketmine\block\utils\CoralType::BRAIN(), - 1 => \pocketmine\block\utils\CoralType::BUBBLE(), - 2 => \pocketmine\block\utils\CoralType::FIRE(), - 3 => \pocketmine\block\utils\CoralType::HORN(), - 4 => \pocketmine\block\utils\CoralType::TUBE(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for CoralType") - }; - } - - public function dirtType(\pocketmine\block\utils\DirtType &$value) : void{ - $value = match($this->readInt(2)){ - 0 => \pocketmine\block\utils\DirtType::COARSE(), - 1 => \pocketmine\block\utils\DirtType::NORMAL(), - 2 => \pocketmine\block\utils\DirtType::ROOTED(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for DirtType") - }; - } - - public function dripleafState(\pocketmine\block\utils\DripleafState &$value) : void{ - $value = match($this->readInt(2)){ - 0 => \pocketmine\block\utils\DripleafState::FULL_TILT(), - 1 => \pocketmine\block\utils\DripleafState::PARTIAL_TILT(), - 2 => \pocketmine\block\utils\DripleafState::STABLE(), - 3 => \pocketmine\block\utils\DripleafState::UNSTABLE(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for DripleafState") - }; - } - - public function dyeColor(\pocketmine\block\utils\DyeColor &$value) : void{ - $value = match($this->readInt(4)){ - 0 => \pocketmine\block\utils\DyeColor::BLACK(), - 1 => \pocketmine\block\utils\DyeColor::BLUE(), - 2 => \pocketmine\block\utils\DyeColor::BROWN(), - 3 => \pocketmine\block\utils\DyeColor::CYAN(), - 4 => \pocketmine\block\utils\DyeColor::GRAY(), - 5 => \pocketmine\block\utils\DyeColor::GREEN(), - 6 => \pocketmine\block\utils\DyeColor::LIGHT_BLUE(), - 7 => \pocketmine\block\utils\DyeColor::LIGHT_GRAY(), - 8 => \pocketmine\block\utils\DyeColor::LIME(), - 9 => \pocketmine\block\utils\DyeColor::MAGENTA(), - 10 => \pocketmine\block\utils\DyeColor::ORANGE(), - 11 => \pocketmine\block\utils\DyeColor::PINK(), - 12 => \pocketmine\block\utils\DyeColor::PURPLE(), - 13 => \pocketmine\block\utils\DyeColor::RED(), - 14 => \pocketmine\block\utils\DyeColor::WHITE(), - 15 => \pocketmine\block\utils\DyeColor::YELLOW(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for DyeColor") - }; - } - - public function froglightType(\pocketmine\block\utils\FroglightType &$value) : void{ - $value = match($this->readInt(2)){ - 0 => \pocketmine\block\utils\FroglightType::OCHRE(), - 1 => \pocketmine\block\utils\FroglightType::PEARLESCENT(), - 2 => \pocketmine\block\utils\FroglightType::VERDANT(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for FroglightType") - }; - } - - public function leverFacing(\pocketmine\block\utils\LeverFacing &$value) : void{ - $value = match($this->readInt(3)){ - 0 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X(), - 1 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z(), - 2 => \pocketmine\block\utils\LeverFacing::EAST(), - 3 => \pocketmine\block\utils\LeverFacing::NORTH(), - 4 => \pocketmine\block\utils\LeverFacing::SOUTH(), - 5 => \pocketmine\block\utils\LeverFacing::UP_AXIS_X(), - 6 => \pocketmine\block\utils\LeverFacing::UP_AXIS_Z(), - 7 => \pocketmine\block\utils\LeverFacing::WEST(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for LeverFacing") - }; - } - - public function medicineType(\pocketmine\item\MedicineType &$value) : void{ - $value = match($this->readInt(2)){ - 0 => \pocketmine\item\MedicineType::ANTIDOTE(), - 1 => \pocketmine\item\MedicineType::ELIXIR(), - 2 => \pocketmine\item\MedicineType::EYE_DROPS(), - 3 => \pocketmine\item\MedicineType::TONIC(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for MedicineType") - }; - } - - public function mobHeadType(\pocketmine\block\utils\MobHeadType &$value) : void{ - $value = match($this->readInt(3)){ - 0 => \pocketmine\block\utils\MobHeadType::CREEPER(), - 1 => \pocketmine\block\utils\MobHeadType::DRAGON(), - 2 => \pocketmine\block\utils\MobHeadType::PIGLIN(), - 3 => \pocketmine\block\utils\MobHeadType::PLAYER(), - 4 => \pocketmine\block\utils\MobHeadType::SKELETON(), - 5 => \pocketmine\block\utils\MobHeadType::WITHER_SKELETON(), - 6 => \pocketmine\block\utils\MobHeadType::ZOMBIE(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for MobHeadType") - }; - } - - public function mushroomBlockType(\pocketmine\block\utils\MushroomBlockType &$value) : void{ - $value = match($this->readInt(4)){ - 0 => \pocketmine\block\utils\MushroomBlockType::ALL_CAP(), - 1 => \pocketmine\block\utils\MushroomBlockType::CAP_EAST(), - 2 => \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE(), - 3 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTH(), - 4 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHEAST(), - 5 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHWEST(), - 6 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTH(), - 7 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHEAST(), - 8 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHWEST(), - 9 => \pocketmine\block\utils\MushroomBlockType::CAP_WEST(), - 10 => \pocketmine\block\utils\MushroomBlockType::PORES(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for MushroomBlockType") - }; - } - - public function potionType(\pocketmine\item\PotionType &$value) : void{ - $value = match($this->readInt(6)){ - 0 => \pocketmine\item\PotionType::AWKWARD(), - 1 => \pocketmine\item\PotionType::FIRE_RESISTANCE(), - 2 => \pocketmine\item\PotionType::HARMING(), - 3 => \pocketmine\item\PotionType::HEALING(), - 4 => \pocketmine\item\PotionType::INVISIBILITY(), - 5 => \pocketmine\item\PotionType::LEAPING(), - 6 => \pocketmine\item\PotionType::LONG_FIRE_RESISTANCE(), - 7 => \pocketmine\item\PotionType::LONG_INVISIBILITY(), - 8 => \pocketmine\item\PotionType::LONG_LEAPING(), - 9 => \pocketmine\item\PotionType::LONG_MUNDANE(), - 10 => \pocketmine\item\PotionType::LONG_NIGHT_VISION(), - 11 => \pocketmine\item\PotionType::LONG_POISON(), - 12 => \pocketmine\item\PotionType::LONG_REGENERATION(), - 13 => \pocketmine\item\PotionType::LONG_SLOWNESS(), - 14 => \pocketmine\item\PotionType::LONG_SLOW_FALLING(), - 15 => \pocketmine\item\PotionType::LONG_STRENGTH(), - 16 => \pocketmine\item\PotionType::LONG_SWIFTNESS(), - 17 => \pocketmine\item\PotionType::LONG_TURTLE_MASTER(), - 18 => \pocketmine\item\PotionType::LONG_WATER_BREATHING(), - 19 => \pocketmine\item\PotionType::LONG_WEAKNESS(), - 20 => \pocketmine\item\PotionType::MUNDANE(), - 21 => \pocketmine\item\PotionType::NIGHT_VISION(), - 22 => \pocketmine\item\PotionType::POISON(), - 23 => \pocketmine\item\PotionType::REGENERATION(), - 24 => \pocketmine\item\PotionType::SLOWNESS(), - 25 => \pocketmine\item\PotionType::SLOW_FALLING(), - 26 => \pocketmine\item\PotionType::STRENGTH(), - 27 => \pocketmine\item\PotionType::STRONG_HARMING(), - 28 => \pocketmine\item\PotionType::STRONG_HEALING(), - 29 => \pocketmine\item\PotionType::STRONG_LEAPING(), - 30 => \pocketmine\item\PotionType::STRONG_POISON(), - 31 => \pocketmine\item\PotionType::STRONG_REGENERATION(), - 32 => \pocketmine\item\PotionType::STRONG_SLOWNESS(), - 33 => \pocketmine\item\PotionType::STRONG_STRENGTH(), - 34 => \pocketmine\item\PotionType::STRONG_SWIFTNESS(), - 35 => \pocketmine\item\PotionType::STRONG_TURTLE_MASTER(), - 36 => \pocketmine\item\PotionType::SWIFTNESS(), - 37 => \pocketmine\item\PotionType::THICK(), - 38 => \pocketmine\item\PotionType::TURTLE_MASTER(), - 39 => \pocketmine\item\PotionType::WATER(), - 40 => \pocketmine\item\PotionType::WATER_BREATHING(), - 41 => \pocketmine\item\PotionType::WEAKNESS(), - 42 => \pocketmine\item\PotionType::WITHER(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for PotionType") - }; - } - - public function slabType(\pocketmine\block\utils\SlabType &$value) : void{ - $value = match($this->readInt(2)){ - 0 => \pocketmine\block\utils\SlabType::BOTTOM(), - 1 => \pocketmine\block\utils\SlabType::DOUBLE(), - 2 => \pocketmine\block\utils\SlabType::TOP(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for SlabType") - }; - } - - public function suspiciousStewType(\pocketmine\item\SuspiciousStewType &$value) : void{ - $value = match($this->readInt(4)){ - 0 => \pocketmine\item\SuspiciousStewType::ALLIUM(), - 1 => \pocketmine\item\SuspiciousStewType::AZURE_BLUET(), - 2 => \pocketmine\item\SuspiciousStewType::BLUE_ORCHID(), - 3 => \pocketmine\item\SuspiciousStewType::CORNFLOWER(), - 4 => \pocketmine\item\SuspiciousStewType::DANDELION(), - 5 => \pocketmine\item\SuspiciousStewType::LILY_OF_THE_VALLEY(), - 6 => \pocketmine\item\SuspiciousStewType::OXEYE_DAISY(), - 7 => \pocketmine\item\SuspiciousStewType::POPPY(), - 8 => \pocketmine\item\SuspiciousStewType::TULIP(), - 9 => \pocketmine\item\SuspiciousStewType::WITHER_ROSE(), - default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for SuspiciousStewType") - }; - } - -} diff --git a/src/data/runtime/RuntimeEnumMetadata.php b/src/data/runtime/RuntimeEnumMetadata.php new file mode 100644 index 0000000000..261b7a1bc3 --- /dev/null +++ b/src/data/runtime/RuntimeEnumMetadata.php @@ -0,0 +1,114 @@ + + */ + private readonly array $intToEnum; + /** + * @var int[] + * @phpstan-var array + */ + private readonly array $enumToInt; + + /** + * @param \UnitEnum[] $members + * @phpstan-param list $members + */ + public function __construct( + array $members + ){ + usort($members, fn(\UnitEnum $a, \UnitEnum $b) => $a->name <=> $b->name); //sort by name to ensure consistent ordering (and thus consistent bit assignments) + + $this->bits = (int) ceil(log(count($members), 2)); + $this->intToEnum = array_values($members); + + $reversed = []; + foreach($this->intToEnum as $int => $enum){ + $reversed[spl_object_id($enum)] = $int; + } + + $this->enumToInt = $reversed; + } + + /** + * @phpstan-return T|null + */ + public function intToEnum(int $value) : ?object{ + return $this->intToEnum[$value] ?? null; + } + + /** + * @phpstan-param T $enum + */ + public function enumToInt(object $enum) : int{ + return $this->enumToInt[spl_object_id($enum)]; + } + + /** + * @var self[] + * @phpstan-var array + */ + private static array $cache = []; + + /** + * @phpstan-template TEnum of \UnitEnum + * @phpstan-param TEnum $case + * + * @phpstan-return self + */ + public static function from(\UnitEnum $case) : self{ + $class = $case::class; + /** @phpstan-var self|null $metadata */ + $metadata = self::$cache[$class] ?? null; + if($metadata === null){ + /** + * PHPStan can't infer this correctly :( https://github.com/phpstan/phpstan/issues/7162 + * @phpstan-var list $cases + */ + $cases = $case::cases(); + self::$cache[$class] = $metadata = new self($cases); + } + + return $metadata; + } +} diff --git a/src/data/runtime/RuntimeEnumSerializerTrait.php b/src/data/runtime/RuntimeEnumSerializerTrait.php deleted file mode 100644 index 8c3d671181..0000000000 --- a/src/data/runtime/RuntimeEnumSerializerTrait.php +++ /dev/null @@ -1,243 +0,0 @@ -writeInt(2, match($value){ - \pocketmine\block\utils\BellAttachmentType::CEILING() => 0, - \pocketmine\block\utils\BellAttachmentType::FLOOR() => 1, - \pocketmine\block\utils\BellAttachmentType::ONE_WALL() => 2, - \pocketmine\block\utils\BellAttachmentType::TWO_WALLS() => 3, - default => throw new \pocketmine\utils\AssumptionFailedError("All BellAttachmentType cases should be covered") - }); - } - - public function copperOxidation(\pocketmine\block\utils\CopperOxidation &$value) : void{ - $this->writeInt(2, match($value){ - \pocketmine\block\utils\CopperOxidation::EXPOSED() => 0, - \pocketmine\block\utils\CopperOxidation::NONE() => 1, - \pocketmine\block\utils\CopperOxidation::OXIDIZED() => 2, - \pocketmine\block\utils\CopperOxidation::WEATHERED() => 3, - default => throw new \pocketmine\utils\AssumptionFailedError("All CopperOxidation cases should be covered") - }); - } - - public function coralType(\pocketmine\block\utils\CoralType &$value) : void{ - $this->writeInt(3, match($value){ - \pocketmine\block\utils\CoralType::BRAIN() => 0, - \pocketmine\block\utils\CoralType::BUBBLE() => 1, - \pocketmine\block\utils\CoralType::FIRE() => 2, - \pocketmine\block\utils\CoralType::HORN() => 3, - \pocketmine\block\utils\CoralType::TUBE() => 4, - default => throw new \pocketmine\utils\AssumptionFailedError("All CoralType cases should be covered") - }); - } - - public function dirtType(\pocketmine\block\utils\DirtType &$value) : void{ - $this->writeInt(2, match($value){ - \pocketmine\block\utils\DirtType::COARSE() => 0, - \pocketmine\block\utils\DirtType::NORMAL() => 1, - \pocketmine\block\utils\DirtType::ROOTED() => 2, - default => throw new \pocketmine\utils\AssumptionFailedError("All DirtType cases should be covered") - }); - } - - public function dripleafState(\pocketmine\block\utils\DripleafState &$value) : void{ - $this->writeInt(2, match($value){ - \pocketmine\block\utils\DripleafState::FULL_TILT() => 0, - \pocketmine\block\utils\DripleafState::PARTIAL_TILT() => 1, - \pocketmine\block\utils\DripleafState::STABLE() => 2, - \pocketmine\block\utils\DripleafState::UNSTABLE() => 3, - default => throw new \pocketmine\utils\AssumptionFailedError("All DripleafState cases should be covered") - }); - } - - public function dyeColor(\pocketmine\block\utils\DyeColor &$value) : void{ - $this->writeInt(4, match($value){ - \pocketmine\block\utils\DyeColor::BLACK() => 0, - \pocketmine\block\utils\DyeColor::BLUE() => 1, - \pocketmine\block\utils\DyeColor::BROWN() => 2, - \pocketmine\block\utils\DyeColor::CYAN() => 3, - \pocketmine\block\utils\DyeColor::GRAY() => 4, - \pocketmine\block\utils\DyeColor::GREEN() => 5, - \pocketmine\block\utils\DyeColor::LIGHT_BLUE() => 6, - \pocketmine\block\utils\DyeColor::LIGHT_GRAY() => 7, - \pocketmine\block\utils\DyeColor::LIME() => 8, - \pocketmine\block\utils\DyeColor::MAGENTA() => 9, - \pocketmine\block\utils\DyeColor::ORANGE() => 10, - \pocketmine\block\utils\DyeColor::PINK() => 11, - \pocketmine\block\utils\DyeColor::PURPLE() => 12, - \pocketmine\block\utils\DyeColor::RED() => 13, - \pocketmine\block\utils\DyeColor::WHITE() => 14, - \pocketmine\block\utils\DyeColor::YELLOW() => 15, - default => throw new \pocketmine\utils\AssumptionFailedError("All DyeColor cases should be covered") - }); - } - - public function froglightType(\pocketmine\block\utils\FroglightType &$value) : void{ - $this->writeInt(2, match($value){ - \pocketmine\block\utils\FroglightType::OCHRE() => 0, - \pocketmine\block\utils\FroglightType::PEARLESCENT() => 1, - \pocketmine\block\utils\FroglightType::VERDANT() => 2, - default => throw new \pocketmine\utils\AssumptionFailedError("All FroglightType cases should be covered") - }); - } - - public function leverFacing(\pocketmine\block\utils\LeverFacing &$value) : void{ - $this->writeInt(3, match($value){ - \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X() => 0, - \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z() => 1, - \pocketmine\block\utils\LeverFacing::EAST() => 2, - \pocketmine\block\utils\LeverFacing::NORTH() => 3, - \pocketmine\block\utils\LeverFacing::SOUTH() => 4, - \pocketmine\block\utils\LeverFacing::UP_AXIS_X() => 5, - \pocketmine\block\utils\LeverFacing::UP_AXIS_Z() => 6, - \pocketmine\block\utils\LeverFacing::WEST() => 7, - default => throw new \pocketmine\utils\AssumptionFailedError("All LeverFacing cases should be covered") - }); - } - - public function medicineType(\pocketmine\item\MedicineType &$value) : void{ - $this->writeInt(2, match($value){ - \pocketmine\item\MedicineType::ANTIDOTE() => 0, - \pocketmine\item\MedicineType::ELIXIR() => 1, - \pocketmine\item\MedicineType::EYE_DROPS() => 2, - \pocketmine\item\MedicineType::TONIC() => 3, - default => throw new \pocketmine\utils\AssumptionFailedError("All MedicineType cases should be covered") - }); - } - - public function mobHeadType(\pocketmine\block\utils\MobHeadType &$value) : void{ - $this->writeInt(3, match($value){ - \pocketmine\block\utils\MobHeadType::CREEPER() => 0, - \pocketmine\block\utils\MobHeadType::DRAGON() => 1, - \pocketmine\block\utils\MobHeadType::PIGLIN() => 2, - \pocketmine\block\utils\MobHeadType::PLAYER() => 3, - \pocketmine\block\utils\MobHeadType::SKELETON() => 4, - \pocketmine\block\utils\MobHeadType::WITHER_SKELETON() => 5, - \pocketmine\block\utils\MobHeadType::ZOMBIE() => 6, - default => throw new \pocketmine\utils\AssumptionFailedError("All MobHeadType cases should be covered") - }); - } - - public function mushroomBlockType(\pocketmine\block\utils\MushroomBlockType &$value) : void{ - $this->writeInt(4, match($value){ - \pocketmine\block\utils\MushroomBlockType::ALL_CAP() => 0, - \pocketmine\block\utils\MushroomBlockType::CAP_EAST() => 1, - \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE() => 2, - \pocketmine\block\utils\MushroomBlockType::CAP_NORTH() => 3, - \pocketmine\block\utils\MushroomBlockType::CAP_NORTHEAST() => 4, - \pocketmine\block\utils\MushroomBlockType::CAP_NORTHWEST() => 5, - \pocketmine\block\utils\MushroomBlockType::CAP_SOUTH() => 6, - \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHEAST() => 7, - \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHWEST() => 8, - \pocketmine\block\utils\MushroomBlockType::CAP_WEST() => 9, - \pocketmine\block\utils\MushroomBlockType::PORES() => 10, - default => throw new \pocketmine\utils\AssumptionFailedError("All MushroomBlockType cases should be covered") - }); - } - - public function potionType(\pocketmine\item\PotionType &$value) : void{ - $this->writeInt(6, match($value){ - \pocketmine\item\PotionType::AWKWARD() => 0, - \pocketmine\item\PotionType::FIRE_RESISTANCE() => 1, - \pocketmine\item\PotionType::HARMING() => 2, - \pocketmine\item\PotionType::HEALING() => 3, - \pocketmine\item\PotionType::INVISIBILITY() => 4, - \pocketmine\item\PotionType::LEAPING() => 5, - \pocketmine\item\PotionType::LONG_FIRE_RESISTANCE() => 6, - \pocketmine\item\PotionType::LONG_INVISIBILITY() => 7, - \pocketmine\item\PotionType::LONG_LEAPING() => 8, - \pocketmine\item\PotionType::LONG_MUNDANE() => 9, - \pocketmine\item\PotionType::LONG_NIGHT_VISION() => 10, - \pocketmine\item\PotionType::LONG_POISON() => 11, - \pocketmine\item\PotionType::LONG_REGENERATION() => 12, - \pocketmine\item\PotionType::LONG_SLOWNESS() => 13, - \pocketmine\item\PotionType::LONG_SLOW_FALLING() => 14, - \pocketmine\item\PotionType::LONG_STRENGTH() => 15, - \pocketmine\item\PotionType::LONG_SWIFTNESS() => 16, - \pocketmine\item\PotionType::LONG_TURTLE_MASTER() => 17, - \pocketmine\item\PotionType::LONG_WATER_BREATHING() => 18, - \pocketmine\item\PotionType::LONG_WEAKNESS() => 19, - \pocketmine\item\PotionType::MUNDANE() => 20, - \pocketmine\item\PotionType::NIGHT_VISION() => 21, - \pocketmine\item\PotionType::POISON() => 22, - \pocketmine\item\PotionType::REGENERATION() => 23, - \pocketmine\item\PotionType::SLOWNESS() => 24, - \pocketmine\item\PotionType::SLOW_FALLING() => 25, - \pocketmine\item\PotionType::STRENGTH() => 26, - \pocketmine\item\PotionType::STRONG_HARMING() => 27, - \pocketmine\item\PotionType::STRONG_HEALING() => 28, - \pocketmine\item\PotionType::STRONG_LEAPING() => 29, - \pocketmine\item\PotionType::STRONG_POISON() => 30, - \pocketmine\item\PotionType::STRONG_REGENERATION() => 31, - \pocketmine\item\PotionType::STRONG_SLOWNESS() => 32, - \pocketmine\item\PotionType::STRONG_STRENGTH() => 33, - \pocketmine\item\PotionType::STRONG_SWIFTNESS() => 34, - \pocketmine\item\PotionType::STRONG_TURTLE_MASTER() => 35, - \pocketmine\item\PotionType::SWIFTNESS() => 36, - \pocketmine\item\PotionType::THICK() => 37, - \pocketmine\item\PotionType::TURTLE_MASTER() => 38, - \pocketmine\item\PotionType::WATER() => 39, - \pocketmine\item\PotionType::WATER_BREATHING() => 40, - \pocketmine\item\PotionType::WEAKNESS() => 41, - \pocketmine\item\PotionType::WITHER() => 42, - default => throw new \pocketmine\utils\AssumptionFailedError("All PotionType cases should be covered") - }); - } - - public function slabType(\pocketmine\block\utils\SlabType &$value) : void{ - $this->writeInt(2, match($value){ - \pocketmine\block\utils\SlabType::BOTTOM() => 0, - \pocketmine\block\utils\SlabType::DOUBLE() => 1, - \pocketmine\block\utils\SlabType::TOP() => 2, - default => throw new \pocketmine\utils\AssumptionFailedError("All SlabType cases should be covered") - }); - } - - public function suspiciousStewType(\pocketmine\item\SuspiciousStewType &$value) : void{ - $this->writeInt(4, match($value){ - \pocketmine\item\SuspiciousStewType::ALLIUM() => 0, - \pocketmine\item\SuspiciousStewType::AZURE_BLUET() => 1, - \pocketmine\item\SuspiciousStewType::BLUE_ORCHID() => 2, - \pocketmine\item\SuspiciousStewType::CORNFLOWER() => 3, - \pocketmine\item\SuspiciousStewType::DANDELION() => 4, - \pocketmine\item\SuspiciousStewType::LILY_OF_THE_VALLEY() => 5, - \pocketmine\item\SuspiciousStewType::OXEYE_DAISY() => 6, - \pocketmine\item\SuspiciousStewType::POPPY() => 7, - \pocketmine\item\SuspiciousStewType::TULIP() => 8, - \pocketmine\item\SuspiciousStewType::WITHER_ROSE() => 9, - default => throw new \pocketmine\utils\AssumptionFailedError("All SuspiciousStewType cases should be covered") - }); - } - -} diff --git a/src/entity/Human.php b/src/entity/Human.php index 436e336a8a..17c59f262d 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -37,6 +37,7 @@ use pocketmine\inventory\PlayerEnderInventory; use pocketmine\inventory\PlayerInventory; use pocketmine\inventory\PlayerOffHandInventory; +use pocketmine\item\enchantment\EnchantingHelper; use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\Item; use pocketmine\item\Totem; @@ -67,7 +68,6 @@ use pocketmine\network\mcpe\protocol\types\PlayerPermissions; use pocketmine\network\mcpe\protocol\UpdateAbilitiesPacket; use pocketmine\player\Player; -use pocketmine\utils\Limits; use pocketmine\world\sound\TotemUseSound; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; @@ -78,7 +78,6 @@ use function array_merge; use function array_values; use function min; -use function mt_rand; class Human extends Living implements ProjectileSource, InventoryHolder{ @@ -227,8 +226,8 @@ public function setEnchantmentSeed(int $seed) : void{ $this->xpSeed = $seed; } - public function generateEnchantmentSeed() : int{ - return mt_rand(Limits::INT32_MIN, Limits::INT32_MAX); + public function regenerateEnchantmentSeed() : void{ + $this->xpSeed = EnchantingHelper::generateSeed(); } public function getXpDropAmount() : int{ @@ -362,7 +361,7 @@ function(Inventory $unused, array $oldItems) use ($syncHeldItem) : void{ if(($xpSeedTag = $nbt->getTag(self::TAG_XP_SEED)) instanceof IntTag){ $this->xpSeed = $xpSeedTag->getValue(); }else{ - $this->xpSeed = $this->generateEnchantmentSeed(); + $this->xpSeed = EnchantingHelper::generateSeed(); } } diff --git a/src/entity/HungerManager.php b/src/entity/HungerManager.php index 304dcd30b4..a318558918 100644 --- a/src/entity/HungerManager.php +++ b/src/entity/HungerManager.php @@ -133,14 +133,18 @@ public function exhaust(float $amount, int $cause = PlayerExhaustEvent::CAUSE_CU if(!$this->enabled){ return 0; } - $ev = new PlayerExhaustEvent($this->entity, $amount, $cause); - $ev->call(); - if($ev->isCancelled()){ - return 0.0; + $evAmount = $amount; + if(PlayerExhaustEvent::hasHandlers()){ + $ev = new PlayerExhaustEvent($this->entity, $amount, $cause); + $ev->call(); + if($ev->isCancelled()){ + return 0.0; + } + $evAmount = $ev->getAmount(); } $exhaustion = $this->getExhaustion(); - $exhaustion += $ev->getAmount(); + $exhaustion += $evAmount; while($exhaustion >= 4.0){ $exhaustion -= 4.0; @@ -159,7 +163,7 @@ public function exhaust(float $amount, int $cause = PlayerExhaustEvent::CAUSE_CU } $this->setExhaustion($exhaustion); - return $ev->getAmount(); + return $evAmount; } public function getFoodTickTimer() : int{ diff --git a/src/entity/projectile/SplashPotion.php b/src/entity/projectile/SplashPotion.php index 622c6b097f..033d371255 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -128,7 +128,7 @@ protected function onHit(ProjectileHitEvent $event) : void{ }else{ //TODO: lingering potions } - }elseif($event instanceof ProjectileHitBlockEvent && $this->getPotionType()->equals(PotionType::WATER())){ + }elseif($event instanceof ProjectileHitBlockEvent && $this->getPotionType() === PotionType::WATER){ $blockIn = $event->getBlockHit()->getSide($event->getRayTraceResult()->getHitFace()); if($blockIn->hasTypeTag(BlockTypeTags::FIRE)){ diff --git a/src/event/block/PressurePlateUpdateEvent.php b/src/event/block/PressurePlateUpdateEvent.php index 485a3a6bea..e6f2e92ba4 100644 --- a/src/event/block/PressurePlateUpdateEvent.php +++ b/src/event/block/PressurePlateUpdateEvent.php @@ -25,13 +25,12 @@ use pocketmine\block\Block; use pocketmine\entity\Entity; -use pocketmine\event\Cancellable; /** * Called whenever the list of entities on a pressure plate changes. * Depending on the type of pressure plate, this might turn on/off its signal, or change the signal strength. */ -final class PressurePlateUpdateEvent extends BaseBlockChangeEvent implements Cancellable{ +final class PressurePlateUpdateEvent extends BaseBlockChangeEvent{ /** * @param Entity[] $activatingEntities */ diff --git a/src/event/player/PlayerEnchantOptionsRequestEvent.php b/src/event/player/PlayerEnchantingOptionsRequestEvent.php similarity index 77% rename from src/event/player/PlayerEnchantOptionsRequestEvent.php rename to src/event/player/PlayerEnchantingOptionsRequestEvent.php index 0d5b1a3949..833185f760 100644 --- a/src/event/player/PlayerEnchantOptionsRequestEvent.php +++ b/src/event/player/PlayerEnchantingOptionsRequestEvent.php @@ -26,7 +26,8 @@ use pocketmine\block\inventory\EnchantInventory; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; -use pocketmine\item\enchantment\EnchantOption; +use pocketmine\event\Event; +use pocketmine\item\enchantment\EnchantingOption; use pocketmine\player\Player; use pocketmine\utils\Utils; use function count; @@ -35,36 +36,36 @@ * Called when a player inserts an item into an enchanting table's input slot. * The options provided by the event will be shown on the enchanting table menu. */ -class PlayerEnchantOptionsRequestEvent extends PlayerEvent implements Cancellable{ +class PlayerEnchantingOptionsRequestEvent extends PlayerEvent implements Cancellable{ use CancellableTrait; /** - * @param EnchantOption[] $options + * @param EnchantingOption[] $options */ public function __construct( Player $player, - private readonly EnchantInventory $enchantInventory, + private readonly EnchantInventory $inventory, private array $options ){ $this->player = $player; } - public function getEnchantInventory() : EnchantInventory{ - return $this->enchantInventory; + public function getInventory() : EnchantInventory{ + return $this->inventory; } /** - * @return EnchantOption[] + * @return EnchantingOption[] */ public function getOptions() : array{ return $this->options; } /** - * @param EnchantOption[] $options + * @param EnchantingOption[] $options */ public function setOptions(array $options) : void{ - Utils::validateArrayValueType($options, function(EnchantOption $_) : void{ }); + Utils::validateArrayValueType($options, function(EnchantingOption $_) : void{ }); if(($optionCount = count($options)) > 3){ throw new \LogicException("The maximum number of options for an enchanting table is 3, but $optionCount have been passed"); } diff --git a/src/event/player/PlayerItemEnchantEvent.php b/src/event/player/PlayerItemEnchantEvent.php index 9974ab40a2..76151384d3 100644 --- a/src/event/player/PlayerItemEnchantEvent.php +++ b/src/event/player/PlayerItemEnchantEvent.php @@ -25,8 +25,8 @@ use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; -use pocketmine\inventory\transaction\EnchantTransaction; -use pocketmine\item\enchantment\EnchantOption; +use pocketmine\inventory\transaction\EnchantingTransaction; +use pocketmine\item\enchantment\EnchantingOption; use pocketmine\item\Item; use pocketmine\player\Player; @@ -38,8 +38,8 @@ class PlayerItemEnchantEvent extends PlayerEvent implements Cancellable{ public function __construct( Player $player, - private readonly EnchantTransaction $transaction, - private readonly EnchantOption $option, + private readonly EnchantingTransaction $transaction, + private readonly EnchantingOption $option, private readonly Item $inputItem, private readonly Item $outputItem, private readonly int $cost @@ -50,14 +50,14 @@ public function __construct( /** * Returns the inventory transaction involved in this enchant event. */ - public function getTransaction() : EnchantTransaction{ + public function getTransaction() : EnchantingTransaction{ return $this->transaction; } /** * Returns the enchantment option used. */ - public function getOption() : EnchantOption{ + public function getOption() : EnchantingOption{ return $this->option; } diff --git a/src/inventory/transaction/EnchantTransaction.php b/src/inventory/transaction/EnchantingTransaction.php similarity index 91% rename from src/inventory/transaction/EnchantTransaction.php rename to src/inventory/transaction/EnchantingTransaction.php index 5ea8a997f8..d00df97e21 100644 --- a/src/inventory/transaction/EnchantTransaction.php +++ b/src/inventory/transaction/EnchantingTransaction.php @@ -24,8 +24,8 @@ namespace pocketmine\inventory\transaction; use pocketmine\event\player\PlayerItemEnchantEvent; -use pocketmine\item\enchantment\EnchantmentHelper; -use pocketmine\item\enchantment\EnchantOption; +use pocketmine\item\enchantment\EnchantingHelper; +use pocketmine\item\enchantment\EnchantingOption; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; use pocketmine\player\Player; @@ -33,14 +33,14 @@ use function count; use function min; -class EnchantTransaction extends InventoryTransaction{ +class EnchantingTransaction extends InventoryTransaction{ private ?Item $inputItem = null; private ?Item $outputItem = null; public function __construct( Player $source, - private readonly EnchantOption $option, + private readonly EnchantingOption $option, private readonly int $cost ){ parent::__construct($source); @@ -51,7 +51,7 @@ private function validateOutput() : void{ throw new AssumptionFailedError("Expected that inputItem and outputItem are not null before validating output"); } - $enchantedInput = EnchantmentHelper::enchantItem($this->inputItem, $this->option->getEnchantments()); + $enchantedInput = EnchantingHelper::enchantItem($this->inputItem, $this->option->getEnchantments()); if(!$this->outputItem->equalsExact($enchantedInput)){ throw new TransactionValidationException("Invalid output item"); } @@ -119,7 +119,7 @@ public function execute() : void{ //In this case, as much XP as possible will be taken. $this->source->getXpManager()->subtractXpLevels(min($this->cost, $this->source->getXpManager()->getXpLevel())); } - $this->source->setEnchantmentSeed($this->source->generateEnchantmentSeed()); + $this->source->regenerateEnchantmentSeed(); } protected function callExecuteEvent() : bool{ diff --git a/src/item/Armor.php b/src/item/Armor.php index e52732caf6..e9667a8a89 100644 --- a/src/item/Armor.php +++ b/src/item/Armor.php @@ -150,7 +150,7 @@ public function onClickAir(Player $player, Vector3 $directionVector, array &$ret //if the stack size was bigger than 1 (usually won't happen, but might be caused by plugins) $returnedItems[] = $thisCopy; } - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } protected function deserializeCompoundTag(CompoundTag $tag) : void{ diff --git a/src/item/Banner.php b/src/item/Banner.php index 250f2099ef..2fc53f5ae6 100644 --- a/src/item/Banner.php +++ b/src/item/Banner.php @@ -23,7 +23,6 @@ namespace pocketmine\item; -use pocketmine\block\Block; use pocketmine\block\tile\Banner as TileBanner; use pocketmine\block\utils\BannerPatternLayer; use pocketmine\block\utils\DyeColor; @@ -40,7 +39,7 @@ class Banner extends ItemBlockWallOrFloor{ public const TAG_PATTERN_COLOR = TileBanner::TAG_PATTERN_COLOR; public const TAG_PATTERN_NAME = TileBanner::TAG_PATTERN_NAME; - private DyeColor $color; + private DyeColor $color = DyeColor::BLACK; /** * @var BannerPatternLayer[] @@ -48,11 +47,6 @@ class Banner extends ItemBlockWallOrFloor{ */ private array $patterns = []; - public function __construct(ItemIdentifier $identifier, Block $floorVariant, Block $wallVariant){ - parent::__construct($identifier, $floorVariant, $wallVariant); - $this->color = DyeColor::BLACK(); - } - public function getColor() : DyeColor{ return $this->color; } @@ -64,7 +58,7 @@ public function setColor(DyeColor $color) : self{ } protected function describeState(RuntimeDataDescriber $w) : void{ - $w->dyeColor($this->color); + $w->enum($this->color); } /** @@ -102,7 +96,7 @@ protected function deserializeCompoundTag(CompoundTag $tag) : void{ if($patterns !== null && $patterns->getTagType() === NBT::TAG_Compound){ /** @var CompoundTag $t */ foreach($patterns as $t){ - $patternColor = $colorIdMap->fromInvertedId($t->getInt(self::TAG_PATTERN_COLOR)) ?? DyeColor::BLACK(); //TODO: missing pattern colour should be an error + $patternColor = $colorIdMap->fromInvertedId($t->getInt(self::TAG_PATTERN_COLOR)) ?? DyeColor::BLACK; //TODO: missing pattern colour should be an error $patternType = $patternIdMap->fromId($t->getString(self::TAG_PATTERN_NAME)); if($patternType === null){ continue; //TODO: this should be an error diff --git a/src/item/BoatType.php b/src/item/BoatType.php index 5ef0c9255b..518a1324e7 100644 --- a/src/item/BoatType.php +++ b/src/item/BoatType.php @@ -24,13 +24,11 @@ namespace pocketmine\item; use pocketmine\block\utils\WoodType; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static BoatType ACACIA() * @method static BoatType BIRCH() @@ -40,33 +38,30 @@ * @method static BoatType OAK() * @method static BoatType SPRUCE() */ -final class BoatType{ - use EnumTrait { - __construct as Enum___construct; - } +enum BoatType{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("oak", WoodType::OAK()), - new self("spruce", WoodType::SPRUCE()), - new self("birch", WoodType::BIRCH()), - new self("jungle", WoodType::JUNGLE()), - new self("acacia", WoodType::ACACIA()), - new self("dark_oak", WoodType::DARK_OAK()), - new self("mangrove", WoodType::MANGROVE()), - ); - } + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + case MANGROVE; - private function __construct( - string $enumName, - private WoodType $woodType, - ){ - $this->Enum___construct($enumName); + public function getWoodType() : WoodType{ + return match($this){ + self::OAK => WoodType::OAK, + self::SPRUCE => WoodType::SPRUCE, + self::BIRCH => WoodType::BIRCH, + self::JUNGLE => WoodType::JUNGLE, + self::ACACIA => WoodType::ACACIA, + self::DARK_OAK => WoodType::DARK_OAK, + self::MANGROVE => WoodType::MANGROVE, + }; } - public function getWoodType() : WoodType{ return $this->woodType; } - public function getDisplayName() : string{ - return $this->woodType->getDisplayName(); + return $this->getWoodType()->getDisplayName(); } } diff --git a/src/item/Bow.php b/src/item/Bow.php index 3c1320f037..1b25312a8e 100644 --- a/src/item/Bow.php +++ b/src/item/Bow.php @@ -53,7 +53,7 @@ public function onReleaseUsing(Player $player, array &$returnedItems) : ItemUseR }; if($player->hasFiniteResources() && $inventory === null){ - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $location = $player->getLocation(); @@ -95,7 +95,7 @@ public function onReleaseUsing(Player $player, array &$returnedItems) : ItemUseR if($ev->isCancelled()){ $entity->flagForDespawn(); - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $entity->setMotion($entity->getMotion()->multiply($ev->getForce())); @@ -105,7 +105,7 @@ public function onReleaseUsing(Player $player, array &$returnedItems) : ItemUseR $projectileEv->call(); if($projectileEv->isCancelled()){ $ev->getProjectile()->flagForDespawn(); - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $ev->getProjectile()->spawnToAll(); @@ -121,7 +121,7 @@ public function onReleaseUsing(Player $player, array &$returnedItems) : ItemUseR $this->applyDamage(1); } - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } public function canStartUsingItem(Player $player) : bool{ diff --git a/src/item/Bucket.php b/src/item/Bucket.php index 4446a055b2..b598530dda 100644 --- a/src/item/Bucket.php +++ b/src/item/Bucket.php @@ -51,7 +51,7 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc default => null }; if($resultItem === null){ - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $ev = new PlayerBucketFillEvent($player, $blockReplace, $face, $this, $resultItem); @@ -62,12 +62,12 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc $this->pop(); $returnedItems[] = $ev->getItem(); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } } diff --git a/src/item/CoralFan.php b/src/item/CoralFan.php index 294eb6d6e2..7fdfc9114b 100644 --- a/src/item/CoralFan.php +++ b/src/item/CoralFan.php @@ -24,7 +24,6 @@ namespace pocketmine\item; use pocketmine\block\Block; -use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\VanillaBlocks; use pocketmine\data\runtime\RuntimeDataDescriber; @@ -37,7 +36,6 @@ final class CoralFan extends Item{ } public function __construct(ItemIdentifier $identifier){ - $this->coralType = CoralType::TUBE(); parent::__construct($identifier, VanillaBlocks::CORAL_FAN()->getName()); } diff --git a/src/item/Dye.php b/src/item/Dye.php index f71b44e3a9..9fdfb96710 100644 --- a/src/item/Dye.php +++ b/src/item/Dye.php @@ -27,15 +27,10 @@ use pocketmine\data\runtime\RuntimeDataDescriber; class Dye extends Item{ - private DyeColor $color; - - public function __construct(ItemIdentifier $identifier, string $name){ - $this->color = DyeColor::BLACK(); - parent::__construct($identifier, $name); - } + private DyeColor $color = DyeColor::BLACK; protected function describeState(RuntimeDataDescriber $w) : void{ - $w->dyeColor($this->color); + $w->enum($this->color); } public function getColor() : DyeColor{ diff --git a/src/item/FireCharge.php b/src/item/FireCharge.php index 20e7e4f89e..a612e0897d 100644 --- a/src/item/FireCharge.php +++ b/src/item/FireCharge.php @@ -40,9 +40,9 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc $this->pop(); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } } diff --git a/src/item/FlintSteel.php b/src/item/FlintSteel.php index 0ff2e754cd..3e694eb0db 100644 --- a/src/item/FlintSteel.php +++ b/src/item/FlintSteel.php @@ -40,10 +40,10 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc $this->applyDamage(1); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } public function getMaxDurability() : int{ diff --git a/src/item/GlassBottle.php b/src/item/GlassBottle.php index bda6d132eb..c638b109f7 100644 --- a/src/item/GlassBottle.php +++ b/src/item/GlassBottle.php @@ -33,11 +33,11 @@ class GlassBottle extends Item{ public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if($blockClicked->getTypeId() === BlockTypeIds::WATER){ $this->pop(); - $returnedItems[] = VanillaItems::POTION()->setType(PotionType::WATER()); + $returnedItems[] = VanillaItems::POTION()->setType(PotionType::WATER); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } } diff --git a/src/item/Item.php b/src/item/Item.php index 775a82d756..1a74345b55 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -588,7 +588,7 @@ public function getMiningEfficiency(bool $isCorrectTool) : float{ * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if the inventory is full) */ public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } /** @@ -598,7 +598,7 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if the inventory is full) */ public function onClickAir(Player $player, Vector3 $directionVector, array &$returnedItems) : ItemUseResult{ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } /** @@ -608,7 +608,7 @@ public function onClickAir(Player $player, Vector3 $directionVector, array &$ret * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if the inventory is full) */ public function onReleaseUsing(Player $player, array &$returnedItems) : ItemUseResult{ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } /** diff --git a/src/item/ItemUseResult.php b/src/item/ItemUseResult.php index ff78b94e43..e3fbe10fb4 100644 --- a/src/item/ItemUseResult.php +++ b/src/item/ItemUseResult.php @@ -23,26 +23,20 @@ namespace pocketmine\item; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static ItemUseResult FAIL() * @method static ItemUseResult NONE() * @method static ItemUseResult SUCCESS() */ -final class ItemUseResult{ - use EnumTrait; +enum ItemUseResult{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("none"), - new self("fail"), - new self("success") - ); - } + case NONE; + case FAIL; + case SUCCESS; } diff --git a/src/item/LiquidBucket.php b/src/item/LiquidBucket.php index d23ba0af8b..81561eb157 100644 --- a/src/item/LiquidBucket.php +++ b/src/item/LiquidBucket.php @@ -63,12 +63,12 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc $toReplace = $blockReplace->canBeReplaced() ? $blockReplace : $toReplace; $toReplace = $blockClicked->canWaterlogged($resultBlock) ? $blockClicked->getBlockLayer(1) : $toReplace; if($toReplace === null){ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } if(!in_array(1, $resultBlock->getSupportedLayers(), true)){ if(!$blockReplace->canBeReplaced()){ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } $toReplace = $blockReplace; } @@ -81,10 +81,10 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc $this->pop(); $returnedItems[] = $ev->getItem(); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } public function getLiquid() : Liquid{ diff --git a/src/item/Medicine.php b/src/item/Medicine.php index a15ac03535..bd2f724649 100644 --- a/src/item/Medicine.php +++ b/src/item/Medicine.php @@ -29,15 +29,10 @@ class Medicine extends Item implements ConsumableItem{ - private MedicineType $medicineType; - - public function __construct(ItemIdentifier $identifier, string $name){ - $this->medicineType = MedicineType::EYE_DROPS(); - parent::__construct($identifier, $name); - } + private MedicineType $medicineType = MedicineType::EYE_DROPS; protected function describeState(RuntimeDataDescriber $w) : void{ - $w->medicineType($this->medicineType); + $w->enum($this->medicineType); } public function getType() : MedicineType{ return $this->medicineType; } diff --git a/src/item/MedicineType.php b/src/item/MedicineType.php index f7ce2b816d..ea99bb75dc 100644 --- a/src/item/MedicineType.php +++ b/src/item/MedicineType.php @@ -25,42 +25,39 @@ use pocketmine\entity\effect\Effect; use pocketmine\entity\effect\VanillaEffects; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static MedicineType ANTIDOTE() * @method static MedicineType ELIXIR() * @method static MedicineType EYE_DROPS() * @method static MedicineType TONIC() */ -final class MedicineType{ - use EnumTrait { - __construct as Enum___construct; +enum MedicineType{ + use LegacyEnumShimTrait; + + case ANTIDOTE; + case ELIXIR; + case EYE_DROPS; + case TONIC; + + /** + * @phpstan-return array{0: string, 1: Effect} + */ + private function getMetadata() : array{ + //cache not required here - VanillaEffects always returns the same object + return match($this){ + self::ANTIDOTE => ['Antidote', VanillaEffects::POISON()], + self::ELIXIR => ['Elixir', VanillaEffects::WEAKNESS()], + self::EYE_DROPS => ['Eye Drops', VanillaEffects::BLINDNESS()], + self::TONIC => ['Tonic', VanillaEffects::NAUSEA()] + }; } - protected static function setup() : void{ - self::registerAll( - new self('antidote', 'Antidote', VanillaEffects::POISON()), - new self('elixir', 'Elixir', VanillaEffects::WEAKNESS()), - new self('eye_drops', 'Eye Drops', VanillaEffects::BLINDNESS()), - new self('tonic', 'Tonic', VanillaEffects::NAUSEA()) - ); - } - - private function __construct( - string $enumName, - private string $displayName, - private Effect $curedEffect - ){ - $this->Enum___construct($enumName); - } - - public function getDisplayName() : string{ return $this->displayName; } + public function getDisplayName() : string{ return $this->getMetadata()[0]; } - public function getCuredEffect() : Effect{ return $this->curedEffect; } + public function getCuredEffect() : Effect{ return $this->getMetadata()[1]; } } diff --git a/src/item/PaintingItem.php b/src/item/PaintingItem.php index f3821d0b26..a83c8dba8f 100644 --- a/src/item/PaintingItem.php +++ b/src/item/PaintingItem.php @@ -39,7 +39,7 @@ class PaintingItem extends Item{ public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{ if(Facing::axis($face) === Axis::Y){ - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } $motives = []; @@ -67,7 +67,7 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc } if(count($motives) === 0){ //No space available - return ItemUseResult::NONE(); + return ItemUseResult::NONE; } /** @var PaintingMotive $motive */ @@ -81,6 +81,6 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc $entity->spawnToAll(); $player->getWorld()->addSound($replacePos->add(0.5, 0.5, 0.5), new PaintingPlaceSound()); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } } diff --git a/src/item/Potion.php b/src/item/Potion.php index 0ef3398666..41b0f634a8 100644 --- a/src/item/Potion.php +++ b/src/item/Potion.php @@ -29,15 +29,10 @@ class Potion extends Item implements ConsumableItem{ - private PotionType $potionType; - - public function __construct(ItemIdentifier $identifier, string $name){ - $this->potionType = PotionType::WATER(); - parent::__construct($identifier, $name); - } + private PotionType $potionType = PotionType::WATER; protected function describeState(RuntimeDataDescriber $w) : void{ - $w->potionType($this->potionType); + $w->enum($this->potionType); } public function getType() : PotionType{ return $this->potionType; } diff --git a/src/item/PotionType.php b/src/item/PotionType.php index e7feb0b8ec..3f4773e6de 100644 --- a/src/item/PotionType.php +++ b/src/item/PotionType.php @@ -25,13 +25,12 @@ use pocketmine\entity\effect\EffectInstance; use pocketmine\entity\effect\VanillaEffects; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; +use function spl_object_id; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static PotionType AWKWARD() * @method static PotionType FIRE_RESISTANCE() @@ -76,157 +75,196 @@ * @method static PotionType WATER_BREATHING() * @method static PotionType WEAKNESS() * @method static PotionType WITHER() + * + * @phpstan-type TMetadata array{0: string, 1: \Closure() : list} */ -final class PotionType{ - use EnumTrait { - __construct as Enum___construct; - } +enum PotionType{ + use LegacyEnumShimTrait; + + case WATER; + case MUNDANE; + case LONG_MUNDANE; + case THICK; + case AWKWARD; + case NIGHT_VISION; + case LONG_NIGHT_VISION; + case INVISIBILITY; + case LONG_INVISIBILITY; + case LEAPING; + case LONG_LEAPING; + case STRONG_LEAPING; + case FIRE_RESISTANCE; + case LONG_FIRE_RESISTANCE; + case SWIFTNESS; + case LONG_SWIFTNESS; + case STRONG_SWIFTNESS; + case SLOWNESS; + case LONG_SLOWNESS; + case WATER_BREATHING; + case LONG_WATER_BREATHING; + case HEALING; + case STRONG_HEALING; + case HARMING; + case STRONG_HARMING; + case POISON; + case LONG_POISON; + case STRONG_POISON; + case REGENERATION; + case LONG_REGENERATION; + case STRONG_REGENERATION; + case STRENGTH; + case LONG_STRENGTH; + case STRONG_STRENGTH; + case WEAKNESS; + case LONG_WEAKNESS; + case WITHER; + case TURTLE_MASTER; + case LONG_TURTLE_MASTER; + case STRONG_TURTLE_MASTER; + case SLOW_FALLING; + case LONG_SLOW_FALLING; + case STRONG_SLOWNESS; + + /** + * @phpstan-return TMetadata + */ + private function getMetadata() : array{ + /** @phpstan-var array $cache */ + static $cache = []; - protected static function setup() : void{ - self::registerAll( - new self("water", "Water", fn() => []), - new self("mundane", "Mundane", fn() => []), - new self("long_mundane", "Long Mundane", fn() => []), - new self("thick", "Thick", fn() => []), - new self("awkward", "Awkward", fn() => []), - new self("night_vision", "Night Vision", fn() => [ + return $cache[spl_object_id($this)] ??= match($this){ + self::WATER => ["Water", fn() => []], + self::MUNDANE => ["Mundane", fn() => []], + self::LONG_MUNDANE => ["Long Mundane", fn() => []], + self::THICK => ["Thick", fn() => []], + self::AWKWARD => ["Awkward", fn() => []], + self::NIGHT_VISION => ["Night Vision", fn() => [ new EffectInstance(VanillaEffects::NIGHT_VISION(), 3600) - ]), - new self("long_night_vision", "Long Night Vision", fn() => [ + ]], + self::LONG_NIGHT_VISION => ["Long Night Vision", fn() => [ new EffectInstance(VanillaEffects::NIGHT_VISION(), 9600) - ]), - new self("invisibility", "Invisibility", fn() => [ + ]], + self::INVISIBILITY => ["Invisibility", fn() => [ new EffectInstance(VanillaEffects::INVISIBILITY(), 3600) - ]), - new self("long_invisibility", "Long Invisibility", fn() => [ + ]], + self::LONG_INVISIBILITY => ["Long Invisibility", fn() => [ new EffectInstance(VanillaEffects::INVISIBILITY(), 9600) - ]), - new self("leaping", "Leaping", fn() => [ + ]], + self::LEAPING => ["Leaping", fn() => [ new EffectInstance(VanillaEffects::JUMP_BOOST(), 3600) - ]), - new self("long_leaping", "Long Leaping", fn() => [ + ]], + self::LONG_LEAPING => ["Long Leaping", fn() => [ new EffectInstance(VanillaEffects::JUMP_BOOST(), 9600) - ]), - new self("strong_leaping", "Strong Leaping", fn() => [ + ]], + self::STRONG_LEAPING => ["Strong Leaping", fn() => [ new EffectInstance(VanillaEffects::JUMP_BOOST(), 1800, 1) - ]), - new self("fire_resistance", "Fire Resistance", fn() => [ + ]], + self::FIRE_RESISTANCE => ["Fire Resistance", fn() => [ new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 3600) - ]), - new self("long_fire_resistance", "Long Fire Resistance", fn() => [ + ]], + self::LONG_FIRE_RESISTANCE => ["Long Fire Resistance", fn() => [ new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 9600) - ]), - new self("swiftness", "Swiftness", fn() => [ + ]], + self::SWIFTNESS => ["Swiftness", fn() => [ new EffectInstance(VanillaEffects::SPEED(), 3600) - ]), - new self("long_swiftness", "Long Swiftness", fn() => [ + ]], + self::LONG_SWIFTNESS => ["Long Swiftness", fn() => [ new EffectInstance(VanillaEffects::SPEED(), 9600) - ]), - new self("strong_swiftness", "Strong Swiftness", fn() => [ + ]], + self::STRONG_SWIFTNESS => ["Strong Swiftness", fn() => [ new EffectInstance(VanillaEffects::SPEED(), 1800, 1) - ]), - new self("slowness", "Slowness", fn() => [ + ]], + self::SLOWNESS => ["Slowness", fn() => [ new EffectInstance(VanillaEffects::SLOWNESS(), 1800) - ]), - new self("long_slowness", "Long Slowness", fn() => [ + ]], + self::LONG_SLOWNESS => ["Long Slowness", fn() => [ new EffectInstance(VanillaEffects::SLOWNESS(), 4800) - ]), - new self("water_breathing", "Water Breathing", fn() => [ + ]], + self::WATER_BREATHING => ["Water Breathing", fn() => [ new EffectInstance(VanillaEffects::WATER_BREATHING(), 3600) - ]), - new self("long_water_breathing", "Long Water Breathing", fn() => [ + ]], + self::LONG_WATER_BREATHING => ["Long Water Breathing", fn() => [ new EffectInstance(VanillaEffects::WATER_BREATHING(), 9600) - ]), - new self("healing", "Healing", fn() => [ + ]], + self::HEALING => ["Healing", fn() => [ new EffectInstance(VanillaEffects::INSTANT_HEALTH()) - ]), - new self("strong_healing", "Strong Healing", fn() => [ + ]], + self::STRONG_HEALING => ["Strong Healing", fn() => [ new EffectInstance(VanillaEffects::INSTANT_HEALTH(), null, 1) - ]), - new self("harming", "Harming", fn() => [ + ]], + self::HARMING => ["Harming", fn() => [ new EffectInstance(VanillaEffects::INSTANT_DAMAGE()) - ]), - new self("strong_harming", "Strong Harming", fn() => [ + ]], + self::STRONG_HARMING => ["Strong Harming", fn() => [ new EffectInstance(VanillaEffects::INSTANT_DAMAGE(), null, 1) - ]), - new self("poison", "Poison", fn() => [ + ]], + self::POISON => ["Poison", fn() => [ new EffectInstance(VanillaEffects::POISON(), 900) - ]), - new self("long_poison", "Long Poison", fn() => [ + ]], + self::LONG_POISON => ["Long Poison", fn() => [ new EffectInstance(VanillaEffects::POISON(), 2400) - ]), - new self("strong_poison", "Strong Poison", fn() => [ + ]], + self::STRONG_POISON => ["Strong Poison", fn() => [ new EffectInstance(VanillaEffects::POISON(), 440, 1) - ]), - new self("regeneration", "Regeneration", fn() => [ + ]], + self::REGENERATION => ["Regeneration", fn() => [ new EffectInstance(VanillaEffects::REGENERATION(), 900) - ]), - new self("long_regeneration", "Long Regeneration", fn() => [ + ]], + self::LONG_REGENERATION => ["Long Regeneration", fn() => [ new EffectInstance(VanillaEffects::REGENERATION(), 2400) - ]), - new self("strong_regeneration", "Strong Regeneration", fn() => [ + ]], + self::STRONG_REGENERATION => ["Strong Regeneration", fn() => [ new EffectInstance(VanillaEffects::REGENERATION(), 440, 1) - ]), - new self("strength", "Strength", fn() => [ + ]], + self::STRENGTH => ["Strength", fn() => [ new EffectInstance(VanillaEffects::STRENGTH(), 3600) - ]), - new self("long_strength", "Long Strength", fn() => [ + ]], + self::LONG_STRENGTH => ["Long Strength", fn() => [ new EffectInstance(VanillaEffects::STRENGTH(), 9600) - ]), - new self("strong_strength", "Strong Strength", fn() => [ + ]], + self::STRONG_STRENGTH => ["Strong Strength", fn() => [ new EffectInstance(VanillaEffects::STRENGTH(), 1800, 1) - ]), - new self("weakness", "Weakness", fn() => [ + ]], + self::WEAKNESS => ["Weakness", fn() => [ new EffectInstance(VanillaEffects::WEAKNESS(), 1800) - ]), - new self("long_weakness", "Long Weakness", fn() => [ + ]], + self::LONG_WEAKNESS => ["Long Weakness", fn() => [ new EffectInstance(VanillaEffects::WEAKNESS(), 4800) - ]), - new self("wither", "Wither", fn() => [ + ]], + self::WITHER => ["Wither", fn() => [ new EffectInstance(VanillaEffects::WITHER(), 800, 1) - ]), - new self("turtle_master", "Turtle Master", fn() => [ + ]], + self::TURTLE_MASTER => ["Turtle Master", fn() => [ new EffectInstance(VanillaEffects::SLOWNESS(), 20 * 20, 3), new EffectInstance(VanillaEffects::RESISTANCE(), 20 * 20, 2), - ]), - new self("long_turtle_master", "Long Turtle Master", fn() => [ + ]], + self::LONG_TURTLE_MASTER => ["Long Turtle Master", fn() => [ new EffectInstance(VanillaEffects::SLOWNESS(), 40 * 20, 3), new EffectInstance(VanillaEffects::RESISTANCE(), 40 * 20, 2), - ]), - new self("strong_turtle_master", "Strong Turtle Master", fn() => [ + ]], + self::STRONG_TURTLE_MASTER => ["Strong Turtle Master", fn() => [ new EffectInstance(VanillaEffects::SLOWNESS(), 20 * 20, 5), new EffectInstance(VanillaEffects::RESISTANCE(), 20 * 20, 3), - ]), - new self("slow_falling", "Slow Falling", fn() => [ + ]], + self::SLOW_FALLING => ["Slow Falling", fn() => [ //TODO - ]), - new self("long_slow_falling", "Long Slow Falling", fn() => [ + ]], + self::LONG_SLOW_FALLING => ["Long Slow Falling", fn() => [ //TODO - ]), - new self("strong_slowness", "Strong Slowness", fn() => [ + ]], + self::STRONG_SLOWNESS => ["Strong Slowness", fn() => [ new EffectInstance(VanillaEffects::SLOWNESS(), 20 * 20, 3) - ]) - ); - } - - /** - * @phpstan-param \Closure() : list $effectsGetter - */ - private function __construct( - string $enumName, - private string $displayName, - private \Closure $effectsGetter - ){ - $this->Enum___construct($enumName); + ]] + }; } - public function getDisplayName() : string{ return $this->displayName; } + public function getDisplayName() : string{ return $this->getMetadata()[0]; } /** * @return EffectInstance[] * @phpstan-return list */ public function getEffects() : array{ - return ($this->effectsGetter)(); + return ($this->getMetadata()[1])(); } } diff --git a/src/item/ProjectileItem.php b/src/item/ProjectileItem.php index 8056af505a..47c4583e04 100644 --- a/src/item/ProjectileItem.php +++ b/src/item/ProjectileItem.php @@ -46,7 +46,7 @@ public function onClickAir(Player $player, Vector3 $directionVector, array &$ret $projectileEv->call(); if($projectileEv->isCancelled()){ $projectile->flagForDespawn(); - return ItemUseResult::FAIL(); + return ItemUseResult::FAIL; } $projectile->spawnToAll(); @@ -55,6 +55,6 @@ public function onClickAir(Player $player, Vector3 $directionVector, array &$ret $this->pop(); - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } } diff --git a/src/item/SpawnEgg.php b/src/item/SpawnEgg.php index 1147a951dd..51dcceebd2 100644 --- a/src/item/SpawnEgg.php +++ b/src/item/SpawnEgg.php @@ -43,6 +43,6 @@ public function onInteractBlock(Player $player, Block $blockReplace, Block $bloc $this->pop(); $entity->spawnToAll(); //TODO: what if the entity was marked for deletion? - return ItemUseResult::SUCCESS(); + return ItemUseResult::SUCCESS; } } diff --git a/src/item/SplashPotion.php b/src/item/SplashPotion.php index c54562f2b0..e1c9167ac3 100644 --- a/src/item/SplashPotion.php +++ b/src/item/SplashPotion.php @@ -31,15 +31,10 @@ class SplashPotion extends ProjectileItem{ - private PotionType $potionType; - - public function __construct(ItemIdentifier $identifier, string $name){ - $this->potionType = PotionType::WATER(); - parent::__construct($identifier, $name); - } + private PotionType $potionType = PotionType::WATER; protected function describeState(RuntimeDataDescriber $w) : void{ - $w->potionType($this->potionType); + $w->enum($this->potionType); } public function getType() : PotionType{ return $this->potionType; } diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index fc5533323f..66c919233e 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -37,6 +37,7 @@ use pocketmine\utils\SingletonTrait; use pocketmine\utils\StringToTParser; use function array_keys; +use function strtolower; /** * Handles parsing items from strings. This is used to interpret names from the /give command (and others). @@ -58,8 +59,8 @@ private static function make() : self{ } private static function registerDynamicBlocks(self $result) : void{ - foreach(DyeColor::getAll() as $color){ - $register = fn(string $name, \Closure $callback) => $result->registerBlock($color->name() . "_" . $name, $callback); + foreach(DyeColor::cases() as $color){ + $register = fn(string $name, \Closure $callback) => $result->registerBlock(strtolower($color->name) . "_" . $name, $callback); //wall and floor banner are the same item $register("banner", fn() => Blocks::BANNER()->setColor($color)); $register("bed", fn() => Blocks::BED()->setColor($color)); @@ -77,8 +78,8 @@ private static function registerDynamicBlocks(self $result) : void{ $register("shulker_box", fn() => Blocks::DYED_SHULKER_BOX()->setColor($color)); } - foreach(CoralType::getAll() as $coralType){ - $register = fn(string $name, \Closure $callback) => $result->registerBlock($coralType->name() . "_" . $name, $callback); + foreach(CoralType::cases() as $coralType){ + $register = fn(string $name, \Closure $callback) => $result->registerBlock(strtolower($coralType->name) . "_" . $name, $callback); $register("coral", fn() => Blocks::CORAL()->setCoralType($coralType)); $register("coral_block", fn() => Blocks::CORAL_BLOCK()->setCoralType($coralType)); //wall and floor coral fans are the same item @@ -90,8 +91,8 @@ private static function registerDynamicBlocks(self $result) : void{ $result->registerBlock("light_block_$i", fn() => Blocks::LIGHT()->setLightLevel($i)); } - foreach(CopperOxidation::getAll() as $oxidation){ - $oxPrefix = $oxidation->equals(CopperOxidation::NONE()) ? "" : $oxidation->name() . "_"; + foreach(CopperOxidation::cases() as $oxidation){ + $oxPrefix = $oxidation === CopperOxidation::NONE ? "" : strtolower($oxidation->name) . "_"; foreach(["" => false, "waxed_" => true] as $waxedPrefix => $waxed){ $register = fn(string $name, \Closure $callback) => $result->registerBlock($waxedPrefix . $oxPrefix . $name, $callback); @@ -102,8 +103,8 @@ private static function registerDynamicBlocks(self $result) : void{ } } - foreach(FroglightType::getAll() as $froglightType){ - $result->registerBlock($froglightType->name() . "_froglight", fn() => Blocks::FROGLIGHT()->setFroglightType($froglightType)); + foreach(FroglightType::cases() as $froglightType){ + $result->registerBlock(strtolower($froglightType->name) . "_froglight", fn() => Blocks::FROGLIGHT()->setFroglightType($froglightType)); } } @@ -238,7 +239,7 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("clay_block", fn() => Blocks::CLAY()); $result->registerBlock("coal_block", fn() => Blocks::COAL()); $result->registerBlock("coal_ore", fn() => Blocks::COAL_ORE()); - $result->registerBlock("coarse_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::COARSE())); + $result->registerBlock("coarse_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::COARSE)); $result->registerBlock("cobble", fn() => Blocks::COBBLESTONE()); $result->registerBlock("cobble_stairs", fn() => Blocks::COBBLESTONE_STAIRS()); $result->registerBlock("cobble_wall", fn() => Blocks::COBBLESTONE_WALL()); @@ -267,10 +268,10 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("coral", fn() => Blocks::CORAL()); $result->registerBlock("coral_block", fn() => Blocks::CORAL_BLOCK()); $result->registerBlock("coral_fan", fn() => Blocks::CORAL_FAN()); - $result->registerBlock("coral_fan_dead", fn() => Blocks::CORAL_FAN()->setCoralType(CoralType::TUBE())->setDead(true)); + $result->registerBlock("coral_fan_dead", fn() => Blocks::CORAL_FAN()->setCoralType(CoralType::TUBE)->setDead(true)); $result->registerBlock("coral_fan_hang", fn() => Blocks::WALL_CORAL_FAN()); - $result->registerBlock("coral_fan_hang2", fn() => Blocks::WALL_CORAL_FAN()->setCoralType(CoralType::BUBBLE())); - $result->registerBlock("coral_fan_hang3", fn() => Blocks::WALL_CORAL_FAN()->setCoralType(CoralType::HORN())); + $result->registerBlock("coral_fan_hang2", fn() => Blocks::WALL_CORAL_FAN()->setCoralType(CoralType::BUBBLE)); + $result->registerBlock("coral_fan_hang3", fn() => Blocks::WALL_CORAL_FAN()->setCoralType(CoralType::HORN)); $result->registerBlock("cornflower", fn() => Blocks::CORNFLOWER()); $result->registerBlock("cracked_deepslate_bricks", fn() => Blocks::CRACKED_DEEPSLATE_BRICKS()); $result->registerBlock("cracked_deepslate_tiles", fn() => Blocks::CRACKED_DEEPSLATE_TILES()); @@ -278,7 +279,7 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("cracked_polished_blackstone_bricks", fn() => Blocks::CRACKED_POLISHED_BLACKSTONE_BRICKS()); $result->registerBlock("cracked_stone_bricks", fn() => Blocks::CRACKED_STONE_BRICKS()); $result->registerBlock("crafting_table", fn() => Blocks::CRAFTING_TABLE()); - $result->registerBlock("creeper_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::CREEPER())); + $result->registerBlock("creeper_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::CREEPER)); $result->registerBlock("crimson_button", fn() => Blocks::CRIMSON_BUTTON()); $result->registerBlock("crimson_door", fn() => Blocks::CRIMSON_DOOR()); $result->registerBlock("crimson_fence", fn() => Blocks::CRIMSON_FENCE()); @@ -353,24 +354,24 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("diorite_slab", fn() => Blocks::DIORITE_SLAB()); $result->registerBlock("diorite_stairs", fn() => Blocks::DIORITE_STAIRS()); $result->registerBlock("diorite_wall", fn() => Blocks::DIORITE_WALL()); - $result->registerBlock("dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::NORMAL())); - $result->registerBlock("dirt_with_roots", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED())); + $result->registerBlock("dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::NORMAL)); + $result->registerBlock("dirt_with_roots", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED)); $result->registerBlock("door_block", fn() => Blocks::OAK_DOOR()); $result->registerBlock("double_plant", fn() => Blocks::SUNFLOWER()); - $result->registerBlock("double_red_sandstone_slab", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_slab", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_slabs", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_stone_slab", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_stone_slab2", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_stone_slab3", fn() => Blocks::END_STONE_BRICK_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_stone_slab4", fn() => Blocks::MOSSY_STONE_BRICK_SLAB()->setSlabType(SlabType::DOUBLE())); + $result->registerBlock("double_red_sandstone_slab", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_slab", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_slabs", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_stone_slab", fn() => Blocks::STONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_stone_slab2", fn() => Blocks::RED_SANDSTONE_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_stone_slab3", fn() => Blocks::END_STONE_BRICK_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_stone_slab4", fn() => Blocks::MOSSY_STONE_BRICK_SLAB()->setSlabType(SlabType::DOUBLE)); $result->registerBlock("double_tallgrass", fn() => Blocks::DOUBLE_TALLGRASS()); - $result->registerBlock("double_wood_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_wood_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_wooden_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE())); - $result->registerBlock("double_wooden_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE())); + $result->registerBlock("double_wood_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_wood_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_wooden_slab", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE)); + $result->registerBlock("double_wooden_slabs", fn() => Blocks::OAK_SLAB()->setSlabType(SlabType::DOUBLE)); $result->registerBlock("dragon_egg", fn() => Blocks::DRAGON_EGG()); - $result->registerBlock("dragon_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::DRAGON())); + $result->registerBlock("dragon_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::DRAGON)); $result->registerBlock("dried_kelp_block", fn() => Blocks::DRIED_KELP()); $result->registerBlock("dyed_shulker_box", fn() => Blocks::DYED_SHULKER_BOX()); $result->registerBlock("element_0", fn() => Blocks::ELEMENT_ZERO()); @@ -858,10 +859,10 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("peony", fn() => Blocks::PEONY()); $result->registerBlock("pink_petals", fn() => Blocks::PINK_PETALS()); $result->registerBlock("pink_tulip", fn() => Blocks::PINK_TULIP()); - $result->registerBlock("piglin_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::PIGLIN())); + $result->registerBlock("piglin_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::PIGLIN)); $result->registerBlock("plank", fn() => Blocks::OAK_PLANKS()); $result->registerBlock("planks", fn() => Blocks::OAK_PLANKS()); - $result->registerBlock("player_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::PLAYER())); + $result->registerBlock("player_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::PLAYER)); $result->registerBlock("podzol", fn() => Blocks::PODZOL()); $result->registerBlock("polished_andesite", fn() => Blocks::POLISHED_ANDESITE()); $result->registerBlock("polished_andesite_slab", fn() => Blocks::POLISHED_ANDESITE_SLAB()); @@ -950,7 +951,7 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("repeater", fn() => Blocks::REDSTONE_REPEATER()); $result->registerBlock("repeater_block", fn() => Blocks::REDSTONE_REPEATER()); $result->registerBlock("reserved6", fn() => Blocks::RESERVED6()); - $result->registerBlock("rooted_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED())); + $result->registerBlock("rooted_dirt", fn() => Blocks::DIRT()->setDirtType(DirtType::ROOTED)); $result->registerBlock("rose", fn() => Blocks::POPPY()); $result->registerBlock("rose_bush", fn() => Blocks::ROSE_BUSH()); $result->registerBlock("sand", fn() => Blocks::SAND()); @@ -967,8 +968,8 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("shulker_box", fn() => Blocks::SHULKER_BOX()); $result->registerBlock("sign", fn() => Blocks::OAK_SIGN()); $result->registerBlock("sign_post", fn() => Blocks::OAK_SIGN()); - $result->registerBlock("skeleton_skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::SKELETON())); - $result->registerBlock("skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::SKELETON())); + $result->registerBlock("skeleton_skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::SKELETON)); + $result->registerBlock("skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::SKELETON)); $result->registerBlock("skull_block", fn() => Blocks::MOB_HEAD()); $result->registerBlock("slab", fn() => Blocks::SMOOTH_STONE_SLAB()); $result->registerBlock("slabs", fn() => Blocks::SMOOTH_STONE_SLAB()); @@ -1119,7 +1120,7 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("wheat_block", fn() => Blocks::WHEAT()); $result->registerBlock("white_tulip", fn() => Blocks::WHITE_TULIP()); $result->registerBlock("wither_rose", fn() => Blocks::WITHER_ROSE()); - $result->registerBlock("wither_skeleton_skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::WITHER_SKELETON())); + $result->registerBlock("wither_skeleton_skull", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::WITHER_SKELETON)); $result->registerBlock("wood", fn() => Blocks::OAK_LOG()->setStripped(false)); $result->registerBlock("wood2", fn() => Blocks::ACACIA_LOG()->setStripped(false)); $result->registerBlock("wood_door_block", fn() => Blocks::OAK_DOOR()); @@ -1139,17 +1140,17 @@ private static function registerBlocks(self $result) : void{ $result->registerBlock("wool", fn() => Blocks::WOOL()); $result->registerBlock("workbench", fn() => Blocks::CRAFTING_TABLE()); $result->registerBlock("yellow_flower", fn() => Blocks::DANDELION()); - $result->registerBlock("zombie_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::ZOMBIE())); + $result->registerBlock("zombie_head", fn() => Blocks::MOB_HEAD()->setMobHeadType(MobHeadType::ZOMBIE)); } private static function registerDynamicItems(self $result) : void{ - foreach(DyeColor::getAll() as $color){ - $prefix = fn(string $name) => $color->name() . "_" . $name; + foreach(DyeColor::cases() as $color){ + $prefix = fn(string $name) => strtolower($color->name) . "_" . $name; $result->register($prefix("dye"), fn() => Items::DYE()->setColor($color)); } - foreach(SuspiciousStewType::getAll() as $suspiciousStewType){ - $prefix = fn(string $name) => $suspiciousStewType->name() . "_" . $name; + foreach(SuspiciousStewType::cases() as $suspiciousStewType){ + $prefix = fn(string $name) => strtolower($suspiciousStewType->name) . "_" . $name; $result->register($prefix("suspicious_stew"), fn() => Items::SUSPICIOUS_STEW()->setType($suspiciousStewType)); } @@ -1159,13 +1160,13 @@ private static function registerItems(self $result) : void{ $result->register("acacia_boat", fn() => Items::ACACIA_BOAT()); $result->register("amethyst_shard", fn() => Items::AMETHYST_SHARD()); - $result->register("antidote", fn() => Items::MEDICINE()->setType(MedicineType::ANTIDOTE())); + $result->register("antidote", fn() => Items::MEDICINE()->setType(MedicineType::ANTIDOTE)); $result->register("apple", fn() => Items::APPLE()); $result->register("apple_enchanted", fn() => Items::ENCHANTED_GOLDEN_APPLE()); $result->register("appleenchanted", fn() => Items::ENCHANTED_GOLDEN_APPLE()); $result->register("arrow", fn() => Items::ARROW()); - $result->register("awkward_potion", fn() => Items::POTION()->setType(PotionType::AWKWARD())); - $result->register("awkward_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::AWKWARD())); + $result->register("awkward_potion", fn() => Items::POTION()->setType(PotionType::AWKWARD)); + $result->register("awkward_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::AWKWARD)); $result->register("baked_potato", fn() => Items::BAKED_POTATO()); $result->register("baked_potatoes", fn() => Items::BAKED_POTATO()); $result->register("beef", fn() => Items::RAW_BEEF()); @@ -1275,22 +1276,22 @@ private static function registerItems(self $result) : void{ $result->register("dye", fn() => Items::INK_SAC()); $result->register("echo_shard", fn() => Items::ECHO_SHARD()); $result->register("egg", fn() => Items::EGG()); - $result->register("elixir", fn() => Items::MEDICINE()->setType(MedicineType::ELIXIR())); + $result->register("elixir", fn() => Items::MEDICINE()->setType(MedicineType::ELIXIR)); $result->register("emerald", fn() => Items::EMERALD()); $result->register("enchanted_book", fn() => Items::ENCHANTED_BOOK()); $result->register("enchanted_golden_apple", fn() => Items::ENCHANTED_GOLDEN_APPLE()); $result->register("enchanting_bottle", fn() => Items::EXPERIENCE_BOTTLE()); $result->register("ender_pearl", fn() => Items::ENDER_PEARL()); $result->register("experience_bottle", fn() => Items::EXPERIENCE_BOTTLE()); - $result->register("eye_drops", fn() => Items::MEDICINE()->setType(MedicineType::EYE_DROPS())); + $result->register("eye_drops", fn() => Items::MEDICINE()->setType(MedicineType::EYE_DROPS)); $result->register("feather", fn() => Items::FEATHER()); $result->register("fermented_spider_eye", fn() => Items::FERMENTED_SPIDER_EYE()); $result->register("firework_rocket", fn() => Items::FIREWORK_ROCKET()); $result->register("firework_star", fn() => Items::FIREWORK_STAR()); $result->register("fireworks", fn() => Items::FIREWORK_ROCKET()); $result->register("fire_charge", fn() => Items::FIRE_CHARGE()); - $result->register("fire_resistance_potion", fn() => Items::POTION()->setType(PotionType::FIRE_RESISTANCE())); - $result->register("fire_resistance_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::FIRE_RESISTANCE())); + $result->register("fire_resistance_potion", fn() => Items::POTION()->setType(PotionType::FIRE_RESISTANCE)); + $result->register("fire_resistance_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::FIRE_RESISTANCE)); $result->register("fish", fn() => Items::RAW_FISH()); $result->register("fishing_rod", fn() => Items::FISHING_ROD()); $result->register("flint", fn() => Items::FLINT()); @@ -1326,16 +1327,16 @@ private static function registerItems(self $result) : void{ $result->register("golden_shovel", fn() => Items::GOLDEN_SHOVEL()); $result->register("golden_sword", fn() => Items::GOLDEN_SWORD()); $result->register("gunpowder", fn() => Items::GUNPOWDER()); - $result->register("harming_potion", fn() => Items::POTION()->setType(PotionType::HARMING())); - $result->register("harming_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::HARMING())); - $result->register("healing_potion", fn() => Items::POTION()->setType(PotionType::HEALING())); - $result->register("healing_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::HEALING())); + $result->register("harming_potion", fn() => Items::POTION()->setType(PotionType::HARMING)); + $result->register("harming_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::HARMING)); + $result->register("healing_potion", fn() => Items::POTION()->setType(PotionType::HEALING)); + $result->register("healing_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::HEALING)); $result->register("heart_of_the_sea", fn() => Items::HEART_OF_THE_SEA()); $result->register("honey_bottle", fn() => Items::HONEY_BOTTLE()); $result->register("honeycomb", fn() => Items::HONEYCOMB()); $result->register("ink_sac", fn() => Items::INK_SAC()); - $result->register("invisibility_potion", fn() => Items::POTION()->setType(PotionType::INVISIBILITY())); - $result->register("invisibility_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::INVISIBILITY())); + $result->register("invisibility_potion", fn() => Items::POTION()->setType(PotionType::INVISIBILITY)); + $result->register("invisibility_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::INVISIBILITY)); $result->register("iron_axe", fn() => Items::IRON_AXE()); $result->register("iron_boots", fn() => Items::IRON_BOOTS()); $result->register("iron_chestplate", fn() => Items::IRON_CHESTPLATE()); @@ -1350,8 +1351,8 @@ private static function registerItems(self $result) : void{ $result->register("jungle_boat", fn() => Items::JUNGLE_BOAT()); $result->register("lapis_lazuli", fn() => Items::LAPIS_LAZULI()); $result->register("lava_bucket", fn() => Items::LAVA_BUCKET()); - $result->register("leaping_potion", fn() => Items::POTION()->setType(PotionType::LEAPING())); - $result->register("leaping_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LEAPING())); + $result->register("leaping_potion", fn() => Items::POTION()->setType(PotionType::LEAPING)); + $result->register("leaping_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LEAPING)); $result->register("leather", fn() => Items::LEATHER()); $result->register("leather_boots", fn() => Items::LEATHER_BOOTS()); $result->register("leather_cap", fn() => Items::LEATHER_CAP()); @@ -1360,42 +1361,42 @@ private static function registerItems(self $result) : void{ $result->register("leather_leggings", fn() => Items::LEATHER_PANTS()); $result->register("leather_pants", fn() => Items::LEATHER_PANTS()); $result->register("leather_tunic", fn() => Items::LEATHER_TUNIC()); - $result->register("long_fire_resistance_potion", fn() => Items::POTION()->setType(PotionType::LONG_FIRE_RESISTANCE())); - $result->register("long_fire_resistance_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_FIRE_RESISTANCE())); - $result->register("long_invisibility_potion", fn() => Items::POTION()->setType(PotionType::LONG_INVISIBILITY())); - $result->register("long_invisibility_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_INVISIBILITY())); - $result->register("long_leaping_potion", fn() => Items::POTION()->setType(PotionType::LONG_LEAPING())); - $result->register("long_leaping_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_LEAPING())); - $result->register("long_mundane_potion", fn() => Items::POTION()->setType(PotionType::LONG_MUNDANE())); - $result->register("long_mundane_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_MUNDANE())); - $result->register("long_night_vision_potion", fn() => Items::POTION()->setType(PotionType::LONG_NIGHT_VISION())); - $result->register("long_night_vision_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_NIGHT_VISION())); - $result->register("long_poison_potion", fn() => Items::POTION()->setType(PotionType::LONG_POISON())); - $result->register("long_poison_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_POISON())); - $result->register("long_regeneration_potion", fn() => Items::POTION()->setType(PotionType::LONG_REGENERATION())); - $result->register("long_regeneration_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_REGENERATION())); - $result->register("long_slow_falling_potion", fn() => Items::POTION()->setType(PotionType::LONG_SLOW_FALLING())); - $result->register("long_slow_falling_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_SLOW_FALLING())); - $result->register("long_slowness_potion", fn() => Items::POTION()->setType(PotionType::LONG_SLOWNESS())); - $result->register("long_slowness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_SLOWNESS())); - $result->register("long_strength_potion", fn() => Items::POTION()->setType(PotionType::LONG_STRENGTH())); - $result->register("long_strength_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_STRENGTH())); - $result->register("long_swiftness_potion", fn() => Items::POTION()->setType(PotionType::LONG_SWIFTNESS())); - $result->register("long_swiftness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_SWIFTNESS())); - $result->register("long_turtle_master_potion", fn() => Items::POTION()->setType(PotionType::LONG_TURTLE_MASTER())); - $result->register("long_turtle_master_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_TURTLE_MASTER())); - $result->register("long_water_breathing_potion", fn() => Items::POTION()->setType(PotionType::LONG_WATER_BREATHING())); - $result->register("long_water_breathing_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_WATER_BREATHING())); - $result->register("long_weakness_potion", fn() => Items::POTION()->setType(PotionType::LONG_WEAKNESS())); - $result->register("long_weakness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_WEAKNESS())); + $result->register("long_fire_resistance_potion", fn() => Items::POTION()->setType(PotionType::LONG_FIRE_RESISTANCE)); + $result->register("long_fire_resistance_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_FIRE_RESISTANCE)); + $result->register("long_invisibility_potion", fn() => Items::POTION()->setType(PotionType::LONG_INVISIBILITY)); + $result->register("long_invisibility_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_INVISIBILITY)); + $result->register("long_leaping_potion", fn() => Items::POTION()->setType(PotionType::LONG_LEAPING)); + $result->register("long_leaping_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_LEAPING)); + $result->register("long_mundane_potion", fn() => Items::POTION()->setType(PotionType::LONG_MUNDANE)); + $result->register("long_mundane_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_MUNDANE)); + $result->register("long_night_vision_potion", fn() => Items::POTION()->setType(PotionType::LONG_NIGHT_VISION)); + $result->register("long_night_vision_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_NIGHT_VISION)); + $result->register("long_poison_potion", fn() => Items::POTION()->setType(PotionType::LONG_POISON)); + $result->register("long_poison_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_POISON)); + $result->register("long_regeneration_potion", fn() => Items::POTION()->setType(PotionType::LONG_REGENERATION)); + $result->register("long_regeneration_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_REGENERATION)); + $result->register("long_slow_falling_potion", fn() => Items::POTION()->setType(PotionType::LONG_SLOW_FALLING)); + $result->register("long_slow_falling_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_SLOW_FALLING)); + $result->register("long_slowness_potion", fn() => Items::POTION()->setType(PotionType::LONG_SLOWNESS)); + $result->register("long_slowness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_SLOWNESS)); + $result->register("long_strength_potion", fn() => Items::POTION()->setType(PotionType::LONG_STRENGTH)); + $result->register("long_strength_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_STRENGTH)); + $result->register("long_swiftness_potion", fn() => Items::POTION()->setType(PotionType::LONG_SWIFTNESS)); + $result->register("long_swiftness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_SWIFTNESS)); + $result->register("long_turtle_master_potion", fn() => Items::POTION()->setType(PotionType::LONG_TURTLE_MASTER)); + $result->register("long_turtle_master_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_TURTLE_MASTER)); + $result->register("long_water_breathing_potion", fn() => Items::POTION()->setType(PotionType::LONG_WATER_BREATHING)); + $result->register("long_water_breathing_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_WATER_BREATHING)); + $result->register("long_weakness_potion", fn() => Items::POTION()->setType(PotionType::LONG_WEAKNESS)); + $result->register("long_weakness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::LONG_WEAKNESS)); $result->register("magma_cream", fn() => Items::MAGMA_CREAM()); $result->register("melon", fn() => Items::MELON()); $result->register("melon_seeds", fn() => Items::MELON_SEEDS()); $result->register("melon_slice", fn() => Items::MELON()); $result->register("milk_bucket", fn() => Items::MILK_BUCKET()); $result->register("minecart", fn() => Items::MINECART()); - $result->register("mundane_potion", fn() => Items::POTION()->setType(PotionType::MUNDANE())); - $result->register("mundane_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::MUNDANE())); + $result->register("mundane_potion", fn() => Items::POTION()->setType(PotionType::MUNDANE)); + $result->register("mundane_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::MUNDANE)); $result->register("mushroom_stew", fn() => Items::MUSHROOM_STEW()); $result->register("mutton", fn() => Items::RAW_MUTTON()); $result->register("mutton_cooked", fn() => Items::COOKED_MUTTON()); @@ -1419,14 +1420,14 @@ private static function registerItems(self $result) : void{ $result->register("netherite_shovel", fn() => Items::NETHERITE_SHOVEL()); $result->register("netherite_sword", fn() => Items::NETHERITE_SWORD()); $result->register("netherstar", fn() => Items::NETHER_STAR()); - $result->register("night_vision_potion", fn() => Items::POTION()->setType(PotionType::NIGHT_VISION())); - $result->register("night_vision_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::NIGHT_VISION())); + $result->register("night_vision_potion", fn() => Items::POTION()->setType(PotionType::NIGHT_VISION)); + $result->register("night_vision_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::NIGHT_VISION)); $result->register("oak_boat", fn() => Items::OAK_BOAT()); $result->register("painting", fn() => Items::PAINTING()); $result->register("paper", fn() => Items::PAPER()); $result->register("phantom_membrane", fn() => Items::PHANTOM_MEMBRANE()); - $result->register("poison_potion", fn() => Items::POTION()->setType(PotionType::POISON())); - $result->register("poison_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::POISON())); + $result->register("poison_potion", fn() => Items::POTION()->setType(PotionType::POISON)); + $result->register("poison_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::POISON)); $result->register("poisonous_potato", fn() => Items::POISONOUS_POTATO()); $result->register("popped_chorus_fruit", fn() => Items::POPPED_CHORUS_FRUIT()); $result->register("porkchop", fn() => Items::RAW_PORKCHOP()); @@ -1471,8 +1472,8 @@ private static function registerItems(self $result) : void{ $result->register("record_ward", fn() => Items::RECORD_WARD()); $result->register("redstone", fn() => Items::REDSTONE_DUST()); $result->register("redstone_dust", fn() => Items::REDSTONE_DUST()); - $result->register("regeneration_potion", fn() => Items::POTION()->setType(PotionType::REGENERATION())); - $result->register("regeneration_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::REGENERATION())); + $result->register("regeneration_potion", fn() => Items::POTION()->setType(PotionType::REGENERATION)); + $result->register("regeneration_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::REGENERATION)); $result->register("rotten_flesh", fn() => Items::ROTTEN_FLESH()); $result->register("salmon", fn() => Items::RAW_SALMON()); $result->register("scute", fn() => Items::SCUTE()); @@ -1481,10 +1482,10 @@ private static function registerItems(self $result) : void{ $result->register("shulker_shell", fn() => Items::SHULKER_SHELL()); $result->register("slime_ball", fn() => Items::SLIMEBALL()); $result->register("slimeball", fn() => Items::SLIMEBALL()); - $result->register("slow_falling_potion", fn() => Items::POTION()->setType(PotionType::SLOW_FALLING())); - $result->register("slow_falling_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::SLOW_FALLING())); - $result->register("slowness_potion", fn() => Items::POTION()->setType(PotionType::SLOWNESS())); - $result->register("slowness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::SLOWNESS())); + $result->register("slow_falling_potion", fn() => Items::POTION()->setType(PotionType::SLOW_FALLING)); + $result->register("slow_falling_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::SLOW_FALLING)); + $result->register("slowness_potion", fn() => Items::POTION()->setType(PotionType::SLOWNESS)); + $result->register("slowness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::SLOWNESS)); $result->register("snowball", fn() => Items::SNOWBALL()); $result->register("speckled_melon", fn() => Items::GLISTERING_MELON()); $result->register("spider_eye", fn() => Items::SPIDER_EYE()); @@ -1500,52 +1501,52 @@ private static function registerItems(self $result) : void{ $result->register("stone_pickaxe", fn() => Items::STONE_PICKAXE()); $result->register("stone_shovel", fn() => Items::STONE_SHOVEL()); $result->register("stone_sword", fn() => Items::STONE_SWORD()); - $result->register("strength_potion", fn() => Items::POTION()->setType(PotionType::STRENGTH())); - $result->register("strength_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRENGTH())); + $result->register("strength_potion", fn() => Items::POTION()->setType(PotionType::STRENGTH)); + $result->register("strength_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRENGTH)); $result->register("string", fn() => Items::STRING()); - $result->register("strong_harming_potion", fn() => Items::POTION()->setType(PotionType::STRONG_HARMING())); - $result->register("strong_harming_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_HARMING())); - $result->register("strong_healing_potion", fn() => Items::POTION()->setType(PotionType::STRONG_HEALING())); - $result->register("strong_healing_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_HEALING())); - $result->register("strong_leaping_potion", fn() => Items::POTION()->setType(PotionType::STRONG_LEAPING())); - $result->register("strong_leaping_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_LEAPING())); - $result->register("strong_poison_potion", fn() => Items::POTION()->setType(PotionType::STRONG_POISON())); - $result->register("strong_poison_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_POISON())); - $result->register("strong_regeneration_potion", fn() => Items::POTION()->setType(PotionType::STRONG_REGENERATION())); - $result->register("strong_regeneration_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_REGENERATION())); - $result->register("strong_slowness_potion", fn() => Items::POTION()->setType(PotionType::STRONG_SLOWNESS())); - $result->register("strong_slowness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_SLOWNESS())); - $result->register("strong_strength_potion", fn() => Items::POTION()->setType(PotionType::STRONG_STRENGTH())); - $result->register("strong_strength_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_STRENGTH())); - $result->register("strong_swiftness_potion", fn() => Items::POTION()->setType(PotionType::STRONG_SWIFTNESS())); - $result->register("strong_swiftness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_SWIFTNESS())); - $result->register("strong_turtle_master_potion", fn() => Items::POTION()->setType(PotionType::STRONG_TURTLE_MASTER())); - $result->register("strong_turtle_master_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_TURTLE_MASTER())); + $result->register("strong_harming_potion", fn() => Items::POTION()->setType(PotionType::STRONG_HARMING)); + $result->register("strong_harming_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_HARMING)); + $result->register("strong_healing_potion", fn() => Items::POTION()->setType(PotionType::STRONG_HEALING)); + $result->register("strong_healing_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_HEALING)); + $result->register("strong_leaping_potion", fn() => Items::POTION()->setType(PotionType::STRONG_LEAPING)); + $result->register("strong_leaping_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_LEAPING)); + $result->register("strong_poison_potion", fn() => Items::POTION()->setType(PotionType::STRONG_POISON)); + $result->register("strong_poison_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_POISON)); + $result->register("strong_regeneration_potion", fn() => Items::POTION()->setType(PotionType::STRONG_REGENERATION)); + $result->register("strong_regeneration_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_REGENERATION)); + $result->register("strong_slowness_potion", fn() => Items::POTION()->setType(PotionType::STRONG_SLOWNESS)); + $result->register("strong_slowness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_SLOWNESS)); + $result->register("strong_strength_potion", fn() => Items::POTION()->setType(PotionType::STRONG_STRENGTH)); + $result->register("strong_strength_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_STRENGTH)); + $result->register("strong_swiftness_potion", fn() => Items::POTION()->setType(PotionType::STRONG_SWIFTNESS)); + $result->register("strong_swiftness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_SWIFTNESS)); + $result->register("strong_turtle_master_potion", fn() => Items::POTION()->setType(PotionType::STRONG_TURTLE_MASTER)); + $result->register("strong_turtle_master_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::STRONG_TURTLE_MASTER)); $result->register("sugar", fn() => Items::SUGAR()); $result->register("suspicious_stew", fn() => Items::SUSPICIOUS_STEW()); $result->register("sweet_berries", fn() => Items::SWEET_BERRIES()); - $result->register("swiftness_potion", fn() => Items::POTION()->setType(PotionType::SWIFTNESS())); - $result->register("swiftness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::SWIFTNESS())); - $result->register("thick_potion", fn() => Items::POTION()->setType(PotionType::THICK())); - $result->register("thick_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::THICK())); - $result->register("tonic", fn() => Items::MEDICINE()->setType(MedicineType::TONIC())); + $result->register("swiftness_potion", fn() => Items::POTION()->setType(PotionType::SWIFTNESS)); + $result->register("swiftness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::SWIFTNESS)); + $result->register("thick_potion", fn() => Items::POTION()->setType(PotionType::THICK)); + $result->register("thick_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::THICK)); + $result->register("tonic", fn() => Items::MEDICINE()->setType(MedicineType::TONIC)); $result->register("totem", fn() => Items::TOTEM()); $result->register("turtle_helmet", fn() => Items::TURTLE_HELMET()); - $result->register("turtle_master_potion", fn() => Items::POTION()->setType(PotionType::TURTLE_MASTER())); - $result->register("turtle_master_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::TURTLE_MASTER())); + $result->register("turtle_master_potion", fn() => Items::POTION()->setType(PotionType::TURTLE_MASTER)); + $result->register("turtle_master_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::TURTLE_MASTER)); $result->register("turtle_shell_piece", fn() => Items::SCUTE()); $result->register("villager_spawn_egg", fn() => Items::VILLAGER_SPAWN_EGG()); - $result->register("water_breathing_potion", fn() => Items::POTION()->setType(PotionType::WATER_BREATHING())); - $result->register("water_breathing_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WATER_BREATHING())); + $result->register("water_breathing_potion", fn() => Items::POTION()->setType(PotionType::WATER_BREATHING)); + $result->register("water_breathing_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WATER_BREATHING)); $result->register("water_bucket", fn() => Items::WATER_BUCKET()); - $result->register("water_potion", fn() => Items::POTION()->setType(PotionType::WATER())); - $result->register("water_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WATER())); - $result->register("weakness_potion", fn() => Items::POTION()->setType(PotionType::WEAKNESS())); - $result->register("weakness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WEAKNESS())); + $result->register("water_potion", fn() => Items::POTION()->setType(PotionType::WATER)); + $result->register("water_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WATER)); + $result->register("weakness_potion", fn() => Items::POTION()->setType(PotionType::WEAKNESS)); + $result->register("weakness_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WEAKNESS)); $result->register("wheat", fn() => Items::WHEAT()); $result->register("wheat_seeds", fn() => Items::WHEAT_SEEDS()); - $result->register("wither_potion", fn() => Items::POTION()->setType(PotionType::WITHER())); - $result->register("wither_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WITHER())); + $result->register("wither_potion", fn() => Items::POTION()->setType(PotionType::WITHER)); + $result->register("wither_splash_potion", fn() => Items::SPLASH_POTION()->setType(PotionType::WITHER)); $result->register("wooden_axe", fn() => Items::WOODEN_AXE()); $result->register("wooden_hoe", fn() => Items::WOODEN_HOE()); $result->register("wooden_pickaxe", fn() => Items::WOODEN_PICKAXE()); diff --git a/src/item/SuspiciousStew.php b/src/item/SuspiciousStew.php index a2adc0b617..7d1d30cc09 100644 --- a/src/item/SuspiciousStew.php +++ b/src/item/SuspiciousStew.php @@ -27,15 +27,10 @@ class SuspiciousStew extends Food{ - private SuspiciousStewType $suspiciousStewType; - - public function __construct(ItemIdentifier $identifier, string $name){ - $this->suspiciousStewType = SuspiciousStewType::POPPY(); - parent::__construct($identifier, $name); - } + private SuspiciousStewType $suspiciousStewType = SuspiciousStewType::POPPY; protected function describeState(RuntimeDataDescriber $w) : void{ - $w->suspiciousStewType($this->suspiciousStewType); + $w->enum($this->suspiciousStewType); } public function getType() : SuspiciousStewType{ return $this->suspiciousStewType; } diff --git a/src/item/SuspiciousStewType.php b/src/item/SuspiciousStewType.php index 27209b5731..d53b82a3fa 100644 --- a/src/item/SuspiciousStewType.php +++ b/src/item/SuspiciousStewType.php @@ -25,13 +25,11 @@ use pocketmine\entity\effect\EffectInstance; use pocketmine\entity\effect\VanillaEffects; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static SuspiciousStewType ALLIUM() * @method static SuspiciousStewType AZURE_BLUET() @@ -44,61 +42,36 @@ * @method static SuspiciousStewType TULIP() * @method static SuspiciousStewType WITHER_ROSE() */ -final class SuspiciousStewType{ - use EnumTrait { - __construct as Enum___construct; - } - - protected static function setup() : void{ - self::registerAll( - new self("poppy", fn() => [ - new EffectInstance(VanillaEffects::NIGHT_VISION(), 80) - ]), - new self("cornflower", fn() => [ - new EffectInstance(VanillaEffects::JUMP_BOOST(), 80) - ]), - new self("tulip", fn() => [ - new EffectInstance(VanillaEffects::WEAKNESS(), 140) - ]), - new self("azure_bluet", fn() => [ - new EffectInstance(VanillaEffects::BLINDNESS(), 120) - ]), - new self("lily_of_the_valley", fn() => [ - new EffectInstance(VanillaEffects::POISON(), 200) - ]), - new self("dandelion", fn() => [ - new EffectInstance(VanillaEffects::SATURATION(), 6) - ]), - new self("blue_orchid", fn() => [ - new EffectInstance(VanillaEffects::SATURATION(), 6) - ]), - new self("allium", fn() => [ - new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 40) - ]), - new self("oxeye_daisy", fn() => [ - new EffectInstance(VanillaEffects::REGENERATION(), 120) - ]), - new self("wither_rose", fn() => [ - new EffectInstance(VanillaEffects::WITHER(), 120) - ]) - ); - } +enum SuspiciousStewType{ + use LegacyEnumShimTrait; - /** - * @phpstan-param \Closure() : list $effectsGetter - */ - private function __construct( - string $enumName, - private \Closure $effectsGetter - ){ - $this->Enum___construct($enumName); - } + case POPPY; + case CORNFLOWER; + case TULIP; + case AZURE_BLUET; + case LILY_OF_THE_VALLEY; + case DANDELION; + case BLUE_ORCHID; + case ALLIUM; + case OXEYE_DAISY; + case WITHER_ROSE; /** * @return EffectInstance[] * @phpstan-return list */ public function getEffects() : array{ - return ($this->effectsGetter)(); + return match($this){ + self::POPPY => [new EffectInstance(VanillaEffects::NIGHT_VISION(), 80)], + self::CORNFLOWER => [new EffectInstance(VanillaEffects::JUMP_BOOST(), 80)], + self::TULIP => [new EffectInstance(VanillaEffects::WEAKNESS(), 140)], + self::AZURE_BLUET => [new EffectInstance(VanillaEffects::BLINDNESS(), 120)], + self::LILY_OF_THE_VALLEY => [new EffectInstance(VanillaEffects::POISON(), 200)], + self::DANDELION, + self::BLUE_ORCHID => [new EffectInstance(VanillaEffects::SATURATION(), 6)], + self::ALLIUM => [new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 40)], + self::OXEYE_DAISY => [new EffectInstance(VanillaEffects::REGENERATION(), 120)], + self::WITHER_ROSE => [new EffectInstance(VanillaEffects::WITHER(), 120)] + }; } } diff --git a/src/item/TieredTool.php b/src/item/TieredTool.php index dc00aebcf8..20b40bbcb4 100644 --- a/src/item/TieredTool.php +++ b/src/item/TieredTool.php @@ -51,7 +51,7 @@ public function getEnchantability() : int{ } public function getFuelTime() : int{ - if($this->tier->equals(ToolTier::WOOD())){ + if($this->tier === ToolTier::WOOD){ return 200; } @@ -59,6 +59,6 @@ public function getFuelTime() : int{ } public function isFireProof() : bool{ - return $this->tier->equals(ToolTier::NETHERITE()); + return $this->tier === ToolTier::NETHERITE; } } diff --git a/src/item/ToolTier.php b/src/item/ToolTier.php index 4ca910c0bb..8469bc7e5f 100644 --- a/src/item/ToolTier.php +++ b/src/item/ToolTier.php @@ -23,13 +23,11 @@ namespace pocketmine\item; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static ToolTier DIAMOND() * @method static ToolTier GOLD() @@ -37,48 +35,55 @@ * @method static ToolTier NETHERITE() * @method static ToolTier STONE() * @method static ToolTier WOOD() + * + * @phpstan-type TMetadata array{0: int, 1: int, 2: int, 3: int, 4: int} */ -final class ToolTier{ - use EnumTrait { - __construct as Enum___construct; - } +enum ToolTier{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("wood", 1, 60, 5, 2, 15), - new self("gold", 2, 33, 5, 12, 22), - new self("stone", 3, 132, 6, 4, 5), - new self("iron", 4, 251, 7, 6, 14), - new self("diamond", 5, 1562, 8, 8, 10), - new self("netherite", 6, 2032, 9, 9, 15) - ); + case WOOD; + case GOLD; + case STONE; + case IRON; + case DIAMOND; + case NETHERITE; + + /** + * This function exists only to permit the use of named arguments and to make the code easier to read in PhpStorm. + * @phpstan-return TMetadata + */ + private static function meta(int $harvestLevel, int $maxDurability, int $baseAttackPoints, int $baseEfficiency, int $enchantability) : array{ + return [$harvestLevel, $maxDurability, $baseAttackPoints, $baseEfficiency, $enchantability]; } - private function __construct( - string $name, - private int $harvestLevel, - private int $maxDurability, - private int $baseAttackPoints, - private int $baseEfficiency, - private int $enchantability - ){ - $this->Enum___construct($name); + /** + * @phpstan-return TMetadata + */ + private function getMetadata() : array{ + return match($this){ + self::WOOD => self::meta(1, 60, 5, 2, 15), + self::GOLD => self::meta(2, 33, 5, 12, 22), + self::STONE => self::meta(3, 132, 6, 4, 5), + self::IRON => self::meta(4, 251, 7, 6, 14), + self::DIAMOND => self::meta(5, 1562, 8, 8, 10), + self::NETHERITE => self::meta(6, 2032, 9, 9, 15) + }; } public function getHarvestLevel() : int{ - return $this->harvestLevel; + return $this->getMetadata()[0]; } public function getMaxDurability() : int{ - return $this->maxDurability; + return $this->getMetadata()[1]; } public function getBaseAttackPoints() : int{ - return $this->baseAttackPoints; + return $this->getMetadata()[2]; } public function getBaseEfficiency() : int{ - return $this->baseEfficiency; + return $this->getMetadata()[3]; } /** @@ -88,6 +93,6 @@ public function getBaseEfficiency() : int{ * or multiple enchantments upon being enchanted in an enchanting table. */ public function getEnchantability() : int{ - return $this->enchantability; + return $this->getMetadata()[4]; } } diff --git a/src/item/VanillaItems.php b/src/item/VanillaItems.php index 20c3e996fb..c5f8a58740 100644 --- a/src/item/VanillaItems.php +++ b/src/item/VanillaItems.php @@ -36,9 +36,9 @@ use pocketmine\item\ItemTypeIds as Ids; use pocketmine\item\VanillaArmorMaterials as ArmorMaterials; use pocketmine\math\Vector3; -use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\CloningRegistryTrait; use pocketmine\world\World; +use function strtolower; /** * This doc-block is generated automatically, do not modify it manually. @@ -510,21 +510,21 @@ public function isFireProof() : bool{ return true; } self::register("raw_porkchop", new RawPorkchop(new IID(Ids::RAW_PORKCHOP), "Raw Porkchop")); self::register("raw_rabbit", new RawRabbit(new IID(Ids::RAW_RABBIT), "Raw Rabbit")); self::register("raw_salmon", new RawSalmon(new IID(Ids::RAW_SALMON), "Raw Salmon")); - self::register("record_11", new Record(new IID(Ids::RECORD_11), RecordType::DISK_11(), "Record 11")); - self::register("record_13", new Record(new IID(Ids::RECORD_13), RecordType::DISK_13(), "Record 13")); - self::register("record_5", new Record(new IID(Ids::RECORD_5), RecordType::DISK_5(), "Record 5")); - self::register("record_blocks", new Record(new IID(Ids::RECORD_BLOCKS), RecordType::DISK_BLOCKS(), "Record Blocks")); - self::register("record_cat", new Record(new IID(Ids::RECORD_CAT), RecordType::DISK_CAT(), "Record Cat")); - self::register("record_chirp", new Record(new IID(Ids::RECORD_CHIRP), RecordType::DISK_CHIRP(), "Record Chirp")); - self::register("record_far", new Record(new IID(Ids::RECORD_FAR), RecordType::DISK_FAR(), "Record Far")); - self::register("record_mall", new Record(new IID(Ids::RECORD_MALL), RecordType::DISK_MALL(), "Record Mall")); - self::register("record_mellohi", new Record(new IID(Ids::RECORD_MELLOHI), RecordType::DISK_MELLOHI(), "Record Mellohi")); - self::register("record_otherside", new Record(new IID(Ids::RECORD_OTHERSIDE), RecordType::DISK_OTHERSIDE(), "Record Otherside")); - self::register("record_pigstep", new Record(new IID(Ids::RECORD_PIGSTEP), RecordType::DISK_PIGSTEP(), "Record Pigstep")); - self::register("record_stal", new Record(new IID(Ids::RECORD_STAL), RecordType::DISK_STAL(), "Record Stal")); - self::register("record_strad", new Record(new IID(Ids::RECORD_STRAD), RecordType::DISK_STRAD(), "Record Strad")); - self::register("record_wait", new Record(new IID(Ids::RECORD_WAIT), RecordType::DISK_WAIT(), "Record Wait")); - self::register("record_ward", new Record(new IID(Ids::RECORD_WARD), RecordType::DISK_WARD(), "Record Ward")); + self::register("record_11", new Record(new IID(Ids::RECORD_11), RecordType::DISK_11, "Record 11")); + self::register("record_13", new Record(new IID(Ids::RECORD_13), RecordType::DISK_13, "Record 13")); + self::register("record_5", new Record(new IID(Ids::RECORD_5), RecordType::DISK_5, "Record 5")); + self::register("record_blocks", new Record(new IID(Ids::RECORD_BLOCKS), RecordType::DISK_BLOCKS, "Record Blocks")); + self::register("record_cat", new Record(new IID(Ids::RECORD_CAT), RecordType::DISK_CAT, "Record Cat")); + self::register("record_chirp", new Record(new IID(Ids::RECORD_CHIRP), RecordType::DISK_CHIRP, "Record Chirp")); + self::register("record_far", new Record(new IID(Ids::RECORD_FAR), RecordType::DISK_FAR, "Record Far")); + self::register("record_mall", new Record(new IID(Ids::RECORD_MALL), RecordType::DISK_MALL, "Record Mall")); + self::register("record_mellohi", new Record(new IID(Ids::RECORD_MELLOHI), RecordType::DISK_MELLOHI, "Record Mellohi")); + self::register("record_otherside", new Record(new IID(Ids::RECORD_OTHERSIDE), RecordType::DISK_OTHERSIDE, "Record Otherside")); + self::register("record_pigstep", new Record(new IID(Ids::RECORD_PIGSTEP), RecordType::DISK_PIGSTEP, "Record Pigstep")); + self::register("record_stal", new Record(new IID(Ids::RECORD_STAL), RecordType::DISK_STAL, "Record Stal")); + self::register("record_strad", new Record(new IID(Ids::RECORD_STRAD), RecordType::DISK_STRAD, "Record Strad")); + self::register("record_wait", new Record(new IID(Ids::RECORD_WAIT), RecordType::DISK_WAIT, "Record Wait")); + self::register("record_ward", new Record(new IID(Ids::RECORD_WARD), RecordType::DISK_WARD, "Record Ward")); self::register("redstone_dust", new Redstone(new IID(Ids::REDSTONE_DUST), "Redstone")); self::register("rotten_flesh", new RottenFlesh(new IID(Ids::ROTTEN_FLESH), "Rotten Flesh")); self::register("scute", new Item(new IID(Ids::SCUTE), "Scute")); @@ -550,17 +550,16 @@ public function isFireProof() : bool{ return true; } self::register("writable_book", new WritableBook(new IID(Ids::WRITABLE_BOOK), "Book & Quill")); self::register("written_book", new WrittenBook(new IID(Ids::WRITTEN_BOOK), "Written Book")); - foreach(BoatType::getAll() as $type){ + foreach(BoatType::cases() as $type){ //boat type is static, because different types of wood may have different properties - self::register($type->name() . "_boat", new Boat(new IID(match($type){ - BoatType::OAK() => Ids::OAK_BOAT, - BoatType::SPRUCE() => Ids::SPRUCE_BOAT, - BoatType::BIRCH() => Ids::BIRCH_BOAT, - BoatType::JUNGLE() => Ids::JUNGLE_BOAT, - BoatType::ACACIA() => Ids::ACACIA_BOAT, - BoatType::DARK_OAK() => Ids::DARK_OAK_BOAT, - BoatType::MANGROVE() => Ids::MANGROVE_BOAT, - default => throw new AssumptionFailedError("Unhandled tree type " . $type->name()) + self::register(strtolower($type->name) . "_boat", new Boat(new IID(match($type){ + BoatType::OAK => Ids::OAK_BOAT, + BoatType::SPRUCE => Ids::SPRUCE_BOAT, + BoatType::BIRCH => Ids::BIRCH_BOAT, + BoatType::JUNGLE => Ids::JUNGLE_BOAT, + BoatType::ACACIA => Ids::ACACIA_BOAT, + BoatType::DARK_OAK => Ids::DARK_OAK_BOAT, + BoatType::MANGROVE => Ids::MANGROVE_BOAT, }), $type->getDisplayName() . " Boat", $type)); } } @@ -584,36 +583,36 @@ public function createEntity(World $world, Vector3 $pos, float $yaw, float $pitc } private static function registerTierToolItems() : void{ - self::register("diamond_axe", new Axe(new IID(Ids::DIAMOND_AXE), "Diamond Axe", ToolTier::DIAMOND(), [EnchantmentTags::AXE])); - self::register("golden_axe", new Axe(new IID(Ids::GOLDEN_AXE), "Golden Axe", ToolTier::GOLD(), [EnchantmentTags::AXE])); - self::register("iron_axe", new Axe(new IID(Ids::IRON_AXE), "Iron Axe", ToolTier::IRON(), [EnchantmentTags::AXE])); - self::register("netherite_axe", new Axe(new IID(Ids::NETHERITE_AXE), "Netherite Axe", ToolTier::NETHERITE(), [EnchantmentTags::AXE])); - self::register("stone_axe", new Axe(new IID(Ids::STONE_AXE), "Stone Axe", ToolTier::STONE(), [EnchantmentTags::AXE])); - self::register("wooden_axe", new Axe(new IID(Ids::WOODEN_AXE), "Wooden Axe", ToolTier::WOOD(), [EnchantmentTags::AXE])); - self::register("diamond_hoe", new Hoe(new IID(Ids::DIAMOND_HOE), "Diamond Hoe", ToolTier::DIAMOND(), [EnchantmentTags::HOE])); - self::register("golden_hoe", new Hoe(new IID(Ids::GOLDEN_HOE), "Golden Hoe", ToolTier::GOLD(), [EnchantmentTags::HOE])); - self::register("iron_hoe", new Hoe(new IID(Ids::IRON_HOE), "Iron Hoe", ToolTier::IRON(), [EnchantmentTags::HOE])); - self::register("netherite_hoe", new Hoe(new IID(Ids::NETHERITE_HOE), "Netherite Hoe", ToolTier::NETHERITE(), [EnchantmentTags::HOE])); - self::register("stone_hoe", new Hoe(new IID(Ids::STONE_HOE), "Stone Hoe", ToolTier::STONE(), [EnchantmentTags::HOE])); - self::register("wooden_hoe", new Hoe(new IID(Ids::WOODEN_HOE), "Wooden Hoe", ToolTier::WOOD(), [EnchantmentTags::HOE])); - self::register("diamond_pickaxe", new Pickaxe(new IID(Ids::DIAMOND_PICKAXE), "Diamond Pickaxe", ToolTier::DIAMOND(), [EnchantmentTags::PICKAXE])); - self::register("golden_pickaxe", new Pickaxe(new IID(Ids::GOLDEN_PICKAXE), "Golden Pickaxe", ToolTier::GOLD(), [EnchantmentTags::PICKAXE])); - self::register("iron_pickaxe", new Pickaxe(new IID(Ids::IRON_PICKAXE), "Iron Pickaxe", ToolTier::IRON(), [EnchantmentTags::PICKAXE])); - self::register("netherite_pickaxe", new Pickaxe(new IID(Ids::NETHERITE_PICKAXE), "Netherite Pickaxe", ToolTier::NETHERITE(), [EnchantmentTags::PICKAXE])); - self::register("stone_pickaxe", new Pickaxe(new IID(Ids::STONE_PICKAXE), "Stone Pickaxe", ToolTier::STONE(), [EnchantmentTags::PICKAXE])); - self::register("wooden_pickaxe", new Pickaxe(new IID(Ids::WOODEN_PICKAXE), "Wooden Pickaxe", ToolTier::WOOD(), [EnchantmentTags::PICKAXE])); - self::register("diamond_shovel", new Shovel(new IID(Ids::DIAMOND_SHOVEL), "Diamond Shovel", ToolTier::DIAMOND(), [EnchantmentTags::SHOVEL])); - self::register("golden_shovel", new Shovel(new IID(Ids::GOLDEN_SHOVEL), "Golden Shovel", ToolTier::GOLD(), [EnchantmentTags::SHOVEL])); - self::register("iron_shovel", new Shovel(new IID(Ids::IRON_SHOVEL), "Iron Shovel", ToolTier::IRON(), [EnchantmentTags::SHOVEL])); - self::register("netherite_shovel", new Shovel(new IID(Ids::NETHERITE_SHOVEL), "Netherite Shovel", ToolTier::NETHERITE(), [EnchantmentTags::SHOVEL])); - self::register("stone_shovel", new Shovel(new IID(Ids::STONE_SHOVEL), "Stone Shovel", ToolTier::STONE(), [EnchantmentTags::SHOVEL])); - self::register("wooden_shovel", new Shovel(new IID(Ids::WOODEN_SHOVEL), "Wooden Shovel", ToolTier::WOOD(), [EnchantmentTags::SHOVEL])); - self::register("diamond_sword", new Sword(new IID(Ids::DIAMOND_SWORD), "Diamond Sword", ToolTier::DIAMOND(), [EnchantmentTags::SWORD])); - self::register("golden_sword", new Sword(new IID(Ids::GOLDEN_SWORD), "Golden Sword", ToolTier::GOLD(), [EnchantmentTags::SWORD])); - self::register("iron_sword", new Sword(new IID(Ids::IRON_SWORD), "Iron Sword", ToolTier::IRON(), [EnchantmentTags::SWORD])); - self::register("netherite_sword", new Sword(new IID(Ids::NETHERITE_SWORD), "Netherite Sword", ToolTier::NETHERITE(), [EnchantmentTags::SWORD])); - self::register("stone_sword", new Sword(new IID(Ids::STONE_SWORD), "Stone Sword", ToolTier::STONE(), [EnchantmentTags::SWORD])); - self::register("wooden_sword", new Sword(new IID(Ids::WOODEN_SWORD), "Wooden Sword", ToolTier::WOOD(), [EnchantmentTags::SWORD])); + self::register("diamond_axe", new Axe(new IID(Ids::DIAMOND_AXE), "Diamond Axe", ToolTier::DIAMOND, [EnchantmentTags::AXE])); + self::register("golden_axe", new Axe(new IID(Ids::GOLDEN_AXE), "Golden Axe", ToolTier::GOLD, [EnchantmentTags::AXE])); + self::register("iron_axe", new Axe(new IID(Ids::IRON_AXE), "Iron Axe", ToolTier::IRON, [EnchantmentTags::AXE])); + self::register("netherite_axe", new Axe(new IID(Ids::NETHERITE_AXE), "Netherite Axe", ToolTier::NETHERITE, [EnchantmentTags::AXE])); + self::register("stone_axe", new Axe(new IID(Ids::STONE_AXE), "Stone Axe", ToolTier::STONE, [EnchantmentTags::AXE])); + self::register("wooden_axe", new Axe(new IID(Ids::WOODEN_AXE), "Wooden Axe", ToolTier::WOOD, [EnchantmentTags::AXE])); + self::register("diamond_hoe", new Hoe(new IID(Ids::DIAMOND_HOE), "Diamond Hoe", ToolTier::DIAMOND, [EnchantmentTags::HOE])); + self::register("golden_hoe", new Hoe(new IID(Ids::GOLDEN_HOE), "Golden Hoe", ToolTier::GOLD, [EnchantmentTags::HOE])); + self::register("iron_hoe", new Hoe(new IID(Ids::IRON_HOE), "Iron Hoe", ToolTier::IRON, [EnchantmentTags::HOE])); + self::register("netherite_hoe", new Hoe(new IID(Ids::NETHERITE_HOE), "Netherite Hoe", ToolTier::NETHERITE, [EnchantmentTags::HOE])); + self::register("stone_hoe", new Hoe(new IID(Ids::STONE_HOE), "Stone Hoe", ToolTier::STONE, [EnchantmentTags::HOE])); + self::register("wooden_hoe", new Hoe(new IID(Ids::WOODEN_HOE), "Wooden Hoe", ToolTier::WOOD, [EnchantmentTags::HOE])); + self::register("diamond_pickaxe", new Pickaxe(new IID(Ids::DIAMOND_PICKAXE), "Diamond Pickaxe", ToolTier::DIAMOND, [EnchantmentTags::PICKAXE])); + self::register("golden_pickaxe", new Pickaxe(new IID(Ids::GOLDEN_PICKAXE), "Golden Pickaxe", ToolTier::GOLD, [EnchantmentTags::PICKAXE])); + self::register("iron_pickaxe", new Pickaxe(new IID(Ids::IRON_PICKAXE), "Iron Pickaxe", ToolTier::IRON, [EnchantmentTags::PICKAXE])); + self::register("netherite_pickaxe", new Pickaxe(new IID(Ids::NETHERITE_PICKAXE), "Netherite Pickaxe", ToolTier::NETHERITE, [EnchantmentTags::PICKAXE])); + self::register("stone_pickaxe", new Pickaxe(new IID(Ids::STONE_PICKAXE), "Stone Pickaxe", ToolTier::STONE, [EnchantmentTags::PICKAXE])); + self::register("wooden_pickaxe", new Pickaxe(new IID(Ids::WOODEN_PICKAXE), "Wooden Pickaxe", ToolTier::WOOD, [EnchantmentTags::PICKAXE])); + self::register("diamond_shovel", new Shovel(new IID(Ids::DIAMOND_SHOVEL), "Diamond Shovel", ToolTier::DIAMOND, [EnchantmentTags::SHOVEL])); + self::register("golden_shovel", new Shovel(new IID(Ids::GOLDEN_SHOVEL), "Golden Shovel", ToolTier::GOLD, [EnchantmentTags::SHOVEL])); + self::register("iron_shovel", new Shovel(new IID(Ids::IRON_SHOVEL), "Iron Shovel", ToolTier::IRON, [EnchantmentTags::SHOVEL])); + self::register("netherite_shovel", new Shovel(new IID(Ids::NETHERITE_SHOVEL), "Netherite Shovel", ToolTier::NETHERITE, [EnchantmentTags::SHOVEL])); + self::register("stone_shovel", new Shovel(new IID(Ids::STONE_SHOVEL), "Stone Shovel", ToolTier::STONE, [EnchantmentTags::SHOVEL])); + self::register("wooden_shovel", new Shovel(new IID(Ids::WOODEN_SHOVEL), "Wooden Shovel", ToolTier::WOOD, [EnchantmentTags::SHOVEL])); + self::register("diamond_sword", new Sword(new IID(Ids::DIAMOND_SWORD), "Diamond Sword", ToolTier::DIAMOND, [EnchantmentTags::SWORD])); + self::register("golden_sword", new Sword(new IID(Ids::GOLDEN_SWORD), "Golden Sword", ToolTier::GOLD, [EnchantmentTags::SWORD])); + self::register("iron_sword", new Sword(new IID(Ids::IRON_SWORD), "Iron Sword", ToolTier::IRON, [EnchantmentTags::SWORD])); + self::register("netherite_sword", new Sword(new IID(Ids::NETHERITE_SWORD), "Netherite Sword", ToolTier::NETHERITE, [EnchantmentTags::SWORD])); + self::register("stone_sword", new Sword(new IID(Ids::STONE_SWORD), "Stone Sword", ToolTier::STONE, [EnchantmentTags::SWORD])); + self::register("wooden_sword", new Sword(new IID(Ids::WOODEN_SWORD), "Wooden Sword", ToolTier::WOOD, [EnchantmentTags::SWORD])); } private static function registerArmorItems() : void{ diff --git a/src/item/enchantment/AvailableEnchantmentRegistry.php b/src/item/enchantment/AvailableEnchantmentRegistry.php index af8484049a..2c6f421ede 100644 --- a/src/item/enchantment/AvailableEnchantmentRegistry.php +++ b/src/item/enchantment/AvailableEnchantmentRegistry.php @@ -59,9 +59,9 @@ private function __construct(){ $this->register(Enchantments::SHARPNESS(), [Tags::SWORD, Tags::AXE], []); $this->register(Enchantments::KNOCKBACK(), [Tags::SWORD], []); $this->register(Enchantments::FIRE_ASPECT(), [Tags::SWORD], []); - $this->register(Enchantments::EFFICIENCY(), [Tags::DIG_TOOLS], [Tags::SHEARS]); - $this->register(Enchantments::FORTUNE(), [Tags::DIG_TOOLS], []); - $this->register(Enchantments::SILK_TOUCH(), [Tags::DIG_TOOLS], [Tags::SHEARS]); + $this->register(Enchantments::EFFICIENCY(), [Tags::BLOCK_TOOLS], [Tags::SHEARS]); + $this->register(Enchantments::FORTUNE(), [Tags::BLOCK_TOOLS], []); + $this->register(Enchantments::SILK_TOUCH(), [Tags::BLOCK_TOOLS], [Tags::SHEARS]); $this->register( Enchantments::UNBREAKING(), [Tags::ARMOR, Tags::WEAPONS, Tags::FISHING_ROD], diff --git a/src/item/enchantment/EnchantmentHelper.php b/src/item/enchantment/EnchantingHelper.php similarity index 87% rename from src/item/enchantment/EnchantmentHelper.php rename to src/item/enchantment/EnchantingHelper.php index bd4b689633..fb4e8f27ce 100644 --- a/src/item/enchantment/EnchantmentHelper.php +++ b/src/item/enchantment/EnchantingHelper.php @@ -28,6 +28,7 @@ use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; use pocketmine\item\VanillaItems as Items; +use pocketmine\utils\Limits; use pocketmine\utils\Random; use pocketmine\world\Position; use function abs; @@ -37,12 +38,27 @@ use function floor; use function max; use function min; +use function mt_rand; use function ord; use function round; -final class EnchantmentHelper{ +/** + * Helper methods used for enchanting using the enchanting table. + */ +final class EnchantingHelper{ private const MAX_BOOKSHELF_COUNT = 15; + private function __construct(){ + //NOOP + } + + /** + * Generates a new random seed for enchant option randomization. + */ + public static function generateSeed() : int{ + return mt_rand(Limits::INT32_MIN, Limits::INT32_MAX); + } + /** * @param EnchantmentInstance[] $enchantments */ @@ -57,9 +73,9 @@ public static function enchantItem(Item $item, array $enchantments) : Item{ } /** - * @return EnchantOption[] + * @return EnchantingOption[] */ - public static function getEnchantOptions(Position $tablePos, Item $input, int $seed) : array{ + public static function generateOptions(Position $tablePos, Item $input, int $seed) : array{ if($input->isNull() || $input->hasEnchantments()){ return []; } @@ -73,9 +89,9 @@ public static function getEnchantOptions(Position $tablePos, Item $input, int $s $bottomRequiredLevel = max($baseRequiredLevel, $bookshelfCount * 2); return [ - self::createEnchantOption($random, $input, $topRequiredLevel), - self::createEnchantOption($random, $input, $middleRequiredLevel), - self::createEnchantOption($random, $input, $bottomRequiredLevel), + self::createOption($random, $input, $topRequiredLevel), + self::createOption($random, $input, $middleRequiredLevel), + self::createOption($random, $input, $bottomRequiredLevel), ]; } @@ -117,7 +133,7 @@ private static function countBookshelves(Position $tablePos) : int{ return $bookshelfCount; } - private static function createEnchantOption(Random $random, Item $inputItem, int $requiredXpLevel) : EnchantOption{ + private static function createOption(Random $random, Item $inputItem, int $requiredXpLevel) : EnchantingOption{ $enchantingPower = $requiredXpLevel; $enchantability = $inputItem->getEnchantability(); @@ -155,7 +171,7 @@ function(EnchantmentInstance $e) use ($lastEnchantment){ } } - return new EnchantOption($requiredXpLevel, self::getRandomOptionName($random), $resultEnchantments); + return new EnchantingOption($requiredXpLevel, self::getRandomOptionName($random), $resultEnchantments); } /** diff --git a/src/item/enchantment/EnchantOption.php b/src/item/enchantment/EnchantingOption.php similarity index 98% rename from src/item/enchantment/EnchantOption.php rename to src/item/enchantment/EnchantingOption.php index b1c3a7af5a..2bedb0cc41 100644 --- a/src/item/enchantment/EnchantOption.php +++ b/src/item/enchantment/EnchantingOption.php @@ -27,7 +27,7 @@ * Represents an option on the enchanting table menu. * If selected, all the enchantments in the option will be applied to the item. */ -class EnchantOption{ +class EnchantingOption{ /** * @param EnchantmentInstance[] $enchantments diff --git a/src/item/enchantment/Enchantment.php b/src/item/enchantment/Enchantment.php index 22c0cdb015..948f4648bc 100644 --- a/src/item/enchantment/Enchantment.php +++ b/src/item/enchantment/Enchantment.php @@ -83,6 +83,7 @@ public function getRarity() : int{ * Returns a bitset indicating what item types can have this item applied from an enchanting table. * * @deprecated + * @see AvailableEnchantmentRegistry::getPrimaryItemTags() */ public function getPrimaryItemFlags() : int{ return $this->primaryItemFlags; @@ -93,6 +94,7 @@ public function getPrimaryItemFlags() : int{ * an anvil. * * @deprecated + * @see AvailableEnchantmentRegistry::getSecondaryItemTags() */ public function getSecondaryItemFlags() : int{ return $this->secondaryItemFlags; @@ -102,6 +104,7 @@ public function getSecondaryItemFlags() : int{ * Returns whether this enchantment can apply to the item type from an enchanting table. * * @deprecated + * @see AvailableEnchantmentRegistry */ public function hasPrimaryItemType(int $flag) : bool{ return ($this->primaryItemFlags & $flag) !== 0; @@ -111,6 +114,7 @@ public function hasPrimaryItemType(int $flag) : bool{ * Returns whether this enchantment can apply to the item type from an anvil, if it is not a primary item. * * @deprecated + * @see AvailableEnchantmentRegistry */ public function hasSecondaryItemType(int $flag) : bool{ return ($this->secondaryItemFlags & $flag) !== 0; diff --git a/src/item/enchantment/IncompatibleEnchantmentGroups.php b/src/item/enchantment/IncompatibleEnchantmentGroups.php index ed1141beea..74574562c5 100644 --- a/src/item/enchantment/IncompatibleEnchantmentGroups.php +++ b/src/item/enchantment/IncompatibleEnchantmentGroups.php @@ -30,5 +30,5 @@ final class IncompatibleEnchantmentGroups{ public const PROTECTION = "protection"; public const BOW_INFINITE = "bow_infinite"; - public const DIG_DROP = "dig_drop"; + public const BLOCK_DROPS = "block_drops"; } diff --git a/src/item/enchantment/IncompatibleEnchantmentRegistry.php b/src/item/enchantment/IncompatibleEnchantmentRegistry.php index 8dce4777e1..629a159709 100644 --- a/src/item/enchantment/IncompatibleEnchantmentRegistry.php +++ b/src/item/enchantment/IncompatibleEnchantmentRegistry.php @@ -46,7 +46,7 @@ final class IncompatibleEnchantmentRegistry{ private function __construct(){ $this->register(Groups::PROTECTION, [Enchantments::PROTECTION(), Enchantments::FIRE_PROTECTION(), Enchantments::BLAST_PROTECTION(), Enchantments::PROJECTILE_PROTECTION()]); $this->register(Groups::BOW_INFINITE, [Enchantments::INFINITY(), Enchantments::MENDING()]); - $this->register(Groups::DIG_DROP, [Enchantments::FORTUNE(), Enchantments::SILK_TOUCH()]); + $this->register(Groups::BLOCK_DROPS, [Enchantments::FORTUNE(), Enchantments::SILK_TOUCH()]); } /** diff --git a/src/item/enchantment/ItemEnchantmentTagRegistry.php b/src/item/enchantment/ItemEnchantmentTagRegistry.php index 9c607f9d28..210cd8e864 100644 --- a/src/item/enchantment/ItemEnchantmentTagRegistry.php +++ b/src/item/enchantment/ItemEnchantmentTagRegistry.php @@ -56,7 +56,7 @@ private function __construct(){ $this->register(Tags::CROSSBOW); $this->register(Tags::SHEARS); $this->register(Tags::FLINT_AND_STEEL); - $this->register(Tags::DIG_TOOLS, [Tags::AXE, Tags::PICKAXE, Tags::SHOVEL, Tags::HOE]); + $this->register(Tags::BLOCK_TOOLS, [Tags::AXE, Tags::PICKAXE, Tags::SHOVEL, Tags::HOE]); $this->register(Tags::FISHING_ROD); $this->register(Tags::CARROT_ON_STICK); $this->register(Tags::COMPASS); @@ -68,7 +68,7 @@ private function __construct(){ Tags::TRIDENT, Tags::BOW, Tags::CROSSBOW, - Tags::DIG_TOOLS, + Tags::BLOCK_TOOLS, ]); } diff --git a/src/item/enchantment/ItemEnchantmentTags.php b/src/item/enchantment/ItemEnchantmentTags.php index 485cb5d0c1..50abf8db3b 100644 --- a/src/item/enchantment/ItemEnchantmentTags.php +++ b/src/item/enchantment/ItemEnchantmentTags.php @@ -42,7 +42,7 @@ final class ItemEnchantmentTags{ public const CROSSBOW = "crossbow"; public const SHEARS = "shears"; public const FLINT_AND_STEEL = "flint_and_steel"; - public const DIG_TOOLS = "dig_tools"; + public const BLOCK_TOOLS = "block_tools"; public const AXE = "axe"; public const PICKAXE = "pickaxe"; public const SHOVEL = "shovel"; diff --git a/src/network/mcpe/InventoryManager.php b/src/network/mcpe/InventoryManager.php index 0e1c159164..32c4cbb517 100644 --- a/src/network/mcpe/InventoryManager.php +++ b/src/network/mcpe/InventoryManager.php @@ -39,8 +39,8 @@ use pocketmine\inventory\Inventory; use pocketmine\inventory\transaction\action\SlotChangeAction; use pocketmine\inventory\transaction\InventoryTransaction; +use pocketmine\item\enchantment\EnchantingOption; use pocketmine\item\enchantment\EnchantmentInstance; -use pocketmine\item\enchantment\EnchantOption; use pocketmine\network\mcpe\cache\CreativeInventoryCache; use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; @@ -352,11 +352,10 @@ protected static function createContainerOpen(int $id, Inventory $inv) : ?array{ $blockPosition = BlockPosition::fromVector3($inv->getHolder()); $windowType = match(true){ $inv instanceof LoomInventory => WindowTypes::LOOM, - $inv instanceof FurnaceInventory => match($inv->getFurnaceType()->id()){ - FurnaceType::FURNACE()->id() => WindowTypes::FURNACE, - FurnaceType::BLAST_FURNACE()->id() => WindowTypes::BLAST_FURNACE, - FurnaceType::SMOKER()->id() => WindowTypes::SMOKER, - default => throw new AssumptionFailedError("Unreachable") + $inv instanceof FurnaceInventory => match($inv->getFurnaceType()){ + FurnaceType::FURNACE => WindowTypes::FURNACE, + FurnaceType::BLAST_FURNACE => WindowTypes::BLAST_FURNACE, + FurnaceType::SMOKER => WindowTypes::SMOKER, }, $inv instanceof EnchantInventory => WindowTypes::ENCHANTMENT, $inv instanceof BrewingStandInventory => WindowTypes::BREWING_STAND, @@ -645,7 +644,7 @@ public function syncCreative() : void{ } /** - * @param EnchantOption[] $options + * @param EnchantingOption[] $options */ public function syncEnchantingTableOptions(array $options) : void{ $protocolOptions = []; diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index d6f589f175..ad59d5c63e 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -23,7 +23,6 @@ namespace pocketmine\network\mcpe; -use pocketmine\block\tile\Spawnable; use pocketmine\entity\effect\EffectInstance; use pocketmine\event\player\PlayerDuplicateLoginEvent; use pocketmine\event\player\SessionDisconnectEvent; @@ -53,9 +52,7 @@ use pocketmine\network\mcpe\handler\ResourcePacksPacketHandler; use pocketmine\network\mcpe\handler\SessionStartPacketHandler; use pocketmine\network\mcpe\handler\SpawnResponsePacketHandler; -use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; use pocketmine\network\mcpe\protocol\AvailableCommandsPacket; -use pocketmine\network\mcpe\protocol\BlockActorDataPacket; use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\ClientCacheMissResponsePacket; @@ -114,6 +111,7 @@ use pocketmine\utils\ObjectSet; use pocketmine\utils\TextFormat; use pocketmine\world\Position; +use pocketmine\YmlServerProperties; use function array_keys; use function array_map; use function array_replace; @@ -819,7 +817,7 @@ private function setAuthenticationStatus(bool $authenticated, bool $authRequired } $this->logger->debug("Xbox Live authenticated: " . ($this->authenticated ? "YES" : "NO")); - $checkXUID = $this->server->getConfigGroup()->getPropertyBool("player.verify-xuid", true); + $checkXUID = $this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::PLAYER_VERIFY_XUID, true); $myXUID = $this->info instanceof XboxLivePlayerInfo ? $this->info->getXuid() : ""; $kickForXUIDMismatch = function(string $xuid) use ($checkXUID, $myXUID) : bool{ if($checkXUID && $myXUID !== $xuid){ @@ -986,85 +984,62 @@ public function syncGameMode(GameMode $mode, bool $isRollback = false) : void{ public function syncAbilities(Player $for) : void{ $isOp = $for->hasPermission(DefaultPermissions::ROOT_OPERATOR); - if($this->getProtocolId() >= ProtocolInfo::PROTOCOL_1_19_10){ - //ALL of these need to be set for the base layer, otherwise the client will cry - $boolAbilities = [ - AbilitiesLayer::ABILITY_ALLOW_FLIGHT => $for->getAllowFlight(), - AbilitiesLayer::ABILITY_FLYING => $for->isFlying(), - AbilitiesLayer::ABILITY_NO_CLIP => !$for->hasBlockCollision(), - AbilitiesLayer::ABILITY_OPERATOR => $isOp, - AbilitiesLayer::ABILITY_TELEPORT => $for->hasPermission(DefaultPermissionNames::COMMAND_TELEPORT_SELF), - AbilitiesLayer::ABILITY_INVULNERABLE => $for->isCreative(), - AbilitiesLayer::ABILITY_MUTED => false, - AbilitiesLayer::ABILITY_WORLD_BUILDER => false, - AbilitiesLayer::ABILITY_INFINITE_RESOURCES => !$for->hasFiniteResources(), - AbilitiesLayer::ABILITY_LIGHTNING => false, - AbilitiesLayer::ABILITY_BUILD => !$for->isSpectator(), - AbilitiesLayer::ABILITY_MINE => !$for->isSpectator(), - AbilitiesLayer::ABILITY_DOORS_AND_SWITCHES => !$for->isSpectator(), - AbilitiesLayer::ABILITY_OPEN_CONTAINERS => !$for->isSpectator(), - AbilitiesLayer::ABILITY_ATTACK_PLAYERS => !$for->isSpectator(), - AbilitiesLayer::ABILITY_ATTACK_MOBS => !$for->isSpectator(), - AbilitiesLayer::ABILITY_PRIVILEGED_BUILDER => false, - ]; - - $layers = [ - //TODO: dynamic flying speed! FINALLY!!!!!!!!!!!!!!!!! - new AbilitiesLayer(AbilitiesLayer::LAYER_BASE, $boolAbilities, 0.05, 0.1), - ]; - if(!$for->hasBlockCollision() && $this->getProtocolId() >= ProtocolInfo::PROTOCOL_1_19_80){ - //TODO: HACK! In 1.19.80, the client starts falling in our faux spectator mode when it clips into a - //block. We can't seem to prevent this short of forcing the player to always fly when block collision is - //disabled. Also, for some reason the client always reads flight state from this layer if present, even - //though the player isn't in spectator mode. - - $layers[] = new AbilitiesLayer(AbilitiesLayer::LAYER_SPECTATOR, [ - AbilitiesLayer::ABILITY_FLYING => true, - ], null, null); - } - - $pk = UpdateAbilitiesPacket::create(new AbilitiesData( - $isOp ? CommandPermissions::OPERATOR : CommandPermissions::NORMAL, - $isOp ? PlayerPermissions::OPERATOR : PlayerPermissions::MEMBER, - $for->getId(), - $layers - )); - }else{ - $pk = AdventureSettingsPacket::create( - 0, - $isOp ? CommandPermissions::OPERATOR : CommandPermissions::NORMAL, - 0, - $isOp ? PlayerPermissions::OPERATOR : PlayerPermissions::MEMBER, - 0, - $for->getId() - ); - - $pk->setFlag(AdventureSettingsPacket::WORLD_IMMUTABLE, $for->isSpectator()); - $pk->setFlag(AdventureSettingsPacket::NO_PVP, $for->isSpectator()); - $pk->setFlag(AdventureSettingsPacket::AUTO_JUMP, $for->hasAutoJump()); - $pk->setFlag(AdventureSettingsPacket::ALLOW_FLIGHT, $for->getAllowFlight()); - $pk->setFlag(AdventureSettingsPacket::NO_CLIP, !$for->hasBlockCollision()); - $pk->setFlag(AdventureSettingsPacket::FLYING, $for->isFlying()); + //ALL of these need to be set for the base layer, otherwise the client will cry + $boolAbilities = [ + AbilitiesLayer::ABILITY_ALLOW_FLIGHT => $for->getAllowFlight(), + AbilitiesLayer::ABILITY_FLYING => $for->isFlying(), + AbilitiesLayer::ABILITY_NO_CLIP => !$for->hasBlockCollision(), + AbilitiesLayer::ABILITY_OPERATOR => $isOp, + AbilitiesLayer::ABILITY_TELEPORT => $for->hasPermission(DefaultPermissionNames::COMMAND_TELEPORT_SELF), + AbilitiesLayer::ABILITY_INVULNERABLE => $for->isCreative(), + AbilitiesLayer::ABILITY_MUTED => false, + AbilitiesLayer::ABILITY_WORLD_BUILDER => false, + AbilitiesLayer::ABILITY_INFINITE_RESOURCES => !$for->hasFiniteResources(), + AbilitiesLayer::ABILITY_LIGHTNING => false, + AbilitiesLayer::ABILITY_BUILD => !$for->isSpectator(), + AbilitiesLayer::ABILITY_MINE => !$for->isSpectator(), + AbilitiesLayer::ABILITY_DOORS_AND_SWITCHES => !$for->isSpectator(), + AbilitiesLayer::ABILITY_OPEN_CONTAINERS => !$for->isSpectator(), + AbilitiesLayer::ABILITY_ATTACK_PLAYERS => !$for->isSpectator(), + AbilitiesLayer::ABILITY_ATTACK_MOBS => !$for->isSpectator(), + AbilitiesLayer::ABILITY_PRIVILEGED_BUILDER => false, + ]; + + $layers = [ + //TODO: dynamic flying speed! FINALLY!!!!!!!!!!!!!!!!! + new AbilitiesLayer(AbilitiesLayer::LAYER_BASE, $boolAbilities, 0.05, 0.1), + ]; + if(!$for->hasBlockCollision()){ + //TODO: HACK! In 1.19.80, the client starts falling in our faux spectator mode when it clips into a + //block. We can't seem to prevent this short of forcing the player to always fly when block collision is + //disabled. Also, for some reason the client always reads flight state from this layer if present, even + //though the player isn't in spectator mode. + + $layers[] = new AbilitiesLayer(AbilitiesLayer::LAYER_SPECTATOR, [ + AbilitiesLayer::ABILITY_FLYING => true, + ], null, null); } - $this->sendDataPacket($pk); + $this->sendDataPacket(UpdateAbilitiesPacket::create(new AbilitiesData( + $isOp ? CommandPermissions::OPERATOR : CommandPermissions::NORMAL, + $isOp ? PlayerPermissions::OPERATOR : PlayerPermissions::MEMBER, + $for->getId(), + $layers + ))); } public function syncAdventureSettings() : void{ if($this->player === null){ throw new \LogicException("Cannot sync adventure settings for a player that is not yet created"); } - - if($this->getProtocolId() >= ProtocolInfo::PROTOCOL_1_19_10){ - //everything except auto jump is handled via UpdateAbilitiesPacket - $this->sendDataPacket(UpdateAdventureSettingsPacket::create( - noAttackingMobs: false, - noAttackingPlayers: false, - worldImmutable: false, - showNameTags: true, - autoJump: $this->player->hasAutoJump() - )); - } + //everything except auto jump is handled via UpdateAbilitiesPacket + $this->sendDataPacket(UpdateAdventureSettingsPacket::create( + noAttackingMobs: false, + noAttackingPlayers: false, + worldImmutable: false, + showNameTags: true, + autoJump: $this->player->hasAutoJump() + )); } public function syncAvailableCommands() : void{ @@ -1171,7 +1146,7 @@ function(CachedChunkPromise $promise) use ($world, $onCompletion, $chunkX, $chun $this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName()); return; } - if(!$status->equals(UsedChunkStatus::REQUESTED_SENDING())){ + if($status !== UsedChunkStatus::REQUESTED_SENDING){ //TODO: make this an error //this could be triggered due to the shitty way that chunk resends are handled //right now - not because of the spammy re-requesting, but because the chunk status reverts @@ -1198,24 +1173,6 @@ function(CachedChunkPromise $promise) use ($world, $onCompletion, $chunkX, $chun try{ $this->queueCompressed($compressBatchPromise); $onCompletion(); - - if($this->getProtocolId() === ProtocolInfo::PROTOCOL_1_19_10){ - //TODO: HACK! we send the full tile data here, due to a bug in 1.19.10 which causes items in tiles - //(item frames, lecterns) to not load properly when they are sent in a chunk via the classic chunk - //sending mechanism. We workaround this bug by sending only bare essential data in LevelChunkPacket - //(enough to create the tiles, since BlockActorDataPacket can't create tiles by itself) and then - //send the actual tile properties here. - //TODO: maybe we can stuff these packets inside the cached batch alongside LevelChunkPacket? - $chunk = $currentWorld->getChunk($chunkX, $chunkZ); - if($chunk !== null){ - foreach($chunk->getTiles() as $tile){ - if(!($tile instanceof Spawnable)){ - continue; - } - $this->sendDataPacket(BlockActorDataPacket::create(BlockPosition::fromVector3($tile->getPosition()), $tile->getSerializedSpawnCompound($this->getTypeConverter()))); - } - } - } }finally{ $world->timings->syncChunkSend->stopTiming(); } @@ -1297,9 +1254,7 @@ public function onToastNotification(string $title, string $body) : void{ } public function onOpenSignEditor(Vector3 $signPosition, bool $frontSide) : void{ - if($this->getProtocolId() >= ProtocolInfo::PROTOCOL_1_19_80){ - $this->sendDataPacket(OpenSignPacket::create(BlockPosition::fromVector3($signPosition), $frontSide)); - } + $this->sendDataPacket(OpenSignPacket::create(BlockPosition::fromVector3($signPosition), $frontSide)); } public function tick() : void{ diff --git a/src/network/mcpe/cache/CraftingDataCache.php b/src/network/mcpe/cache/CraftingDataCache.php index 666292928d..dfc47b2d3f 100644 --- a/src/network/mcpe/cache/CraftingDataCache.php +++ b/src/network/mcpe/cache/CraftingDataCache.php @@ -83,12 +83,11 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData foreach($manager->getCraftingRecipeIndex() as $index => $recipe){ try{ if($recipe instanceof ShapelessRecipe){ - $typeTag = match($recipe->getType()->id()){ - ShapelessRecipeType::CRAFTING()->id() => CraftingRecipeBlockName::CRAFTING_TABLE, - ShapelessRecipeType::STONECUTTER()->id() => CraftingRecipeBlockName::STONECUTTER, - ShapelessRecipeType::CARTOGRAPHY()->id() => CraftingRecipeBlockName::CARTOGRAPHY_TABLE, - ShapelessRecipeType::SMITHING()->id() => CraftingRecipeBlockName::SMITHING_TABLE, - default => throw new AssumptionFailedError("Unreachable"), + $typeTag = match($recipe->getType()){ + ShapelessRecipeType::CRAFTING => CraftingRecipeBlockName::CRAFTING_TABLE, + ShapelessRecipeType::STONECUTTER => CraftingRecipeBlockName::STONECUTTER, + ShapelessRecipeType::CARTOGRAPHY => CraftingRecipeBlockName::CARTOGRAPHY_TABLE, + ShapelessRecipeType::SMITHING => CraftingRecipeBlockName::SMITHING_TABLE, }; $recipesWithTypeIds[] = new ProtocolShapelessRecipe( CraftingDataPacket::ENTRY_SHAPELESS, @@ -128,12 +127,10 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData foreach(FurnaceType::getAll() as $furnaceType){ try{ - $typeTag = match($furnaceType->id()){ - FurnaceType::FURNACE()->id() => FurnaceRecipeBlockName::FURNACE, - FurnaceType::BLAST_FURNACE()->id() => FurnaceRecipeBlockName::BLAST_FURNACE, - FurnaceType::SMOKER()->id() => FurnaceRecipeBlockName::SMOKER, - ShapelessRecipeType::SMITHING()->id() => CraftingRecipeBlockName::SMITHING_TABLE, - default => throw new AssumptionFailedError("Unreachable"), + $typeTag = match($furnaceType){ + FurnaceType::FURNACE => FurnaceRecipeBlockName::FURNACE, + FurnaceType::BLAST_FURNACE => FurnaceRecipeBlockName::BLAST_FURNACE, + FurnaceType::SMOKER => FurnaceRecipeBlockName::SMOKER, }; foreach($manager->getFurnaceRecipeManager($furnaceType)->getAll() as $recipe){ $input = $converter->coreRecipeIngredientToNet($recipe->getInput())->getDescriptor(); diff --git a/src/network/mcpe/convert/TypeConverter.php b/src/network/mcpe/convert/TypeConverter.php index 88ec8a7420..a8090e940d 100644 --- a/src/network/mcpe/convert/TypeConverter.php +++ b/src/network/mcpe/convert/TypeConverter.php @@ -121,33 +121,23 @@ public function setSkinAdapter(SkinAdapter $skinAdapter) : void{ * @internal */ public function coreGameModeToProtocol(GameMode $gamemode) : int{ - switch($gamemode->id()){ - case GameMode::SURVIVAL()->id(): - return ProtocolGameMode::SURVIVAL; - case GameMode::CREATIVE()->id(): - case GameMode::SPECTATOR()->id(): - return ProtocolGameMode::CREATIVE; - case GameMode::ADVENTURE()->id(): - return ProtocolGameMode::ADVENTURE; - default: - throw new AssumptionFailedError("Unknown game mode"); - } + return match($gamemode){ + GameMode::SURVIVAL => ProtocolGameMode::SURVIVAL, + //TODO: native spectator support + GameMode::CREATIVE, GameMode::SPECTATOR => ProtocolGameMode::CREATIVE, + GameMode::ADVENTURE => ProtocolGameMode::ADVENTURE, + }; } public function protocolGameModeToCore(int $gameMode) : ?GameMode{ - switch($gameMode){ - case ProtocolGameMode::SURVIVAL: - return GameMode::SURVIVAL(); - case ProtocolGameMode::CREATIVE: - return GameMode::CREATIVE(); - case ProtocolGameMode::ADVENTURE: - return GameMode::ADVENTURE(); - case ProtocolGameMode::CREATIVE_VIEWER: - case ProtocolGameMode::SURVIVAL_VIEWER: - return GameMode::SPECTATOR(); - default: - return null; - } + return match($gameMode){ + ProtocolGameMode::SURVIVAL => GameMode::SURVIVAL, + ProtocolGameMode::CREATIVE => GameMode::CREATIVE, + ProtocolGameMode::ADVENTURE => GameMode::ADVENTURE, + ProtocolGameMode::SURVIVAL_VIEWER, ProtocolGameMode::CREATIVE_VIEWER => GameMode::SPECTATOR, + //TODO: native spectator support + default => null, + }; } public function coreRecipeIngredientToNet(?RecipeIngredient $ingredient) : ProtocolRecipeIngredient{ diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index a52bfd7d5f..0f1ab74ab6 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -49,7 +49,6 @@ use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\protocol\ActorEventPacket; use pocketmine\network\mcpe\protocol\ActorPickRequestPacket; -use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; use pocketmine\network\mcpe\protocol\AnimatePacket; use pocketmine\network\mcpe\protocol\BlockActorDataPacket; use pocketmine\network\mcpe\protocol\BlockPickRequestPacket; @@ -80,8 +79,6 @@ use pocketmine\network\mcpe\protocol\PlayerHotbarPacket; use pocketmine\network\mcpe\protocol\PlayerInputPacket; use pocketmine\network\mcpe\protocol\PlayerSkinPacket; -use pocketmine\network\mcpe\protocol\ProtocolInfo; -use pocketmine\network\mcpe\protocol\RequestAbilityPacket; use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket; use pocketmine\network\mcpe\protocol\SetActorMotionPacket; @@ -118,7 +115,6 @@ use function get_debug_type; use function implode; use function in_array; -use function is_bool; use function is_infinite; use function is_nan; use function json_decode; @@ -205,7 +201,7 @@ public function handlePlayerAuthInput(PlayerAuthInputPacket $packet) : bool{ } $hasMoved = $this->lastPlayerAuthInputPosition === null || !$this->lastPlayerAuthInputPosition->equals($rawPos); - $newPos = $rawPos->round(4)->subtract(0, 1.62, 0); + $newPos = $rawPos->subtract(0, 1.62, 0)->round(4); if($this->forceMoveSync && $hasMoved){ $curPos = $this->player->getLocation(); @@ -228,11 +224,13 @@ public function handlePlayerAuthInput(PlayerAuthInputPacket $packet) : bool{ $sprinting = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SPRINTING, PlayerAuthInputFlags::STOP_SPRINTING); $swimming = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SWIMMING, PlayerAuthInputFlags::STOP_SWIMMING); $gliding = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_GLIDING, PlayerAuthInputFlags::STOP_GLIDING); + $flying = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_FLYING, PlayerAuthInputFlags::STOP_FLYING); $mismatch = ($sneaking !== null && !$this->player->toggleSneak($sneaking)) | ($sprinting !== null && !$this->player->toggleSprint($sprinting)) | ($swimming !== null && !$this->player->toggleSwim($swimming)) | - ($gliding !== null && !$this->player->toggleGlide($gliding)); + ($gliding !== null && !$this->player->toggleGlide($gliding)) | + ($flying !== null && !$this->player->toggleFlight($flying)); if((bool) $mismatch){ $this->player->sendData([$this->player]); } @@ -739,30 +737,6 @@ public function handleCraftingEvent(CraftingEventPacket $packet) : bool{ return true; //this is a broken useless packet, so we don't use it } - public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ - if($this->session->getProtocolId() >= ProtocolInfo::PROTOCOL_1_19_0){ - return true; //no longer used, but the client still sends it for flight changes - } - - if($packet->targetActorUniqueId !== $this->player->getId()){ - return false; //TODO: operators can change other people's permissions using this - } - - $handled = false; - - $isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING); - if($isFlying !== $this->player->isFlying()){ - if(!$this->player->toggleFlight($isFlying)){ - $this->session->syncAbilities($this->player); - } - $handled = true; - } - - //TODO: check for other changes - - return $handled; - } - public function handleBlockActorData(BlockActorDataPacket $packet) : bool{ $pos = new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ()); if($pos->distanceSquared($this->player->getLocation()) > 10000){ @@ -774,16 +748,11 @@ public function handleBlockActorData(BlockActorDataPacket $packet) : bool{ if(!($nbt instanceof CompoundTag)) throw new AssumptionFailedError("PHPStan should ensure this is a CompoundTag"); //for phpstorm's benefit if($block instanceof BaseSign){ - if($this->session->getProtocolId() >= ProtocolInfo::PROTOCOL_1_19_80){ - $frontTextTag = $nbt->getTag(Sign::TAG_FRONT_TEXT); - if(!$frontTextTag instanceof CompoundTag){ - throw new PacketHandlingException("Invalid tag type " . get_debug_type($frontTextTag) . " for tag \"" . Sign::TAG_FRONT_TEXT . "\" in sign update data"); - } - $textBlobTag = $frontTextTag->getTag(Sign::TAG_TEXT_BLOB); - }else{ - $textBlobTag = $nbt->getTag(Sign::TAG_TEXT_BLOB); + $frontTextTag = $nbt->getTag(Sign::TAG_FRONT_TEXT); + if(!$frontTextTag instanceof CompoundTag){ + throw new PacketHandlingException("Invalid tag type " . get_debug_type($frontTextTag) . " for tag \"" . Sign::TAG_FRONT_TEXT . "\" in sign update data"); } - + $textBlobTag = $frontTextTag->getTag(Sign::TAG_TEXT_BLOB); if(!$textBlobTag instanceof StringTag){ throw new PacketHandlingException("Invalid tag type " . get_debug_type($textBlobTag) . " for tag \"" . Sign::TAG_TEXT_BLOB . "\" in sign update data"); } @@ -816,7 +785,7 @@ public function handlePlayerInput(PlayerInputPacket $packet) : bool{ public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ $gameMode = $this->session->getTypeConverter()->protocolGameModeToCore($packet->gamemode); - if($gameMode === null || !$gameMode->equals($this->player->getGamemode())){ + if($gameMode !== $this->player->getGamemode()){ //Set this back to default. TODO: handle this properly $this->session->syncGameMode($this->player->getGamemode(), true); } @@ -1065,26 +1034,4 @@ public function handleEmote(EmotePacket $packet) : bool{ $this->player->emote($packet->getEmoteId()); return true; } - - public function handleRequestAbility(RequestAbilityPacket $packet) : bool{ - if($this->session->getProtocolId() < ProtocolInfo::PROTOCOL_1_19_0){ - return false; - } - - if($packet->getAbilityId() === RequestAbilityPacket::ABILITY_FLYING){ - $isFlying = $packet->getAbilityValue(); - if(!is_bool($isFlying)){ - throw new PacketHandlingException("Flying ability should always have a bool value"); - } - if($isFlying !== $this->player->isFlying()){ - if(!$this->player->toggleFlight($isFlying)){ - $this->session->syncAbilities($this->player); - } - } - - return true; - } - - return false; - } } diff --git a/src/network/mcpe/handler/ItemStackRequestExecutor.php b/src/network/mcpe/handler/ItemStackRequestExecutor.php index 3713538397..a63f5f348e 100644 --- a/src/network/mcpe/handler/ItemStackRequestExecutor.php +++ b/src/network/mcpe/handler/ItemStackRequestExecutor.php @@ -31,7 +31,7 @@ use pocketmine\inventory\transaction\action\DropItemAction; use pocketmine\inventory\transaction\AnvilTransaction; use pocketmine\inventory\transaction\CraftingTransaction; -use pocketmine\inventory\transaction\EnchantTransaction; +use pocketmine\inventory\transaction\EnchantingTransaction; use pocketmine\inventory\transaction\InventoryTransaction; use pocketmine\inventory\transaction\TransactionBuilder; use pocketmine\inventory\transaction\TransactionBuilderInventory; @@ -292,7 +292,7 @@ protected function takeCreatedItem(int $count) : Item{ * @throws ItemStackRequestProcessException */ private function assertDoingCrafting() : void{ - if(!$this->specialTransaction instanceof CraftingTransaction && !$this->specialTransaction instanceof EnchantTransaction && !$this->specialTransaction instanceof AnvilTransaction){ + if(!$this->specialTransaction instanceof CraftingTransaction && !$this->specialTransaction instanceof EnchantingTransaction && !$this->specialTransaction instanceof AnvilTransaction){ if($this->specialTransaction === null){ throw new ItemStackRequestProcessException("Expected CraftRecipe or CraftRecipeAuto action to precede this action"); }else{ @@ -342,7 +342,7 @@ protected function processItemStackRequestAction(ItemStackRequestAction $action) if($window instanceof EnchantInventory){ $optionId = $this->inventoryManager->getEnchantingTableOptionIndex($action->getRecipeId()); if($optionId !== null && ($option = $window->getOption($optionId)) !== null){ - $this->specialTransaction = new EnchantTransaction($this->player, $option, $optionId + 1); + $this->specialTransaction = new EnchantingTransaction($this->player, $option, $optionId + 1); $this->setNextCreatedItem($window->getOutput($optionId)); } }else{ diff --git a/src/network/mcpe/handler/LoginPacketHandler.php b/src/network/mcpe/handler/LoginPacketHandler.php index 9ab4493b60..370177e3fb 100644 --- a/src/network/mcpe/handler/LoginPacketHandler.php +++ b/src/network/mcpe/handler/LoginPacketHandler.php @@ -107,6 +107,9 @@ public function handleLogin(LoginPacket $packet) : bool{ throw new PacketHandlingException("Invalid login UUID"); } $uuid = Uuid::fromString($extraData->identity); + $arrClientData = (array) $clientData; + $arrClientData["TitleID"] = $extraData->titleId; + if($extraData->XUID !== ""){ $playerInfo = new XboxLivePlayerInfo( $extraData->XUID, @@ -114,7 +117,7 @@ public function handleLogin(LoginPacket $packet) : bool{ $uuid, $skin, $clientData->LanguageCode, - (array) $clientData + $arrClientData ); }else{ $playerInfo = new PlayerInfo( @@ -122,7 +125,7 @@ public function handleLogin(LoginPacket $packet) : bool{ $uuid, $skin, $clientData->LanguageCode, - (array) $clientData + $arrClientData ); } ($this->playerInfoConsumer)($playerInfo); diff --git a/src/network/mcpe/handler/ResourcePacksPacketHandler.php b/src/network/mcpe/handler/ResourcePacksPacketHandler.php index 8a557cf9e2..bf7626abad 100644 --- a/src/network/mcpe/handler/ResourcePacksPacketHandler.php +++ b/src/network/mcpe/handler/ResourcePacksPacketHandler.php @@ -82,7 +82,7 @@ public function setUp() : void{ ); }, $this->resourcePackManager->getResourceStack()); //TODO: support forcing server packs - $this->session->sendDataPacket(ResourcePacksInfoPacket::create($resourcePackEntries, [], $this->resourcePackManager->resourcePacksRequired(), false, false)); + $this->session->sendDataPacket(ResourcePacksInfoPacket::create($resourcePackEntries, [], $this->resourcePackManager->resourcePacksRequired(), false, false, [])); $this->session->getLogger()->debug("Waiting for client to accept resource packs"); } diff --git a/src/network/mcpe/raklib/RakLibInterface.php b/src/network/mcpe/raklib/RakLibInterface.php index 4bf8ffb15f..d189cf0fd3 100644 --- a/src/network/mcpe/raklib/RakLibInterface.php +++ b/src/network/mcpe/raklib/RakLibInterface.php @@ -42,6 +42,7 @@ use pocketmine\thread\ThreadCrashException; use pocketmine\timings\Timings; use pocketmine\utils\Utils; +use pocketmine\YmlServerProperties; use raklib\generic\DisconnectReason; use raklib\generic\SocketException; use raklib\protocol\EncapsulatedPacket; @@ -125,7 +126,7 @@ public function __construct( $threadToMainBuffer, new InternetAddress($ip, $port, $ipV6 ? 6 : 4), $this->rakServerId, - $this->server->getConfigGroup()->getPropertyInt("network.max-mtu-size", 1492), + $this->server->getConfigGroup()->getPropertyInt(YmlServerProperties::NETWORK_MAX_MTU_SIZE, 1492), self::MCPE_RAKNET_PROTOCOL_VERSION, $sleeperEntry ); @@ -270,8 +271,8 @@ public function setName(string $name) : void{ $this->rakServerId, $this->server->getName(), match($this->server->getGamemode()){ - GameMode::SURVIVAL() => "Survival", - GameMode::ADVENTURE() => "Adventure", + GameMode::SURVIVAL => "Survival", + GameMode::ADVENTURE => "Adventure", default => "Creative" } ]) . ";" diff --git a/src/network/query/QueryInfo.php b/src/network/query/QueryInfo.php index 2d36ac7e6e..0bf5b4f65e 100644 --- a/src/network/query/QueryInfo.php +++ b/src/network/query/QueryInfo.php @@ -29,6 +29,7 @@ use pocketmine\Server; use pocketmine\utils\Binary; use pocketmine\utils\Utils; +use pocketmine\YmlServerProperties; use function array_map; use function chr; use function count; @@ -66,11 +67,11 @@ final class QueryInfo{ public function __construct(Server $server){ $this->serverName = $server->getMotd(); - $this->listPlugins = $server->getConfigGroup()->getPropertyBool("settings.query-plugins", true); + $this->listPlugins = $server->getConfigGroup()->getPropertyBool(YmlServerProperties::SETTINGS_QUERY_PLUGINS, true); $this->plugins = $server->getPluginManager()->getPlugins(); $this->players = array_map(fn(Player $p) => $p->getName(), $server->getOnlinePlayers()); - $this->gametype = ($server->getGamemode()->equals(GameMode::SURVIVAL()) || $server->getGamemode()->equals(GameMode::ADVENTURE())) ? "SMP" : "CMP"; + $this->gametype = ($server->getGamemode() === GameMode::SURVIVAL || $server->getGamemode() === GameMode::ADVENTURE) ? "SMP" : "CMP"; $this->version = $server->getVersion(); $this->server_engine = $server->getName() . " " . $server->getPocketMineVersion(); $world = $server->getWorldManager()->getDefaultWorld(); diff --git a/src/player/GameMode.php b/src/player/GameMode.php index 0fc60ece46..519cbbe8ae 100644 --- a/src/player/GameMode.php +++ b/src/player/GameMode.php @@ -25,73 +25,76 @@ use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\Translatable; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; use function mb_strtolower; +use function spl_object_id; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static GameMode ADVENTURE() * @method static GameMode CREATIVE() * @method static GameMode SPECTATOR() * @method static GameMode SURVIVAL() + * + * @phpstan-type TMetadata array{0: string, 1: Translatable, 2: list} */ -final class GameMode{ - use EnumTrait { - __construct as Enum___construct; - register as Enum_register; - } +enum GameMode{ + use LegacyEnumShimTrait; - /** @var self[] */ - protected static array $aliasMap = []; + case SURVIVAL; + case CREATIVE; + case ADVENTURE; + case SPECTATOR; - protected static function setup() : void{ - self::registerAll( - new self("survival", "Survival", KnownTranslationFactory::gameMode_survival(), ["survival", "s", "0"]), - new self("creative", "Creative", KnownTranslationFactory::gameMode_creative(), ["creative", "c", "1"]), - new self("adventure", "Adventure", KnownTranslationFactory::gameMode_adventure(), ["adventure", "a", "2"]), - new self("spectator", "Spectator", KnownTranslationFactory::gameMode_spectator(), ["spectator", "v", "view", "3"]) - ); - } + public static function fromString(string $str) : ?self{ + /** + * @var self[]|null $aliasMap + * @phpstan-var array|null $aliasMap + */ + static $aliasMap = null; - protected static function register(self $member) : void{ - self::Enum_register($member); - foreach($member->getAliases() as $alias){ - self::$aliasMap[mb_strtolower($alias)] = $member; + if($aliasMap === null){ + $aliasMap = []; + foreach(self::cases() as $case){ + foreach($case->getAliases() as $alias){ + $aliasMap[$alias] = $case; + } + } } - } - public static function fromString(string $str) : ?self{ - self::checkInit(); - return self::$aliasMap[mb_strtolower($str)] ?? null; + return $aliasMap[mb_strtolower($str)] ?? null; } /** - * @param string[] $aliases + * @phpstan-return TMetadata */ - private function __construct( - string $enumName, - private string $englishName, - private Translatable $translatableName, - private array $aliases = [] - ){ - $this->Enum___construct($enumName); + private function getMetadata() : array{ + /** @phpstan-var array $cache */ + static $cache = []; + + return $cache[spl_object_id($this)] ??= match($this){ + self::SURVIVAL => ["Survival", KnownTranslationFactory::gameMode_survival(), ["survival", "s", "0"]], + self::CREATIVE => ["Creative", KnownTranslationFactory::gameMode_creative(), ["creative", "c", "1"]], + self::ADVENTURE => ["Adventure", KnownTranslationFactory::gameMode_adventure(), ["adventure", "a", "2"]], + self::SPECTATOR => ["Spectator", KnownTranslationFactory::gameMode_spectator(), ["spectator", "v", "view", "3"]] + }; } public function getEnglishName() : string{ - return $this->englishName; + return $this->getMetadata()[0]; } - public function getTranslatableName() : Translatable{ return $this->translatableName; } + public function getTranslatableName() : Translatable{ + return $this->getMetadata()[1]; + } /** * @return string[] */ public function getAliases() : array{ - return $this->aliases; + return $this->getMetadata()[2]; } //TODO: ability sets per gamemode diff --git a/src/player/Player.php b/src/player/Player.php index 3b59d0b1c1..961345e25f 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -120,6 +120,7 @@ use pocketmine\permission\PermissibleDelegateTrait; use pocketmine\player\chat\StandardChatFormatter; use pocketmine\Server; +use pocketmine\ServerProperties; use pocketmine\timings\Timings; use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\TextFormat; @@ -135,6 +136,7 @@ use pocketmine\world\sound\ItemBreakSound; use pocketmine\world\sound\Sound; use pocketmine\world\World; +use pocketmine\YmlServerProperties; use Ramsey\Uuid\UuidInterface; use function abs; use function array_filter; @@ -318,8 +320,8 @@ public function __construct(Server $server, NetworkSession $session, PlayerInfo $rootPermissions[DefaultPermissions::ROOT_OPERATOR] = true; } $this->perm = new PermissibleBase($rootPermissions); - $this->chunksPerTick = $this->server->getConfigGroup()->getPropertyInt("chunk-sending.per-tick", 4); - $this->spawnThreshold = (int) (($this->server->getConfigGroup()->getPropertyInt("chunk-sending.spawn-radius", 4) ** 2) * M_PI); + $this->chunksPerTick = $this->server->getConfigGroup()->getPropertyInt(YmlServerProperties::CHUNK_SENDING_PER_TICK, 4); + $this->spawnThreshold = (int) (($this->server->getConfigGroup()->getPropertyInt(YmlServerProperties::CHUNK_SENDING_SPAWN_RADIUS, 4) ** 2) * M_PI); $this->chunkSelector = new ChunkSelector(); $this->chunkLoader = new class implements ChunkLoader{}; @@ -330,7 +332,7 @@ public function __construct(Server $server, NetworkSession $session, PlayerInfo $zSpawnChunk = $spawnLocation->getFloorZ() >> Chunk::COORD_BIT_SIZE; $world->registerChunkLoader($this->chunkLoader, $xSpawnChunk, $zSpawnChunk, true); $world->registerChunkListener($this, $xSpawnChunk, $zSpawnChunk); - $this->usedChunks[World::chunkHash($xSpawnChunk, $zSpawnChunk)] = UsedChunkStatus::NEEDED(); + $this->usedChunks[World::chunkHash($xSpawnChunk, $zSpawnChunk)] = UsedChunkStatus::NEEDED; parent::__construct($spawnLocation, $this->playerInfo->getSkin(), $namedtag); } @@ -371,7 +373,7 @@ function() : void{ $this->lastPlayed = $nbt->getLong(self::TAG_LAST_PLAYED, $now); if(!$this->server->getForceGamemode() && ($gameModeTag = $nbt->getTag(self::TAG_GAME_MODE)) instanceof IntTag){ - $this->internalSetGameMode(GameModeIdMap::getInstance()->fromId($gameModeTag->getValue()) ?? GameMode::SURVIVAL()); //TODO: bad hack here to avoid crashes on corrupted data + $this->internalSetGameMode(GameModeIdMap::getInstance()->fromId($gameModeTag->getValue()) ?? GameMode::SURVIVAL); //TODO: bad hack here to avoid crashes on corrupted data }else{ $this->internalSetGameMode($this->server->getGamemode()); } @@ -588,7 +590,7 @@ public function setViewDistance(int $distance) : void{ $this->viewDistance = $newViewDistance; - $this->spawnThreshold = (int) (min($this->viewDistance, $this->server->getConfigGroup()->getPropertyInt("chunk-sending.spawn-radius", 4)) ** 2 * M_PI); + $this->spawnThreshold = (int) (min($this->viewDistance, $this->server->getConfigGroup()->getPropertyInt(YmlServerProperties::CHUNK_SENDING_SPAWN_RADIUS, 4)) ** 2 * M_PI); $this->nextChunkOrderRun = 0; @@ -771,7 +773,7 @@ protected function unloadChunk(int $x, int $z, ?World $world = null) : void{ protected function spawnEntitiesOnAllChunks() : void{ foreach($this->usedChunks as $chunkHash => $status){ - if($status->equals(UsedChunkStatus::SENT())){ + if($status === UsedChunkStatus::SENT){ World::getXZ($chunkHash, $chunkX, $chunkZ); $this->spawnEntitiesOnChunk($chunkX, $chunkZ); } @@ -813,7 +815,7 @@ protected function requestChunks() : void{ ++$count; - $this->usedChunks[$index] = UsedChunkStatus::REQUESTED_GENERATION(); + $this->usedChunks[$index] = UsedChunkStatus::REQUESTED_GENERATION; $this->activeChunkGenerationRequests[$index] = true; unset($this->loadQueue[$index]); $this->getWorld()->registerChunkLoader($this->chunkLoader, $X, $Z, true); @@ -827,17 +829,17 @@ function() use ($X, $Z, $index, $world) : void{ if(!$this->isConnected() || !isset($this->usedChunks[$index]) || $world !== $this->getWorld()){ return; } - if(!$this->usedChunks[$index]->equals(UsedChunkStatus::REQUESTED_GENERATION())){ + if($this->usedChunks[$index] !== UsedChunkStatus::REQUESTED_GENERATION){ //We may have previously requested this, decided we didn't want it, and then decided we did want //it again, all before the generation request got executed. In that case, the promise would have //multiple callbacks for this player. In that case, only the first one matters. return; } unset($this->activeChunkGenerationRequests[$index]); - $this->usedChunks[$index] = UsedChunkStatus::REQUESTED_SENDING(); + $this->usedChunks[$index] = UsedChunkStatus::REQUESTED_SENDING; $this->getNetworkSession()->startUsingChunk($X, $Z, function() use ($X, $Z, $index) : void{ - $this->usedChunks[$index] = UsedChunkStatus::SENT(); + $this->usedChunks[$index] = UsedChunkStatus::SENT; if($this->spawnChunkLoadCount === -1){ $this->spawnEntitiesOnChunk($X, $Z); }elseif($this->spawnChunkLoadCount++ === $this->spawnThreshold){ @@ -954,7 +956,7 @@ protected function orderChunks() : void{ $this->location->getFloorX() >> Chunk::COORD_BIT_SIZE, $this->location->getFloorZ() >> Chunk::COORD_BIT_SIZE ) as $radius => $hash){ - if(!isset($this->usedChunks[$hash]) || $this->usedChunks[$hash]->equals(UsedChunkStatus::NEEDED())){ + if(!isset($this->usedChunks[$hash]) || $this->usedChunks[$hash] === UsedChunkStatus::NEEDED){ $newOrder[$hash] = true; } if($radius < $tickingChunkRadius){ @@ -1008,7 +1010,7 @@ public function getUsedChunkStatus(int $chunkX, int $chunkZ) : ?UsedChunkStatus{ */ public function hasReceivedChunk(int $chunkX, int $chunkZ) : bool{ $status = $this->usedChunks[World::chunkHash($chunkX, $chunkZ)] ?? null; - return $status !== null && $status->equals(UsedChunkStatus::SENT()); + return $status === UsedChunkStatus::SENT; } /** @@ -1116,7 +1118,7 @@ public function getGamemode() : GameMode{ protected function internalSetGameMode(GameMode $gameMode) : void{ $this->gamemode = $gameMode; - $this->allowFlight = $this->gamemode->equals(GameMode::CREATIVE()); + $this->allowFlight = $this->gamemode === GameMode::CREATIVE; $this->hungerManager->setEnabled($this->isSurvival()); if($this->isSpectator()){ @@ -1142,7 +1144,7 @@ protected function internalSetGameMode(GameMode $gameMode) : void{ * Sets the provided gamemode. */ public function setGamemode(GameMode $gm) : bool{ - if($this->gamemode->equals($gm)){ + if($this->gamemode === $gm){ return false; } @@ -1171,7 +1173,7 @@ public function setGamemode(GameMode $gm) : bool{ * @param bool $literal whether a literal check should be performed */ public function isSurvival(bool $literal = false) : bool{ - return $this->gamemode->equals(GameMode::SURVIVAL()) || (!$literal && $this->gamemode->equals(GameMode::ADVENTURE())); + return $this->gamemode === GameMode::SURVIVAL || (!$literal && $this->gamemode === GameMode::ADVENTURE); } /** @@ -1181,7 +1183,7 @@ public function isSurvival(bool $literal = false) : bool{ * @param bool $literal whether a literal check should be performed */ public function isCreative(bool $literal = false) : bool{ - return $this->gamemode->equals(GameMode::CREATIVE()) || (!$literal && $this->gamemode->equals(GameMode::SPECTATOR())); + return $this->gamemode === GameMode::CREATIVE || (!$literal && $this->gamemode === GameMode::SPECTATOR); } /** @@ -1191,18 +1193,18 @@ public function isCreative(bool $literal = false) : bool{ * @param bool $literal whether a literal check should be performed */ public function isAdventure(bool $literal = false) : bool{ - return $this->gamemode->equals(GameMode::ADVENTURE()) || (!$literal && $this->gamemode->equals(GameMode::SPECTATOR())); + return $this->gamemode === GameMode::ADVENTURE || (!$literal && $this->gamemode === GameMode::SPECTATOR); } public function isSpectator() : bool{ - return $this->gamemode->equals(GameMode::SPECTATOR()); + return $this->gamemode === GameMode::SPECTATOR; } /** * TODO: make this a dynamic ability instead of being hardcoded */ public function hasFiniteResources() : bool{ - return !$this->gamemode->equals(GameMode::CREATIVE()); + return $this->gamemode !== GameMode::CREATIVE; } public function getDrops() : array{ @@ -1335,18 +1337,20 @@ protected function processMostRecentMovements() : void{ $deltaAngle = abs($this->lastLocation->yaw - $to->yaw) + abs($this->lastLocation->pitch - $to->pitch); if($delta > 0.0001 || $deltaAngle > 1.0){ - $ev = new PlayerMoveEvent($this, $from, $to); + if(PlayerMoveEvent::hasHandlers()){ + $ev = new PlayerMoveEvent($this, $from, $to); - $ev->call(); + $ev->call(); - if($ev->isCancelled()){ - $this->revertMovement($from); - return; - } + if($ev->isCancelled()){ + $this->revertMovement($from); + return; + } - if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination - $this->teleport($ev->getTo()); - return; + if($to->distanceSquared($ev->getTo()) > 0.01){ //If plugins modify the destination + $this->teleport($ev->getTo()); + return; + } } $this->lastLocation = $to; @@ -1613,7 +1617,7 @@ public function useHeldItem() : bool{ $returnedItems = []; $result = $item->onClickAir($this, $directionVector, $returnedItems); - if($result->equals(ItemUseResult::FAIL())){ + if($result === ItemUseResult::FAIL){ return false; } @@ -1673,7 +1677,7 @@ public function releaseHeldItem() : bool{ $returnedItems = []; $result = $item->onReleaseUsing($this, $returnedItems); - if($result->equals(ItemUseResult::SUCCESS())){ + if($result === ItemUseResult::SUCCESS){ $this->resetItemCooldown($item); $this->returnItemsFromAction($oldItem, $item, $returnedItems); return true; @@ -1847,7 +1851,7 @@ public function attackEntity(Entity $entity) : bool{ if(!$this->canInteract($entity->getLocation(), self::MAX_REACH_DISTANCE_ENTITY_INTERACTION)){ $this->logger->debug("Cancelled attack of entity " . $entity->getId() . " due to not currently being interactable"); $ev->cancel(); - }elseif($this->isSpectator() || ($entity instanceof Player && !$this->server->getConfigGroup()->getConfigBool("pvp"))){ + }elseif($this->isSpectator() || ($entity instanceof Player && !$this->server->getConfigGroup()->getConfigBool(ServerProperties::PVP))){ $ev->cancel(); } @@ -2729,8 +2733,8 @@ public function openSignEditor(Vector3 $position) : void{ public function onChunkChanged(int $chunkX, int $chunkZ, Chunk $chunk) : void{ $status = $this->usedChunks[$hash = World::chunkHash($chunkX, $chunkZ)] ?? null; - if($status !== null && $status->equals(UsedChunkStatus::SENT())){ - $this->usedChunks[$hash] = UsedChunkStatus::NEEDED(); + if($status === UsedChunkStatus::SENT){ + $this->usedChunks[$hash] = UsedChunkStatus::NEEDED; $this->nextChunkOrderRun = 0; } } diff --git a/src/player/UsedChunkStatus.php b/src/player/UsedChunkStatus.php index 69e249a24d..dda41fe7e7 100644 --- a/src/player/UsedChunkStatus.php +++ b/src/player/UsedChunkStatus.php @@ -23,28 +23,22 @@ namespace pocketmine\player; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static UsedChunkStatus NEEDED() * @method static UsedChunkStatus REQUESTED_GENERATION() * @method static UsedChunkStatus REQUESTED_SENDING() * @method static UsedChunkStatus SENT() */ -final class UsedChunkStatus{ - use EnumTrait; +enum UsedChunkStatus{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("NEEDED"), - new self("REQUESTED_GENERATION"), - new self("REQUESTED_SENDING"), - new self("SENT") - ); - } + case NEEDED; + case REQUESTED_GENERATION; + case REQUESTED_SENDING; + case SENT; } diff --git a/src/plugin/PluginDescription.php b/src/plugin/PluginDescription.php index 9fc562af91..72f0add7fd 100644 --- a/src/plugin/PluginDescription.php +++ b/src/plugin/PluginDescription.php @@ -203,7 +203,7 @@ private function loadMap(array $plugin) : void{ } $this->order = $order; }else{ - $this->order = PluginEnableOrder::POSTWORLD(); + $this->order = PluginEnableOrder::POSTWORLD; } $this->authors = []; diff --git a/src/plugin/PluginEnableOrder.php b/src/plugin/PluginEnableOrder.php index 5e6255a16e..c942ea33f9 100644 --- a/src/plugin/PluginEnableOrder.php +++ b/src/plugin/PluginEnableOrder.php @@ -23,63 +23,48 @@ namespace pocketmine\plugin; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; use function mb_strtolower; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static PluginEnableOrder POSTWORLD() * @method static PluginEnableOrder STARTUP() */ -final class PluginEnableOrder{ - use EnumTrait { - __construct as Enum___construct; - register as Enum_register; - } +enum PluginEnableOrder{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("startup", ["startup"]), - new self("postworld", ["postworld"]) - ); - } - - /** - * @var self[] - * @phpstan-var array - */ - private static array $aliasMap = []; - - protected static function register(self $member) : void{ - self::Enum_register($member); - foreach($member->getAliases() as $alias){ - self::$aliasMap[mb_strtolower($alias)] = $member; - } - } + case STARTUP; + case POSTWORLD; public static function fromString(string $name) : ?self{ - self::checkInit(); - return self::$aliasMap[mb_strtolower($name)] ?? null; - } + /** + * @var self[]|null $aliasMap + * @phpstan-var array|null $aliasMap + */ + static $aliasMap = null; - /** - * @param string[] $aliases - * @phpstan-param list $aliases - */ - private function __construct( - string $enumName, - private array $aliases - ){ - $this->Enum___construct($enumName); + if($aliasMap === null){ + $aliasMap = []; + foreach(self::cases() as $case){ + foreach($case->getAliases() as $alias){ + $aliasMap[$alias] = $case; + } + } + } + return $aliasMap[mb_strtolower($name)] ?? null; } /** * @return string[] * @phpstan-return list */ - public function getAliases() : array{ return $this->aliases; } + public function getAliases() : array{ + return match($this){ + self::STARTUP => ["startup"], + self::POSTWORLD => ["postworld"] + }; + } } diff --git a/src/stats/SendUsageTask.php b/src/stats/SendUsageTask.php index 08c17c73a8..d218774b5f 100644 --- a/src/stats/SendUsageTask.php +++ b/src/stats/SendUsageTask.php @@ -31,6 +31,7 @@ use pocketmine\utils\Process; use pocketmine\utils\Utils; use pocketmine\VersionInfo; +use pocketmine\YmlServerProperties; use Ramsey\Uuid\Uuid; use function array_map; use function array_values; @@ -57,7 +58,7 @@ class SendUsageTask extends AsyncTask{ * @phpstan-param array $playerList */ public function __construct(Server $server, int $type, array $playerList = []){ - $endpoint = "http://" . $server->getConfigGroup()->getPropertyString("anonymous-statistics.host", "stats.pocketmine.net") . "/"; + $endpoint = "http://" . $server->getConfigGroup()->getPropertyString(YmlServerProperties::ANONYMOUS_STATISTICS_HOST, "stats.pocketmine.net") . "/"; $data = []; $data["uniqueServerId"] = $server->getServerUniqueId()->toString(); diff --git a/src/updater/UpdateChecker.php b/src/updater/UpdateChecker.php index ddb0f4d669..4a3ee34446 100644 --- a/src/updater/UpdateChecker.php +++ b/src/updater/UpdateChecker.php @@ -27,6 +27,7 @@ use pocketmine\Server; use pocketmine\utils\VersionString; use pocketmine\VersionInfo; +use pocketmine\YmlServerProperties; use function date; use function strtolower; use function ucfirst; @@ -43,7 +44,7 @@ public function __construct(Server $server, string $endpoint){ $this->logger = new \PrefixedLogger($server->getLogger(), "Update Checker"); $this->endpoint = "http://$endpoint/api/"; - if($server->getConfigGroup()->getPropertyBool("auto-updater.enabled", true)){ + if($server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_UPDATER_ENABLED, true)){ $this->doCheck(); } } @@ -59,7 +60,7 @@ public function checkUpdateCallback(UpdateInfo $updateInfo) : void{ $this->checkUpdate($updateInfo); if($this->hasUpdate()){ (new UpdateNotifyEvent($this))->call(); - if($this->server->getConfigGroup()->getPropertyBool("auto-updater.on-update.warn-console", true)){ + if($this->server->getConfigGroup()->getPropertyBool(YmlServerProperties::AUTO_UPDATER_ON_UPDATE_WARN_CONSOLE, true)){ $this->showConsoleUpdate(); } }else{ @@ -157,7 +158,7 @@ protected function checkUpdate(UpdateInfo $updateInfo) : void{ * Returns the channel used for update checking (stable, beta, dev) */ public function getChannel() : string{ - return strtolower($this->server->getConfigGroup()->getPropertyString("auto-updater.preferred-channel", "stable")); + return strtolower($this->server->getConfigGroup()->getPropertyString(YmlServerProperties::AUTO_UPDATER_PREFERRED_CHANNEL, "stable")); } /** diff --git a/src/utils/EnumTrait.php b/src/utils/EnumTrait.php index ba0a4fcf24..ee1bd4e350 100644 --- a/src/utils/EnumTrait.php +++ b/src/utils/EnumTrait.php @@ -29,6 +29,9 @@ * * Classes using this trait need to include \@method tags in their class docblock for every enum member. * Alternatively, just put \@generate-registry-docblock in the docblock and run tools/generate-registry-annotations.php + * + * @deprecated Use native PHP 8.1 enums instead. Use {@link LegacyEnumShimTrait} if you need to provide backwards + * compatible EnumTrait-like API for migrated enums. */ trait EnumTrait{ use RegistryTrait; diff --git a/src/utils/LegacyEnumShimTrait.php b/src/utils/LegacyEnumShimTrait.php new file mode 100644 index 0000000000..4bb3587ab9 --- /dev/null +++ b/src/utils/LegacyEnumShimTrait.php @@ -0,0 +1,92 @@ + 0){ + throw new \ArgumentCountError("Expected exactly 0 arguments, " . count($arguments) . " passed"); + } + return self::getAll()[mb_strtoupper($name)]; + } + + /** + * Returns a list of all cases, indexed by name. + * + * @return self[] + * @phpstan-return array + */ + public static function getAll() : array{ + /** @var array|null $result */ + static $result = null; + if($result === null){ + $result = []; + foreach(self::cases() as $case){ + $result[mb_strtoupper($case->name)] = $case; + } + } + return $result; + } + + /** + * Shim for {@link \UnitEnum::name}. + * + * @deprecated Use the native enum's name property instead. + */ + public function name() : string{ + return $this->name; + } + + /** + * Alias of spl_object_id($this). + * + * @deprecated + */ + public function id() : int{ + return spl_object_id($this); + } + + /** + * Returns whether the two objects are equivalent. + * + * @deprecated Native enums can be safely compared with ===. + */ + public function equals(self $other) : bool{ + return $this === $other; + } +} diff --git a/src/utils/RegistryTrait.php b/src/utils/RegistryTrait.php index 573f4737f1..2071f4c07c 100644 --- a/src/utils/RegistryTrait.php +++ b/src/utils/RegistryTrait.php @@ -37,8 +37,8 @@ */ trait RegistryTrait{ /** - * @var object[] - * @phpstan-var array + * @var object[]|null + * @phpstan-var array|null */ private static $members = null; @@ -54,6 +54,9 @@ private static function verifyName(string $name) : void{ * @throws \InvalidArgumentException */ private static function _registryRegister(string $name, object $member) : void{ + if(self::$members === null){ + throw new AssumptionFailedError("Cannot register members outside of " . self::class . "::setup()"); + } self::verifyName($name); $upperName = mb_strtoupper($name); if(isset(self::$members[$upperName])){ @@ -86,6 +89,9 @@ protected static function checkInit() : void{ */ private static function _registryFromString(string $name) : object{ self::checkInit(); + if(self::$members === null){ + throw new AssumptionFailedError(self::class . "::checkInit() did not initialize self::\$members correctly"); + } $upperName = mb_strtoupper($name); if(!isset(self::$members[$upperName])){ throw new \InvalidArgumentException("No such registry member: " . self::class . "::" . $upperName); @@ -121,6 +127,6 @@ public static function __callStatic($name, $arguments){ */ private static function _registryGetAll() : array{ self::checkInit(); - return array_map(self::preprocessMember(...), self::$members); + return array_map(self::preprocessMember(...), self::$members ?? throw new AssumptionFailedError(self::class . "::checkInit() did not initialize self::\$members correctly")); } } diff --git a/src/utils/StringToTParser.php b/src/utils/StringToTParser.php index 0166e2a284..d98153ac15 100644 --- a/src/utils/StringToTParser.php +++ b/src/utils/StringToTParser.php @@ -58,6 +58,21 @@ public function override(string $alias, \Closure $callback) : void{ $this->callbackMap[$this->reprocess($alias)] = $callback; } + /** + * Registers a new alias for an existing known alias. + */ + public function registerAlias(string $existing, string $alias) : void{ + $existingKey = $this->reprocess($existing); + if(!isset($this->callbackMap[$existingKey])){ + throw new \InvalidArgumentException("Cannot register new alias for unknown existing alias \"$existing\""); + } + $newKey = $this->reprocess($alias); + if(isset($this->callbackMap[$newKey])){ + throw new \InvalidArgumentException("Alias \"$newKey\" is already registered"); + } + $this->callbackMap[$newKey] = $this->callbackMap[$existingKey]; + } + /** * Tries to parse the specified string into a corresponding instance of T. * @phpstan-return T|null diff --git a/src/wizard/SetupWizard.php b/src/wizard/SetupWizard.php index c9170bd8dd..0f1a99f4b3 100644 --- a/src/wizard/SetupWizard.php +++ b/src/wizard/SetupWizard.php @@ -27,13 +27,13 @@ */ namespace pocketmine\wizard; -use pocketmine\data\java\GameModeIdMap; use pocketmine\lang\KnownTranslationFactory; use pocketmine\lang\Language; use pocketmine\lang\LanguageNotFoundException; use pocketmine\lang\Translatable; use pocketmine\player\GameMode; use pocketmine\Server; +use pocketmine\ServerProperties; use pocketmine\utils\Config; use pocketmine\utils\Internet; use pocketmine\utils\InternetException; @@ -48,8 +48,11 @@ use const STDIN; class SetupWizard{ + /** @deprecated */ public const DEFAULT_NAME = Server::DEFAULT_SERVER_NAME; + /** @deprecated */ public const DEFAULT_PORT = Server::DEFAULT_PORT_IPV4; + /** @deprecated */ public const DEFAULT_PLAYERS = Server::DEFAULT_MAX_PLAYERS; private Language $lang; @@ -91,7 +94,7 @@ public function run() : bool{ //this has to happen here to prevent user avoiding agreeing to license $config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES); - $config->set("language", $lang); + $config->set(ServerProperties::LANGUAGE, $lang); $config->save(); if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::skip_installer()), "n", "y/N")) === "y"){ @@ -101,10 +104,12 @@ public function run() : bool{ $this->writeLine(); $this->welcome(); - $this->generateBaseConfig(); - $this->generateUserFiles(); - $this->networkFunctions(); + $this->generateBaseConfig($config); + $this->generateUserFiles($config); + $this->networkFunctions($config); + $config->save(); + $this->printIpDetails(); $this->endWizard(); @@ -151,32 +156,33 @@ private function askPort(Translatable $prompt, int $default) : int{ } } - private function generateBaseConfig() : void{ - $config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES); - - $config->set("motd", ($name = $this->getInput($this->lang->translate(KnownTranslationFactory::name_your_server()), self::DEFAULT_NAME))); - $config->set("server-name", $name); + private function generateBaseConfig(Config $config) : void{ + $config->set(ServerProperties::MOTD, ($name = $this->getInput($this->lang->translate(KnownTranslationFactory::name_your_server()), Server::DEFAULT_SERVER_NAME))); $this->message($this->lang->translate(KnownTranslationFactory::port_warning())); - $config->set("server-port", $this->askPort(KnownTranslationFactory::server_port_v4(), Server::DEFAULT_PORT_IPV4)); - $config->set("server-portv6", $this->askPort(KnownTranslationFactory::server_port_v6(), Server::DEFAULT_PORT_IPV6)); + $config->set(ServerProperties::SERVER_PORT_IPV4, $this->askPort(KnownTranslationFactory::server_port_v4(), Server::DEFAULT_PORT_IPV4)); + $config->set(ServerProperties::SERVER_PORT_IPV6, $this->askPort(KnownTranslationFactory::server_port_v6(), Server::DEFAULT_PORT_IPV6)); $this->message($this->lang->translate(KnownTranslationFactory::gamemode_info())); do{ - $gamemode = GameModeIdMap::getInstance()->fromId((int) $this->getInput($this->lang->translate(KnownTranslationFactory::default_gamemode()), (string) GameModeIdMap::getInstance()->toId(GameMode::SURVIVAL()))); + $input = (int) $this->getInput($this->lang->translate(KnownTranslationFactory::default_gamemode()), "0"); + $gamemode = match($input){ + 0 => GameMode::SURVIVAL, + 1 => GameMode::CREATIVE, + default => null + }; }while($gamemode === null); - $config->set("gamemode", $gamemode->name()); - - $config->set("max-players", (int) $this->getInput($this->lang->translate(KnownTranslationFactory::max_players()), (string) self::DEFAULT_PLAYERS)); + //TODO: this probably shouldn't use the enum name directly + $config->set(ServerProperties::GAME_MODE, $gamemode->name); - $config->set("view-distance", (int) $this->getInput($this->lang->translate(KnownTranslationFactory::view_distance()), (string) Server::DEFAULT_MAX_VIEW_DISTANCE)); + $config->set(ServerProperties::MAX_PLAYERS, (int) $this->getInput($this->lang->translate(KnownTranslationFactory::max_players()), (string) Server::DEFAULT_MAX_PLAYERS)); - $config->save(); + $config->set(ServerProperties::VIEW_DISTANCE, (int) $this->getInput($this->lang->translate(KnownTranslationFactory::view_distance()), (string) Server::DEFAULT_MAX_VIEW_DISTANCE)); } - private function generateUserFiles() : void{ + private function generateUserFiles(Config $config) : void{ $this->message($this->lang->translate(KnownTranslationFactory::op_info())); $op = strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::op_who()), "")); @@ -190,27 +196,22 @@ private function generateUserFiles() : void{ $this->message($this->lang->translate(KnownTranslationFactory::whitelist_info())); - $config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES); if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::whitelist_enable()), "n", "y/N")) === "y"){ $this->error($this->lang->translate(KnownTranslationFactory::whitelist_warning())); - $config->set("white-list", true); + $config->set(ServerProperties::WHITELIST, true); }else{ - $config->set("white-list", false); + $config->set(ServerProperties::WHITELIST, false); } - $config->save(); } - private function networkFunctions() : void{ - $config = new Config(Path::join($this->dataPath, "server.properties"), Config::PROPERTIES); + private function networkFunctions(Config $config) : void{ $this->error($this->lang->translate(KnownTranslationFactory::query_warning1())); $this->error($this->lang->translate(KnownTranslationFactory::query_warning2())); if(strtolower($this->getInput($this->lang->translate(KnownTranslationFactory::query_disable()), "n", "y/N")) === "y"){ - $config->set("enable-query", false); + $config->set(ServerProperties::ENABLE_QUERY, false); }else{ - $config->set("enable-query", true); + $config->set(ServerProperties::ENABLE_QUERY, true); } - - $config->save(); } private function printIpDetails() : void{ diff --git a/src/world/World.php b/src/world/World.php index fea4dcade2..1ef4ae4859 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -113,6 +113,7 @@ use pocketmine\world\sound\BlockSound; use pocketmine\world\sound\Sound; use pocketmine\world\utils\SubChunkExplorer; +use pocketmine\YmlServerProperties; use function abs; use function array_filter; use function array_key_exists; @@ -528,14 +529,14 @@ public function __construct( $this->time = $this->provider->getWorldData()->getTime(); $cfg = $this->server->getConfigGroup(); - $this->chunkTickRadius = min($this->server->getViewDistance(), max(0, $cfg->getPropertyInt("chunk-ticking.tick-radius", 4))); + $this->chunkTickRadius = min($this->server->getViewDistance(), max(0, $cfg->getPropertyInt(YmlServerProperties::CHUNK_TICKING_TICK_RADIUS, 4))); if($cfg->getPropertyInt("chunk-ticking.per-tick", 40) <= 0){ //TODO: this needs l10n $this->logger->warning("\"chunk-ticking.per-tick\" setting is deprecated, but you've used it to disable chunk ticking. Set \"chunk-ticking.tick-radius\" to 0 in \"pocketmine.yml\" instead."); $this->chunkTickRadius = 0; } - $this->tickedBlocksPerSubchunkPerTick = $cfg->getPropertyInt("chunk-ticking.blocks-per-subchunk-per-tick", self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK); - $this->maxConcurrentChunkPopulationTasks = $cfg->getPropertyInt("chunk-generation.population-queue-size", 2); + $this->tickedBlocksPerSubchunkPerTick = $cfg->getPropertyInt(YmlServerProperties::CHUNK_TICKING_BLOCKS_PER_SUBCHUNK_PER_TICK, self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK); + $this->maxConcurrentChunkPopulationTasks = $cfg->getPropertyInt(YmlServerProperties::CHUNK_GENERATION_POPULATION_QUEUE_SIZE, 2); $this->initRandomTickBlocksFromConfig($cfg); @@ -556,7 +557,7 @@ public function __construct( private function initRandomTickBlocksFromConfig(ServerConfigGroup $cfg) : void{ $dontTickBlocks = []; $parser = StringToItemParser::getInstance(); - foreach($cfg->getProperty("chunk-ticking.disable-block-ticking", []) as $name){ + foreach($cfg->getProperty(YmlServerProperties::CHUNK_TICKING_DISABLE_BLOCK_TICKING, []) as $name){ $name = (string) $name; $item = $parser->parse($name); if($item !== null){ @@ -709,15 +710,18 @@ private function filterViewersForPosition(Vector3 $pos, array $allowed) : array{ */ public function addSound(Vector3 $pos, Sound $sound, ?array $players = null) : void{ $players ??= $this->getViewersForPosition($pos); - $ev = new WorldSoundEvent($this, $sound, $pos, $players); - $ev->call(); + if(WorldSoundEvent::hasHandlers()){ + $ev = new WorldSoundEvent($this, $sound, $pos, $players); + $ev->call(); + if($ev->isCancelled()){ + return; + } - if($ev->isCancelled()){ - return; + $sound = $ev->getSound(); + $players = $ev->getRecipients(); } - $players = $ev->getRecipients(); if($sound instanceof BlockSound){ $closure = function(TypeConverter $typeConverter) use ($sound, $pos) : array{ $sound->setBlockTranslator($typeConverter->getBlockTranslator()); @@ -749,15 +753,18 @@ public function addSound(Vector3 $pos, Sound $sound, ?array $players = null) : v */ public function addParticle(Vector3 $pos, Particle $particle, ?array $players = null) : void{ $players ??= $this->getViewersForPosition($pos); - $ev = new WorldParticleEvent($this, $particle, $pos, $players); - $ev->call(); + if(WorldParticleEvent::hasHandlers()){ + $ev = new WorldParticleEvent($this, $particle, $pos, $players); + $ev->call(); + if($ev->isCancelled()){ + return; + } - if($ev->isCancelled()){ - return; + $particle = $ev->getParticle(); + $players = $ev->getRecipients(); } - $players = $ev->getRecipients(); if($particle instanceof BlockParticle || $particle instanceof ItemParticle){ $closure = function(TypeConverter $typeConverter) use ($particle, $pos) : array{ if($particle instanceof ItemParticle){ @@ -2243,8 +2250,8 @@ public function useItemOn(Vector3 $vector, Item &$item, int $face, ?Vector3 $cli } $result = $item->onInteractBlock($player, $blockReplace, $blockClicked, $face, $clickVector, $returnedItems); - if(!$result->equals(ItemUseResult::NONE())){ - return $result->equals(ItemUseResult::SUCCESS()); + if($result !== ItemUseResult::NONE){ + return $result === ItemUseResult::SUCCESS; } }else{ return false; @@ -2640,7 +2647,9 @@ public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk) : void{ } if($oldChunk === null){ - (new ChunkLoadEvent($this, $chunkX, $chunkZ, $chunk, true))->call(); + if(ChunkLoadEvent::hasHandlers()){ + (new ChunkLoadEvent($this, $chunkX, $chunkZ, $chunk, true))->call(); + } foreach($this->getChunkListeners($chunkX, $chunkZ) as $listener){ $listener->onChunkLoaded($chunkX, $chunkZ, $chunk); @@ -2914,7 +2923,9 @@ public function loadChunk(int $x, int $z) : ?Chunk{ $this->initChunk($x, $z, $chunkData); - (new ChunkLoadEvent($this, $x, $z, $this->chunks[$chunkHash], false))->call(); + if(ChunkLoadEvent::hasHandlers()){ + (new ChunkLoadEvent($this, $x, $z, $this->chunks[$chunkHash], false))->call(); + } if(!$this->isChunkInUse($x, $z)){ $this->logger->debug("Newly loaded chunk $x $z has no loaders registered, will be unloaded at next available opportunity"); @@ -3027,12 +3038,14 @@ public function unloadChunk(int $x, int $z, bool $safe = true, bool $trySave = t $chunk = $this->chunks[$chunkHash] ?? null; if($chunk !== null){ - $ev = new ChunkUnloadEvent($this, $x, $z, $chunk); - $ev->call(); - if($ev->isCancelled()){ - $this->timings->doChunkUnload->stopTiming(); + if(ChunkUnloadEvent::hasHandlers()){ + $ev = new ChunkUnloadEvent($this, $x, $z, $chunk); + $ev->call(); + if($ev->isCancelled()){ + $this->timings->doChunkUnload->stopTiming(); - return false; + return false; + } } if($trySave && $this->getAutoSave()){ @@ -3489,7 +3502,9 @@ private function generateChunkCallback(ChunkLockId $chunkLockId, int $x, int $z, } if(($oldChunk === null || !$oldChunk->isPopulated()) && $chunk->isPopulated()){ - (new ChunkPopulateEvent($this, $x, $z, $chunk))->call(); + if(ChunkPopulateEvent::hasHandlers()){ + (new ChunkPopulateEvent($this, $x, $z, $chunk))->call(); + } foreach($this->getChunkListeners($x, $z) as $listener){ $listener->onChunkPopulated($x, $z, $chunk); diff --git a/src/world/biome/BiomeRegistry.php b/src/world/biome/BiomeRegistry.php index 6481842095..1af60fcd59 100644 --- a/src/world/biome/BiomeRegistry.php +++ b/src/world/biome/BiomeRegistry.php @@ -54,7 +54,7 @@ public function __construct(){ $this->register(BiomeIds::EXTREME_HILLS_EDGE, new SmallMountainsBiome()); - $this->register(BiomeIds::BIRCH_FOREST, new ForestBiome(TreeType::BIRCH())); + $this->register(BiomeIds::BIRCH_FOREST, new ForestBiome(TreeType::BIRCH)); } public function register(int $id, Biome $biome) : void{ diff --git a/src/world/biome/ForestBiome.php b/src/world/biome/ForestBiome.php index 8f80cb474a..94d3e567cc 100644 --- a/src/world/biome/ForestBiome.php +++ b/src/world/biome/ForestBiome.php @@ -33,7 +33,7 @@ class ForestBiome extends GrassyBiome{ public function __construct(?TreeType $type = null){ parent::__construct(); - $this->type = $type ?? TreeType::OAK(); + $this->type = $type ?? TreeType::OAK; $trees = new Tree($type); $trees->setBaseAmount(5); @@ -46,7 +46,7 @@ public function __construct(?TreeType $type = null){ $this->setElevation(63, 81); - if($this->type->equals(TreeType::BIRCH())){ + if($this->type === TreeType::BIRCH){ $this->temperature = 0.6; $this->rainfall = 0.5; }else{ diff --git a/src/world/biome/TaigaBiome.php b/src/world/biome/TaigaBiome.php index cd68c97486..979ca66ec2 100644 --- a/src/world/biome/TaigaBiome.php +++ b/src/world/biome/TaigaBiome.php @@ -32,7 +32,7 @@ class TaigaBiome extends SnowyBiome{ public function __construct(){ parent::__construct(); - $trees = new Tree(TreeType::SPRUCE()); + $trees = new Tree(TreeType::SPRUCE); $trees->setBaseAmount(10); $this->addPopulator($trees); diff --git a/src/world/format/io/data/BedrockWorldData.php b/src/world/format/io/data/BedrockWorldData.php index f4e26257b8..20b1210f98 100644 --- a/src/world/format/io/data/BedrockWorldData.php +++ b/src/world/format/io/data/BedrockWorldData.php @@ -51,12 +51,12 @@ class BedrockWorldData extends BaseNbtWorldData{ public const CURRENT_STORAGE_VERSION = 10; - public const CURRENT_STORAGE_NETWORK_VERSION = 594; + public const CURRENT_STORAGE_NETWORK_VERSION = 618; public const CURRENT_CLIENT_VERSION_TARGET = [ 1, //major 20, //minor - 10, //patch - 1, //revision + 30, //patch + 2, //revision 0 //is beta ]; diff --git a/src/world/generator/object/TreeFactory.php b/src/world/generator/object/TreeFactory.php index 1d95a77b19..d1f3dbebb3 100644 --- a/src/world/generator/object/TreeFactory.php +++ b/src/world/generator/object/TreeFactory.php @@ -31,27 +31,13 @@ final class TreeFactory{ * @param TreeType|null $type default oak */ public static function get(Random $random, ?TreeType $type = null) : ?Tree{ - $type = $type ?? TreeType::OAK(); - if($type->equals(TreeType::SPRUCE())){ - return new SpruceTree(); - }elseif($type->equals(TreeType::BIRCH())){ - if($random->nextBoundedInt(39) === 0){ - return new BirchTree(true); - }else{ - return new BirchTree(); - } - }elseif($type->equals(TreeType::JUNGLE())){ - return new JungleTree(); - }elseif($type->equals(TreeType::OAK())){ //default - return new OakTree(); - /*if($random->nextRange(0, 9) === 0){ - $tree = new BigTree(); - }else{*/ - - //} - }elseif($type->equals(TreeType::ACACIA())){ - return new AcaciaTree(); - } - return null; + return match($type){ + null, TreeType::OAK => new OakTree(), //TODO: big oak has a 1/10 chance + TreeType::SPRUCE => new SpruceTree(), + TreeType::JUNGLE => new JungleTree(), + TreeType::ACACIA => new AcaciaTree(), + TreeType::BIRCH => new BirchTree($random->nextBoundedInt(39) === 0), + default => null, + }; } } diff --git a/src/world/generator/object/TreeType.php b/src/world/generator/object/TreeType.php index 1e8bf56e9a..d4d62946a5 100644 --- a/src/world/generator/object/TreeType.php +++ b/src/world/generator/object/TreeType.php @@ -23,13 +23,11 @@ namespace pocketmine\world\generator\object; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static TreeType ACACIA() * @method static TreeType BIRCH() @@ -38,34 +36,27 @@ * @method static TreeType OAK() * @method static TreeType SPRUCE() */ -final class TreeType{ - use EnumTrait { - register as Enum_register; - __construct as Enum___construct; - } - - protected static function setup() : void{ - self::registerAll( - new TreeType("oak", "Oak"), - new TreeType("spruce", "Spruce"), - new TreeType("birch", "Birch"), - new TreeType("jungle", "Jungle"), - new TreeType("acacia", "Acacia"), - new TreeType("dark_oak", "Dark Oak"), - //TODO: cherry blossom, mangrove, azalea - //TODO: do crimson and warped "trees" belong here? I'm not sure if they're actually trees or just fungi - //TODO: perhaps huge mushrooms should be here too??? - ); - } - - private function __construct( - string $enumName, - private string $displayName - ){ - $this->Enum___construct($enumName); - } +enum TreeType{ + use LegacyEnumShimTrait; + + case OAK; + case SPRUCE; + case BIRCH; + case JUNGLE; + case ACACIA; + case DARK_OAK; + //TODO: cherry blossom, mangrove, azalea + //TODO: do crimson and warped "trees" belong here? I'm not sure if they're actually trees or just fungi + //TODO: perhaps huge mushrooms should be here too??? public function getDisplayName() : string{ - return $this->displayName; + return match($this){ + self::OAK => "Oak", + self::SPRUCE => "Spruce", + self::BIRCH => "Birch", + self::JUNGLE => "Jungle", + self::ACACIA => "Acacia", + self::DARK_OAK => "Dark Oak", + }; } } diff --git a/src/world/generator/populator/Tree.php b/src/world/generator/populator/Tree.php index 3e5aef0a77..e470c46f0b 100644 --- a/src/world/generator/populator/Tree.php +++ b/src/world/generator/populator/Tree.php @@ -40,7 +40,7 @@ class Tree implements Populator{ * @param TreeType|null $type default oak */ public function __construct(?TreeType $type = null){ - $this->type = $type ?? TreeType::OAK(); + $this->type = $type ?? TreeType::OAK; } public function setRandomAmount(int $amount) : void{ diff --git a/src/world/sound/NoteInstrument.php b/src/world/sound/NoteInstrument.php index 87e5d496d9..a91d52cf70 100644 --- a/src/world/sound/NoteInstrument.php +++ b/src/world/sound/NoteInstrument.php @@ -23,13 +23,11 @@ namespace pocketmine\world\sound; -use pocketmine\utils\EnumTrait; +use pocketmine\utils\LegacyEnumShimTrait; /** - * This doc-block is generated automatically, do not modify it manually. - * This must be regenerated whenever registry members are added, removed or changed. - * @see build/generate-registry-annotations.php - * @generate-registry-docblock + * TODO: These tags need to be removed once we get rid of LegacyEnumShimTrait (PM6) + * These are retained for backwards compatibility only. * * @method static NoteInstrument BANJO() * @method static NoteInstrument BASS_DRUM() @@ -48,27 +46,23 @@ * @method static NoteInstrument SNARE() * @method static NoteInstrument XYLOPHONE() */ -final class NoteInstrument{ - use EnumTrait; +enum NoteInstrument{ + use LegacyEnumShimTrait; - protected static function setup() : void{ - self::registerAll( - new self("piano"), - new self("bass_drum"), - new self("snare"), - new self("clicks_and_sticks"), - new self("double_bass"), - new self("bell"), - new self("flute"), - new self("chime"), - new self("guitar"), - new self("xylophone"), - new self("iron_xylophone"), - new self("cow_bell"), - new self("didgeridoo"), - new self("bit"), - new self("banjo"), - new self("pling") - ); - } + case PIANO; + case BASS_DRUM; + case SNARE; + case CLICKS_AND_STICKS; + case DOUBLE_BASS; + case BELL; + case FLUTE; + case CHIME; + case GUITAR; + case XYLOPHONE; + case IRON_XYLOPHONE; + case COW_BELL; + case DIDGERIDOO; + case BIT; + case BANJO; + case PLING; } diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index 75118cc934..070858e804 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -1200,16 +1200,6 @@ parameters: count: 1 path: ../../phpunit/block/regenerate_consistency_check.php - - - message: "#^Property pocketmine\\\\event\\\\HandlerListManagerTest\\:\\:\\$isValidFunc \\(Closure\\(ReflectionClass\\\\)\\: bool\\) does not accept Closure\\|null\\.$#" - count: 1 - path: ../../phpunit/event/HandlerListManagerTest.php - - - - message: "#^Property pocketmine\\\\event\\\\HandlerListManagerTest\\:\\:\\$resolveParentFunc \\(Closure\\(ReflectionClass\\\\)\\: \\(ReflectionClass\\\\|null\\)\\) does not accept Closure\\|null\\.$#" - count: 1 - path: ../../phpunit/event/HandlerListManagerTest.php - - message: "#^Parameter \\#1 \\$logFile of class pocketmine\\\\utils\\\\MainLogger constructor expects string, string\\|false given\\.$#" count: 1 diff --git a/tests/phpstan/configs/php-bugs.neon b/tests/phpstan/configs/php-bugs.neon index 4475ec4684..13a42a53bb 100644 --- a/tests/phpstan/configs/php-bugs.neon +++ b/tests/phpstan/configs/php-bugs.neon @@ -1,6 +1,11 @@ parameters: ignoreErrors: - - message: "#^Property pocketmine\\\\network\\\\mcpe\\\\handler\\\\StupidJsonDecodeTest\\:\\:\\$stupidJsonDecodeFunc \\(Closure\\(string, bool\\=\\)\\: mixed\\) does not accept Closure\\|null\\.$#" + message: "#^Property pocketmine\\\\event\\\\HandlerListManagerTest\\:\\:\\$isValidFunc \\(Closure\\(ReflectionClass\\\\)\\: bool\\) does not accept Closure\\|null\\.$#" count: 1 - path: ../../phpunit/network/mcpe/handler/StupidJsonDecodeTest.php + path: ../../phpunit/event/HandlerListManagerTest.php + + - + message: "#^Property pocketmine\\\\event\\\\HandlerListManagerTest\\:\\:\\$resolveParentFunc \\(Closure\\(ReflectionClass\\\\)\\: \\(ReflectionClass\\\\|null\\)\\) does not accept Closure\\|null\\.$#" + count: 1 + path: ../../phpunit/event/HandlerListManagerTest.php diff --git a/tests/phpstan/configs/phpstan-bugs.neon b/tests/phpstan/configs/phpstan-bugs.neon index 42d682f686..7b6b7b4267 100644 --- a/tests/phpstan/configs/phpstan-bugs.neon +++ b/tests/phpstan/configs/phpstan-bugs.neon @@ -5,11 +5,26 @@ parameters: count: 1 path: ../../../src/block/BaseBanner.php + - + message: "#^Method pocketmine\\\\block\\\\CakeWithCandle\\:\\:onInteractCandle\\(\\) has parameter \\$returnedItems with no value type specified in iterable type array\\.$#" + count: 1 + path: ../../../src/block/CakeWithCandle.php + + - + message: "#^Method pocketmine\\\\block\\\\DoubleTallGrass\\:\\:traitGetDropsForIncompatibleTool\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: ../../../src/block/DoubleTallGrass.php + - message: "#^Call to function assert\\(\\) with false and 'unknown hit type' will always evaluate to false\\.$#" count: 1 path: ../../../src/entity/projectile/Projectile.php + - + message: "#^Match arm comparison between 1\\|2\\|3\\|4 and 0 is always false\\.$#" + count: 1 + path: ../../../src/network/mcpe/handler/InGamePacketHandler.php + - message: "#^Match arm comparison between 4 and 4 is always true\\.$#" count: 1 @@ -35,11 +50,6 @@ parameters: count: 1 path: ../../../src/plugin/PluginManager.php - - - message: "#^Static property pocketmine\\\\scheduler\\\\AsyncTask\\:\\:\\$threadLocalStorage \\(ArrayObject\\\\>\\|null\\) does not accept non\\-empty\\-array\\\\>\\|ArrayObject\\\\>\\.$#" - count: 1 - path: ../../../src/scheduler/AsyncTask.php - - message: "#^Casting to int something that's already int\\.$#" count: 1 diff --git a/tests/phpstan/rules/DeprecatedLegacyEnumAccessRule.php b/tests/phpstan/rules/DeprecatedLegacyEnumAccessRule.php new file mode 100644 index 0000000000..4fa7670224 --- /dev/null +++ b/tests/phpstan/rules/DeprecatedLegacyEnumAccessRule.php @@ -0,0 +1,79 @@ + + */ +final class DeprecatedLegacyEnumAccessRule implements Rule{ + + public function getNodeType() : string{ + return StaticCall::class; + } + + public function processNode(Node $node, Scope $scope) : array{ + /** @var StaticCall $node */ + if(!$node->name instanceof Node\Identifier){ + return []; + } + $caseName = $node->name->name; + $classType = $node->class instanceof Node\Name ? + $scope->resolveTypeByName($node->class) : + $scope->getType($node->class); + + if(!$classType instanceof TypeWithClassName){ + return []; + } + + $reflection = $classType->getClassReflection(); + if($reflection === null || !$reflection->hasTraitUse(LegacyEnumShimTrait::class) || !$reflection->implementsInterface(\UnitEnum::class)){ + return []; + } + + if(!$reflection->hasNativeMethod($caseName)){ + return [ + RuleErrorBuilder::message(sprintf( + 'Use of legacy enum case accessor %s::%s().', + $reflection->getName(), + $caseName + ))->tip(sprintf( + 'Access the enum constant directly instead (remove the brackets), e.g. %s::%s', + $reflection->getName(), + $caseName + ))->build() + ]; + } + + return []; + } +} diff --git a/tests/phpstan/stubs/phpasn1.stub b/tests/phpstan/stubs/phpasn1.stub deleted file mode 100644 index b459289efb..0000000000 --- a/tests/phpstan/stubs/phpasn1.stub +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace FG\ASN1\Universal; - -class Integer -{ - /** - * @param int|string $value - */ - public function __construct($value){} - - /** @return int|string */ - public function getContent(){} -} diff --git a/tests/phpunit/block/BrewingStandTest.php b/tests/phpunit/block/BrewingStandTest.php index b3363b98cd..85cdd90e11 100644 --- a/tests/phpunit/block/BrewingStandTest.php +++ b/tests/phpunit/block/BrewingStandTest.php @@ -25,7 +25,6 @@ use PHPUnit\Framework\TestCase; use pocketmine\block\utils\BrewingStandSlot; -use function array_values; use function count; class BrewingStandTest extends TestCase{ @@ -34,9 +33,9 @@ class BrewingStandTest extends TestCase{ * @phpstan-return \Generator}, void, void> */ public static function slotsProvider() : \Generator{ - yield [array_values(BrewingStandSlot::getAll())]; - yield [[BrewingStandSlot::EAST()]]; - yield [[BrewingStandSlot::EAST(), BrewingStandSlot::NORTHWEST()]]; + yield [BrewingStandSlot::cases()]; + yield [[BrewingStandSlot::EAST]]; + yield [[BrewingStandSlot::EAST, BrewingStandSlot::NORTHWEST]]; } /** diff --git a/tests/phpunit/data/bedrock/DyeColorIdMapTest.php b/tests/phpunit/data/bedrock/DyeColorIdMapTest.php index b5561019fa..a3ca6db25c 100644 --- a/tests/phpunit/data/bedrock/DyeColorIdMapTest.php +++ b/tests/phpunit/data/bedrock/DyeColorIdMapTest.php @@ -29,10 +29,10 @@ class DyeColorIdMapTest extends TestCase{ public function testAllColorsMapped() : void{ - foreach(DyeColor::getAll() as $color){ + foreach(DyeColor::cases() as $color){ $id = DyeColorIdMap::getInstance()->toId($color); $color2 = DyeColorIdMap::getInstance()->fromId($id); - self::assertTrue($color2 !== null && $color->equals($color2)); + self::assertTrue($color === $color2); } } } diff --git a/tests/phpunit/item/BannerTest.php b/tests/phpunit/item/BannerTest.php index c555031a09..797ca60fca 100644 --- a/tests/phpunit/item/BannerTest.php +++ b/tests/phpunit/item/BannerTest.php @@ -36,7 +36,7 @@ public function testBannerPatternSaveRestore() : void{ $item = VanillaBlocks::BANNER()->asItem(); assert($item instanceof Banner); $item->setPatterns([ - new BannerPatternLayer(BannerPatternType::FLOWER(), DyeColor::RED()) + new BannerPatternLayer(BannerPatternType::FLOWER, DyeColor::RED) ]); $data = $item->nbtSerialize(); @@ -45,6 +45,6 @@ public function testBannerPatternSaveRestore() : void{ self::assertInstanceOf(Banner::class, $item2); $patterns = $item2->getPatterns(); self::assertCount(1, $patterns); - self::assertTrue(BannerPatternType::FLOWER()->equals($patterns[0]->getType())); + self::assertTrue(BannerPatternType::FLOWER === $patterns[0]->getType()); } } diff --git a/tools/generate-bedrock-data-from-packets.php b/tools/generate-bedrock-data-from-packets.php index 36ef5ff6d8..593ce9645d 100644 --- a/tools/generate-bedrock-data-from-packets.php +++ b/tools/generate-bedrock-data-from-packets.php @@ -440,17 +440,22 @@ public function handleCraftingData(CraftingDataPacket $packet) : bool{ //how the data is ordered doesn't matter as long as it's reproducible foreach($recipes as $_type => $entries){ $_sortedRecipes = []; + $_seen = []; foreach($entries as $entry){ $entry = self::sort($entry); $_key = json_encode($entry); - while(isset($_sortedRecipes[$_key])){ - echo "warning: duplicated $_type recipe: $_key\n"; - $_key .= "a"; - } - $_sortedRecipes[$_key] = $entry; + $duplicates = $_seen[$_key] ??= 0; + $_seen[$_key]++; + $suffix = chr(ord("a") + $duplicates); + $_sortedRecipes[$_key . $suffix] = $entry; } ksort($_sortedRecipes, SORT_STRING); $recipes[$_type] = array_values($_sortedRecipes); + foreach($_seen as $_key => $_seenCount){ + if($_seenCount > 1){ + fwrite(STDERR, "warning: $_type recipe $_key was seen $_seenCount times\n"); + } + } } ksort($recipes, SORT_STRING);