mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Clean up EnderChestInventory implementation
now, EnderChestInventory is just a temporary window, much like anvil/enchanting windows. It provides a gateway to the player's PlayerEnderInventory. This removes one of the remaining obstacles to disallowing null World in Position constructor.
This commit is contained in:
@ -117,13 +117,7 @@ abstract class BaseInventory implements Inventory{
|
||||
$this->viewers[$id] = $viewer;
|
||||
}
|
||||
|
||||
foreach($this->listeners as $listener){
|
||||
$listener->onContentChange($this, $oldContents);
|
||||
}
|
||||
|
||||
foreach($this->getViewers() as $viewer){
|
||||
$viewer->getNetworkSession()->getInvManager()->syncContents($this);
|
||||
}
|
||||
$this->onContentChange($oldContents);
|
||||
}
|
||||
|
||||
public function setItem(int $index, Item $item) : void{
|
||||
@ -179,6 +173,20 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item[] $itemsBefore
|
||||
* @phpstan-param array<int, Item> $itemsBefore
|
||||
*/
|
||||
protected function onContentChange(array $itemsBefore) : void{
|
||||
foreach($this->listeners as $listener){
|
||||
$listener->onContentChange($this, $itemsBefore);
|
||||
}
|
||||
|
||||
foreach($this->getViewers() as $viewer){
|
||||
$viewer->getNetworkSession()->getInvManager()->syncContents($this);
|
||||
}
|
||||
}
|
||||
|
||||
public function slotExists(int $slot) : bool{
|
||||
return $slot >= 0 and $slot < $this->slots->getSize();
|
||||
}
|
||||
|
38
src/inventory/PlayerEnderInventory.php
Normal file
38
src/inventory/PlayerEnderInventory.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\inventory;
|
||||
|
||||
use pocketmine\entity\Human;
|
||||
|
||||
final class PlayerEnderInventory extends BaseInventory{
|
||||
|
||||
private Human $holder;
|
||||
|
||||
public function __construct(Human $holder, int $size = 27){
|
||||
$this->holder = $holder;
|
||||
parent::__construct($size);
|
||||
}
|
||||
|
||||
public function getHolder() : Human{ return $this->holder; }
|
||||
}
|
Reference in New Issue
Block a user