Inventory: reduce API duplication by using a Set for viewers

This commit is contained in:
Dylan K. Taylor
2020-05-14 14:13:28 +01:00
parent 3dafee6aa6
commit 4437756987
8 changed files with 25 additions and 47 deletions

View File

@@ -221,8 +221,8 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
$inventoryTag = $nbt->getListTag("Inventory");
if($inventoryTag !== null){
$armorListeners = $this->armorInventory->getListeners();
$this->armorInventory->removeListeners(...$armorListeners);
$armorListeners = $this->armorInventory->getListeners()->toArray();
$this->armorInventory->getListeners()->clear();
/** @var CompoundTag $item */
foreach($inventoryTag as $i => $item){
@@ -236,7 +236,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
}
}
$this->armorInventory->addListeners(...$armorListeners);
$this->armorInventory->getListeners()->add(...$armorListeners);
}
$enderChestInventoryTag = $nbt->getListTag("EnderChestInventory");

View File

@@ -110,7 +110,7 @@ abstract class Living extends Entity{
$this->armorInventory = new ArmorInventory($this);
//TODO: load/save armor inventory contents
$this->armorInventory->addListeners(CallbackInventoryListener::onAnyChange(
$this->armorInventory->getListeners()->add(CallbackInventoryListener::onAnyChange(
function(Inventory $unused) : void{
foreach($this->getViewers() as $viewer){
$viewer->getNetworkSession()->onMobArmorChange($this);