Skip to content

Commit 9f35f47

Browse files
committed
[sync] Update embedded LibWindow from standalone
1 parent c6bace0 commit 9f35f47

12 files changed

Lines changed: 53 additions & 38 deletions

src/imperazim/window/Window.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace imperazim\window;
66

77
use Closure;
8+
use pocketmine\item\Item;
9+
use pocketmine\inventory\Inventory;
810
use pocketmine\player\Player;
911
use imperazim\window\transaction\WindowTransaction;
1012
use imperazim\window\type\WindowTypeIds;
@@ -95,7 +97,7 @@ protected function readonly(bool $readonly = true): static {
9597
return $this;
9698
}
9799

98-
protected function fill(int $slot, \pocketmine\item\Item $item): static {
100+
protected function fill(int $slot, Item $item): static {
99101
$this->window->fill($slot, $item);
100102
return $this;
101103
}
@@ -105,12 +107,12 @@ protected function fillSlots(array $items): static {
105107
return $this;
106108
}
107109

108-
protected function fillAll(\pocketmine\item\Item $item): static {
110+
protected function fillAll(Item $item): static {
109111
$this->window->fillAll($item);
110112
return $this;
111113
}
112114

113-
protected function fillBorder(\pocketmine\item\Item $item): static {
115+
protected function fillBorder(Item $item): static {
114116
$this->window->fillBorder($item);
115117
return $this;
116118
}
@@ -120,7 +122,7 @@ protected function clearAll(): static {
120122
return $this;
121123
}
122124

123-
protected function bindInventory(?\pocketmine\inventory\Inventory $external): static {
125+
protected function bindInventory(?Inventory $external): static {
124126
$this->window->bindInventory($external);
125127
return $this;
126128
}
@@ -143,7 +145,7 @@ public function getDynamicWindow(): DynamicWindow {
143145
return $this->window;
144146
}
145147

146-
public function getInventory(): \pocketmine\inventory\Inventory {
148+
public function getInventory(): Inventory {
147149
return $this->window->getInventory();
148150
}
149151

src/imperazim/window/WindowManager.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
use pocketmine\event\inventory\InventoryCloseEvent;
1414
use pocketmine\event\inventory\InventoryTransactionEvent;
1515
use pocketmine\inventory\transaction\action\SlotChangeAction;
16+
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
1617
use pocketmine\network\mcpe\protocol\NetworkStackLatencyPacket;
1718
use pocketmine\plugin\Plugin;
19+
use RuntimeException;
1820
use pocketmine\block\VanillaBlocks;
1921
use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes;
2022
use imperazim\window\inventory\WindowInventory;
@@ -63,14 +65,14 @@ public static function init(Plugin $plugin): void {
6365
* Get the type registry for registering/retrieving window types.
6466
*/
6567
public static function getTypeRegistry(): WindowTypeRegistry {
66-
return self::$typeRegistry ?? throw new \RuntimeException("WindowManager not initialized. Call WindowManager::init() first.");
68+
return self::$typeRegistry ?? throw new RuntimeException("WindowManager not initialized. Call WindowManager::init() first.");
6769
}
6870

6971
/**
7072
* Get the session manager for accessing player sessions.
7173
*/
7274
public static function getSessionManager(): SessionManager {
73-
return self::$sessionManager ?? throw new \RuntimeException("WindowManager not initialized. Call WindowManager::init() first.");
75+
return self::$sessionManager ?? throw new RuntimeException("WindowManager not initialized. Call WindowManager::init() first.");
7476
}
7577

7678
/**
@@ -102,7 +104,7 @@ public function onDataPacketDecode(DataPacketDecodeEvent $event): void {
102104
static $packets = null;
103105
$packets ??= [
104106
NetworkStackLatencyPacket::NETWORK_ID => true,
105-
\pocketmine\network\mcpe\protocol\ContainerClosePacket::NETWORK_ID => true,
107+
ContainerClosePacket::NETWORK_ID => true,
106108
];
107109
if (isset($packets[$event->getPacketId()])) {
108110
$event->uncancel();
@@ -129,8 +131,8 @@ public function onDataPacketReceive(DataPacketReceiveEvent $event): void {
129131
return;
130132
}
131133

132-
// Suppress ContainerClosePacket during open sequence (like InvMenu)
133-
if ($packet instanceof \pocketmine\network\mcpe\protocol\ContainerClosePacket) {
134+
// Suppress ContainerClosePacket during open sequence
135+
if ($packet instanceof ContainerClosePacket) {
134136
$player = $event->getOrigin()->getPlayer();
135137
if ($player === null) return;
136138

@@ -172,7 +174,7 @@ public function onInventoryClose(InventoryCloseEvent $event): void {
172174
return;
173175
}
174176

175-
// Single network round-trip wait for close animation (matches InvMenu pattern)
177+
// Single network round-trip wait for close animation
176178
$session->network->wait(
177179
WindowNetwork::DELAY_ANIMATION,
178180
static fn(bool $success): bool => false

src/imperazim/window/graphic/BlockActorGraphic.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use pocketmine\network\mcpe\protocol\types\CacheableNbt;
1818
use pocketmine\network\mcpe\convert\TypeConverter;
1919
use imperazim\window\graphic\translator\PacketTranslator;
20+
use imperazim\window\inventory\WindowInventory;
21+
use pocketmine\world\Position;
2022

2123
/**
2224
* Sends a fake block + tile entity (NBT) to the client.
@@ -63,8 +65,8 @@ public function send(Player $player): void {
6365
}
6466

6567
public function sendInventory(Player $player, Inventory $inventory, ?string $customName): bool {
66-
if ($inventory instanceof \imperazim\window\inventory\WindowInventory) {
67-
$inventory->setHolderPosition(new \pocketmine\world\Position(
68+
if ($inventory instanceof WindowInventory) {
69+
$inventory->setHolderPosition(new Position(
6870
(int) $this->position->x, (int) $this->position->y, (int) $this->position->z,
6971
$player->getWorld()
7072
));

src/imperazim/window/graphic/MinecartChestGraphic.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
1313
use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData;
1414
use imperazim\window\graphic\translator\PacketTranslator;
15+
use imperazim\window\inventory\WindowInventory;
16+
use pocketmine\world\Position;
1517

1618
/**
1719
* Entity-based graphic using a chest minecart.
@@ -54,8 +56,8 @@ public function send(Player $player): void {
5456
}
5557

5658
public function sendInventory(Player $player, Inventory $inventory, ?string $customName): bool {
57-
if ($inventory instanceof \imperazim\window\inventory\WindowInventory) {
58-
$inventory->setHolderPosition(new \pocketmine\world\Position(
59+
if ($inventory instanceof WindowInventory) {
60+
$inventory->setHolderPosition(new Position(
5961
(int) $this->position->x, (int) $this->position->y, (int) $this->position->z,
6062
$player->getWorld()
6163
));

src/imperazim/window/graphic/PairedChestGraphic.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use pocketmine\player\Player;
1919
use imperazim\window\graphic\translator\BlockTranslator;
2020
use imperazim\window\graphic\translator\PacketTranslator;
21+
use imperazim\window\inventory\WindowInventory;
22+
use pocketmine\world\Position;
2123

2224
/**
2325
* A chest graphic that includes pairing NBT for double chests.
@@ -67,8 +69,8 @@ public function send(Player $player): void {
6769
}
6870

6971
public function sendInventory(Player $player, Inventory $inventory, ?string $customName): bool {
70-
if ($inventory instanceof \imperazim\window\inventory\WindowInventory) {
71-
$inventory->setHolderPosition(new \pocketmine\world\Position(
72+
if ($inventory instanceof WindowInventory) {
73+
$inventory->setHolderPosition(new Position(
7274
(int) $this->position->x, (int) $this->position->y, (int) $this->position->z,
7375
$player->getWorld()
7476
));

src/imperazim/window/layout/Layout.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace imperazim\window\layout;
66

77
use pocketmine\item\Item;
8+
use imperazim\window\DynamicWindow;
89

910
/**
1011
* Pre-defined layout configurations for common inventory patterns.
@@ -20,7 +21,7 @@ final class Layout {
2021
*
2122
* @param Item[] $contentItems Items to place in the inner slots
2223
*/
23-
public static function bordered(\imperazim\window\DynamicWindow $window, Item $borderItem, array $contentItems = []): void {
24+
public static function bordered(DynamicWindow $window, Item $borderItem, array $contentItems = []): void {
2425
Pattern::border($window, $borderItem);
2526

2627
if (!empty($contentItems)) {
@@ -35,7 +36,7 @@ public static function bordered(\imperazim\window\DynamicWindow $window, Item $b
3536
*
3637
* @param array<int, Item[]> $rows Row index => array of items (up to 9 per row)
3738
*/
38-
public static function rows(\imperazim\window\DynamicWindow $window, array $rows): void {
39+
public static function rows(DynamicWindow $window, array $rows): void {
3940
foreach ($rows as $rowIndex => $items) {
4041
$start = $rowIndex * 9;
4142
foreach (array_values($items) as $col => $item) {
@@ -52,7 +53,7 @@ public static function rows(\imperazim\window\DynamicWindow $window, array $rows
5253
*
5354
* @param array<int, Item> $navItems Slot offset (0-8) => Item for the nav bar
5455
*/
55-
public static function navBar(\imperazim\window\DynamicWindow $window, array $navItems, ?Item $fillerItem = null): void {
56+
public static function navBar(DynamicWindow $window, array $navItems, ?Item $fillerItem = null): void {
5657
$size = $window->getInventory()->getSize();
5758
$lastRow = (intdiv($size - 1, 9)) * 9;
5859

@@ -75,7 +76,7 @@ public static function navBar(\imperazim\window\DynamicWindow $window, array $na
7576
*
7677
* @param Item[] $items Items to center (1-9)
7778
*/
78-
public static function centerRow(\imperazim\window\DynamicWindow $window, int $row, array $items): void {
79+
public static function centerRow(DynamicWindow $window, int $row, array $items): void {
7980
$count = count($items);
8081
if ($count === 0 || $count > 9) return;
8182

src/imperazim/window/layout/Pattern.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace imperazim\window\layout;
66

77
use pocketmine\item\Item;
8+
use imperazim\window\DynamicWindow;
89

910
/**
1011
* Visual patterns for filling inventory slots.
@@ -19,7 +20,7 @@ final class Pattern {
1920
/**
2021
* Fill border slots with an item.
2122
*/
22-
public static function border(\imperazim\window\DynamicWindow $window, Item $item): void {
23+
public static function border(DynamicWindow $window, Item $item): void {
2324
$size = $window->getInventory()->getSize();
2425
$group = SlotGroup::border($size);
2526
foreach ($group->slots as $slot) {
@@ -30,7 +31,7 @@ public static function border(\imperazim\window\DynamicWindow $window, Item $ite
3031
/**
3132
* Fill inner (non-border) slots with an item.
3233
*/
33-
public static function inner(\imperazim\window\DynamicWindow $window, Item $item): void {
34+
public static function inner(DynamicWindow $window, Item $item): void {
3435
$size = $window->getInventory()->getSize();
3536
$group = SlotGroup::inner($size);
3637
foreach ($group->slots as $slot) {
@@ -41,14 +42,14 @@ public static function inner(\imperazim\window\DynamicWindow $window, Item $item
4142
/**
4243
* Fill all slots with an item.
4344
*/
44-
public static function fill(\imperazim\window\DynamicWindow $window, Item $item): void {
45+
public static function fill(DynamicWindow $window, Item $item): void {
4546
$window->fillAll($item);
4647
}
4748

4849
/**
4950
* Checkerboard pattern with two alternating items.
5051
*/
51-
public static function checkerboard(\imperazim\window\DynamicWindow $window, Item $item1, Item $item2): void {
52+
public static function checkerboard(DynamicWindow $window, Item $item1, Item $item2): void {
5253
$size = $window->getInventory()->getSize();
5354
for ($i = 0; $i < $size; $i++) {
5455
$row = intdiv($i, 9);
@@ -60,7 +61,7 @@ public static function checkerboard(\imperazim\window\DynamicWindow $window, Ite
6061
/**
6162
* Fill a specific row with an item.
6263
*/
63-
public static function row(\imperazim\window\DynamicWindow $window, int $row, Item $item): void {
64+
public static function row(DynamicWindow $window, int $row, Item $item): void {
6465
$group = SlotGroup::row($row);
6566
foreach ($group->slots as $slot) {
6667
if ($slot < $window->getInventory()->getSize()) {
@@ -72,7 +73,7 @@ public static function row(\imperazim\window\DynamicWindow $window, int $row, It
7273
/**
7374
* Fill specific slots from a SlotGroup with an item.
7475
*/
75-
public static function group(\imperazim\window\DynamicWindow $window, SlotGroup $group, Item $item): void {
76+
public static function group(DynamicWindow $window, SlotGroup $group, Item $item): void {
7677
foreach ($group->slots as $slot) {
7778
if ($slot < $window->getInventory()->getSize()) {
7879
$window->fill($slot, $item);
@@ -85,7 +86,7 @@ public static function group(\imperazim\window\DynamicWindow $window, SlotGroup
8586
*
8687
* @param Item[] $items Items to distribute across group slots
8788
*/
88-
public static function groupItems(\imperazim\window\DynamicWindow $window, SlotGroup $group, array $items): void {
89+
public static function groupItems(DynamicWindow $window, SlotGroup $group, array $items): void {
8990
$items = array_values($items);
9091
foreach ($group->slots as $idx => $slot) {
9192
if (!isset($items[$idx])) break;

src/imperazim/window/session/SessionManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace imperazim\window\session;
66

7+
use RuntimeException;
78
use pocketmine\player\Player;
89
use pocketmine\event\Listener;
910
use pocketmine\event\EventPriority;
@@ -41,7 +42,7 @@ public function get(Player $player): ?WindowSession {
4142
*/
4243
public function getOrThrow(Player $player): WindowSession {
4344
return $this->sessions[$player->getId()]
44-
?? throw new \RuntimeException("No WindowSession for player {$player->getName()}");
45+
?? throw new RuntimeException("No WindowSession for player {$player->getName()}");
4546
}
4647

4748
/**

src/imperazim/window/session/network/NetworkHandlerRegistry.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ final class NetworkHandlerRegistry {
1818

1919
public function __construct() {
2020
// Default handler: client echoes timestamp * 1000000
21-
// Matches InvMenu's exact encoding for non-PS platforms
2221
$this->default = new class implements NetworkHandler {
2322
public function createEntry(int $type, Closure $then): LatencyEntry {
2423
$ts = mt_rand();

src/imperazim/window/session/network/WindowNetwork.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use pocketmine\network\mcpe\protocol\NetworkStackLatencyPacket;
1111
use pocketmine\inventory\Inventory;
1212
use pocketmine\network\mcpe\protocol\ContainerOpenPacket;
13+
use pocketmine\network\mcpe\protocol\types\BlockPosition;
14+
use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes;
15+
use imperazim\window\graphic\PositionedGraphic;
1316
use imperazim\window\session\WindowSession;
1417
use imperazim\window\session\WindowInfo;
1518
use imperazim\window\graphic\translator\PacketTranslator;
@@ -61,9 +64,6 @@ public function wait(int $type, Closure $then): void {
6164
* Queue an operation that waits at least $waitMs milliseconds.
6265
* The callback may return true to repeat (wait again).
6366
*
64-
* Time is measured from the initial call, not from each retry,
65-
* matching InvMenu's behavior.
66-
*
6767
* @param int $type DELAY_ANIMATION or DELAY_OPERATION
6868
* @param int $waitMs Minimum wait in milliseconds
6969
* @param Closure(bool): bool $then Callback
@@ -207,12 +207,12 @@ public function hookContainerOpen(WindowSession $windowSession, WindowInfo $info
207207

208208
if ($packets === null) {
209209
$graphic = $info->graphic;
210-
if ($graphic instanceof \imperazim\window\graphic\PositionedGraphic) {
210+
if ($graphic instanceof PositionedGraphic) {
211211
$pos = $graphic->getPosition();
212212
$packets = [ContainerOpenPacket::blockInv(
213213
$id,
214-
\pocketmine\network\mcpe\protocol\types\inventory\WindowTypes::CONTAINER,
215-
new \pocketmine\network\mcpe\protocol\types\BlockPosition((int) $pos->x, (int) $pos->y, (int) $pos->z),
214+
WindowTypes::CONTAINER,
215+
new BlockPosition((int) $pos->x, (int) $pos->y, (int) $pos->z),
216216
)];
217217
}
218218
}

0 commit comments

Comments
 (0)