From ca401ec3f53c58f3ee24d21e2dd49004b9c4bdc2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 3 Oct 2017 11:33:09 +0100 Subject: [PATCH] Force-close the crafting window only when doing crafting transactions otherwise the client will crash when using right-click on the recipe book --- src/pocketmine/inventory/CraftingGrid.php | 16 +--------------- .../transaction/CraftingTransaction.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/inventory/CraftingGrid.php b/src/pocketmine/inventory/CraftingGrid.php index 90b2b2b466..425699fa80 100644 --- a/src/pocketmine/inventory/CraftingGrid.php +++ b/src/pocketmine/inventory/CraftingGrid.php @@ -50,20 +50,6 @@ class CraftingGrid extends BaseInventory{ } public function sendContents($target) : void{ - if(!is_array($target)){ - $target = [$target]; - } - - /* - * TODO: HACK! - * we can't resend the contents of this window, so we force the client to close it instead. - * So people don't whine about messy desync issues when someone cancels CraftItemEvent, or when a crafting - * transaction goes wrong. - */ - $pk = new ContainerClosePacket(); - $pk->windowId = ContainerIds::NONE; - foreach($target as $player){ - $player->dataPacket($pk); - } + //no way to do this } } \ No newline at end of file diff --git a/src/pocketmine/inventory/transaction/CraftingTransaction.php b/src/pocketmine/inventory/transaction/CraftingTransaction.php index 157cf97c6d..f98d38fb97 100644 --- a/src/pocketmine/inventory/transaction/CraftingTransaction.php +++ b/src/pocketmine/inventory/transaction/CraftingTransaction.php @@ -28,6 +28,8 @@ use pocketmine\inventory\BigCraftingGrid; use pocketmine\inventory\CraftingRecipe; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\network\mcpe\protocol\ContainerClosePacket; +use pocketmine\network\mcpe\protocol\types\ContainerIds; use pocketmine\Player; class CraftingTransaction extends InventoryTransaction{ @@ -142,6 +144,20 @@ class CraftingTransaction extends InventoryTransaction{ return !$ev->isCancelled(); } + protected function sendInventories() : void{ + parent::sendInventories(); + + /* + * TODO: HACK! + * we can't resend the contents of the crafting window, so we force the client to close it instead. + * So people don't whine about messy desync issues when someone cancels CraftItemEvent, or when a crafting + * transaction goes wrong. + */ + $pk = new ContainerClosePacket(); + $pk->windowId = ContainerIds::NONE; + $this->source->dataPacket($pk); + } + public function execute() : bool{ if(parent::execute()){ switch($this->primaryOutput->getId()){