mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
Avoid unnecessary repeated calls
This commit is contained in:
parent
1738355357
commit
7f58122ac6
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user