mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
Implemented sound when equipping armor (#6303)
This commit is contained in:
@ -149,6 +149,22 @@ abstract class Living extends Entity{
|
||||
$this->getViewers(),
|
||||
fn(EntityEventBroadcaster $broadcaster, array $recipients) => $broadcaster->onMobArmorChange($recipients, $this)
|
||||
)));
|
||||
$playArmorSound = function(Item $newItem, Item $oldItem) : void{
|
||||
if(!$newItem->isNull() && $newItem instanceof Armor && !$newItem->equalsExact($oldItem)){
|
||||
$equipSound = $newItem->getMaterial()->getEquipSound();
|
||||
if($equipSound !== null){
|
||||
$this->broadcastSound($equipSound);
|
||||
}
|
||||
}
|
||||
};
|
||||
$this->armorInventory->getListeners()->add(new CallbackInventoryListener(
|
||||
fn(Inventory $inventory, int $slot, Item $oldItem) => $playArmorSound($inventory->getItem($slot), $oldItem),
|
||||
function(Inventory $inventory, array $oldContents) use ($playArmorSound) : void{
|
||||
foreach($oldContents as $slot => $oldItem){
|
||||
$playArmorSound($inventory->getItem($slot), $oldItem);
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
$health = $this->getMaxHealth();
|
||||
|
||||
|
Reference in New Issue
Block a user