mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 10:19:39 +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\inventory\Inventory;
|
||||||
use pocketmine\player\InventoryWindow;
|
use pocketmine\player\InventoryWindow;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
|
use pocketmine\world\Position;
|
||||||
|
|
||||||
class BlockInventoryWindow extends InventoryWindow{
|
class BlockInventoryWindow extends InventoryWindow{
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Player $viewer,
|
Player $viewer,
|
||||||
Inventory $inventory,
|
Inventory $inventory,
|
||||||
protected Block $holder
|
protected Position $holder
|
||||||
){
|
){
|
||||||
parent::__construct($viewer, $inventory);
|
parent::__construct($viewer, $inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHolder() : Block{ return $this->holder; }
|
public function getHolder() : Position{ return $this->holder; }
|
||||||
|
|
||||||
public function onOpen() : void{
|
public function onOpen() : void{
|
||||||
parent::onOpen();
|
parent::onOpen();
|
||||||
if($this->holder instanceof AnimatedContainer){
|
$block = $this->holder->getWorld()->getBlock($this->holder);
|
||||||
$this->holder->onContainerOpen();
|
if($block instanceof AnimatedContainer){
|
||||||
|
$block->onContainerOpen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onClose() : void{
|
public function onClose() : void{
|
||||||
if($this->holder instanceof AnimatedContainer){
|
$block = $this->holder->getWorld()->getBlock($this->holder);
|
||||||
$this->holder->onContainerClose();
|
if($block instanceof AnimatedContainer){
|
||||||
|
$block->onContainerClose();
|
||||||
}
|
}
|
||||||
parent::onClose();
|
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
|
//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 the class isn't final, not to mention being inflexible.
|
||||||
if($window instanceof BlockInventoryWindow){
|
if($window instanceof BlockInventoryWindow){
|
||||||
$blockPosition = BlockPosition::fromVector3($window->getHolder()->getPosition());
|
$blockPosition = BlockPosition::fromVector3($window->getHolder());
|
||||||
$windowType = match(true){
|
$windowType = match(true){
|
||||||
$window instanceof LoomInventoryWindow => WindowTypes::LOOM,
|
$window instanceof LoomInventoryWindow => WindowTypes::LOOM,
|
||||||
$window instanceof FurnaceInventoryWindow => match($window->getFurnaceType()){
|
$window instanceof FurnaceInventoryWindow => match($window->getFurnaceType()){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user