mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-11 08:19:45 +00:00
Remove remaining direct protocol usages for particles
This commit is contained in:
parent
1bf0802275
commit
37b5ad8350
@ -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());
|
||||
|
@ -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));
|
||||
|
@ -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){
|
||||
|
34
src/pocketmine/level/particle/EndermanTeleportParticle.php
Normal file
34
src/pocketmine/level/particle/EndermanTeleportParticle.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\particle;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||
|
||||
class EndermanTeleportParticle implements Particle{
|
||||
|
||||
public function encode(Vector3 $pos){
|
||||
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT, 0, $pos);
|
||||
}
|
||||
}
|
60
src/pocketmine/level/particle/PotionSplashParticle.php
Normal file
60
src/pocketmine/level/particle/PotionSplashParticle.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\particle;
|
||||
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||
use pocketmine\utils\Color;
|
||||
|
||||
class PotionSplashParticle implements Particle{
|
||||
|
||||
/** @var Color */
|
||||
private $color;
|
||||
|
||||
public function __construct(Color $color){
|
||||
$this->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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user