Redesign inventory listening API

given that inventory listeners are no longer allowed to fiddle with the outcome of changing contents, it's now possible to allow having multiple listeners receiving events.

It's likely that this will be used for network inventory sync in the near future.
This commit is contained in:
Dylan K. Taylor
2019-05-19 16:36:38 +01:00
parent dec6c9f49b
commit cd103cefcc
7 changed files with 145 additions and 33 deletions

View File

@ -618,8 +618,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$inventoryTag = $nbt->getListTag("Inventory");
if($inventoryTag !== null){
$armorListener = $this->armorInventory->getSlotChangeListener();
$this->armorInventory->setSlotChangeListener(null);
$armorListeners = $this->armorInventory->getChangeListeners();
$this->armorInventory->removeChangeListeners(...$armorListeners);
/** @var CompoundTag $item */
foreach($inventoryTag as $i => $item){
@ -633,7 +633,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
}
}
$this->armorInventory->setSlotChangeListener($armorListener);
$this->armorInventory->addChangeListeners(...$armorListeners);
}
$enderChestInventoryTag = $nbt->getListTag("EnderChestInventory");