Do not cache ItemStacks for every item

this is very memory inefficient, and only provides a performance advantage in cold code anyway.
This commit is contained in:
Dylan K. Taylor
2023-03-20 23:18:43 +00:00
parent 1992d3b6db
commit 63310cf764
4 changed files with 14 additions and 21 deletions

View File

@ -394,14 +394,11 @@ class InGamePacketHandler extends PacketHandler{
//it's technically possible to see this more than once, but a normal client should never do that.
$inventory = $this->player->getInventory();
$heldItemStack = $this->inventoryManager->getItemStackInfo($inventory, $inventory->getHeldItemIndex())?->getItemStack();
if($heldItemStack === null){
throw new AssumptionFailedError("Missing itemstack info for held item");
}
$heldItemStack = TypeConverter::getInstance()->coreItemStackToNet($inventory->getItemInHand());
$droppedItemStack = $networkInventoryAction->newItem->getItemStack();
//because the client doesn't tell us the expected itemstack ID, we have to deep-compare our known
//itemstack info with the one the client sent. This is costly, but we don't have any other option :(
if(!$heldItemStack->equalsWithoutCount($droppedItemStack) || $heldItemStack->getCount() < $droppedItemStack->getCount()){
if($heldItemStack->getCount() < $droppedItemStack->getCount() || !$heldItemStack->equalsWithoutCount($droppedItemStack)){
return false;
}