From 11612ed0e2a554ed94f654a625656e5f6b9a14b3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 11 Aug 2025 00:49:37 +0100 Subject: [PATCH] Fixed content log warning about recipe with missing ID --- src/network/mcpe/cache/CraftingDataCache.php | 16 ++++++++++++---- .../mcpe/handler/ItemStackRequestExecutor.php | 6 ++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/network/mcpe/cache/CraftingDataCache.php b/src/network/mcpe/cache/CraftingDataCache.php index 14523f74c..da0f37c44 100644 --- a/src/network/mcpe/cache/CraftingDataCache.php +++ b/src/network/mcpe/cache/CraftingDataCache.php @@ -56,6 +56,12 @@ final class CraftingDataCache{ */ private array $caches = []; + /** + * The client doesn't like recipes with ID 0 (as of 1.21.100) and complains about them in the content log + * This doesn't actually affect the function of the recipe, but it is annoying, so this offset fixes it + */ + public const RECIPE_ID_OFFSET = 1; + public function getCache(CraftingManager $manager) : CraftingDataPacket{ $id = spl_object_id($manager); if(!isset($this->caches[$id])){ @@ -82,6 +88,8 @@ final class CraftingDataCache{ $noUnlockingRequirement = new RecipeUnlockingRequirement(null); foreach($manager->getCraftingRecipeIndex() as $index => $recipe){ + //the client doesn't like recipes with an ID of 0, so we need to offset them + $recipeNetId = $index + self::RECIPE_ID_OFFSET; if($recipe instanceof ShapelessRecipe){ $typeTag = match($recipe->getType()){ ShapelessRecipeType::CRAFTING => CraftingRecipeBlockName::CRAFTING_TABLE, @@ -91,14 +99,14 @@ final class CraftingDataCache{ }; $recipesWithTypeIds[] = new ProtocolShapelessRecipe( CraftingDataPacket::ENTRY_SHAPELESS, - Binary::writeInt($index), + Binary::writeInt($recipeNetId), array_map($converter->coreRecipeIngredientToNet(...), $recipe->getIngredientList()), array_map($converter->coreItemStackToNet(...), $recipe->getResults()), $nullUUID, $typeTag, 50, $noUnlockingRequirement, - $index + $recipeNetId ); }elseif($recipe instanceof ShapedRecipe){ $inputs = []; @@ -110,7 +118,7 @@ final class CraftingDataCache{ } $recipesWithTypeIds[] = $r = new ProtocolShapedRecipe( CraftingDataPacket::ENTRY_SHAPED, - Binary::writeInt($index), + Binary::writeInt($recipeNetId), $inputs, array_map($converter->coreItemStackToNet(...), $recipe->getResults()), $nullUUID, @@ -118,7 +126,7 @@ final class CraftingDataCache{ 50, true, $noUnlockingRequirement, - $index, + $recipeNetId, ); }else{ //TODO: probably special recipe types diff --git a/src/network/mcpe/handler/ItemStackRequestExecutor.php b/src/network/mcpe/handler/ItemStackRequestExecutor.php index d71a1c6bf..4eddf3100 100644 --- a/src/network/mcpe/handler/ItemStackRequestExecutor.php +++ b/src/network/mcpe/handler/ItemStackRequestExecutor.php @@ -35,6 +35,7 @@ use pocketmine\inventory\transaction\TransactionBuilder; use pocketmine\inventory\transaction\TransactionBuilderInventory; use pocketmine\item\Durable; use pocketmine\item\Item; +use pocketmine\network\mcpe\cache\CraftingDataCache; use pocketmine\network\mcpe\InventoryManager; use pocketmine\network\mcpe\protocol\types\inventory\ContainerUIIds; use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName; @@ -238,9 +239,10 @@ class ItemStackRequestExecutor{ throw new ItemStackRequestProcessException("Cannot craft a recipe more than 256 times"); } $craftingManager = $this->player->getServer()->getCraftingManager(); - $recipe = $craftingManager->getCraftingRecipeFromIndex($recipeId); + $recipeIndex = $recipeId - CraftingDataCache::RECIPE_ID_OFFSET; + $recipe = $craftingManager->getCraftingRecipeFromIndex($recipeIndex); if($recipe === null){ - throw new ItemStackRequestProcessException("No such crafting recipe index: $recipeId"); + throw new ItemStackRequestProcessException("No such crafting recipe index: $recipeIndex"); } $this->specialTransaction = new CraftingTransaction($this->player, $craftingManager, [], $recipe, $repetitions);