mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-11 14:02:05 +00:00
Merge 'stable' into 'minor-next'
Automatic merge performed by: https://github.com/pmmp/RestrictedActions/actions/runs/16867858213
This commit is contained in:
commit
1f87c67e37
16
src/network/mcpe/cache/CraftingDataCache.php
vendored
16
src/network/mcpe/cache/CraftingDataCache.php
vendored
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user