mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-22 19:06:35 +00:00
Avoid repeated calls to getItemInHand() in drop item handler
This commit is contained in:
parent
097632902a
commit
ccd288d7fa
@ -398,18 +398,19 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
}
|
}
|
||||||
$inventory = $this->player->getInventory();
|
$inventory = $this->player->getInventory();
|
||||||
|
|
||||||
$heldItemStack = TypeConverter::getInstance()->coreItemStackToNet($inventory->getItemInHand());
|
$heldItem = $inventory->getItemInHand();
|
||||||
|
$heldItemStack = TypeConverter::getInstance()->coreItemStackToNet($heldItem);
|
||||||
//because the client doesn't tell us the expected itemstack ID, we have to deep-compare our known
|
//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 :(
|
//itemstack info with the one the client sent. This is costly, but we don't have any other option :(
|
||||||
if($heldItemStack->getCount() < $droppedItemStack->getCount() || !$heldItemStack->equalsWithoutCount($droppedItemStack)){
|
if($heldItemStack->getCount() < $droppedItemStack->getCount() || !$heldItemStack->equalsWithoutCount($droppedItemStack)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newHeldItem = $inventory->getItemInHand();
|
//this modifies $heldItem
|
||||||
$droppedItem = $newHeldItem->pop($droppedItemStack->getCount());
|
$droppedItem = $heldItem->pop($droppedItemStack->getCount());
|
||||||
|
|
||||||
$builder = new TransactionBuilder();
|
$builder = new TransactionBuilder();
|
||||||
$builder->getInventory($inventory)->setItem($inventory->getHeldItemIndex(), $newHeldItem);
|
$builder->getInventory($inventory)->setItem($inventory->getHeldItemIndex(), $heldItem);
|
||||||
$builder->addAction(new DropItemAction($droppedItem));
|
$builder->addAction(new DropItemAction($droppedItem));
|
||||||
|
|
||||||
$transaction = new InventoryTransaction($this->player, $builder->generateActions());
|
$transaction = new InventoryTransaction($this->player, $builder->generateActions());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user