From 37b5ad835033aca63446d49e403e09e19f413ada Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 26 Mar 2019 17:00:00 +0000 Subject: [PATCH] Remove remaining direct protocol usages for particles --- .../entity/projectile/EnderPearl.php | 4 +- .../entity/projectile/ExperienceBottle.php | 5 +- .../entity/projectile/SplashPotion.php | 9 ++- .../particle/EndermanTeleportParticle.php | 34 +++++++++++ .../level/particle/PotionSplashParticle.php | 60 +++++++++++++++++++ 5 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 src/pocketmine/level/particle/EndermanTeleportParticle.php create mode 100644 src/pocketmine/level/particle/PotionSplashParticle.php diff --git a/src/pocketmine/entity/projectile/EnderPearl.php b/src/pocketmine/entity/projectile/EnderPearl.php index da9610732..2d102909c 100644 --- a/src/pocketmine/entity/projectile/EnderPearl.php +++ b/src/pocketmine/entity/projectile/EnderPearl.php @@ -27,11 +27,11 @@ use pocketmine\block\Block; use pocketmine\block\BlockLegacyIds; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\ProjectileHitEvent; +use pocketmine\level\particle\EndermanTeleportParticle; use pocketmine\level\sound\EndermanTeleportSound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\protocol\LevelEventPacket; class EnderPearl extends Throwable{ public const NETWORK_ID = self::ENDER_PEARL; @@ -51,7 +51,7 @@ class EnderPearl extends Throwable{ //TODO: check end gateways (when they are added) //TODO: spawn endermites at origin - $this->level->broadcastLevelEvent($owner, LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT); + $this->level->addParticle($owner, new EndermanTeleportParticle()); $this->level->addSound($owner, new EndermanTeleportSound()); $owner->teleport($target = $event->getRayTraceResult()->getHitVector()); $this->level->addSound($target, new EndermanTeleportSound()); diff --git a/src/pocketmine/entity/projectile/ExperienceBottle.php b/src/pocketmine/entity/projectile/ExperienceBottle.php index 213f52b0b..ff7095f5d 100644 --- a/src/pocketmine/entity/projectile/ExperienceBottle.php +++ b/src/pocketmine/entity/projectile/ExperienceBottle.php @@ -24,9 +24,8 @@ declare(strict_types=1); namespace pocketmine\entity\projectile; use pocketmine\event\entity\ProjectileHitEvent; -use pocketmine\network\mcpe\protocol\LevelEventPacket; +use pocketmine\level\particle\PotionSplashParticle; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; -use pocketmine\utils\Color; use function mt_rand; class ExperienceBottle extends Throwable{ @@ -39,7 +38,7 @@ class ExperienceBottle extends Throwable{ } public function onHit(ProjectileHitEvent $event) : void{ - $this->level->broadcastLevelEvent($this, LevelEventPacket::EVENT_PARTICLE_SPLASH, (new Color(0x38, 0x5d, 0xc6))->toARGB()); + $this->level->addParticle($this, new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR())); $this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_GLASS); $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 54e93c2e3..9a2a8b07e 100644 --- a/src/pocketmine/entity/projectile/SplashPotion.php +++ b/src/pocketmine/entity/projectile/SplashPotion.php @@ -32,8 +32,8 @@ use pocketmine\event\entity\ProjectileHitBlockEvent; use pocketmine\event\entity\ProjectileHitEntityEvent; use pocketmine\event\entity\ProjectileHitEvent; use pocketmine\item\Potion; +use pocketmine\level\particle\PotionSplashParticle; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\utils\Color; use function round; @@ -68,9 +68,7 @@ class SplashPotion extends Throwable{ $hasEffects = true; if(empty($effects)){ - $colors = [ - new Color(0x38, 0x5d, 0xc6) //Default colour for splash water bottle and similar with no effects. - ]; + $particle = new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR()); $hasEffects = false; }else{ $colors = []; @@ -80,9 +78,10 @@ class SplashPotion extends Throwable{ $colors[] = $effect->getColor(); } } + $particle = new PotionSplashParticle(Color::mix(...$colors)); } - $this->level->broadcastLevelEvent($this, LevelEventPacket::EVENT_PARTICLE_SPLASH, Color::mix(...$colors)->toARGB()); + $this->level->addParticle($this, $particle); $this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_GLASS); if($hasEffects){ diff --git a/src/pocketmine/level/particle/EndermanTeleportParticle.php b/src/pocketmine/level/particle/EndermanTeleportParticle.php new file mode 100644 index 000000000..cb117e107 --- /dev/null +++ b/src/pocketmine/level/particle/EndermanTeleportParticle.php @@ -0,0 +1,34 @@ +color = $color; + } + + /** + * Returns the default water-bottle splash colour. + * + * TODO: replace this with a standard surrogate object constant (first we need to implement them!) + * + * @return Color + */ + public static function DEFAULT_COLOR() : Color{ + return new Color(0x38, 0x5d, 0xc6); + } + + /** + * @return Color + */ + public function getColor() : Color{ + return $this->color; + } + + public function encode(Vector3 $pos){ + return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_SPLASH, $this->color->toARGB(), $pos); + } +}