diff --git a/src/inventory/transaction/CraftingTransaction.php b/src/inventory/transaction/CraftingTransaction.php index db9428447..35f592f73 100644 --- a/src/inventory/transaction/CraftingTransaction.php +++ b/src/inventory/transaction/CraftingTransaction.php @@ -23,9 +23,11 @@ declare(strict_types=1); namespace pocketmine\inventory\transaction; +use pocketmine\crafting\CraftingManager; use pocketmine\crafting\CraftingRecipe; use pocketmine\event\inventory\CraftItemEvent; use pocketmine\item\Item; +use pocketmine\player\Player; use function array_pop; use function count; use function intdiv; @@ -55,6 +57,13 @@ class CraftingTransaction extends InventoryTransaction{ protected $inputs = []; /** @var Item[] */ protected $outputs = []; + /** @var CraftingManager */ + private $craftingManager; + + public function __construct(Player $source, CraftingManager $craftingManager, array $actions = []){ + parent::__construct($source, $actions); + $this->craftingManager = $craftingManager; + } /** * @param Item[] $txItems @@ -126,7 +135,7 @@ class CraftingTransaction extends InventoryTransaction{ $this->matchItems($this->outputs, $this->inputs); $failed = 0; - foreach($this->source->getServer()->getCraftingManager()->matchRecipeByOutputs($this->outputs) as $recipe){ + foreach($this->craftingManager->matchRecipeByOutputs($this->outputs) as $recipe){ try{ //compute number of times recipe was crafted $this->repetitions = $this->matchRecipeItems($this->outputs, $recipe->getResultsFor($this->source->getCraftingGrid()), false); diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index 30a599583..0906e08a9 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -236,7 +236,7 @@ class InGamePacketHandler extends PacketHandler{ //trying to execute it if($this->craftingTransaction === null){ - $this->craftingTransaction = new CraftingTransaction($this->player, $actions); + $this->craftingTransaction = new CraftingTransaction($this->player, $this->player->getServer()->getCraftingManager(), $actions); }else{ foreach($actions as $action){ $this->craftingTransaction->addAction($action);