From fd77dd0066be0baa5cf602a833d0f45e2a4712b0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 13 Dec 2018 10:38:04 +0000 Subject: [PATCH 1/2] Revert "Fixed crafting grid transaction handling, close #2559" This reverts commit dfeb62491a74a402aa269e06c51de8f1a60238e9. --- .../protocol/types/NetworkInventoryAction.php | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php index a621caabc..9f52a8351 100644 --- a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php +++ b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php @@ -36,7 +36,6 @@ class NetworkInventoryAction{ public const SOURCE_WORLD = 2; //drop/pickup item entity public const SOURCE_CREATIVE = 3; - public const SOURCE_CRAFTING_GRID = 100; public const SOURCE_TODO = 99999; /** @@ -48,8 +47,8 @@ class NetworkInventoryAction{ * * Expect these to change in the future. */ - public const SOURCE_TYPE_CRAFTING_USELESS_MAGIC_NUMBER = -2; - + public const SOURCE_TYPE_CRAFTING_ADD_INGREDIENT = -2; + public const SOURCE_TYPE_CRAFTING_REMOVE_INGREDIENT = -3; public const SOURCE_TYPE_CRAFTING_RESULT = -4; public const SOURCE_TYPE_CRAFTING_USE_INGREDIENT = -5; @@ -108,12 +107,6 @@ class NetworkInventoryAction{ break; case self::SOURCE_CREATIVE: break; - case self::SOURCE_CRAFTING_GRID: - $dummy = $packet->getVarInt(); - if($dummy !== self::SOURCE_TYPE_CRAFTING_USELESS_MAGIC_NUMBER){ - throw new \UnexpectedValueException("Useless magic number for crafting-grid type was $dummy, expected " . self::SOURCE_TYPE_CRAFTING_USELESS_MAGIC_NUMBER); - } - break; case self::SOURCE_TODO: $this->windowId = $packet->getVarInt(); switch($this->windowId){ @@ -151,9 +144,6 @@ class NetworkInventoryAction{ break; case self::SOURCE_CREATIVE: break; - case self::SOURCE_CRAFTING_GRID: - $packet->putVarInt(self::SOURCE_TYPE_CRAFTING_USELESS_MAGIC_NUMBER); - break; case self::SOURCE_TODO: $packet->putVarInt($this->windowId); break; @@ -200,11 +190,13 @@ class NetworkInventoryAction{ } return new CreativeInventoryAction($this->oldItem, $this->newItem, $type); - case self::SOURCE_CRAFTING_GRID: - return new SlotChangeAction($player->getCraftingGrid(), $this->inventorySlot, $this->oldItem, $this->newItem); case self::SOURCE_TODO: //These types need special handling. switch($this->windowId){ + case self::SOURCE_TYPE_CRAFTING_ADD_INGREDIENT: + case self::SOURCE_TYPE_CRAFTING_REMOVE_INGREDIENT: + $window = $player->getCraftingGrid(); + return new SlotChangeAction($window, $this->inventorySlot, $this->oldItem, $this->newItem); case self::SOURCE_TYPE_CRAFTING_RESULT: case self::SOURCE_TYPE_CRAFTING_USE_INGREDIENT: return null; From dbeceb02f96b57fcfa69bc4cb7c736a8525dee04 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 13 Dec 2018 10:54:15 +0000 Subject: [PATCH 2/2] fixup 1.8 crafting, take 2 --- .../protocol/types/NetworkInventoryAction.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php index 9f52a8351..dd83a99ad 100644 --- a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php +++ b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php @@ -36,6 +36,7 @@ class NetworkInventoryAction{ public const SOURCE_WORLD = 2; //drop/pickup item entity public const SOURCE_CREATIVE = 3; + public const SOURCE_CRAFTING_GRID = 100; public const SOURCE_TODO = 99999; /** @@ -107,6 +108,7 @@ class NetworkInventoryAction{ break; case self::SOURCE_CREATIVE: break; + case self::SOURCE_CRAFTING_GRID: case self::SOURCE_TODO: $this->windowId = $packet->getVarInt(); switch($this->windowId){ @@ -144,6 +146,7 @@ class NetworkInventoryAction{ break; case self::SOURCE_CREATIVE: break; + case self::SOURCE_CRAFTING_GRID: case self::SOURCE_TODO: $packet->putVarInt($this->windowId); break; @@ -190,27 +193,17 @@ class NetworkInventoryAction{ } return new CreativeInventoryAction($this->oldItem, $this->newItem, $type); + case self::SOURCE_CRAFTING_GRID: case self::SOURCE_TODO: //These types need special handling. switch($this->windowId){ case self::SOURCE_TYPE_CRAFTING_ADD_INGREDIENT: case self::SOURCE_TYPE_CRAFTING_REMOVE_INGREDIENT: - $window = $player->getCraftingGrid(); - return new SlotChangeAction($window, $this->inventorySlot, $this->oldItem, $this->newItem); + case self::SOURCE_TYPE_CONTAINER_DROP_CONTENTS: //TODO: this type applies to all fake windows, not just crafting + return new SlotChangeAction($player->getCraftingGrid(), $this->inventorySlot, $this->oldItem, $this->newItem); case self::SOURCE_TYPE_CRAFTING_RESULT: case self::SOURCE_TYPE_CRAFTING_USE_INGREDIENT: return null; - - case self::SOURCE_TYPE_CONTAINER_DROP_CONTENTS: - //TODO: this type applies to all fake windows, not just crafting - $window = $player->getCraftingGrid(); - - //DROP_CONTENTS doesn't bother telling us what slot the item is in, so we find it ourselves - $inventorySlot = $window->first($this->oldItem, true); - if($inventorySlot === -1){ - throw new \InvalidStateException("Fake container " . get_class($window) . " for " . $player->getName() . " does not contain $this->oldItem"); - } - return new SlotChangeAction($window, $inventorySlot, $this->oldItem, $this->newItem); } //TODO: more stuff