Particle::encode() now always returns ClientboundPacket[]

This commit is contained in:
Dylan K. Taylor 2020-10-31 15:51:17 +00:00
parent 5a320f22b7
commit 66edf5a165
38 changed files with 73 additions and 76 deletions

View File

@ -493,9 +493,6 @@ class World implements ChunkManager{
*/ */
public function addParticle(Vector3 $pos, Particle $particle, ?array $players = null) : void{ public function addParticle(Vector3 $pos, Particle $particle, ?array $players = null) : void{
$pk = $particle->encode($pos); $pk = $particle->encode($pos);
if(!is_array($pk)){
$pk = [$pk];
}
if(count($pk) > 0){ if(count($pk) > 0){
if($players === null){ if($players === null){
foreach($pk as $e){ foreach($pk as $e){

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class AngryVillagerParticle implements Particle{ class AngryVillagerParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::VILLAGER_ANGRY, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::VILLAGER_ANGRY, 0, $pos)];
} }
} }

View File

@ -36,7 +36,7 @@ class BlockForceFieldParticle implements Particle{
$this->data = $data; //TODO: proper encode/decode of data $this->data = $data; //TODO: proper encode/decode of data
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::BLOCK_FORCE_FIELD, $this->data, $pos); return [LevelEventPacket::standardParticle(ParticleIds::BLOCK_FORCE_FIELD, $this->data, $pos)];
} }
} }

View File

@ -43,7 +43,7 @@ class BlockPunchParticle implements Particle{
$this->face = $face; $this->face = $face;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()) | ($this->face << 24), $pos); return [LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()) | ($this->face << 24), $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class BubbleParticle implements Particle{ class BubbleParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::BUBBLE, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::BUBBLE, 0, $pos)];
} }
} }

View File

@ -35,7 +35,7 @@ class CriticalParticle implements Particle{
$this->scale = $scale; $this->scale = $scale;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::CRITICAL, $this->scale, $pos); return [LevelEventPacket::standardParticle(ParticleIds::CRITICAL, $this->scale, $pos)];
} }
} }

View File

@ -37,7 +37,7 @@ class DestroyBlockParticle implements Particle{
$this->block = $b; $this->block = $b;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos); return [LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos)];
} }
} }

View File

@ -49,7 +49,7 @@ class DragonEggTeleportParticle implements Particle{
return $v; return $v;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
$data = ($this->zDiff < 0 ? 1 << 26 : 0) | $data = ($this->zDiff < 0 ? 1 << 26 : 0) |
($this->yDiff < 0 ? 1 << 25 : 0) | ($this->yDiff < 0 ? 1 << 25 : 0) |
($this->xDiff < 0 ? 1 << 24 : 0) | ($this->xDiff < 0 ? 1 << 24 : 0) |
@ -57,6 +57,6 @@ class DragonEggTeleportParticle implements Particle{
(abs($this->yDiff) << 8) | (abs($this->yDiff) << 8) |
abs($this->zDiff); abs($this->zDiff);
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DRAGON_EGG_TELEPORT, $data, $pos); return [LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DRAGON_EGG_TELEPORT, $data, $pos)];
} }
} }

View File

@ -36,7 +36,7 @@ class DustParticle implements Particle{
$this->color = $color; $this->color = $color;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::DUST, $this->color->toARGB(), $pos); return [LevelEventPacket::standardParticle(ParticleIds::DUST, $this->color->toARGB(), $pos)];
} }
} }

View File

@ -37,7 +37,7 @@ class EnchantParticle implements Particle{
$this->color = $color; $this->color = $color;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::MOB_SPELL, $this->color->toARGB(), $pos); return [LevelEventPacket::standardParticle(ParticleIds::MOB_SPELL, $this->color->toARGB(), $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class EnchantmentTableParticle implements Particle{ class EnchantmentTableParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::ENCHANTMENT_TABLE, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::ENCHANTMENT_TABLE, 0, $pos)];
} }
} }

View File

@ -28,7 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
class EndermanTeleportParticle implements Particle{ class EndermanTeleportParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT, 0, $pos); return [LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT, 0, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class EntityFlameParticle implements Particle{ class EntityFlameParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::MOB_FLAME, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::MOB_FLAME, 0, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class ExplodeParticle implements Particle{ class ExplodeParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::EXPLODE, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::EXPLODE, 0, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class FlameParticle implements Particle{ class FlameParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::FLAME, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::FLAME, 0, $pos)];
} }
} }

View File

@ -80,7 +80,7 @@ class FloatingTextParticle implements Particle{
$this->invisible = $value; $this->invisible = $value;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
$p = []; $p = [];
if($this->entityId === null){ if($this->entityId === null){

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class HappyVillagerParticle implements Particle{ class HappyVillagerParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::VILLAGER_HAPPY, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::VILLAGER_HAPPY, 0, $pos)];
} }
} }

View File

@ -35,7 +35,7 @@ class HeartParticle implements Particle{
$this->scale = $scale; $this->scale = $scale;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::HEART, $this->scale, $pos); return [LevelEventPacket::standardParticle(ParticleIds::HEART, $this->scale, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class HugeExplodeParticle implements Particle{ class HugeExplodeParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::HUGE_EXPLODE, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::HUGE_EXPLODE, 0, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class HugeExplodeSeedParticle implements Particle{ class HugeExplodeSeedParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::HUGE_EXPLODE_SEED, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::HUGE_EXPLODE_SEED, 0, $pos)];
} }
} }

View File

@ -35,7 +35,7 @@ class InkParticle implements Particle{
$this->scale = $scale; $this->scale = $scale;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::INK, $this->scale, $pos); return [LevelEventPacket::standardParticle(ParticleIds::INK, $this->scale, $pos)];
} }
} }

View File

@ -36,7 +36,7 @@ class InstantEnchantParticle implements Particle{
$this->color = $color; $this->color = $color;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::MOB_SPELL_INSTANTANEOUS, $this->color->toARGB(), $pos); return [LevelEventPacket::standardParticle(ParticleIds::MOB_SPELL_INSTANTANEOUS, $this->color->toARGB(), $pos)];
} }
} }

View File

@ -36,7 +36,7 @@ class ItemBreakParticle implements Particle{
$this->item = $item; $this->item = $item;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::ITEM_BREAK, ($this->item->getId() << 16) | $this->item->getMeta(), $pos); return [LevelEventPacket::standardParticle(ParticleIds::ITEM_BREAK, ($this->item->getId() << 16) | $this->item->getMeta(), $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class LavaDripParticle implements Particle{ class LavaDripParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::DRIP_LAVA, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::DRIP_LAVA, 0, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class LavaParticle implements Particle{ class LavaParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::LAVA, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::LAVA, 0, $pos)];
} }
} }

View File

@ -38,7 +38,7 @@ class MobSpawnParticle implements Particle{
$this->height = $height; $this->height = $height;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_SPAWN, ($this->width & 0xff) | (($this->height & 0xff) << 8), $pos); return [LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_SPAWN, ($this->width & 0xff) | (($this->height & 0xff) << 8), $pos)];
} }
} }

View File

@ -29,8 +29,8 @@ use pocketmine\network\mcpe\protocol\ClientboundPacket;
interface Particle{ interface Particle{
/** /**
* @return ClientboundPacket|ClientboundPacket[] * @return ClientboundPacket[]
*/ */
public function encode(Vector3 $pos); public function encode(Vector3 $pos) : array;
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class PortalParticle implements Particle{ class PortalParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::PORTAL, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::PORTAL, 0, $pos)];
} }
} }

View File

@ -49,7 +49,7 @@ class PotionSplashParticle implements Particle{
return $this->color; return $this->color;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_SPLASH, $this->color->toARGB(), $pos); return [LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_SPLASH, $this->color->toARGB(), $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class RainSplashParticle implements Particle{ class RainSplashParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::RAIN_SPLASH, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::RAIN_SPLASH, 0, $pos)];
} }
} }

View File

@ -35,7 +35,7 @@ class RedstoneParticle implements Particle{
$this->lifetime = $lifetime; $this->lifetime = $lifetime;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::REDSTONE, $this->lifetime, $pos); return [LevelEventPacket::standardParticle(ParticleIds::REDSTONE, $this->lifetime, $pos)];
} }
} }

View File

@ -35,7 +35,7 @@ class SmokeParticle implements Particle{
$this->scale = $scale; $this->scale = $scale;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::SMOKE, $this->scale, $pos); return [LevelEventPacket::standardParticle(ParticleIds::SMOKE, $this->scale, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class SnowballPoofParticle implements Particle{ class SnowballPoofParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::SNOWBALL_POOF, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::SNOWBALL_POOF, 0, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class SplashParticle implements Particle{ class SplashParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::WATER_SPLASH, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::WATER_SPLASH, 0, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class SporeParticle implements Particle{ class SporeParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::TOWN_AURA, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::TOWN_AURA, 0, $pos)];
} }
} }

View File

@ -37,7 +37,7 @@ class TerrainParticle implements Particle{
$this->block = $b; $this->block = $b;
} }
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos); return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class WaterDripParticle implements Particle{ class WaterDripParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::DRIP_WATER, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::DRIP_WATER, 0, $pos)];
} }
} }

View File

@ -29,7 +29,7 @@ use pocketmine\network\mcpe\protocol\types\ParticleIds;
class WaterParticle implements Particle{ class WaterParticle implements Particle{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos) : array{
return LevelEventPacket::standardParticle(ParticleIds::WATER_WAKE, 0, $pos); return [LevelEventPacket::standardParticle(ParticleIds::WATER_WAKE, 0, $pos)];
} }
} }