Implemented sound when equipping armor (#6303)

This commit is contained in:
ipad54
2024-03-25 17:15:54 +03:00
committed by GitHub
parent 337e462c8f
commit f799cfaba6
10 changed files with 286 additions and 8 deletions

View File

@ -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();