mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-07 10:31:51 +00:00
Merge branch 'stable' into minor-next
This commit is contained in:
commit
8102586ee0
@ -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->backingInventoryChanging = true;
|
||||||
|
try{
|
||||||
$strongThis->onSlotChange($slot, $oldItem);
|
$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->backingInventoryChanging = true;
|
||||||
|
try{
|
||||||
$strongThis->onContentChange($oldContents);
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user