diff --git a/src/entity/Human.php b/src/entity/Human.php index a8b6f9511..38e69724b 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -93,7 +93,6 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ private const TAG_XP_PROGRESS = "XpP"; //TAG_Float private const TAG_LIFETIME_XP_TOTAL = "XpTotal"; //TAG_Int private const TAG_XP_SEED = "XpSeed"; //TAG_Int - private const TAG_NAME_TAG = "NameTag"; //TAG_String private const TAG_SKIN = "Skin"; //TAG_Compound private const TAG_SKIN_NAME = "Name"; //TAG_String private const TAG_SKIN_DATA = "Data"; //TAG_ByteArray @@ -233,10 +232,6 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ * For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT. */ protected function initHumanData(CompoundTag $nbt) : void{ - if(($nameTagTag = $nbt->getTag(self::TAG_NAME_TAG)) instanceof StringTag){ - $this->setNameTag($nameTagTag->getValue()); - } - //TODO: use of NIL UUID for namespace is a hack; we should provide a proper UUID for the namespace $this->uuid = Uuid::uuid3(Uuid::NIL, ((string) $this->getId()) . $this->skin->getSkinData() . $this->getNameTag()); } diff --git a/src/inventory/DelegateInventory.php b/src/inventory/DelegateInventory.php index 391b9599c..ba9e5a983 100644 --- a/src/inventory/DelegateInventory.php +++ b/src/inventory/DelegateInventory.php @@ -30,6 +30,7 @@ use pocketmine\item\Item; */ class DelegateInventory extends BaseInventory{ private InventoryListener $inventoryListener; + private bool $backingInventoryChanging = false; public function __construct( private Inventory $backingInventory @@ -39,12 +40,22 @@ class DelegateInventory extends BaseInventory{ $this->backingInventory->getListeners()->add($this->inventoryListener = new CallbackInventoryListener( static function(Inventory $unused, int $slot, Item $oldItem) use ($weakThis) : void{ if(($strongThis = $weakThis->get()) !== null){ - $strongThis->onSlotChange($slot, $oldItem); + $strongThis->backingInventoryChanging = true; + try{ + $strongThis->onSlotChange($slot, $oldItem); + }finally{ + $strongThis->backingInventoryChanging = false; + } } }, static function(Inventory $unused, array $oldContents) use ($weakThis) : void{ if(($strongThis = $weakThis->get()) !== null){ - $strongThis->onContentChange($oldContents); + $strongThis->backingInventoryChanging = true; + try{ + $strongThis->onContentChange($oldContents); + }finally{ + $strongThis->backingInventoryChanging = false; + } } } )); @@ -73,4 +84,16 @@ class DelegateInventory extends BaseInventory{ protected function internalSetContents(array $items) : void{ $this->backingInventory->setContents($items); } + + protected function onSlotChange(int $index, Item $before) : void{ + if($this->backingInventoryChanging){ + parent::onSlotChange($index, $before); + } + } + + protected function onContentChange(array $itemsBefore) : void{ + if($this->backingInventoryChanging){ + parent::onContentChange($itemsBefore); + } + } } diff --git a/src/network/mcpe/handler/ItemStackRequestExecutor.php b/src/network/mcpe/handler/ItemStackRequestExecutor.php index 81d820c2b..124606112 100644 --- a/src/network/mcpe/handler/ItemStackRequestExecutor.php +++ b/src/network/mcpe/handler/ItemStackRequestExecutor.php @@ -284,12 +284,12 @@ class ItemStackRequestExecutor{ } $this->createdItemsTakenCount += $count; - $createdItem = clone $createdItem; - $createdItem->setCount($count); + $takenItem = clone $createdItem; + $takenItem->setCount($count); if(!$this->createdItemFromCreativeInventory && $this->createdItemsTakenCount >= $createdItem->getCount()){ $this->setNextCreatedItem(null); } - return $createdItem; + return $takenItem; } /**