From 6ccb8f737305059038d695c82db1bfba3047d514 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 20 Mar 2023 16:57:38 +0000 Subject: [PATCH] git --- src/network/mcpe/ComplexInventoryMapEntry.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/network/mcpe/ComplexInventoryMapEntry.php diff --git a/src/network/mcpe/ComplexInventoryMapEntry.php b/src/network/mcpe/ComplexInventoryMapEntry.php new file mode 100644 index 000000000..dfd3e999a --- /dev/null +++ b/src/network/mcpe/ComplexInventoryMapEntry.php @@ -0,0 +1,64 @@ + + */ + private array $reverseSlotMap = []; + + /** + * @param int[] $slotMap + * @phpstan-param array $slotMap + */ + public function __construct( + private Inventory $inventory, + private array $slotMap + ){ + foreach($slotMap as $slot => $index){ + $this->reverseSlotMap[$index] = $slot; + } + } + + public function getInventory() : Inventory{ return $this->inventory; } + + /** + * @return int[] + * @phpstan-return array + */ + public function getSlotMap() : array{ return $this->slotMap; } + + public function mapNetToCore(int $slot) : ?int{ + return $this->slotMap[$slot] ?? null; + } + + public function mapCoreToNet(int $slot) : ?int{ + return $this->reverseSlotMap[$slot] ?? null; + } +}