Avoid unnecessary repeated calls

This commit is contained in:
Dylan K. Taylor 2024-11-24 23:43:51 +00:00
parent 1738355357
commit 7f58122ac6
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 5 additions and 3 deletions

View File

@ -106,9 +106,10 @@ final class SlotChangeActionBuilder extends BaseInventory{
*/ */
public function generateActions() : array{ public function generateActions() : array{
$result = []; $result = [];
$inventory = $this->inventoryWindow->getInventory();
foreach($this->changedSlots as $index => $newItem){ foreach($this->changedSlots as $index => $newItem){
if($newItem !== null){ if($newItem !== null){
$oldItem = $this->inventoryWindow->getInventory()->getItem($index); $oldItem = $inventory->getItem($index);
if(!$newItem->equalsExact($oldItem)){ if(!$newItem->equalsExact($oldItem)){
$result[] = new SlotChangeAction($this->inventoryWindow, $index, $oldItem, $newItem); $result[] = new SlotChangeAction($this->inventoryWindow, $index, $oldItem, $newItem);
} }

View File

@ -615,7 +615,8 @@ class InventoryManager implements InventoryListener{
} }
private function syncContents(InventoryWindow $window) : void{ private function syncContents(InventoryWindow $window) : void{
$entry = $this->getEntry($window->getInventory()); $inventory = $window->getInventory();
$entry = $this->getEntry($inventory);
if($entry === null){ if($entry === null){
//this can happen when an inventory changed during InventoryCloseEvent, or when a temporary inventory //this can happen when an inventory changed during InventoryCloseEvent, or when a temporary inventory
//is cleared before removal. //is cleared before removal.
@ -631,7 +632,7 @@ class InventoryManager implements InventoryListener{
$entry->pendingSyncs = []; $entry->pendingSyncs = [];
$contents = []; $contents = [];
$typeConverter = $this->session->getTypeConverter(); $typeConverter = $this->session->getTypeConverter();
foreach($window->getInventory()->getContents(true) as $slot => $item){ foreach($inventory->getContents(true) as $slot => $item){
$itemStack = $typeConverter->coreItemStackToNet($item); $itemStack = $typeConverter->coreItemStackToNet($item);
$info = $this->trackItemStack($entry, $slot, $itemStack, null); $info = $this->trackItemStack($entry, $slot, $itemStack, null);
$contents[] = new ItemStackWrapper($info->getStackId(), $itemStack); $contents[] = new ItemStackWrapper($info->getStackId(), $itemStack);