mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
Blocks are ephemeral objects, InventoryWindow might exceed its lifetime
This commit is contained in:
parent
310ca684fa
commit
1245ee2575
@ -28,29 +28,32 @@ use pocketmine\block\utils\AnimatedContainer;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\player\InventoryWindow;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
class BlockInventoryWindow extends InventoryWindow{
|
||||
|
||||
public function __construct(
|
||||
Player $viewer,
|
||||
Inventory $inventory,
|
||||
protected Block $holder
|
||||
protected Position $holder
|
||||
){
|
||||
parent::__construct($viewer, $inventory);
|
||||
}
|
||||
|
||||
public function getHolder() : Block{ return $this->holder; }
|
||||
public function getHolder() : Position{ return $this->holder; }
|
||||
|
||||
public function onOpen() : void{
|
||||
parent::onOpen();
|
||||
if($this->holder instanceof AnimatedContainer){
|
||||
$this->holder->onContainerOpen();
|
||||
$block = $this->holder->getWorld()->getBlock($this->holder);
|
||||
if($block instanceof AnimatedContainer){
|
||||
$block->onContainerOpen();
|
||||
}
|
||||
}
|
||||
|
||||
public function onClose() : void{
|
||||
if($this->holder instanceof AnimatedContainer){
|
||||
$this->holder->onContainerClose();
|
||||
$block = $this->holder->getWorld()->getBlock($this->holder);
|
||||
if($block instanceof AnimatedContainer){
|
||||
$block->onContainerClose();
|
||||
}
|
||||
parent::onClose();
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ class InventoryManager implements InventoryListener{
|
||||
//TODO: we should be using some kind of tagging system to identify the types. Instanceof is flaky especially
|
||||
//if the class isn't final, not to mention being inflexible.
|
||||
if($window instanceof BlockInventoryWindow){
|
||||
$blockPosition = BlockPosition::fromVector3($window->getHolder()->getPosition());
|
||||
$blockPosition = BlockPosition::fromVector3($window->getHolder());
|
||||
$windowType = match(true){
|
||||
$window instanceof LoomInventoryWindow => WindowTypes::LOOM,
|
||||
$window instanceof FurnaceInventoryWindow => match($window->getFurnaceType()){
|
||||
|
Loading…
x
Reference in New Issue
Block a user