From 3c6146b5e095f3f8d7c77da3745a7c40b57863c2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 1 Jan 2022 15:05:32 +0000 Subject: [PATCH] ContainerTrait: avoid absurdly inefficient use of setItem() this substantially improves the performance of loading containers such as chests. --- src/block/tile/ContainerTrait.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/block/tile/ContainerTrait.php b/src/block/tile/ContainerTrait.php index ae8cc8ea7..f3dc42390 100644 --- a/src/block/tile/ContainerTrait.php +++ b/src/block/tile/ContainerTrait.php @@ -48,11 +48,14 @@ trait ContainerTrait{ $inventory = $this->getRealInventory(); $listeners = $inventory->getListeners()->toArray(); $inventory->getListeners()->remove(...$listeners); //prevent any events being fired by initialization - $inventory->clearAll(); + + $newContents = []; /** @var CompoundTag $itemNBT */ foreach($inventoryTag as $itemNBT){ - $inventory->setItem($itemNBT->getByte("Slot"), Item::nbtDeserialize($itemNBT)); + $newContents[$itemNBT->getByte("Slot")] = Item::nbtDeserialize($itemNBT); } + $inventory->setContents($newContents); + $inventory->getListeners()->add(...$listeners); }