Force-close the crafting window only when doing crafting transactions

otherwise the client will crash when using right-click on the recipe book
This commit is contained in:
Dylan K. Taylor 2017-10-03 11:33:09 +01:00
parent 9bbebaa071
commit ca401ec3f5
2 changed files with 17 additions and 15 deletions

View File

@ -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
}
}

View File

@ -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()){