mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
Player: Play ItemBreakSounds when items break due to usage
closes #4381
This commit is contained in:
parent
a5b85e095a
commit
bf8b5905e4
@ -75,6 +75,7 @@ use pocketmine\form\FormValidationException;
|
|||||||
use pocketmine\inventory\Inventory;
|
use pocketmine\inventory\Inventory;
|
||||||
use pocketmine\inventory\PlayerCursorInventory;
|
use pocketmine\inventory\PlayerCursorInventory;
|
||||||
use pocketmine\item\ConsumableItem;
|
use pocketmine\item\ConsumableItem;
|
||||||
|
use pocketmine\item\Durable;
|
||||||
use pocketmine\item\enchantment\EnchantmentInstance;
|
use pocketmine\item\enchantment\EnchantmentInstance;
|
||||||
use pocketmine\item\enchantment\MeleeWeaponEnchantment;
|
use pocketmine\item\enchantment\MeleeWeaponEnchantment;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -110,6 +111,7 @@ use pocketmine\world\Position;
|
|||||||
use pocketmine\world\sound\EntityAttackNoDamageSound;
|
use pocketmine\world\sound\EntityAttackNoDamageSound;
|
||||||
use pocketmine\world\sound\EntityAttackSound;
|
use pocketmine\world\sound\EntityAttackSound;
|
||||||
use pocketmine\world\sound\FireExtinguishSound;
|
use pocketmine\world\sound\FireExtinguishSound;
|
||||||
|
use pocketmine\world\sound\ItemBreakSound;
|
||||||
use pocketmine\world\sound\Sound;
|
use pocketmine\world\sound\Sound;
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
use Ramsey\Uuid\UuidInterface;
|
use Ramsey\Uuid\UuidInterface;
|
||||||
@ -1380,6 +1382,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
|
|
||||||
$this->resetItemCooldown($item);
|
$this->resetItemCooldown($item);
|
||||||
if($this->hasFiniteResources() and !$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
|
if($this->hasFiniteResources() and !$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
|
||||||
|
if($item instanceof Durable && $item->isBroken()){
|
||||||
|
$this->broadcastSound(new ItemBreakSound());
|
||||||
|
}
|
||||||
$this->inventory->setItemInHand($item);
|
$this->inventory->setItemInHand($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1441,6 +1446,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
if($result->equals(ItemUseResult::SUCCESS())){
|
if($result->equals(ItemUseResult::SUCCESS())){
|
||||||
$this->resetItemCooldown($item);
|
$this->resetItemCooldown($item);
|
||||||
if(!$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
|
if(!$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
|
||||||
|
if($item instanceof Durable && $item->isBroken()){
|
||||||
|
$this->broadcastSound(new ItemBreakSound());
|
||||||
|
}
|
||||||
$this->inventory->setItemInHand($item);
|
$this->inventory->setItemInHand($item);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1558,6 +1566,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
$oldItem = clone $item;
|
$oldItem = clone $item;
|
||||||
if($this->getWorld()->useBreakOn($pos, $item, $this, true)){
|
if($this->getWorld()->useBreakOn($pos, $item, $this, true)){
|
||||||
if($this->hasFiniteResources() and !$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
|
if($this->hasFiniteResources() and !$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
|
||||||
|
if($item instanceof Durable && $item->isBroken()){
|
||||||
|
$this->broadcastSound(new ItemBreakSound());
|
||||||
|
}
|
||||||
$this->inventory->setItemInHand($item);
|
$this->inventory->setItemInHand($item);
|
||||||
}
|
}
|
||||||
$this->hungerManager->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING);
|
$this->hungerManager->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING);
|
||||||
@ -1582,6 +1593,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
$oldItem = clone $item;
|
$oldItem = clone $item;
|
||||||
if($this->getWorld()->useItemOn($pos, $item, $face, $clickOffset, $this, true)){
|
if($this->getWorld()->useItemOn($pos, $item, $face, $clickOffset, $this, true)){
|
||||||
if($this->hasFiniteResources() and !$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
|
if($this->hasFiniteResources() and !$item->equalsExact($oldItem) and $oldItem->equalsExact($this->inventory->getItemInHand())){
|
||||||
|
if($item instanceof Durable && $item->isBroken()){
|
||||||
|
$this->broadcastSound(new ItemBreakSound());
|
||||||
|
}
|
||||||
$this->inventory->setItemInHand($item);
|
$this->inventory->setItemInHand($item);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1654,6 +1668,9 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
//reactive damage like thorns might cause us to be killed by attacking another mob, which
|
//reactive damage like thorns might cause us to be killed by attacking another mob, which
|
||||||
//would mean we'd already have dropped the inventory by the time we reached here
|
//would mean we'd already have dropped the inventory by the time we reached here
|
||||||
if($heldItem->onAttackEntity($entity) and $this->hasFiniteResources() and $oldItem->equalsExact($this->inventory->getItemInHand())){ //always fire the hook, even if we are survival
|
if($heldItem->onAttackEntity($entity) and $this->hasFiniteResources() and $oldItem->equalsExact($this->inventory->getItemInHand())){ //always fire the hook, even if we are survival
|
||||||
|
if($heldItem instanceof Durable && $heldItem->isBroken()){
|
||||||
|
$this->broadcastSound(new ItemBreakSound());
|
||||||
|
}
|
||||||
$this->inventory->setItemInHand($heldItem);
|
$this->inventory->setItemInHand($heldItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user