mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Inventory: reduce API duplication by using a Set for viewers
This commit is contained in:
@ -54,7 +54,7 @@ class BrewingStand extends Spawnable implements Container, Nameable{
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
parent::__construct($world, $pos);
|
||||
$this->inventory = new BrewingStandInventory($this->pos);
|
||||
$this->inventory->addListeners(CallbackInventoryListener::onAnyChange(function(Inventory $unused) : void{
|
||||
$this->inventory->getListeners()->add(CallbackInventoryListener::onAnyChange(function(Inventory $unused) : void{
|
||||
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1);
|
||||
}));
|
||||
}
|
||||
|
@ -48,14 +48,14 @@ trait ContainerTrait{
|
||||
$inventoryTag = $tag->getListTag(Container::TAG_ITEMS);
|
||||
|
||||
$inventory = $this->getRealInventory();
|
||||
$listeners = $inventory->getListeners();
|
||||
$inventory->removeListeners(...$listeners); //prevent any events being fired by initialization
|
||||
$listeners = $inventory->getListeners()->toArray();
|
||||
$inventory->getListeners()->remove(...$listeners); //prevent any events being fired by initialization
|
||||
$inventory->clearAll();
|
||||
/** @var CompoundTag $itemNBT */
|
||||
foreach($inventoryTag as $itemNBT){
|
||||
$inventory->setItem($itemNBT->getByte("Slot"), Item::nbtDeserialize($itemNBT));
|
||||
}
|
||||
$inventory->addListeners(...$listeners);
|
||||
$inventory->getListeners()->add(...$listeners);
|
||||
}
|
||||
|
||||
if($tag->hasTag(Container::TAG_LOCK, StringTag::class)){
|
||||
|
@ -58,7 +58,7 @@ class Furnace extends Spawnable implements Container, Nameable{
|
||||
public function __construct(World $world, Vector3 $pos){
|
||||
parent::__construct($world, $pos);
|
||||
$this->inventory = new FurnaceInventory($this->pos);
|
||||
$this->inventory->addListeners(CallbackInventoryListener::onAnyChange(
|
||||
$this->inventory->getListeners()->add(CallbackInventoryListener::onAnyChange(
|
||||
function(Inventory $unused) : void{
|
||||
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1);
|
||||
})
|
||||
|
Reference in New Issue
Block a user