Skip to content

Commit

Permalink
Avoid unnecessary repeated calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Nov 24, 2024
1 parent 1738355 commit 7f58122
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/inventory/transaction/SlotChangeActionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ public function getMatchingItemCount(int $slot, Item $test, bool $checkTags) : i
*/
public function generateActions() : array{
$result = [];
$inventory = $this->inventoryWindow->getInventory();
foreach($this->changedSlots as $index => $newItem){
if($newItem !== null){
$oldItem = $this->inventoryWindow->getInventory()->getItem($index);
$oldItem = $inventory->getItem($index);
if(!$newItem->equalsExact($oldItem)){
$result[] = new SlotChangeAction($this->inventoryWindow, $index, $oldItem, $newItem);
}
Expand Down
5 changes: 3 additions & 2 deletions src/network/mcpe/InventoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,8 @@ public function onContentChange(Inventory $inventory, array $oldContents) : void
}

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

0 comments on commit 7f58122

Please sign in to comment.