mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-03 18:42:37 +00:00
Armor: only make sound when the item was equipped by player action
this ensures the greatest amount of consistency with vanilla. in order to prevent the sounds being broadcasted on armor damage with the old method, we'd also have to sacrifice the sound when replacing one leather helmet with another, for example. this approach minimizes the gameplay impact at the possible expense of plugins. closes #6325
This commit is contained in:
parent
55cf24aa02
commit
37322e0d50
@ -149,24 +149,6 @@ 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(
|
||||
function(Inventory $inventory, int $slot, Item $oldItem) use ($playArmorSound) : void{
|
||||
$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();
|
||||
|
||||
|
@ -146,6 +146,10 @@ class Armor extends Durable{
|
||||
$new = $thisCopy->pop();
|
||||
$player->getArmorInventory()->setItem($this->getArmorSlot(), $new);
|
||||
$player->getInventory()->setItemInHand($existing);
|
||||
$sound = $new->getMaterial()->getEquipSound();
|
||||
if($sound !== null){
|
||||
$player->broadcastSound($sound);
|
||||
}
|
||||
if(!$thisCopy->isNull()){
|
||||
//if the stack size was bigger than 1 (usually won't happen, but might be caused by plugins)
|
||||
$returnedItems[] = $thisCopy;
|
||||
|
Loading…
x
Reference in New Issue
Block a user