InventoryManager: avoid useless work in trackItemStack()

this attempts to accommodate slots being set to themselves, which is a rare enough occurrence (only plugins will cause it) that it doesn't make sense to penalize every inventory update this way.
attempting to avoid changing the itemstackID in this way is detrimental to performance, and it doesn't actually matter if we set a new itemstackID anyway.
This commit is contained in:
Dylan K. Taylor
2023-03-20 23:08:17 +00:00
parent 035a0a4e9d
commit 1992d3b6db

View File

@ -603,11 +603,6 @@ class InventoryManager{
} }
private function trackItemStack(InventoryManagerEntry $entry, int $slotId, ItemStack $itemStack, ?int $itemStackRequestId) : ItemStackInfo{ private function trackItemStack(InventoryManagerEntry $entry, int $slotId, ItemStack $itemStack, ?int $itemStackRequestId) : ItemStackInfo{
$existing = $entry->itemStackInfos[$slotId] ?? null;
if($existing !== null && $existing->getItemStack()->equals($itemStack) && $existing->getRequestId() === $itemStackRequestId){
return $existing;
}
//TODO: ItemStack->isNull() would be nice to have here //TODO: ItemStack->isNull() would be nice to have here
$info = new ItemStackInfo($itemStackRequestId, $itemStack->getId() === 0 ? 0 : $this->newItemStackId(), $itemStack); $info = new ItemStackInfo($itemStackRequestId, $itemStack->getId() === 0 ? 0 : $this->newItemStackId(), $itemStack);
return $entry->itemStackInfos[$slotId] = $info; return $entry->itemStackInfos[$slotId] = $info;