From 8ce0022de65b632989365e968a5c932aab766203 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 4 Jul 2020 21:37:37 +0100 Subject: [PATCH] protocol: added UUInventorySlotOffset constants --- .../protocol/types/NetworkInventoryAction.php | 12 +- .../types/inventory/UIInventorySlotOffset.php | 105 ++++++++++++++++++ 2 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/types/inventory/UIInventorySlotOffset.php diff --git a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php index e29e2fd2a..b06235dd2 100644 --- a/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php +++ b/src/pocketmine/network/mcpe/protocol/types/NetworkInventoryAction.php @@ -30,7 +30,9 @@ use pocketmine\inventory\transaction\action\InventoryAction; use pocketmine\inventory\transaction\action\SlotChangeAction; use pocketmine\item\Item; use pocketmine\network\mcpe\NetworkBinaryStream; +use pocketmine\network\mcpe\protocol\types\inventory\UIInventorySlotOffset; use pocketmine\Player; +use function array_key_exists; class NetworkInventoryAction{ public const SOURCE_CONTAINER = 0; @@ -162,21 +164,21 @@ class NetworkInventoryAction{ switch($this->sourceType){ case self::SOURCE_CONTAINER: if($this->windowId === ContainerIds::UI and $this->inventorySlot > 0){ - if($this->inventorySlot === 50){ + if($this->inventorySlot === UIInventorySlotOffset::CREATED_ITEM_OUTPUT){ return null; //useless noise } - if($this->inventorySlot >= 28 and $this->inventorySlot <= 31){ + if(array_key_exists($this->inventorySlot, UIInventorySlotOffset::CRAFTING2X2_INPUT)){ $window = $player->getCraftingGrid(); if($window->getGridWidth() !== CraftingGrid::SIZE_SMALL){ throw new \UnexpectedValueException("Expected small crafting grid"); } - $slot = $this->inventorySlot - 28; - }elseif($this->inventorySlot >= 32 and $this->inventorySlot <= 40){ + $slot = UIInventorySlotOffset::CRAFTING2X2_INPUT[$this->inventorySlot]; + }elseif(array_key_exists($this->inventorySlot, UIInventorySlotOffset::CRAFTING3X3_INPUT)){ $window = $player->getCraftingGrid(); if($window->getGridWidth() !== CraftingGrid::SIZE_BIG){ throw new \UnexpectedValueException("Expected big crafting grid"); } - $slot = $this->inventorySlot - 32; + $slot = UIInventorySlotOffset::CRAFTING3X3_INPUT[$this->inventorySlot]; }else{ throw new \UnexpectedValueException("Unhandled magic UI slot offset $this->inventorySlot"); } diff --git a/src/pocketmine/network/mcpe/protocol/types/inventory/UIInventorySlotOffset.php b/src/pocketmine/network/mcpe/protocol/types/inventory/UIInventorySlotOffset.php new file mode 100644 index 000000000..12e2c60eb --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/inventory/UIInventorySlotOffset.php @@ -0,0 +1,105 @@ + 0, + 2 => 1, + ]; + public const STONE_CUTTER_INPUT = 3; + public const TRADE2_INGREDIENT = [ + 4 => 0, + 5 => 1, + ]; + public const TRADE_INGREDIENT = [ + 6 => 0, + 7 => 1, + ]; + public const MATERIAL_REDUCER_INPUT = 8; + public const LOOM = [ + 9 => 0, + 10 => 1, + 11 => 2, + ]; + public const CARTOGRAPHY_TABLE = [ + 12 => 0, + 13 => 1, + ]; + public const ENCHANTING_TABLE = [ + 14 => 0, + 15 => 1, + ]; + public const GRINDSTONE = [ + 16 => 0, + 17 => 1, + ]; + public const COMPOUND_CREATOR_INPUT = [ + 18 => 0, + 19 => 1, + 20 => 2, + 21 => 3, + 22 => 4, + 23 => 5, + 24 => 6, + 25 => 7, + 26 => 8, + ]; + public const BEACON_PAYMENT = 27; + public const CRAFTING2X2_INPUT = [ + 28 => 0, + 29 => 1, + 30 => 2, + 31 => 3, + ]; + public const CRAFTING3X3_INPUT = [ + 32 => 0, + 33 => 1, + 34 => 2, + 35 => 3, + 36 => 4, + 37 => 5, + 38 => 6, + 39 => 7, + 40 => 8, + ]; + public const MATERIAL_REDUCER_OUTPUT = [ + 41 => 0, + 42 => 1, + 43 => 2, + 44 => 3, + 45 => 4, + 46 => 5, + 47 => 6, + 48 => 7, + 49 => 8, + ]; + public const CREATED_ITEM_OUTPUT = 50; +}