diff --git a/src/network/mcpe/convert/TypeConverter.php b/src/network/mcpe/convert/TypeConverter.php index b421fc8c9..088f202fd 100644 --- a/src/network/mcpe/convert/TypeConverter.php +++ b/src/network/mcpe/convert/TypeConverter.php @@ -38,11 +38,13 @@ use pocketmine\network\mcpe\protocol\types\GameMode as ProtocolGameMode; use pocketmine\network\mcpe\protocol\types\inventory\ContainerIds; use pocketmine\network\mcpe\protocol\types\inventory\ItemStack; use pocketmine\network\mcpe\protocol\types\inventory\NetworkInventoryAction; +use pocketmine\network\mcpe\protocol\types\inventory\UIInventorySlotOffset; use pocketmine\network\mcpe\protocol\types\recipe\RecipeIngredient; use pocketmine\player\GameMode; use pocketmine\player\Player; use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\SingletonTrait; +use function array_key_exists; class TypeConverter{ use SingletonTrait; @@ -168,21 +170,21 @@ class TypeConverter{ switch($action->sourceType){ case NetworkInventoryAction::SOURCE_CONTAINER: if($action->windowId === ContainerIds::UI and $action->inventorySlot > 0){ - if($action->inventorySlot === 50){ + if($action->inventorySlot === UIInventorySlotOffset::CREATED_ITEM_OUTPUT){ return null; //useless noise } - if($action->inventorySlot >= 28 and $action->inventorySlot <= 31){ + if(array_key_exists($action->inventorySlot, UIInventorySlotOffset::CRAFTING2X2_INPUT)){ $window = $player->getCraftingGrid(); if($window->getGridWidth() !== CraftingGrid::SIZE_SMALL){ throw new \UnexpectedValueException("Expected small crafting grid"); } - $slot = $action->inventorySlot - 28; - }elseif($action->inventorySlot >= 32 and $action->inventorySlot <= 40){ + $slot = UIInventorySlotOffset::CRAFTING2X2_INPUT[$action->inventorySlot]; + }elseif(array_key_exists($action->inventorySlot, UIInventorySlotOffset::CRAFTING3X3_INPUT)){ $window = $player->getCraftingGrid(); if($window->getGridWidth() !== CraftingGrid::SIZE_BIG){ throw new \UnexpectedValueException("Expected big crafting grid"); } - $slot = $action->inventorySlot - 32; + $slot = UIInventorySlotOffset::CRAFTING3X3_INPUT[$action->inventorySlot]; }else{ throw new \UnexpectedValueException("Unhandled magic UI slot offset $action->inventorySlot"); } @@ -225,4 +227,4 @@ class TypeConverter{ throw new \UnexpectedValueException("Unknown inventory source type $action->sourceType"); } } -} \ No newline at end of file +} diff --git a/src/network/mcpe/protocol/types/inventory/UIInventorySlotOffset.php b/src/network/mcpe/protocol/types/inventory/UIInventorySlotOffset.php new file mode 100644 index 000000000..12e2c60eb --- /dev/null +++ b/src/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; +}