From b70ff325488093f18899ac9935551220334bd4b9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 28 Apr 2023 13:54:40 +0100 Subject: [PATCH 1/7] ItemTranslator: Fixed log items not displaying correctly on the client closes #5724 this uses a (potentially bogus) assumption that the lowest mapped meta value associated with an ID is valid. I don't want to break this during a patch release, and this works for now. In the future it would probably make more sense to bypass ItemTranslator entirely, and rely solely on the blockstate returned by RuntimeBlockMapping to fetch the correct ID. This is similar to how we serialize items for saving on disk in PM5. --- src/network/mcpe/convert/ItemTranslator.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/network/mcpe/convert/ItemTranslator.php b/src/network/mcpe/convert/ItemTranslator.php index 8342db61f..e3e901e66 100644 --- a/src/network/mcpe/convert/ItemTranslator.php +++ b/src/network/mcpe/convert/ItemTranslator.php @@ -110,6 +110,12 @@ final class ItemTranslator{ //new item without a fixed legacy ID - we can't handle this right now continue; } + if(isset($complexMappings[$newId]) && $complexMappings[$newId][0] === $intId && $complexMappings[$newId][1] <= $meta){ + //TODO: HACK! Multiple legacy ID/meta pairs can be mapped to the same new ID (see minecraft:log) + //Assume that the first one is the most relevant for now + //However, this could catch fire in the future if this assumption is broken + continue; + } $complexMappings[$newId] = [$intId, (int) $meta]; } } From 5dcd8bf2898b49e43f2cc0e0b35fcabf4de09136 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 13:30:02 +0100 Subject: [PATCH 2/7] Bump symfony/filesystem from 5.4.21 to 5.4.23 (#5730) Bumps [symfony/filesystem](https://github.com/symfony/filesystem) from 5.4.21 to 5.4.23. - [Release notes](https://github.com/symfony/filesystem/releases) - [Changelog](https://github.com/symfony/filesystem/blob/6.2/CHANGELOG.md) - [Commits](https://github.com/symfony/filesystem/compare/v5.4.21...v5.4.23) --- updated-dependencies: - dependency-name: symfony/filesystem dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index ee994f84a..bad0235cb 100644 --- a/composer.lock +++ b/composer.lock @@ -1085,16 +1085,16 @@ }, { "name": "symfony/filesystem", - "version": "v5.4.21", + "version": "v5.4.23", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "e75960b1bbfd2b8c9e483e0d74811d555ca3de9f" + "reference": "b2f79d86cd9e7de0fff6d03baa80eaed7a5f38b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/e75960b1bbfd2b8c9e483e0d74811d555ca3de9f", - "reference": "e75960b1bbfd2b8c9e483e0d74811d555ca3de9f", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b2f79d86cd9e7de0fff6d03baa80eaed7a5f38b5", + "reference": "b2f79d86cd9e7de0fff6d03baa80eaed7a5f38b5", "shasum": "" }, "require": { @@ -1129,7 +1129,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.4.21" + "source": "https://github.com/symfony/filesystem/tree/v5.4.23" }, "funding": [ { @@ -1145,7 +1145,7 @@ "type": "tidelift" } ], - "time": "2023-02-14T08:03:56+00:00" + "time": "2023-03-02T11:38:35+00:00" }, { "name": "symfony/polyfill-ctype", From f04151dbe65a4dce6d844bb674d7cd0716f1ef70 Mon Sep 17 00:00:00 2001 From: Lee Siu San <15855635+leolee3914@users.noreply.github.com> Date: Mon, 1 May 2023 21:08:20 +0800 Subject: [PATCH 3/7] README: next-major branch was renamed (#5731) [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f91fdd31d..fb3a09459 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ * [Building and running from source](BUILDING.md) * [Developer documentation](https://devdoc.pmmp.io) - General documentation for PocketMine-MP plugin developers * [Latest release API documentation](https://apidoc.pmmp.io) - Doxygen API documentation generated for each release - * [Latest bleeding-edge API documentation](https://apidoc-dev.pmmp.io) - Doxygen API documentation generated weekly from `next-major` branch + * [Latest bleeding-edge API documentation](https://apidoc-dev.pmmp.io) - Doxygen API documentation generated weekly from `major-next` branch * [DevTools](https://github.com/pmmp/DevTools/) - Development tools plugin for creating plugins * [ExamplePlugin](https://github.com/pmmp/ExamplePlugin/) - Example plugin demonstrating some basic API features * [Contributing Guidelines](CONTRIBUTING.md) From 22f8623e176e6cff5d87069fc300c191b78c2ceb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 4 May 2023 21:06:27 +0100 Subject: [PATCH 4/7] Release 4.20.2 --- changelogs/4.20.md | 7 +++++++ src/VersionInfo.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/changelogs/4.20.md b/changelogs/4.20.md index d8f4c66b0..4a91ab440 100644 --- a/changelogs/4.20.md +++ b/changelogs/4.20.md @@ -44,3 +44,10 @@ Released 27th April 2023. ## Internals - `ItemStackContainerIdTranslator::translate()` now requires an additional `int $slotId` parameter and returns `array{int, int}` (translated window ID, translated slot ID) to be used with `InventoryManager->locateWindowAndSlot()`. - `InventoryManager->locateWindowAndSlot()` now checks if the translated slot actually exists in the requested inventory, and returns `null` if not. Previously, it would return potentially invalid slot IDs without checking them, potentially leading to crashes. + +# 4.20.2 +Released 4th May 2023. + +## Fixes +- Fixed all types of wooden logs appearing as oak in the inventory. +- Fixed a performance issue in `BaseInventory->canAddItem()` (missing `continue` causing useless logic to run). diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 08582cc58..0307d7845 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -32,7 +32,7 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; public const BASE_VERSION = "4.20.2"; - public const IS_DEVELOPMENT_BUILD = true; + public const IS_DEVELOPMENT_BUILD = false; public const BUILD_CHANNEL = "stable"; private function __construct(){ From c09390d20fd10a3e3671195f86d895cf696ce645 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 4 May 2023 21:06:30 +0100 Subject: [PATCH 5/7] 4.20.3 is next --- src/VersionInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VersionInfo.php b/src/VersionInfo.php index 0307d7845..df44e6982 100644 --- a/src/VersionInfo.php +++ b/src/VersionInfo.php @@ -31,8 +31,8 @@ use function str_repeat; final class VersionInfo{ public const NAME = "PocketMine-MP"; - public const BASE_VERSION = "4.20.2"; - public const IS_DEVELOPMENT_BUILD = false; + public const BASE_VERSION = "4.20.3"; + public const IS_DEVELOPMENT_BUILD = true; public const BUILD_CHANNEL = "stable"; private function __construct(){ From 092d130c963bb2deedc9a10bc178def407b58ef2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 4 May 2023 23:01:10 +0100 Subject: [PATCH 6/7] RuntimeBlockMapping: borrow a hack from PM5 to reduce memory footprint we can't change the internals of this on a patch release, but this hack provides a 12 MB memory usage reduction, which is very significant. --- .../mcpe/convert/RuntimeBlockMapping.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/network/mcpe/convert/RuntimeBlockMapping.php b/src/network/mcpe/convert/RuntimeBlockMapping.php index dd396af9b..64984c3c1 100644 --- a/src/network/mcpe/convert/RuntimeBlockMapping.php +++ b/src/network/mcpe/convert/RuntimeBlockMapping.php @@ -27,7 +27,10 @@ use pocketmine\block\Block; use pocketmine\block\BlockLegacyIds; use pocketmine\data\bedrock\BedrockDataFiles; use pocketmine\data\bedrock\LegacyBlockIdToStringIdMap; +use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\nbt\tag\IntTag; +use pocketmine\nbt\tag\StringTag; use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer; use pocketmine\utils\BinaryStream; use pocketmine\utils\Filesystem; @@ -53,15 +56,45 @@ final class RuntimeBlockMapping{ ); } + /** + * @param string[] $keyIndex + * @param (ByteTag|StringTag|IntTag)[][] $valueIndex + * @phpstan-param array $keyIndex + * @phpstan-param array> $valueIndex + */ + private static function deduplicateCompound(CompoundTag $tag, array &$keyIndex, array &$valueIndex) : CompoundTag{ + if($tag->count() === 0){ + return $tag; + } + + $newTag = CompoundTag::create(); + foreach($tag as $key => $value){ + $key = $keyIndex[$key] ??= $key; + + if($value instanceof CompoundTag){ + $value = self::deduplicateCompound($value, $keyIndex, $valueIndex); + }elseif($value instanceof ByteTag || $value instanceof IntTag || $value instanceof StringTag){ + $value = $valueIndex[$value->getType()][$value->getValue()] ??= $value; + } + + $newTag->setTag($key, $value); + } + + return $newTag; + } + public function __construct(string $canonicalBlockStatesFile, string $r12ToCurrentBlockMapFile){ $stream = new BinaryStream(Filesystem::fileGetContents($canonicalBlockStatesFile)); $list = []; $nbtReader = new NetworkNbtSerializer(); + + $keyIndex = []; + $valueIndex = []; while(!$stream->feof()){ $offset = $stream->getOffset(); $blockState = $nbtReader->read($stream->getBuffer(), $offset)->mustGetCompoundTag(); $stream->setOffset($offset); - $list[] = $blockState; + $list[] = self::deduplicateCompound($blockState, $keyIndex, $valueIndex); } $this->bedrockKnownStates = $list; From 633e77a34cf9741a48fd9b5f19e3c83d24fdb02b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 4 May 2023 23:21:54 +0100 Subject: [PATCH 7/7] RuntimeBlockMapping: share states CompoundTags if they are the same this allows saving about 4 MB of memory, because there are many blocks which have identical states, although they have different IDs. this relies on a potentially risky assumption that the tags in knownStates won't be modified. If they are modified, the changes will influence all blockstates which share the tag. However, I don't expect this to happen, and the 4 MB memory saving is substantial enough to be worth the risk. --- src/network/mcpe/convert/RuntimeBlockMapping.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/network/mcpe/convert/RuntimeBlockMapping.php b/src/network/mcpe/convert/RuntimeBlockMapping.php index 64984c3c1..c2123364b 100644 --- a/src/network/mcpe/convert/RuntimeBlockMapping.php +++ b/src/network/mcpe/convert/RuntimeBlockMapping.php @@ -27,10 +27,12 @@ use pocketmine\block\Block; use pocketmine\block\BlockLegacyIds; use pocketmine\data\bedrock\BedrockDataFiles; use pocketmine\data\bedrock\LegacyBlockIdToStringIdMap; +use pocketmine\nbt\LittleEndianNbtSerializer; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\StringTag; +use pocketmine\nbt\TreeRoot; use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer; use pocketmine\utils\BinaryStream; use pocketmine\utils\Filesystem; @@ -72,7 +74,7 @@ final class RuntimeBlockMapping{ $key = $keyIndex[$key] ??= $key; if($value instanceof CompoundTag){ - $value = self::deduplicateCompound($value, $keyIndex, $valueIndex); + $value = $valueIndex[$value->getType()][(new LittleEndianNbtSerializer())->write(new TreeRoot($value))] ??= self::deduplicateCompound($value, $keyIndex, $valueIndex); }elseif($value instanceof ByteTag || $value instanceof IntTag || $value instanceof StringTag){ $value = $valueIndex[$value->getType()][$value->getValue()] ??= $value; }