Added keep on death methods for items (#5395)

This commit is contained in:
Javier León
2022-12-15 17:10:20 -03:00
committed by GitHub
parent 95d0a3bf41
commit c5d716dc9d
3 changed files with 29 additions and 4 deletions

View File

@ -131,6 +131,7 @@ use pocketmine\world\sound\Sound;
use pocketmine\world\World;
use Ramsey\Uuid\UuidInterface;
use function abs;
use function array_filter;
use function array_map;
use function assert;
use function count;
@ -2265,15 +2266,16 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->getWorld()->dropItem($this->location, $item);
}
$clearInventory = fn(Inventory $inventory) => $inventory->setContents(array_filter($inventory->getContents(), fn(Item $item) => $item->keepOnDeath()));
if($this->inventory !== null){
$this->inventory->setHeldItemIndex(0);
$this->inventory->clearAll();
$clearInventory($this->inventory);
}
if($this->armorInventory !== null){
$this->armorInventory->clearAll();
$clearInventory($this->armorInventory);
}
if($this->offHandInventory !== null){
$this->offHandInventory->clearAll();
$clearInventory($this->offHandInventory);
}
}