Skip to content

Commit 1245ee2

Browse files
committed
Blocks are ephemeral objects, InventoryWindow might exceed its lifetime
1 parent 310ca68 commit 1245ee2

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/block/inventory/window/BlockInventoryWindow.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,32 @@
2828
use pocketmine\inventory\Inventory;
2929
use pocketmine\player\InventoryWindow;
3030
use pocketmine\player\Player;
31+
use pocketmine\world\Position;
3132

3233
class BlockInventoryWindow extends InventoryWindow{
3334

3435
public function __construct(
3536
Player $viewer,
3637
Inventory $inventory,
37-
protected Block $holder
38+
protected Position $holder
3839
){
3940
parent::__construct($viewer, $inventory);
4041
}
4142

42-
public function getHolder() : Block{ return $this->holder; }
43+
public function getHolder() : Position{ return $this->holder; }
4344

4445
public function onOpen() : void{
4546
parent::onOpen();
46-
if($this->holder instanceof AnimatedContainer){
47-
$this->holder->onContainerOpen();
47+
$block = $this->holder->getWorld()->getBlock($this->holder);
48+
if($block instanceof AnimatedContainer){
49+
$block->onContainerOpen();
4850
}
4951
}
5052

5153
public function onClose() : void{
52-
if($this->holder instanceof AnimatedContainer){
53-
$this->holder->onContainerClose();
54+
$block = $this->holder->getWorld()->getBlock($this->holder);
55+
if($block instanceof AnimatedContainer){
56+
$block->onContainerClose();
5457
}
5558
parent::onClose();
5659
}

src/network/mcpe/InventoryManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ protected static function createContainerOpen(int $id, InventoryWindow $window)
382382
//TODO: we should be using some kind of tagging system to identify the types. Instanceof is flaky especially
383383
//if the class isn't final, not to mention being inflexible.
384384
if($window instanceof BlockInventoryWindow){
385-
$blockPosition = BlockPosition::fromVector3($window->getHolder()->getPosition());
385+
$blockPosition = BlockPosition::fromVector3($window->getHolder());
386386
$windowType = match(true){
387387
$window instanceof LoomInventoryWindow => WindowTypes::LOOM,
388388
$window instanceof FurnaceInventoryWindow => match($window->getFurnaceType()){

0 commit comments

Comments
 (0)