Clean up LevelSoundEvent handling

This commit is contained in:
Dylan K. Taylor
2019-03-26 19:53:40 +00:00
parent e1504c668e
commit 0aebb3f4fb
38 changed files with 693 additions and 85 deletions

View File

@ -45,6 +45,7 @@ use pocketmine\item\Totem;
use pocketmine\level\Level;
use pocketmine\level\sound\TotemUseSound;
use pocketmine\level\sound\XpCollectSound;
use pocketmine\level\sound\XpLevelUpSound;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\ByteArrayTag;
use pocketmine\nbt\tag\CompoundTag;
@ -53,7 +54,6 @@ use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
@ -354,7 +354,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($playSound){
$newLevel = $this->getXpLevel();
if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){
$this->playLevelUpSound($newLevel);
$this->level->addSound($this, new XpLevelUpSound($newLevel));
}
}
@ -446,7 +446,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($playSound){
$newLevel = $this->getXpLevel();
if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){
$this->playLevelUpSound($newLevel);
$this->level->addSound($this, new XpLevelUpSound($newLevel));
}elseif($this->getCurrentTotalXp() > $oldTotal){
$this->level->addSound($this, new XpCollectSound());
}
@ -458,11 +458,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
return false;
}
private function playLevelUpSound(int $newLevel) : void{
$volume = 0x10000000 * (min(30, $newLevel) / 5); //No idea why such odd numbers, but this works...
$this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_LEVELUP, (int) $volume);
}
/**
* Takes an amount of XP from the player, recalculating their XP level and progress.
*

View File

@ -40,13 +40,13 @@ use pocketmine\item\Consumable;
use pocketmine\item\Durable;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item;
use pocketmine\level\sound\ItemBreakSound;
use pocketmine\math\Vector3;
use pocketmine\math\VoxelRayTrace;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\MobEffectPacket;
use pocketmine\Player;
use pocketmine\timings\Timings;
@ -544,7 +544,7 @@ abstract class Living extends Entity implements Damageable{
private function damageItem(Durable $item, int $durabilityRemoved) : void{
$item->applyDamage($durabilityRemoved);
if($item->isBroken()){
$this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_BREAK);
$this->level->addSound($this, new ItemBreakSound());
}
}

View File

@ -30,10 +30,10 @@ use pocketmine\event\inventory\InventoryPickupArrowEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\level\sound\ArrowHitSound;
use pocketmine\math\RayTraceResult;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
use pocketmine\Player;
use function mt_rand;
@ -138,7 +138,7 @@ class Arrow extends Projectile{
protected function onHit(ProjectileHitEvent $event) : void{
$this->setCritical(false);
$this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_BOW_HIT);
$this->level->addSound($this, new ArrowHitSound());
}
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{

View File

@ -25,7 +25,7 @@ namespace pocketmine\entity\projectile;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\level\particle\PotionSplashParticle;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\level\sound\PotionSplashSound;
use function mt_rand;
class ExperienceBottle extends Throwable{
@ -39,7 +39,7 @@ class ExperienceBottle extends Throwable{
public function onHit(ProjectileHitEvent $event) : void{
$this->level->addParticle($this, new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR()));
$this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_GLASS);
$this->level->addSound($this, new PotionSplashSound());
$this->level->dropExperience($this, mt_rand(3, 11));
}

View File

@ -33,8 +33,8 @@ use pocketmine\event\entity\ProjectileHitEntityEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\item\Potion;
use pocketmine\level\particle\PotionSplashParticle;
use pocketmine\level\sound\PotionSplashSound;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\utils\Color;
use function round;
use function sqrt;
@ -82,7 +82,7 @@ class SplashPotion extends Throwable{
}
$this->level->addParticle($this, $particle);
$this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_GLASS);
$this->level->addSound($this, new PotionSplashSound());
if($hasEffects){
if(!$this->willLinger()){