Skip to content

Commit 11612ed

Browse files
committed
Fixed content log warning about recipe with missing ID
1 parent 0b9e680 commit 11612ed

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/network/mcpe/cache/CraftingDataCache.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ final class CraftingDataCache{
5656
*/
5757
private array $caches = [];
5858

59+
/**
60+
* The client doesn't like recipes with ID 0 (as of 1.21.100) and complains about them in the content log
61+
* This doesn't actually affect the function of the recipe, but it is annoying, so this offset fixes it
62+
*/
63+
public const RECIPE_ID_OFFSET = 1;
64+
5965
public function getCache(CraftingManager $manager) : CraftingDataPacket{
6066
$id = spl_object_id($manager);
6167
if(!isset($this->caches[$id])){
@@ -82,6 +88,8 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData
8288

8389
$noUnlockingRequirement = new RecipeUnlockingRequirement(null);
8490
foreach($manager->getCraftingRecipeIndex() as $index => $recipe){
91+
//the client doesn't like recipes with an ID of 0, so we need to offset them
92+
$recipeNetId = $index + self::RECIPE_ID_OFFSET;
8593
if($recipe instanceof ShapelessRecipe){
8694
$typeTag = match($recipe->getType()){
8795
ShapelessRecipeType::CRAFTING => CraftingRecipeBlockName::CRAFTING_TABLE,
@@ -91,14 +99,14 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData
9199
};
92100
$recipesWithTypeIds[] = new ProtocolShapelessRecipe(
93101
CraftingDataPacket::ENTRY_SHAPELESS,
94-
Binary::writeInt($index),
102+
Binary::writeInt($recipeNetId),
95103
array_map($converter->coreRecipeIngredientToNet(...), $recipe->getIngredientList()),
96104
array_map($converter->coreItemStackToNet(...), $recipe->getResults()),
97105
$nullUUID,
98106
$typeTag,
99107
50,
100108
$noUnlockingRequirement,
101-
$index
109+
$recipeNetId
102110
);
103111
}elseif($recipe instanceof ShapedRecipe){
104112
$inputs = [];
@@ -110,15 +118,15 @@ private function buildCraftingDataCache(CraftingManager $manager) : CraftingData
110118
}
111119
$recipesWithTypeIds[] = $r = new ProtocolShapedRecipe(
112120
CraftingDataPacket::ENTRY_SHAPED,
113-
Binary::writeInt($index),
121+
Binary::writeInt($recipeNetId),
114122
$inputs,
115123
array_map($converter->coreItemStackToNet(...), $recipe->getResults()),
116124
$nullUUID,
117125
CraftingRecipeBlockName::CRAFTING_TABLE,
118126
50,
119127
true,
120128
$noUnlockingRequirement,
121-
$index,
129+
$recipeNetId,
122130
);
123131
}else{
124132
//TODO: probably special recipe types

src/network/mcpe/handler/ItemStackRequestExecutor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use pocketmine\inventory\transaction\TransactionBuilderInventory;
3636
use pocketmine\item\Durable;
3737
use pocketmine\item\Item;
38+
use pocketmine\network\mcpe\cache\CraftingDataCache;
3839
use pocketmine\network\mcpe\InventoryManager;
3940
use pocketmine\network\mcpe\protocol\types\inventory\ContainerUIIds;
4041
use pocketmine\network\mcpe\protocol\types\inventory\FullContainerName;
@@ -238,9 +239,10 @@ protected function beginCrafting(int $recipeId, int $repetitions) : void{
238239
throw new ItemStackRequestProcessException("Cannot craft a recipe more than 256 times");
239240
}
240241
$craftingManager = $this->player->getServer()->getCraftingManager();
241-
$recipe = $craftingManager->getCraftingRecipeFromIndex($recipeId);
242+
$recipeIndex = $recipeId - CraftingDataCache::RECIPE_ID_OFFSET;
243+
$recipe = $craftingManager->getCraftingRecipeFromIndex($recipeIndex);
242244
if($recipe === null){
243-
throw new ItemStackRequestProcessException("No such crafting recipe index: $recipeId");
245+
throw new ItemStackRequestProcessException("No such crafting recipe index: $recipeIndex");
244246
}
245247

246248
$this->specialTransaction = new CraftingTransaction($this->player, $craftingManager, [], $recipe, $repetitions);

0 commit comments

Comments
 (0)