Merge branch 'minor-next' into major-next

This commit is contained in:
Dylan K. Taylor 2023-04-12 21:04:08 +01:00
commit 499b29b53a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 28 additions and 10 deletions

View File

@ -93,7 +93,6 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
private const TAG_XP_PROGRESS = "XpP"; //TAG_Float private const TAG_XP_PROGRESS = "XpP"; //TAG_Float
private const TAG_LIFETIME_XP_TOTAL = "XpTotal"; //TAG_Int private const TAG_LIFETIME_XP_TOTAL = "XpTotal"; //TAG_Int
private const TAG_XP_SEED = "XpSeed"; //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 = "Skin"; //TAG_Compound
private const TAG_SKIN_NAME = "Name"; //TAG_String private const TAG_SKIN_NAME = "Name"; //TAG_String
private const TAG_SKIN_DATA = "Data"; //TAG_ByteArray 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. * For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT.
*/ */
protected function initHumanData(CompoundTag $nbt) : void{ 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 //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()); $this->uuid = Uuid::uuid3(Uuid::NIL, ((string) $this->getId()) . $this->skin->getSkinData() . $this->getNameTag());
} }

View File

@ -30,6 +30,7 @@ use pocketmine\item\Item;
*/ */
class DelegateInventory extends BaseInventory{ class DelegateInventory extends BaseInventory{
private InventoryListener $inventoryListener; private InventoryListener $inventoryListener;
private bool $backingInventoryChanging = false;
public function __construct( public function __construct(
private Inventory $backingInventory private Inventory $backingInventory
@ -39,12 +40,22 @@ class DelegateInventory extends BaseInventory{
$this->backingInventory->getListeners()->add($this->inventoryListener = new CallbackInventoryListener( $this->backingInventory->getListeners()->add($this->inventoryListener = new CallbackInventoryListener(
static function(Inventory $unused, int $slot, Item $oldItem) use ($weakThis) : void{ static function(Inventory $unused, int $slot, Item $oldItem) use ($weakThis) : void{
if(($strongThis = $weakThis->get()) !== null){ 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{ static function(Inventory $unused, array $oldContents) use ($weakThis) : void{
if(($strongThis = $weakThis->get()) !== null){ 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{ protected function internalSetContents(array $items) : void{
$this->backingInventory->setContents($items); $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);
}
}
} }

View File

@ -284,12 +284,12 @@ class ItemStackRequestExecutor{
} }
$this->createdItemsTakenCount += $count; $this->createdItemsTakenCount += $count;
$createdItem = clone $createdItem; $takenItem = clone $createdItem;
$createdItem->setCount($count); $takenItem->setCount($count);
if(!$this->createdItemFromCreativeInventory && $this->createdItemsTakenCount >= $createdItem->getCount()){ if(!$this->createdItemFromCreativeInventory && $this->createdItemsTakenCount >= $createdItem->getCount()){
$this->setNextCreatedItem(null); $this->setNextCreatedItem(null);
} }
return $createdItem; return $takenItem;
} }
/** /**