From 8aaa6dd176d7c55c187424cf8ea58b377b98fbd0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 Nov 2023 14:47:55 +0000 Subject: [PATCH 01/17] Stem: do not disable ticking when the stem is not attached to a pumpkin fixes #6131 --- src/block/Stem.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/block/Stem.php b/src/block/Stem.php index 7223572dd..73864ff69 100644 --- a/src/block/Stem.php +++ b/src/block/Stem.php @@ -58,6 +58,10 @@ abstract class Stem extends Crops{ parent::onNearbyBlockChange(); } + public function ticksRandomly() : bool{ + return $this->age < self::MAX_AGE || $this->facing === Facing::UP; + } + public function onRandomTick() : void{ if($this->facing === Facing::UP && mt_rand(0, 2) === 1){ $world = $this->position->getWorld(); From 1e4a1565bb7aca234f24460b9725d00d0ce998b8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 Nov 2023 14:48:45 +0000 Subject: [PATCH 02/17] Stem: fixed not attaching to grown pumpkin/melon no idea how this got missed ... --- src/block/Stem.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/block/Stem.php b/src/block/Stem.php index 73864ff69..d7bf8a51a 100644 --- a/src/block/Stem.php +++ b/src/block/Stem.php @@ -80,7 +80,9 @@ abstract class Stem extends Crops{ $facing = Facing::HORIZONTAL[array_rand(Facing::HORIZONTAL)]; $side = $this->getSide($facing); if($side->getTypeId() === BlockTypeIds::AIR && $side->getSide(Facing::DOWN)->hasTypeTag(BlockTypeTags::DIRT)){ - BlockEventHelper::grow($side, $grow, null); + if(BlockEventHelper::grow($side, $grow, null)){ + $this->position->getWorld()->setBlock($this->position, $this->setFacing($facing)); + } } } } From 109673382d213222fcf18b0d08ae18b73a3e1e51 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 Nov 2023 15:16:11 +0000 Subject: [PATCH 03/17] Implemented modifiers for crop growth speed closes #6070 there are some unresolved questions about the growth speed of beetroots, pitcher plants and torchflower crops, but that's a topic for another commit. this change also doesn't account for the light levels. --- src/block/Crops.php | 3 +- src/block/DoublePitcherCrop.php | 5 +- src/block/PitcherCrop.php | 5 +- src/block/Stem.php | 3 +- src/block/TorchflowerCrop.php | 4 +- src/block/utils/CropGrowthHelper.php | 105 +++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 src/block/utils/CropGrowthHelper.php diff --git a/src/block/Crops.php b/src/block/Crops.php index 350268863..e90ac6236 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; +use pocketmine\block\utils\CropGrowthHelper; use pocketmine\block\utils\StaticSupportTrait; use pocketmine\item\Fertilizer; use pocketmine\item\Item; @@ -66,7 +67,7 @@ abstract class Crops extends Flowable{ } public function onRandomTick() : void{ - if($this->age < self::MAX_AGE && mt_rand(0, 2) === 1){ + if($this->age < self::MAX_AGE && CropGrowthHelper::canGrow($this)){ $block = clone $this; ++$block->age; BlockEventHelper::grow($this, $block, null); diff --git a/src/block/DoublePitcherCrop.php b/src/block/DoublePitcherCrop.php index db700a625..e34dd1baf 100644 --- a/src/block/DoublePitcherCrop.php +++ b/src/block/DoublePitcherCrop.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\AgeableTrait; +use pocketmine\block\utils\CropGrowthHelper; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Fertilizer; @@ -34,7 +35,6 @@ use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\BlockTransaction; -use function mt_rand; final class DoublePitcherCrop extends DoublePlant{ use AgeableTrait { @@ -101,9 +101,8 @@ final class DoublePitcherCrop extends DoublePlant{ } public function onRandomTick() : void{ - //TODO: the growth speed is influenced by farmland and nearby crops //only the bottom half of the plant can grow randomly - if(mt_rand(0, 2) === 0 && !$this->top){ + if(CropGrowthHelper::canGrow($this) && !$this->top){ $this->grow(null); } } diff --git a/src/block/PitcherCrop.php b/src/block/PitcherCrop.php index 2d9a02162..e0b9af3d2 100644 --- a/src/block/PitcherCrop.php +++ b/src/block/PitcherCrop.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\block\utils\AgeableTrait; use pocketmine\block\utils\BlockEventHelper; +use pocketmine\block\utils\CropGrowthHelper; use pocketmine\block\utils\StaticSupportTrait; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Fertilizer; @@ -35,7 +36,6 @@ use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; use pocketmine\world\BlockTransaction; -use function mt_rand; final class PitcherCrop extends Flowable{ use AgeableTrait; @@ -97,8 +97,7 @@ final class PitcherCrop extends Flowable{ } public function onRandomTick() : void{ - //TODO: the growth speed is influenced by farmland and nearby crops - if(mt_rand(0, 2) === 0){ + if(CropGrowthHelper::canGrow($this)){ $this->grow(null); } } diff --git a/src/block/Stem.php b/src/block/Stem.php index d7bf8a51a..2ac95aa3f 100644 --- a/src/block/Stem.php +++ b/src/block/Stem.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\BlockEventHelper; +use pocketmine\block\utils\CropGrowthHelper; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; use pocketmine\math\Facing; @@ -63,7 +64,7 @@ abstract class Stem extends Crops{ } public function onRandomTick() : void{ - if($this->facing === Facing::UP && mt_rand(0, 2) === 1){ + if($this->facing === Facing::UP && CropGrowthHelper::canGrow($this)){ $world = $this->position->getWorld(); if($this->age < self::MAX_AGE){ $block = clone $this; diff --git a/src/block/TorchflowerCrop.php b/src/block/TorchflowerCrop.php index 75efe142b..033b08552 100644 --- a/src/block/TorchflowerCrop.php +++ b/src/block/TorchflowerCrop.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\BlockEventHelper; +use pocketmine\block\utils\CropGrowthHelper; use pocketmine\block\utils\StaticSupportTrait; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Fertilizer; @@ -32,7 +33,6 @@ use pocketmine\item\VanillaItems; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\player\Player; -use function mt_rand; final class TorchflowerCrop extends Flowable{ use StaticSupportTrait; @@ -79,7 +79,7 @@ final class TorchflowerCrop extends Flowable{ } public function onRandomTick() : void{ - if(mt_rand(0, 2) === 1){ + if(CropGrowthHelper::canGrow($this)){ BlockEventHelper::grow($this, $this->getNextState(), null); } } diff --git a/src/block/utils/CropGrowthHelper.php b/src/block/utils/CropGrowthHelper.php new file mode 100644 index 000000000..2f2cc1ed3 --- /dev/null +++ b/src/block/utils/CropGrowthHelper.php @@ -0,0 +1,105 @@ +getPosition(); + + $world = $position->getWorld(); + $baseX = $position->getFloorX(); + $baseY = $position->getFloorY(); + $baseZ = $position->getFloorZ(); + + $farmland = $world->getBlockAt($baseX, $baseY - 1, $baseZ); + + if($farmland instanceof Farmland){ + $result += $farmland->getWetness() > 0 ? self::ON_HYDRATED_FARMLAND_BONUS : self::ON_DRY_FARMLAND_BONUS; + } + + $xRow = false; + $zRow = false; + $diagonalRow = false; + for($x = -1; $x <= 1; $x++){ + for($z = -1; $z <= 1; $z++){ + if($x === 0 && $z === 0){ + continue; + } + $nextFarmland = $world->getBlockAt($baseX + $x, $baseY - 1, $baseZ + $z); + + if($nextFarmland instanceof Farmland){ + $result += $nextFarmland->getWetness() > 0 ? self::ADJACENT_HYDRATED_FARMLAND_BONUS : self::ADJACENT_DRY_FARMLAND_BONUS; + } + + $nextCrop = $world->getBlockAt($baseX + $x, $baseY, $baseZ + $z); + if($nextCrop->hasSameTypeId($block)){ + match(0){ + $x => $xRow = true, + $z => $zRow = true, + default => $diagonalRow = true, + }; + } + } + } + + //crops can be arranged in rows, but the rows must not cross and must be spaced apart by at least one block + if(($xRow && $zRow) || $diagonalRow){ + $result /= self::IMPROPER_ARRANGEMENT_DIVISOR; + } + + return $result; + } + + public static function canGrow(Block $block) : bool{ + //while it may be tempting to use mt_rand(0, 25) < multiplier, this would make crops grow a bit faster than + //vanilla in most cases due to the remainder of 25 / multiplier not being discarded + return mt_rand(0, (int) (25 / self::calculateMultiplier($block))) === 0; + } +} From a6b36d6c3cc83c4d02320d332c7dfbbeba0d34dc Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 Nov 2023 15:32:22 +0000 Subject: [PATCH 04/17] CropGrowthHelper: avoid unnecessary checks --- src/block/utils/CropGrowthHelper.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/block/utils/CropGrowthHelper.php b/src/block/utils/CropGrowthHelper.php index 2f2cc1ed3..446c00887 100644 --- a/src/block/utils/CropGrowthHelper.php +++ b/src/block/utils/CropGrowthHelper.php @@ -66,7 +66,8 @@ final class CropGrowthHelper{ $xRow = false; $zRow = false; - $diagonalRow = false; + $improperArrangement = false; + for($x = -1; $x <= 1; $x++){ for($z = -1; $z <= 1; $z++){ if($x === 0 && $z === 0){ @@ -74,23 +75,27 @@ final class CropGrowthHelper{ } $nextFarmland = $world->getBlockAt($baseX + $x, $baseY - 1, $baseZ + $z); - if($nextFarmland instanceof Farmland){ - $result += $nextFarmland->getWetness() > 0 ? self::ADJACENT_HYDRATED_FARMLAND_BONUS : self::ADJACENT_DRY_FARMLAND_BONUS; + if(!$nextFarmland instanceof Farmland){ + continue; } - $nextCrop = $world->getBlockAt($baseX + $x, $baseY, $baseZ + $z); - if($nextCrop->hasSameTypeId($block)){ - match(0){ - $x => $xRow = true, - $z => $zRow = true, - default => $diagonalRow = true, - }; + $result += $nextFarmland->getWetness() > 0 ? self::ADJACENT_HYDRATED_FARMLAND_BONUS : self::ADJACENT_DRY_FARMLAND_BONUS; + + if(!$improperArrangement){ + $nextCrop = $world->getBlockAt($baseX + $x, $baseY, $baseZ + $z); + if($nextCrop->hasSameTypeId($block)){ + match(0){ + $x => $zRow ? $improperArrangement = true : $xRow = true, + $z => $xRow ? $improperArrangement = true : $zRow = true, + default => $improperArrangement = true, + }; + } } } } //crops can be arranged in rows, but the rows must not cross and must be spaced apart by at least one block - if(($xRow && $zRow) || $diagonalRow){ + if($improperArrangement){ $result /= self::IMPROPER_ARRANGEMENT_DIVISOR; } From d3b7861d1ac81e5c7e9542961529d1e147742906 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 Nov 2023 16:15:57 +0000 Subject: [PATCH 05/17] Constify bootstrap options --- src/BootstrapOptions.php | 48 ++++++++++++++++++++++++++++++++++++++++ src/PocketMine.php | 12 +++++----- 2 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 src/BootstrapOptions.php diff --git a/src/BootstrapOptions.php b/src/BootstrapOptions.php new file mode 100644 index 000000000..879c502a6 --- /dev/null +++ b/src/BootstrapOptions.php @@ -0,0 +1,48 @@ +run()){ $exitCode = -1; From 3385087c569744e314b9171ab87629488fd54371 Mon Sep 17 00:00:00 2001 From: ipad54 <63200545+ipad54@users.noreply.github.com> Date: Sat, 4 Nov 2023 13:57:53 +0300 Subject: [PATCH 06/17] Fix Iron & Gold ores not affected by fortune (#6134) --- src/block/GoldOre.php | 3 ++- src/block/IronOre.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/block/GoldOre.php b/src/block/GoldOre.php index ae26d8b4e..75374c1b0 100644 --- a/src/block/GoldOre.php +++ b/src/block/GoldOre.php @@ -23,13 +23,14 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\FortuneDropHelper; use pocketmine\item\Item; use pocketmine\item\VanillaItems; final class GoldOre extends Opaque{ public function getDropsForCompatibleTool(Item $item) : array{ - return [VanillaItems::RAW_GOLD()]; + return [VanillaItems::RAW_GOLD()->setCount(FortuneDropHelper::weighted($item, min: 1, maxBase: 1))]; } public function isAffectedBySilkTouch() : bool{ return true; } diff --git a/src/block/IronOre.php b/src/block/IronOre.php index 8d7e9bd3f..11c8cc299 100644 --- a/src/block/IronOre.php +++ b/src/block/IronOre.php @@ -23,13 +23,14 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\FortuneDropHelper; use pocketmine\item\Item; use pocketmine\item\VanillaItems; final class IronOre extends Opaque{ public function getDropsForCompatibleTool(Item $item) : array{ - return [VanillaItems::RAW_IRON()]; + return [VanillaItems::RAW_IRON()->setCount(FortuneDropHelper::weighted($item, min: 1, maxBase: 1))]; } public function isAffectedBySilkTouch() : bool{ return true; } From 1055b7580a54f67ef5a18ef0af702f07e755088c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:00:06 +0000 Subject: [PATCH 07/17] Bump phpstan/phpstan from 1.10.40 to 1.10.41 (#6139) Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.10.40 to 1.10.41. - [Release notes](https://github.com/phpstan/phpstan/releases) - [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md) - [Commits](https://github.com/phpstan/phpstan/compare/1.10.40...1.10.41) --- updated-dependencies: - dependency-name: phpstan/phpstan dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 2f0b68730..c7bfd7d27 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "symfony/filesystem": "~6.3.0" }, "require-dev": { - "phpstan/phpstan": "1.10.40", + "phpstan/phpstan": "1.10.41", "phpstan/phpstan-phpunit": "^1.1.0", "phpstan/phpstan-strict-rules": "^1.2.0", "phpunit/phpunit": "~10.3.0 || ~10.2.0 || ~10.1.0" diff --git a/composer.lock b/composer.lock index 4c9588263..2888a3291 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ca499c3c5acafac837f7384ecdae136e", + "content-hash": "5c19f4766fd04be0cbd38d9f4681864e", "packages": [ { "name": "adhocore/json-comment", @@ -1378,16 +1378,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.40", + "version": "1.10.41", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d" + "reference": "c6174523c2a69231df55bdc65b61655e72876d76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/93c84b5bf7669920d823631e39904d69b9c7dc5d", - "reference": "93c84b5bf7669920d823631e39904d69b9c7dc5d", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c6174523c2a69231df55bdc65b61655e72876d76", + "reference": "c6174523c2a69231df55bdc65b61655e72876d76", "shasum": "" }, "require": { @@ -1436,7 +1436,7 @@ "type": "tidelift" } ], - "time": "2023-10-30T14:48:31+00:00" + "time": "2023-11-05T12:57:57+00:00" }, { "name": "phpstan/phpstan-phpunit", @@ -2964,5 +2964,5 @@ "platform-overrides": { "php": "8.1.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From 9fc9609694c1b10ee468a01b657667f0efe62eb3 Mon Sep 17 00:00:00 2001 From: ipad54 <63200545+ipad54@users.noreply.github.com> Date: Mon, 6 Nov 2023 18:01:43 +0300 Subject: [PATCH 08/17] Fix ancient debris not being fireproof (#6138) --- src/block/VanillaBlocks.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 8349f70c0..67a77c183 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -1495,7 +1495,9 @@ final class VanillaBlocks{ //for some reason, slabs have weird hardness like the legacy ones $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)))); + self::register("ancient_debris", new class(new BID(Ids::ANCIENT_DEBRIS), "Ancient Debris", new Info(BreakInfo::pickaxe(30, ToolTier::DIAMOND, 3600.0))) extends Opaque{ + public function isFireProofAsItem() : bool{ return true; } + }); $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; } From 457660235e69668b0c92b484e619c7ed2082cd5e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 6 Nov 2023 16:02:57 +0000 Subject: [PATCH 09/17] Crops must have access to a light level of at least 9 --- src/block/utils/CropGrowthHelper.php | 12 ++++++++- src/world/World.php | 38 ++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/block/utils/CropGrowthHelper.php b/src/block/utils/CropGrowthHelper.php index 446c00887..b5fc31362 100644 --- a/src/block/utils/CropGrowthHelper.php +++ b/src/block/utils/CropGrowthHelper.php @@ -36,6 +36,8 @@ final class CropGrowthHelper{ private const IMPROPER_ARRANGEMENT_DIVISOR = 2; + private const MIN_LIGHT_LEVEL = 9; + private function __construct(){ //NOOP } @@ -102,9 +104,17 @@ final class CropGrowthHelper{ return $result; } + public static function hasEnoughLight(Block $block, int $minLevel = self::MIN_LIGHT_LEVEL) : bool{ + $position = $block->getPosition(); + $world = $position->getWorld(); + + //crop growth is not affected by time of day since 1.11 or so + return $world->getPotentialLight($position) >= $minLevel; + } + public static function canGrow(Block $block) : bool{ //while it may be tempting to use mt_rand(0, 25) < multiplier, this would make crops grow a bit faster than //vanilla in most cases due to the remainder of 25 / multiplier not being discarded - return mt_rand(0, (int) (25 / self::calculateMultiplier($block))) === 0; + return mt_rand(0, (int) (25 / self::calculateMultiplier($block))) === 0 && self::hasEnoughLight($block); } } diff --git a/src/world/World.php b/src/world/World.php index 3e1131272..59b02be1a 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1666,16 +1666,16 @@ class World implements ChunkManager{ } /** - * Returns the highest available level of any type of light at the given coordinates, adjusted for the current - * weather and time of day. + * Returns the highest level of any type of light at the given coordinates, adjusted for the current weather and + * time of day. */ public function getFullLight(Vector3 $pos) : int{ return $this->getFullLightAt($pos->x, $pos->y, $pos->z); } /** - * Returns the highest available level of any type of light at the given coordinates, adjusted for the current - * weather and time of day. + * Returns the highest level of any type of light at the given coordinates, adjusted for the current weather and + * time of day. */ public function getFullLightAt(int $x, int $y, int $z) : int{ $skyLight = $this->getRealBlockSkyLightAt($x, $y, $z); @@ -1687,18 +1687,40 @@ class World implements ChunkManager{ } /** - * Returns the highest available level of any type of light at, or adjacent to, the given coordinates, adjusted for - * the current weather and time of day. + * Returns the highest level of any type of light at, or adjacent to, the given coordinates, adjusted for the + * current weather and time of day. */ public function getHighestAdjacentFullLightAt(int $x, int $y, int $z) : int{ return $this->getHighestAdjacentLight($x, $y, $z, $this->getFullLightAt(...)); } + /** + * Returns the highest potential level of any type of light at the target coordinates. + * This is not affected by weather or time of day. + */ + public function getPotentialLight(Vector3 $pos) : int{ + return $this->getPotentialLightAt($pos->x, $pos->y, $pos->z); + } + + /** + * Returns the highest potential level of any type of light at the target coordinates. + * This is not affected by weather or time of day. + */ + public function getPotentialLightAt(int $x, int $y, int $z) : int{ + return max($this->getPotentialBlockSkyLightAt($x, $y, $z), $this->getBlockLightAt($x, $y, $z)); + } + + /** + * Returns the highest potential level of any type of light at, or adjacent to, the given coordinates. + * This is not affected by weather or time of day. + */ + public function getHighestAdjacentPotentialLightAt(int $x, int $y, int $z) : int{ + return $this->getHighestAdjacentLight($x, $y, $z, $this->getPotentialLightAt(...)); + } + /** * Returns the highest potential level of sky light at the target coordinates, regardless of the time of day or * weather conditions. - * You usually don't want to use this for vanilla gameplay logic; prefer the real sky light instead. - * @see World::getRealBlockSkyLightAt() * * @return int 0-15 */ From bbe66e8e0982d9c0efc47d991fad7ad89ac5a661 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 6 Nov 2023 17:04:39 +0000 Subject: [PATCH 10/17] Block: Improve performance of encodeFullState() if there's no state data to encode, we can avoid useless calls and object allocations. For the best cases (blocks which don't use state data at all) this improves the performance of getStateId() by more than 10x. Blocks which use one or the other benefit by a smaller but still significant margin. --- src/block/Block.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/block/Block.php b/src/block/Block.php index a1d553b9d..b2847bb35 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -270,11 +270,22 @@ class Block{ } private function encodeFullState() : int{ - $writer = new RuntimeDataWriter($this->requiredBlockItemStateDataBits + $this->requiredBlockOnlyStateDataBits); - $writer->writeInt($this->requiredBlockItemStateDataBits, $this->encodeBlockItemState()); - $writer->writeInt($this->requiredBlockOnlyStateDataBits, $this->encodeBlockOnlyState()); + $blockItemBits = $this->requiredBlockItemStateDataBits; + $blockOnlyBits = $this->requiredBlockOnlyStateDataBits; - return $writer->getValue(); + if($blockOnlyBits === 0 && $blockItemBits === 0){ + return 0; + } + + $result = 0; + if($blockItemBits > 0){ + $result |= $this->encodeBlockItemState(); + } + if($blockOnlyBits > 0){ + $result |= $this->encodeBlockOnlyState() << $blockItemBits; + } + + return $result; } /** From d09af2e30da6b393dfeb47f1e5cd2f2f5417f5bd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 6 Nov 2023 17:15:17 +0000 Subject: [PATCH 11/17] World: don't assume that random Vector3 are int vectors we can safely assume this for blocks (though the type info doesn't reflect it) but this is not safe to assume for random APIs that might be used by plugins. --- src/block/utils/CropGrowthHelper.php | 2 +- src/world/World.php | 10 ++++++-- tests/phpstan/configs/actual-problems.neon | 30 +++++++++++----------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/block/utils/CropGrowthHelper.php b/src/block/utils/CropGrowthHelper.php index b5fc31362..e85b0b82d 100644 --- a/src/block/utils/CropGrowthHelper.php +++ b/src/block/utils/CropGrowthHelper.php @@ -109,7 +109,7 @@ final class CropGrowthHelper{ $world = $position->getWorld(); //crop growth is not affected by time of day since 1.11 or so - return $world->getPotentialLight($position) >= $minLevel; + return $world->getPotentialLightAt($position->x, $position->y, $position->z) >= $minLevel; } public static function canGrow(Block $block) : bool{ diff --git a/src/world/World.php b/src/world/World.php index 59b02be1a..f554479c9 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1670,7 +1670,10 @@ class World implements ChunkManager{ * time of day. */ public function getFullLight(Vector3 $pos) : int{ - return $this->getFullLightAt($pos->x, $pos->y, $pos->z); + $floorX = $pos->getFloorX(); + $floorY = $pos->getFloorY(); + $floorZ = $pos->getFloorZ(); + return $this->getFullLightAt($floorX, $floorY, $floorZ); } /** @@ -1699,7 +1702,10 @@ class World implements ChunkManager{ * This is not affected by weather or time of day. */ public function getPotentialLight(Vector3 $pos) : int{ - return $this->getPotentialLightAt($pos->x, $pos->y, $pos->z); + $floorX = $pos->getFloorX(); + $floorY = $pos->getFloorY(); + $floorZ = $pos->getFloorZ(); + return $this->getPotentialLightAt($floorX, $floorY, $floorZ); } /** diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index cf7e9b02f..1e5d83dda 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -425,6 +425,21 @@ parameters: count: 3 path: ../../../src/block/tile/Spawnable.php + - + message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getPotentialLightAt\\(\\) expects int, float\\|int given\\.$#" + count: 1 + path: ../../../src/block/utils/CropGrowthHelper.php + + - + message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\World\\:\\:getPotentialLightAt\\(\\) expects int, float\\|int given\\.$#" + count: 1 + path: ../../../src/block/utils/CropGrowthHelper.php + + - + message: "#^Parameter \\#3 \\$z of method pocketmine\\\\world\\\\World\\:\\:getPotentialLightAt\\(\\) expects int, float\\|int given\\.$#" + count: 1 + path: ../../../src/block/utils/CropGrowthHelper.php + - message: "#^Cannot call method addParticle\\(\\) on pocketmine\\\\world\\\\World\\|null\\.$#" count: 1 @@ -910,11 +925,6 @@ parameters: count: 1 path: ../../../src/world/World.php - - - message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getFullLightAt\\(\\) expects int, float\\|int given\\.$#" - count: 1 - path: ../../../src/world/World.php - - message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#" count: 1 @@ -940,11 +950,6 @@ parameters: count: 1 path: ../../../src/world/World.php - - - message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\World\\:\\:getFullLightAt\\(\\) expects int, float\\|int given\\.$#" - count: 1 - path: ../../../src/world/World.php - - message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#" count: 1 @@ -975,11 +980,6 @@ parameters: count: 1 path: ../../../src/world/World.php - - - message: "#^Parameter \\#3 \\$z of method pocketmine\\\\world\\\\World\\:\\:getFullLightAt\\(\\) expects int, float\\|int given\\.$#" - count: 1 - path: ../../../src/world/World.php - - message: "#^Parameter \\#3 \\$z of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#" count: 1 From 6b5c4059396baaa990e033f4f29e2173796507cb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:06:43 +0000 Subject: [PATCH 12/17] Bump shivammathur/setup-php from 2.26.0 to 2.27.1 (#6142) Bumps [shivammathur/setup-php](https://github.com/shivammathur/setup-php) from 2.26.0 to 2.27.1. - [Release notes](https://github.com/shivammathur/setup-php/releases) - [Commits](https://github.com/shivammathur/setup-php/compare/2.26.0...2.27.1) --- updated-dependencies: - dependency-name: shivammathur/setup-php dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/discord-release-notify.yml | 2 +- .github/workflows/draft-release.yml | 2 +- .github/workflows/main.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/discord-release-notify.yml b/.github/workflows/discord-release-notify.yml index 94b7bb99d..f73113098 100644 --- a/.github/workflows/discord-release-notify.yml +++ b/.github/workflows/discord-release-notify.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - name: Setup PHP and tools - uses: shivammathur/setup-php@2.26.0 + uses: shivammathur/setup-php@2.27.1 with: php-version: 8.1 diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index f7026c646..03bfedc89 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -20,7 +20,7 @@ jobs: submodules: true - name: Setup PHP - uses: shivammathur/setup-php@2.26.0 + uses: shivammathur/setup-php@2.27.1 with: php-version: ${{ matrix.php-version }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1fd1731a2..c57cecb84 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -173,7 +173,7 @@ jobs: - uses: actions/checkout@v4 - name: Setup PHP and tools - uses: shivammathur/setup-php@2.26.0 + uses: shivammathur/setup-php@2.27.1 with: php-version: 8.1 tools: php-cs-fixer:3.17 From 8ccaf907d1dfca4459d01a5fa7694d8938156995 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Nov 2023 15:18:46 +0000 Subject: [PATCH 13/17] tools/generate-blockstate-upgrade-schema: do not optimize state remaps with unchanged IDs processRemappedStates() needs to know about the full set of states to generate reliable mappings. Without it, it may generate flattening rules or state matching criteria that unintentionally match states that it's not aware of. Sadly, this does make some schemas bigger, but it's for the best. --- tools/generate-blockstate-upgrade-schema.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tools/generate-blockstate-upgrade-schema.php b/tools/generate-blockstate-upgrade-schema.php index f247d6112..dfb8f6066 100644 --- a/tools/generate-blockstate-upgrade-schema.php +++ b/tools/generate-blockstate-upgrade-schema.php @@ -37,7 +37,6 @@ use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer; use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\Filesystem; use pocketmine\utils\Utils; -use function array_filter; use function array_key_first; use function array_keys; use function array_map; @@ -481,16 +480,9 @@ function generateBlockStateUpgradeSchema(array $upgradeTable) : BlockStateUpgrad throw new \RuntimeException("States with the same ID should be fully consistent"); } }else{ - if(isset($newNameFound[$oldName])){ - //some of the states stayed under the same ID - we can process these as normal states - $stateGroup = array_filter($blockStateMappings, fn(BlockStateMapping $m) => $m->new->getName() === $oldName); - if(processStateGroup($oldName, $stateGroup, $result)){ - foreach(Utils::stringifyKeys($stateGroup) as $k => $mapping){ - unset($blockStateMappings[$k]); - } - } - } //block mapped to multiple different new IDs; we can't guess these, so we just do a plain old remap + //even if some of the states stay under the same ID, the compression techniques used by this function + //implicitly rely on knowing the full set of old states and their new transformations $result->remappedStates[$oldName] = processRemappedStates($blockStateMappings); } } From 5f3a2a5096fc2302512274cae1b64c523fd299f2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Nov 2023 18:52:22 +0000 Subject: [PATCH 14/17] BlockStateUpgrader: fixed undefined array key when flattening a block whose new ID is the same as the old this came up during 1.20.50 testing, where minecraft:stone[stone_type=stone] continues to have an ID minecraft:stone without the stone_type property. This could have appeared in other ways, such as with an invalid legacy blockstate. --- src/data/bedrock/block/upgrade/BlockStateUpgrader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/bedrock/block/upgrade/BlockStateUpgrader.php b/src/data/bedrock/block/upgrade/BlockStateUpgrader.php index 5c84cd383..582039305 100644 --- a/src/data/bedrock/block/upgrade/BlockStateUpgrader.php +++ b/src/data/bedrock/block/upgrade/BlockStateUpgrader.php @@ -86,7 +86,7 @@ final class BlockStateUpgrader{ if(is_string($remap->newName)){ $newName = $remap->newName; }else{ - $flattenedValue = $oldState[$remap->newName->flattenedProperty]; + $flattenedValue = $oldState[$remap->newName->flattenedProperty] ?? null; if($flattenedValue instanceof StringTag){ $newName = sprintf("%s%s%s", $remap->newName->prefix, $flattenedValue->getValue(), $remap->newName->suffix); unset($oldState[$remap->newName->flattenedProperty]); From c1ed182112313d4545accb50735e0ef5d6da0bab Mon Sep 17 00:00:00 2001 From: ace Date: Thu, 9 Nov 2023 22:22:37 +0800 Subject: [PATCH 15/17] Fix loading of sign text from vanilla world (#6122) --- src/block/tile/Sign.php | 56 +++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/block/tile/Sign.php b/src/block/tile/Sign.php index d5d314ee3..2ced414ff 100644 --- a/src/block/tile/Sign.php +++ b/src/block/tile/Sign.php @@ -77,22 +77,30 @@ class Sign extends Spawnable{ parent::__construct($world, $pos); } + private function readTextTag(CompoundTag $nbt, bool $lightingBugResolved) : void{ + $baseColor = new Color(0, 0, 0); + $glowingText = false; + if(($baseColorTag = $nbt->getTag(self::TAG_TEXT_COLOR)) instanceof IntTag){ + $baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue())); + } + if($lightingBugResolved && ($glowingTextTag = $nbt->getTag(self::TAG_GLOWING_TEXT)) instanceof ByteTag){ + //both of these must be 1 - if only one is set, it's a leftover from 1.16.210 experimental features + //see https://bugs.mojang.com/browse/MCPE-117835 + $glowingText = $glowingTextTag->getValue() !== 0; + } + $this->text = SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB), 'UTF-8'), $baseColor, $glowingText); + } + public function readSaveData(CompoundTag $nbt) : void{ - if(($textBlobTag = $nbt->getTag(self::TAG_TEXT_BLOB)) instanceof StringTag){ //MCPE 1.2 save format - $baseColor = new Color(0, 0, 0); - $glowingText = false; - if(($baseColorTag = $nbt->getTag(self::TAG_TEXT_COLOR)) instanceof IntTag){ - $baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue())); + $frontTextTag = $nbt->getTag(self::TAG_FRONT_TEXT); + if($frontTextTag instanceof CompoundTag){ + $this->readTextTag($frontTextTag, true); + }elseif($nbt->getTag(self::TAG_TEXT_BLOB) instanceof StringTag){ //MCPE 1.2 save format + $lightingBugResolved = false; + if(($lightingBugResolvedTag = $nbt->getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag){ + $lightingBugResolved = $lightingBugResolvedTag->getValue() !== 0; } - if( - ($glowingTextTag = $nbt->getTag(self::TAG_GLOWING_TEXT)) instanceof ByteTag && - ($lightingBugResolvedTag = $nbt->getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag - ){ - //both of these must be 1 - if only one is set, it's a leftover from 1.16.210 experimental features - //see https://bugs.mojang.com/browse/MCPE-117835 - $glowingText = $glowingTextTag->getValue() !== 0 && $lightingBugResolvedTag->getValue() !== 0; - } - $this->text = SignText::fromBlob(mb_scrub($textBlobTag->getValue(), 'UTF-8'), $baseColor, $glowingText); + $this->readTextTag($nbt, $lightingBugResolved); }else{ $text = []; for($i = 0; $i < SignText::LINE_COUNT; ++$i){ @@ -107,15 +115,19 @@ class Sign extends Spawnable{ } protected function writeSaveData(CompoundTag $nbt) : void{ - $nbt->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines())); + $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) + ); + $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) + ); - for($i = 0; $i < SignText::LINE_COUNT; ++$i){ //Backwards-compatibility - $textKey = sprintf(self::TAG_TEXT_LINE, $i + 1); - $nbt->setString($textKey, $this->text->getLine($i)); - } - $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); } From 4103631bc10cf20e5dda5e2e85e63cccd9d848f0 Mon Sep 17 00:00:00 2001 From: pandaa-be <135014092+pandaa-be@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:25:49 +0100 Subject: [PATCH 16/17] Added Smithing Template items (#6132) --- .../ItemSerializerDeserializerRegistrar.php | 17 +++++++++ src/item/ItemTypeIds.php | 19 +++++++++- src/item/StringToItemParser.php | 17 +++++++++ src/item/VanillaItems.php | 38 +++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php index 6bb3a56b3..a2bed6ee1 100644 --- a/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php +++ b/src/data/bedrock/item/ItemSerializerDeserializerRegistrar.php @@ -193,6 +193,7 @@ final class ItemSerializerDeserializerRegistrar{ $this->map1to1Item(Ids::CLAY_BALL, Items::CLAY()); $this->map1to1Item(Ids::CLOCK, Items::CLOCK()); $this->map1to1Item(Ids::COAL, Items::COAL()); + $this->map1to1Item(Ids::COAST_ARMOR_TRIM_SMITHING_TEMPLATE, Items::COAST_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::COCOA_BEANS, Items::COCOA_BEANS()); $this->map1to1Item(Ids::COD, Items::RAW_FISH()); $this->map1to1Item(Ids::COMPASS, Items::COMPASS()); @@ -221,6 +222,7 @@ final class ItemSerializerDeserializerRegistrar{ $this->map1to1Item(Ids::DISC_FRAGMENT_5, Items::DISC_FRAGMENT_5()); $this->map1to1Item(Ids::DRAGON_BREATH, Items::DRAGON_BREATH()); $this->map1to1Item(Ids::DRIED_KELP, Items::DRIED_KELP()); + $this->map1to1Item(Ids::DUNE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::DUNE_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::ECHO_SHARD, Items::ECHO_SHARD()); $this->map1to1Item(Ids::EGG, Items::EGG()); $this->map1to1Item(Ids::EMERALD, Items::EMERALD()); @@ -228,6 +230,7 @@ final class ItemSerializerDeserializerRegistrar{ $this->map1to1Item(Ids::ENCHANTED_GOLDEN_APPLE, Items::ENCHANTED_GOLDEN_APPLE()); $this->map1to1Item(Ids::ENDER_PEARL, Items::ENDER_PEARL()); $this->map1to1Item(Ids::EXPERIENCE_BOTTLE, Items::EXPERIENCE_BOTTLE()); + $this->map1to1Item(Ids::EYE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::EYE_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::FEATHER, Items::FEATHER()); $this->map1to1Item(Ids::FERMENTED_SPIDER_EYE, Items::FERMENTED_SPIDER_EYE()); $this->map1to1Item(Ids::FIRE_CHARGE, Items::FIRE_CHARGE()); @@ -257,6 +260,7 @@ final class ItemSerializerDeserializerRegistrar{ $this->map1to1Item(Ids::HEART_OF_THE_SEA, Items::HEART_OF_THE_SEA()); $this->map1to1Item(Ids::HONEY_BOTTLE, Items::HONEY_BOTTLE()); $this->map1to1Item(Ids::HONEYCOMB, Items::HONEYCOMB()); + $this->map1to1Item(Ids::HOST_ARMOR_TRIM_SMITHING_TEMPLATE, Items::HOST_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::INK_SAC, Items::INK_SAC()); $this->map1to1Item(Ids::IRON_AXE, Items::IRON_AXE()); $this->map1to1Item(Ids::IRON_BOOTS, Items::IRON_BOOTS()); @@ -316,6 +320,7 @@ final class ItemSerializerDeserializerRegistrar{ $this->map1to1Item(Ids::NETHERITE_SCRAP, Items::NETHERITE_SCRAP()); $this->map1to1Item(Ids::NETHERITE_SHOVEL, Items::NETHERITE_SHOVEL()); $this->map1to1Item(Ids::NETHERITE_SWORD, Items::NETHERITE_SWORD()); + $this->map1to1Item(Ids::NETHERITE_UPGRADE_SMITHING_TEMPLATE, Items::NETHERITE_UPGRADE_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::OAK_BOAT, Items::OAK_BOAT()); $this->map1to1Item(Ids::OAK_SIGN, Items::OAK_SIGN()); $this->map1to1Item(Ids::PAINTING, Items::PAINTING()); @@ -335,18 +340,25 @@ final class ItemSerializerDeserializerRegistrar{ $this->map1to1Item(Ids::RABBIT_FOOT, Items::RABBIT_FOOT()); $this->map1to1Item(Ids::RABBIT_HIDE, Items::RABBIT_HIDE()); $this->map1to1Item(Ids::RABBIT_STEW, Items::RABBIT_STEW()); + $this->map1to1Item(Ids::RAISER_ARMOR_TRIM_SMITHING_TEMPLATE, Items::RAISER_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::RAW_COPPER, Items::RAW_COPPER()); $this->map1to1Item(Ids::RAW_GOLD, Items::RAW_GOLD()); $this->map1to1Item(Ids::RAW_IRON, Items::RAW_IRON()); $this->map1to1Item(Ids::REDSTONE, Items::REDSTONE_DUST()); + $this->map1to1Item(Ids::RIB_ARMOR_TRIM_SMITHING_TEMPLATE, Items::RIB_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::ROTTEN_FLESH, Items::ROTTEN_FLESH()); $this->map1to1Item(Ids::SALMON, Items::RAW_SALMON()); $this->map1to1Item(Ids::SCUTE, Items::SCUTE()); + $this->map1to1Item(Ids::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE()); + $this->map1to1Item(Ids::SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::SHEARS, Items::SHEARS()); $this->map1to1Item(Ids::SHULKER_SHELL, Items::SHULKER_SHELL()); + $this->map1to1Item(Ids::SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::SLIME_BALL, Items::SLIMEBALL()); + $this->map1to1Item(Ids::SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::SNOWBALL, Items::SNOWBALL()); $this->map1to1Item(Ids::SPIDER_EYE, Items::SPIDER_EYE()); + $this->map1to1Item(Ids::SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::SPRUCE_BOAT, Items::SPRUCE_BOAT()); $this->map1to1Item(Ids::SPRUCE_SIGN, Items::SPRUCE_SIGN()); $this->map1to1Item(Ids::SPYGLASS, Items::SPYGLASS()); @@ -361,14 +373,19 @@ final class ItemSerializerDeserializerRegistrar{ $this->map1to1Item(Ids::SUGAR, Items::SUGAR()); $this->map1to1Item(Ids::SWEET_BERRIES, Items::SWEET_BERRIES()); $this->map1to1Item(Ids::TORCHFLOWER_SEEDS, Items::TORCHFLOWER_SEEDS()); + $this->map1to1Item(Ids::TIDE_ARMOR_TRIM_SMITHING_TEMPLATE, Items::TIDE_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::TOTEM_OF_UNDYING, Items::TOTEM()); $this->map1to1Item(Ids::TROPICAL_FISH, Items::CLOWNFISH()); $this->map1to1Item(Ids::TURTLE_HELMET, Items::TURTLE_HELMET()); + $this->map1to1Item(Ids::VEX_ARMOR_TRIM_SMITHING_TEMPLATE, Items::VEX_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::VILLAGER_SPAWN_EGG, Items::VILLAGER_SPAWN_EGG()); + $this->map1to1Item(Ids::WARD_ARMOR_TRIM_SMITHING_TEMPLATE, Items::WARD_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::WARPED_SIGN, Items::WARPED_SIGN()); $this->map1to1Item(Ids::WATER_BUCKET, Items::WATER_BUCKET()); + $this->map1to1Item(Ids::WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE, Items::WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::WHEAT, Items::WHEAT()); $this->map1to1Item(Ids::WHEAT_SEEDS, Items::WHEAT_SEEDS()); + $this->map1to1Item(Ids::WILD_ARMOR_TRIM_SMITHING_TEMPLATE, Items::WILD_ARMOR_TRIM_SMITHING_TEMPLATE()); $this->map1to1Item(Ids::WOODEN_AXE, Items::WOODEN_AXE()); $this->map1to1Item(Ids::WOODEN_HOE, Items::WOODEN_HOE()); $this->map1to1Item(Ids::WOODEN_PICKAXE, Items::WOODEN_PICKAXE()); diff --git a/src/item/ItemTypeIds.php b/src/item/ItemTypeIds.php index 4c2f0a1ec..451d25a59 100644 --- a/src/item/ItemTypeIds.php +++ b/src/item/ItemTypeIds.php @@ -305,8 +305,25 @@ final class ItemTypeIds{ public const CHERRY_SIGN = 20266; public const ENCHANTED_BOOK = 20267; public const TORCHFLOWER_SEEDS = 20268; + public const NETHERITE_UPGRADE_SMITHING_TEMPLATE = 20269; + public const SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE = 20270; + public const VEX_ARMOR_TRIM_SMITHING_TEMPLATE = 20271; + public const WILD_ARMOR_TRIM_SMITHING_TEMPLATE = 20272; + public const COAST_ARMOR_TRIM_SMITHING_TEMPLATE = 20273; + public const DUNE_ARMOR_TRIM_SMITHING_TEMPLATE = 20274; + public const WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE = 20275; + public const RAISER_ARMOR_TRIM_SMITHING_TEMPLATE = 20276; + public const SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE = 20277; + public const HOST_ARMOR_TRIM_SMITHING_TEMPLATE = 20278; + public const WARD_ARMOR_TRIM_SMITHING_TEMPLATE = 20279; + public const SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE = 20280; + public const TIDE_ARMOR_TRIM_SMITHING_TEMPLATE = 20281; + public const SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE = 20282; + public const RIB_ARMOR_TRIM_SMITHING_TEMPLATE = 20283; + public const EYE_ARMOR_TRIM_SMITHING_TEMPLATE = 20284; + public const SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE = 20285; - public const FIRST_UNUSED_ITEM_ID = 20269; + public const FIRST_UNUSED_ITEM_ID = 20286; private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID; diff --git a/src/item/StringToItemParser.php b/src/item/StringToItemParser.php index d4f242621..8d78fcf95 100644 --- a/src/item/StringToItemParser.php +++ b/src/item/StringToItemParser.php @@ -1264,6 +1264,7 @@ final class StringToItemParser extends StringToTParser{ $result->register("clown_fish", fn() => Items::CLOWNFISH()); $result->register("clownfish", fn() => Items::CLOWNFISH()); $result->register("coal", fn() => Items::COAL()); + $result->register("coast_armor_trim_smithing_template", fn() => Items::COAST_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("cocoa_beans", fn() => Items::COCOA_BEANS()); $result->register("cod", fn() => Items::RAW_FISH()); $result->register("compass", fn() => Items::COMPASS()); @@ -1292,6 +1293,7 @@ final class StringToItemParser extends StringToTParser{ $result->register("disc_fragment_5", fn() => Items::DISC_FRAGMENT_5()); $result->register("dragon_breath", fn() => Items::DRAGON_BREATH()); $result->register("dried_kelp", fn() => Items::DRIED_KELP()); + $result->register("dune_armor_trim_smithing_template", fn() => Items::DUNE_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("dye", fn() => Items::INK_SAC()); $result->register("echo_shard", fn() => Items::ECHO_SHARD()); $result->register("egg", fn() => Items::EGG()); @@ -1302,6 +1304,7 @@ final class StringToItemParser extends StringToTParser{ $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_armor_trim_smithing_template", fn() => Items::EYE_ARMOR_TRIM_SMITHING_TEMPLATE()); $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()); @@ -1343,6 +1346,7 @@ final class StringToItemParser extends StringToTParser{ $result->register("gunpowder", fn() => Items::GUNPOWDER()); $result->register("heart_of_the_sea", fn() => Items::HEART_OF_THE_SEA()); $result->register("honey_bottle", fn() => Items::HONEY_BOTTLE()); + $result->register("host_armor_trim_smithing_template", fn() => Items::HOST_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("honeycomb", fn() => Items::HONEYCOMB()); $result->register("ink_sac", fn() => Items::INK_SAC()); $result->register("iron_axe", fn() => Items::IRON_AXE()); @@ -1396,6 +1400,7 @@ final class StringToItemParser extends StringToTParser{ $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("netherite_upgrade_smithing_template", fn() => Items::NETHERITE_UPGRADE_SMITHING_TEMPLATE()); $result->register("oak_boat", fn() => Items::OAK_BOAT()); $result->register("painting", fn() => Items::PAINTING()); $result->register("paper", fn() => Items::PAPER()); @@ -1416,6 +1421,7 @@ final class StringToItemParser extends StringToTParser{ $result->register("rabbit_foot", fn() => Items::RABBIT_FOOT()); $result->register("rabbit_hide", fn() => Items::RABBIT_HIDE()); $result->register("rabbit_stew", fn() => Items::RABBIT_STEW()); + $result->register("raiser_armor_trim_smithing_template", fn() => Items::RAISER_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("raw_beef", fn() => Items::RAW_BEEF()); $result->register("raw_cod", fn() => Items::RAW_FISH()); $result->register("raw_copper", fn() => Items::RAW_COPPER()); @@ -1444,17 +1450,23 @@ final class StringToItemParser extends StringToTParser{ $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("rib_armor_trim_smithing_template", fn() => Items::RIB_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("rotten_flesh", fn() => Items::ROTTEN_FLESH()); $result->register("salmon", fn() => Items::RAW_SALMON()); $result->register("scute", fn() => Items::SCUTE()); + $result->register("sentry_armor_trim_smithing_template", fn() => Items::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE()); + $result->register("shaper_armor_trim_smithing_template", fn() => Items::SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("seeds", fn() => Items::WHEAT_SEEDS()); $result->register("shears", fn() => Items::SHEARS()); $result->register("shulker_shell", fn() => Items::SHULKER_SHELL()); + $result->register("silence_armor_trim_smithing_template", fn() => Items::SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("slime_ball", fn() => Items::SLIMEBALL()); + $result->register("snout_armor_trim_smithing_template", fn() => Items::SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("slimeball", fn() => Items::SLIMEBALL()); $result->register("snowball", fn() => Items::SNOWBALL()); $result->register("speckled_melon", fn() => Items::GLISTERING_MELON()); $result->register("spider_eye", fn() => Items::SPIDER_EYE()); + $result->register("spire_armor_trim_smithing_template", fn() => Items::SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("splash_potion", fn() => Items::SPLASH_POTION()); $result->register("spruce_boat", fn() => Items::SPRUCE_BOAT()); $result->register("spyglass", fn() => Items::SPYGLASS()); @@ -1473,13 +1485,18 @@ final class StringToItemParser extends StringToTParser{ $result->register("sweet_berries", fn() => Items::SWEET_BERRIES()); $result->register("tonic", fn() => Items::MEDICINE()->setType(MedicineType::TONIC)); $result->register("torchflower_seeds", fn() => Items::TORCHFLOWER_SEEDS()); + $result->register("tide_armor_trim_smithing_template", fn() => Items::TIDE_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("totem", fn() => Items::TOTEM()); $result->register("turtle_helmet", fn() => Items::TURTLE_HELMET()); + $result->register("vex_armor_trim_smithing_template", fn() => Items::VEX_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("turtle_shell_piece", fn() => Items::SCUTE()); $result->register("villager_spawn_egg", fn() => Items::VILLAGER_SPAWN_EGG()); + $result->register("ward_armor_trim_smithing_template", fn() => Items::WARD_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("water_bucket", fn() => Items::WATER_BUCKET()); + $result->register("wayfinder_armor_trim_smithing_template", fn() => Items::WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE()); $result->register("wheat", fn() => Items::WHEAT()); $result->register("wheat_seeds", fn() => Items::WHEAT_SEEDS()); + $result->register("wild_armor_trim_smithing_template", fn() => Items::WILD_ARMOR_TRIM_SMITHING_TEMPLATE()); $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/VanillaItems.php b/src/item/VanillaItems.php index e07d4161b..5f4f60f8e 100644 --- a/src/item/VanillaItems.php +++ b/src/item/VanillaItems.php @@ -121,6 +121,7 @@ use function strtolower; * @method static Clock CLOCK() * @method static Clownfish CLOWNFISH() * @method static Coal COAL() + * @method static Item COAST_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static CocoaBeans COCOA_BEANS() * @method static Compass COMPASS() * @method static CookedChicken COOKED_CHICKEN() @@ -148,6 +149,7 @@ use function strtolower; * @method static Item DISC_FRAGMENT_5() * @method static Item DRAGON_BREATH() * @method static DriedKelp DRIED_KELP() + * @method static Item DUNE_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Dye DYE() * @method static Item ECHO_SHARD() * @method static Egg EGG() @@ -156,6 +158,7 @@ use function strtolower; * @method static GoldenAppleEnchanted ENCHANTED_GOLDEN_APPLE() * @method static EnderPearl ENDER_PEARL() * @method static ExperienceBottle EXPERIENCE_BOTTLE() + * @method static Item EYE_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Item FEATHER() * @method static Item FERMENTED_SPIDER_EYE() * @method static FireCharge FIRE_CHARGE() @@ -185,6 +188,7 @@ use function strtolower; * @method static Item HEART_OF_THE_SEA() * @method static Item HONEYCOMB() * @method static HoneyBottle HONEY_BOTTLE() + * @method static Item HOST_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Item INK_SAC() * @method static Axe IRON_AXE() * @method static Armor IRON_BOOTS() @@ -227,6 +231,7 @@ use function strtolower; * @method static Item NETHERITE_SCRAP() * @method static Shovel NETHERITE_SHOVEL() * @method static Sword NETHERITE_SWORD() + * @method static Item NETHERITE_UPGRADE_SMITHING_TEMPLATE() * @method static Item NETHER_BRICK() * @method static Item NETHER_QUARTZ() * @method static Item NETHER_STAR() @@ -247,6 +252,7 @@ use function strtolower; * @method static Item RABBIT_FOOT() * @method static Item RABBIT_HIDE() * @method static RabbitStew RABBIT_STEW() + * @method static Item RAISER_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static RawBeef RAW_BEEF() * @method static RawChicken RAW_CHICKEN() * @method static Item RAW_COPPER() @@ -273,13 +279,19 @@ use function strtolower; * @method static Record RECORD_WAIT() * @method static Record RECORD_WARD() * @method static Redstone REDSTONE_DUST() + * @method static Item RIB_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static RottenFlesh ROTTEN_FLESH() * @method static Item SCUTE() + * @method static Item SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE() + * @method static Item SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Shears SHEARS() * @method static Item SHULKER_SHELL() + * @method static Item SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Item SLIMEBALL() + * @method static Item SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Snowball SNOWBALL() * @method static SpiderEye SPIDER_EYE() + * @method static Item SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static SplashPotion SPLASH_POTION() * @method static Boat SPRUCE_BOAT() * @method static ItemBlockWallOrFloor SPRUCE_SIGN() @@ -296,14 +308,19 @@ use function strtolower; * @method static Item SUGAR() * @method static SuspiciousStew SUSPICIOUS_STEW() * @method static SweetBerries SWEET_BERRIES() + * @method static Item TIDE_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static TorchflowerSeeds TORCHFLOWER_SEEDS() * @method static Totem TOTEM() * @method static TurtleHelmet TURTLE_HELMET() + * @method static Item VEX_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static SpawnEgg VILLAGER_SPAWN_EGG() + * @method static Item WARD_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static ItemBlockWallOrFloor WARPED_SIGN() * @method static LiquidBucket WATER_BUCKET() + * @method static Item WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Item WHEAT() * @method static WheatSeeds WHEAT_SEEDS() + * @method static Item WILD_ARMOR_TRIM_SMITHING_TEMPLATE() * @method static Axe WOODEN_AXE() * @method static Hoe WOODEN_HOE() * @method static Pickaxe WOODEN_PICKAXE() @@ -339,6 +356,7 @@ final class VanillaItems{ self::registerArmorItems(); self::registerSpawnEggs(); self::registerTierToolItems(); + self::registerSmithingTemplates(); self::register("air", Blocks::AIR()->asItem()->setCount(0)); @@ -644,4 +662,24 @@ final class VanillaItems{ self::register("netherite_leggings", new Armor(new IID(Ids::NETHERITE_LEGGINGS), "Netherite Leggings", new ArmorTypeInfo(6, 556, ArmorInventory::SLOT_LEGS, 3, true, material: ArmorMaterials::NETHERITE()), [EnchantmentTags::LEGGINGS])); } + private static function registerSmithingTemplates() : void{ + self::register("netherite_upgrade_smithing_template", new Item(new IID(Ids::NETHERITE_UPGRADE_SMITHING_TEMPLATE), "Netherite Upgrade Smithing Template")); + self::register("coast_armor_trim_smithing_template", new Item(new IID(Ids::COAST_ARMOR_TRIM_SMITHING_TEMPLATE), "Coast Armor Trim Smithing Template")); + self::register("dune_armor_trim_smithing_template", new Item(new IID(Ids::DUNE_ARMOR_TRIM_SMITHING_TEMPLATE), "Dune Armor Trim Smithing Template")); + self::register("eye_armor_trim_smithing_template", new Item(new IID(Ids::EYE_ARMOR_TRIM_SMITHING_TEMPLATE), "Eye Armor Trim Smithing Template")); + self::register("host_armor_trim_smithing_template", new Item(new IID(Ids::HOST_ARMOR_TRIM_SMITHING_TEMPLATE), "Host Armor Trim Smithing Template")); + self::register("raiser_armor_trim_smithing_template", new Item(new IID(Ids::RAISER_ARMOR_TRIM_SMITHING_TEMPLATE), "Raiser Armor Trim Smithing Template")); + self::register("rib_armor_trim_smithing_template", new Item(new IID(Ids::RIB_ARMOR_TRIM_SMITHING_TEMPLATE), "Rib Armor Trim Smithing Template")); + self::register("sentry_armor_trim_smithing_template", new Item(new IID(Ids::SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE), "Sentry Armor Trim Smithing Template")); + self::register("shaper_armor_trim_smithing_template", new Item(new IID(Ids::SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE), "Shaper Armor Trim Smithing Template")); + self::register("silence_armor_trim_smithing_template", new Item(new IID(Ids::SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE), "Silence Armor Trim Smithing Template")); + self::register("snout_armor_trim_smithing_template", new Item(new IID(Ids::SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE), "Snout Armor Trim Smithing Template")); + self::register("spire_armor_trim_smithing_template", new Item(new IID(Ids::SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE), "Spire Armor Trim Smithing Template")); + self::register("tide_armor_trim_smithing_template", new Item(new IID(Ids::TIDE_ARMOR_TRIM_SMITHING_TEMPLATE), "Tide Armor Trim Smithing Template")); + self::register("vex_armor_trim_smithing_template", new Item(new IID(Ids::VEX_ARMOR_TRIM_SMITHING_TEMPLATE), "Vex Armor Trim Smithing Template")); + self::register("ward_armor_trim_smithing_template", new Item(new IID(Ids::WARD_ARMOR_TRIM_SMITHING_TEMPLATE), "Ward Armor Trim Smithing Template")); + self::register("wayfinder_armor_trim_smithing_template", new Item(new IID(Ids::WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE), "Wayfinder Armor Trim Smithing Template")); + self::register("wild_armor_trim_smithing_template", new Item(new IID(Ids::WILD_ARMOR_TRIM_SMITHING_TEMPLATE), "Wild Armor Trim Smithing Template")); + } + } From e3700cab50555984d50356ffd9fdba41ed521766 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 9 Nov 2023 18:05:07 +0000 Subject: [PATCH 17/17] ZlibCompressor: use libdeflate for level 0 compression this is supported since libdeflate 1.15 and ext-libdeflate 0.2.0. Everyone should be using these versions by now anyway, and if they aren't, they should update. libdeflate's level 0 compression is over 20 times faster than zlib, so this is a nice performance improvement. --- src/PocketMine.php | 7 +++++++ src/network/mcpe/compression/ZlibCompressor.php | 15 +++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/PocketMine.php b/src/PocketMine.php index 4c2ff32a7..296c21a89 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -144,6 +144,13 @@ namespace pocketmine { $messages[] = "chunkutils2 ^$wantedVersionMin is required, while you have $chunkutils2_version."; } + if(($libdeflate_version = phpversion("libdeflate")) !== false){ + //make sure level 0 compression is available + if(version_compare($libdeflate_version, "0.2.0") < 0 || version_compare($libdeflate_version, "0.3.0") >= 0){ + $messages[] = "php-libdeflate ^0.2.0 is required, while you have $libdeflate_version."; + } + } + if(extension_loaded("pocketmine")){ $messages[] = "The native PocketMine extension is no longer supported."; } diff --git a/src/network/mcpe/compression/ZlibCompressor.php b/src/network/mcpe/compression/ZlibCompressor.php index 317a64451..066ba876a 100644 --- a/src/network/mcpe/compression/ZlibCompressor.php +++ b/src/network/mcpe/compression/ZlibCompressor.php @@ -67,17 +67,12 @@ final class ZlibCompressor implements Compressor{ return $result; } - private static function zlib_encode(string $data, int $level) : string{ - return Utils::assumeNotFalse(zlib_encode($data, ZLIB_ENCODING_RAW, $level), "ZLIB compression failed"); - } - public function compress(string $payload) : string{ $compressible = $this->minCompressionSize !== null && strlen($payload) >= $this->minCompressionSize; - if(function_exists('libdeflate_deflate_compress')){ - return $compressible ? - libdeflate_deflate_compress($payload, $this->level) : - self::zlib_encode($payload, 0); - } - return self::zlib_encode($payload, $compressible ? $this->level : 0); + $level = $compressible ? $this->level : 0; + + return function_exists('libdeflate_deflate_compress') ? + libdeflate_deflate_compress($payload, $level) : + Utils::assumeNotFalse(zlib_encode($payload, ZLIB_ENCODING_RAW, $level), "ZLIB compression failed"); } }