diff --git a/src/pocketmine/block/Button.php b/src/pocketmine/block/Button.php index a2d8cc3c6..da13e9aee 100644 --- a/src/pocketmine/block/Button.php +++ b/src/pocketmine/block/Button.php @@ -25,9 +25,10 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; +use pocketmine\level\sound\RedstonePowerOffSound; +use pocketmine\level\sound\RedstonePowerOnSound; use pocketmine\math\Facing; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\Player; abstract class Button extends Flowable{ @@ -64,7 +65,7 @@ abstract class Button extends Flowable{ $this->powered = true; $this->level->setBlock($this, $this); $this->level->scheduleDelayedBlockUpdate($this, $this->getActivationTime()); - $this->level->broadcastLevelSoundEvent($this->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_POWER_ON); + $this->level->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); } return true; @@ -74,7 +75,7 @@ abstract class Button extends Flowable{ if($this->powered){ $this->powered = false; $this->level->setBlock($this, $this); - $this->level->broadcastLevelSoundEvent($this->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_POWER_OFF); + $this->level->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOffSound()); } } } diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 4ac9013d3..388d441d8 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -27,8 +27,10 @@ use pocketmine\entity\Entity; use pocketmine\event\entity\EntityCombustByBlockEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; +use pocketmine\level\sound\BucketEmptyLavaSound; +use pocketmine\level\sound\BucketFillLavaSound; +use pocketmine\level\sound\Sound; use pocketmine\math\Facing; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; class Lava extends Liquid{ @@ -36,12 +38,12 @@ class Lava extends Liquid{ return 15; } - public function getBucketFillSound() : int{ - return LevelSoundEventPacket::SOUND_BUCKET_FILL_LAVA; + public function getBucketFillSound() : Sound{ + return new BucketFillLavaSound(); } - public function getBucketEmptySound() : int{ - return LevelSoundEventPacket::SOUND_BUCKET_EMPTY_LAVA; + public function getBucketEmptySound() : Sound{ + return new BucketEmptyLavaSound(); } public function tickRate() : int{ diff --git a/src/pocketmine/block/Lever.php b/src/pocketmine/block/Lever.php index 3b3b01af3..98d63e299 100644 --- a/src/pocketmine/block/Lever.php +++ b/src/pocketmine/block/Lever.php @@ -25,9 +25,10 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; +use pocketmine\level\sound\RedstonePowerOffSound; +use pocketmine\level\sound\RedstonePowerOnSound; use pocketmine\math\Facing; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\Player; class Lever extends Flowable{ @@ -112,9 +113,9 @@ class Lever extends Flowable{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->powered = !$this->powered; $this->level->setBlock($this, $this); - $this->level->broadcastLevelSoundEvent( + $this->level->addSound( $this->add(0.5, 0.5, 0.5), - $this->powered ? LevelSoundEventPacket::SOUND_POWER_ON : LevelSoundEventPacket::SOUND_POWER_OFF + $this->powered ? new RedstonePowerOnSound() : new RedstonePowerOffSound() ); return true; } diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index e0319ee07..c983267bf 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -30,6 +30,7 @@ use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\level\sound\FizzSound; +use pocketmine\level\sound\Sound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use function array_fill; @@ -125,9 +126,9 @@ abstract class Liquid extends Transparent{ return $b; } - abstract public function getBucketFillSound() : int; + abstract public function getBucketFillSound() : Sound; - abstract public function getBucketEmptySound() : int; + abstract public function getBucketEmptySound() : Sound; public function isSource() : bool{ return !$this->falling and $this->decay === 0; diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index c490df011..5423847bc 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -24,7 +24,9 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\entity\Entity; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; +use pocketmine\level\sound\BucketEmptyWaterSound; +use pocketmine\level\sound\BucketFillWaterSound; +use pocketmine\level\sound\Sound; class Water extends Liquid{ @@ -32,12 +34,12 @@ class Water extends Liquid{ return 2; } - public function getBucketFillSound() : int{ - return LevelSoundEventPacket::SOUND_BUCKET_FILL_WATER; + public function getBucketFillSound() : Sound{ + return new BucketFillWaterSound(); } - public function getBucketEmptySound() : int{ - return LevelSoundEventPacket::SOUND_BUCKET_EMPTY_WATER; + public function getBucketEmptySound() : Sound{ + return new BucketEmptyWaterSound(); } public function tickRate() : int{ diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 816f8cb7d..c116fb2ba 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -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. * diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 23350e3a4..fccfd75bd 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -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()); } } diff --git a/src/pocketmine/entity/projectile/Arrow.php b/src/pocketmine/entity/projectile/Arrow.php index de4b85792..6f79c3ed8 100644 --- a/src/pocketmine/entity/projectile/Arrow.php +++ b/src/pocketmine/entity/projectile/Arrow.php @@ -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{ diff --git a/src/pocketmine/entity/projectile/ExperienceBottle.php b/src/pocketmine/entity/projectile/ExperienceBottle.php index ff7095f5d..2a32aa647 100644 --- a/src/pocketmine/entity/projectile/ExperienceBottle.php +++ b/src/pocketmine/entity/projectile/ExperienceBottle.php @@ -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)); } diff --git a/src/pocketmine/entity/projectile/SplashPotion.php b/src/pocketmine/entity/projectile/SplashPotion.php index 9a2a8b07e..0fb687d6a 100644 --- a/src/pocketmine/entity/projectile/SplashPotion.php +++ b/src/pocketmine/entity/projectile/SplashPotion.php @@ -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()){ diff --git a/src/pocketmine/inventory/ChestInventory.php b/src/pocketmine/inventory/ChestInventory.php index dc4fa69f4..0b5f269b7 100644 --- a/src/pocketmine/inventory/ChestInventory.php +++ b/src/pocketmine/inventory/ChestInventory.php @@ -23,8 +23,10 @@ declare(strict_types=1); namespace pocketmine\inventory; +use pocketmine\level\sound\ChestCloseSound; +use pocketmine\level\sound\ChestOpenSound; +use pocketmine\level\sound\Sound; use pocketmine\network\mcpe\protocol\BlockEventPacket; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\Player; use pocketmine\tile\Chest; @@ -54,12 +56,12 @@ class ChestInventory extends ContainerInventory{ return $this->holder; } - protected function getOpenSound() : int{ - return LevelSoundEventPacket::SOUND_CHEST_OPEN; + protected function getOpenSound() : Sound{ + return new ChestOpenSound(); } - protected function getCloseSound() : int{ - return LevelSoundEventPacket::SOUND_CHEST_CLOSED; + protected function getCloseSound() : Sound{ + return new ChestCloseSound(); } protected function onOpen(Player $who) : void{ @@ -68,7 +70,7 @@ class ChestInventory extends ContainerInventory{ if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){ //TODO: this crap really shouldn't be managed by the inventory $this->broadcastBlockEventPacket(true); - $this->getHolder()->getLevel()->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound()); + $this->getHolder()->getLevel()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound()); } } @@ -76,7 +78,7 @@ class ChestInventory extends ContainerInventory{ if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){ //TODO: this crap really shouldn't be managed by the inventory $this->broadcastBlockEventPacket(false); - $this->getHolder()->getLevel()->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound()); + $this->getHolder()->getLevel()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound()); } parent::onClose($who); } diff --git a/src/pocketmine/inventory/EnderChestInventory.php b/src/pocketmine/inventory/EnderChestInventory.php index a0fdfe24c..7523b8702 100644 --- a/src/pocketmine/inventory/EnderChestInventory.php +++ b/src/pocketmine/inventory/EnderChestInventory.php @@ -24,7 +24,9 @@ declare(strict_types=1); namespace pocketmine\inventory; use pocketmine\level\Position; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; +use pocketmine\level\sound\EnderChestCloseSound; +use pocketmine\level\sound\EnderChestOpenSound; +use pocketmine\level\sound\Sound; use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\tile\EnderChest; @@ -51,12 +53,12 @@ class EnderChestInventory extends ChestInventory{ $this->holder->setLevel($enderChest->getLevel()); } - protected function getOpenSound() : int{ - return LevelSoundEventPacket::SOUND_ENDERCHEST_OPEN; + protected function getOpenSound() : Sound{ + return new EnderChestOpenSound(); } - protected function getCloseSound() : int{ - return LevelSoundEventPacket::SOUND_ENDERCHEST_CLOSED; + protected function getCloseSound() : Sound{ + return new EnderChestCloseSound(); } /** diff --git a/src/pocketmine/item/Bow.php b/src/pocketmine/item/Bow.php index 4718e0408..d3e9a9ba5 100644 --- a/src/pocketmine/item/Bow.php +++ b/src/pocketmine/item/Bow.php @@ -29,7 +29,7 @@ use pocketmine\entity\projectile\Projectile; use pocketmine\event\entity\EntityShootBowEvent; use pocketmine\event\entity\ProjectileLaunchEvent; use pocketmine\item\enchantment\Enchantment; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; +use pocketmine\level\sound\BowShootSound; use pocketmine\Player; use function intdiv; use function min; @@ -106,7 +106,7 @@ class Bow extends Tool{ } $ev->getProjectile()->spawnToAll(); - $player->getLevel()->broadcastLevelSoundEvent($player, LevelSoundEventPacket::SOUND_BOW); + $player->getLevel()->addSound($player, new BowShootSound()); }else{ $entity->spawnToAll(); } diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index f23ce0dd1..b1f0ff6cd 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -48,7 +48,7 @@ class Bucket extends Item{ $ev->call(); if(!$ev->isCancelled()){ $player->getLevel()->setBlock($blockClicked, BlockFactory::get(BlockLegacyIds::AIR)); - $player->getLevel()->broadcastLevelSoundEvent($blockClicked->add(0.5, 0.5, 0.5), $blockClicked->getBucketFillSound()); + $player->getLevel()->addSound($blockClicked->add(0.5, 0.5, 0.5), $blockClicked->getBucketFillSound()); if($player->isSurvival()){ if($stack->getCount() === 0){ $player->getInventory()->setItemInHand($ev->getItem()); diff --git a/src/pocketmine/item/FlintSteel.php b/src/pocketmine/item/FlintSteel.php index ba1752d12..241d4f5af 100644 --- a/src/pocketmine/item/FlintSteel.php +++ b/src/pocketmine/item/FlintSteel.php @@ -26,8 +26,8 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; +use pocketmine\level\sound\FlintSteelSound; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\Player; use function assert; @@ -41,7 +41,7 @@ class FlintSteel extends Tool{ $level = $player->getLevel(); assert($level !== null); $level->setBlock($blockReplace, BlockFactory::get(BlockLegacyIds::FIRE)); - $level->broadcastLevelSoundEvent($blockReplace->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_IGNITE); + $level->addSound($blockReplace->add(0.5, 0.5, 0.5), new FlintSteelSound()); $this->applyDamage(1); diff --git a/src/pocketmine/item/LiquidBucket.php b/src/pocketmine/item/LiquidBucket.php index f8d9eb5e5..3c4c8e4e7 100644 --- a/src/pocketmine/item/LiquidBucket.php +++ b/src/pocketmine/item/LiquidBucket.php @@ -64,7 +64,7 @@ class LiquidBucket extends Item{ $ev->call(); if(!$ev->isCancelled()){ $player->getLevel()->setBlock($blockReplace, $resultBlock->getFlowingForm()); - $player->getLevel()->broadcastLevelSoundEvent($blockClicked->add(0.5, 0.5, 0.5), $resultBlock->getBucketEmptySound()); + $player->getLevel()->addSound($blockClicked->add(0.5, 0.5, 0.5), $resultBlock->getBucketEmptySound()); if($player->isSurvival()){ $player->getInventory()->setItemInHand($ev->getItem()); diff --git a/src/pocketmine/item/ProjectileItem.php b/src/pocketmine/item/ProjectileItem.php index 4208434d7..f633057fe 100644 --- a/src/pocketmine/item/ProjectileItem.php +++ b/src/pocketmine/item/ProjectileItem.php @@ -24,12 +24,11 @@ declare(strict_types=1); namespace pocketmine\item; use pocketmine\entity\EntityFactory; -use pocketmine\entity\EntityIds; use pocketmine\entity\projectile\Throwable; use pocketmine\event\entity\ProjectileLaunchEvent; +use pocketmine\level\sound\ThrowSound; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\Player; use pocketmine\utils\Utils; @@ -73,7 +72,7 @@ abstract class ProjectileItem extends Item{ $projectile->spawnToAll(); - $player->getLevel()->broadcastLevelSoundEvent($player, LevelSoundEventPacket::SOUND_THROW, 0, EntityIds::PLAYER); + $player->getLevel()->addSound($player, new ThrowSound()); $this->pop(); diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index eab86a011..14272a7a7 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -35,12 +35,12 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityExplodeEvent; use pocketmine\item\ItemFactory; use pocketmine\level\particle\HugeExplodeSeedParticle; +use pocketmine\level\sound\ExplodeSound; use pocketmine\level\utils\SubChunkIteratorManager; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\ExplodePacket; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use function ceil; use function floor; use function mt_rand; @@ -247,7 +247,7 @@ class Explosion{ $this->level->broadcastPacketToViewers($source, $pk); $this->level->addParticle($source, new HugeExplodeSeedParticle()); - $this->level->broadcastLevelSoundEvent($source, LevelSoundEventPacket::SOUND_EXPLODE); + $this->level->addSound($source, new ExplodeSound()); return true; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 09cff9285..5f6a88668 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -63,6 +63,7 @@ use pocketmine\level\light\LightPopulationTask; use pocketmine\level\light\SkyLightUpdate; use pocketmine\level\particle\DestroyBlockParticle; use pocketmine\level\particle\Particle; +use pocketmine\level\sound\BlockPlaceSound; use pocketmine\level\sound\Sound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; @@ -73,11 +74,9 @@ use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\mcpe\ChunkRequestTask; use pocketmine\network\mcpe\CompressBatchPromise; -use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\SetDifficultyPacket; use pocketmine\network\mcpe\protocol\SetTimePacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; @@ -515,30 +514,6 @@ class Level implements ChunkManager, Metadatable{ } } - /** - * Broadcasts a LevelSoundEvent to players in the area. - * - * @param Vector3 $pos - * @param int $soundId - * @param int $extraData - * @param int $entityTypeId - * @param bool $isBabyMob - */ - public function broadcastLevelSoundEvent(?Vector3 $pos, int $soundId, int $extraData = -1, int $entityTypeId = -1, bool $isBabyMob = false){ - $pk = LevelSoundEventPacket::create( - $soundId, - $extraData, - $pos, - AddEntityPacket::LEGACY_ID_MAP_BC[$entityTypeId] ?? ":", - $isBabyMob - ); - if($pos !== null){ - $this->broadcastPacketToViewers($pos, $pk); - }else{ - $this->broadcastGlobalPacket($pk); - } - } - public function getAutoSave() : bool{ return $this->autoSave; } @@ -1895,7 +1870,7 @@ class Level implements ChunkManager, Metadatable{ } if($playSound){ - $this->broadcastLevelSoundEvent($hand, LevelSoundEventPacket::SOUND_PLACE, $hand->getRuntimeId()); + $this->addSound($hand, new BlockPlaceSound($hand)); } $item->pop(); diff --git a/src/pocketmine/level/sound/ArrowHitSound.php b/src/pocketmine/level/sound/ArrowHitSound.php new file mode 100644 index 000000000..e19bdd16a --- /dev/null +++ b/src/pocketmine/level/sound/ArrowHitSound.php @@ -0,0 +1,34 @@ +block = $block; + } + + public function encode(Vector3 $pos){ + return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_BREAK, $pos, $this->block->getRuntimeId()); + } +} diff --git a/src/pocketmine/level/sound/BlockPlaceSound.php b/src/pocketmine/level/sound/BlockPlaceSound.php new file mode 100644 index 000000000..1d0b8b75c --- /dev/null +++ b/src/pocketmine/level/sound/BlockPlaceSound.php @@ -0,0 +1,42 @@ +block = $block; + } + + public function encode(Vector3 $pos){ + return LevelSoundEventPacket::create(LevelSoundEventPacket::SOUND_PLACE, $pos, $this->block->getRuntimeId()); + } +} diff --git a/src/pocketmine/level/sound/BowShootSound.php b/src/pocketmine/level/sound/BowShootSound.php new file mode 100644 index 000000000..139abbf34 --- /dev/null +++ b/src/pocketmine/level/sound/BowShootSound.php @@ -0,0 +1,34 @@ +sound = $sound; $result->extraData = $extraData;