Particle no longer extends Vector3

This commit is contained in:
Dylan K. Taylor 2018-12-16 14:15:41 +00:00
parent ebf9cb3e62
commit 3c520aa786
40 changed files with 122 additions and 186 deletions

View File

@ -105,7 +105,7 @@ class ParticleCommand extends VanillaCommand{
$data = isset($args[8]) ? (int) $args[8] : null;
$particle = $this->getParticle($name, $pos, $xd, $yd, $zd, $data);
$particle = $this->getParticle($name, $data);
if($particle === null){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.particle.notFound", [$name]));
@ -118,12 +118,11 @@ class ParticleCommand extends VanillaCommand{
$random = new Random((int) (microtime(true) * 1000) + mt_rand());
for($i = 0; $i < $count; ++$i){
$particle->setComponents(
$pos->x + $random->nextSignedFloat() * $xd,
$pos->y + $random->nextSignedFloat() * $yd,
$pos->z + $random->nextSignedFloat() * $zd
);
$level->addParticle($particle);
$level->addParticle($pos->add(
$random->nextSignedFloat() * $xd,
$random->nextSignedFloat() * $yd,
$random->nextSignedFloat() * $zd
), $particle);
}
return true;
@ -131,97 +130,93 @@ class ParticleCommand extends VanillaCommand{
/**
* @param string $name
* @param Vector3 $pos
* @param float $xd
* @param float $yd
* @param float $zd
* @param int|null $data
*
* @return Particle|null
*/
private function getParticle(string $name, Vector3 $pos, float $xd, float $yd, float $zd, int $data = null){
private function getParticle(string $name, int $data = null){
switch($name){
case "explode":
return new ExplodeParticle($pos);
return new ExplodeParticle();
case "hugeexplosion":
return new HugeExplodeParticle($pos);
return new HugeExplodeParticle();
case "hugeexplosionseed":
return new HugeExplodeSeedParticle($pos);
return new HugeExplodeSeedParticle();
case "bubble":
return new BubbleParticle($pos);
return new BubbleParticle();
case "splash":
return new SplashParticle($pos);
return new SplashParticle();
case "wake":
case "water":
return new WaterParticle($pos);
return new WaterParticle();
case "crit":
return new CriticalParticle($pos);
return new CriticalParticle();
case "smoke":
return new SmokeParticle($pos, $data ?? 0);
return new SmokeParticle($data ?? 0);
case "spell":
return new EnchantParticle($pos);
return new EnchantParticle();
case "instantspell":
return new InstantEnchantParticle($pos);
return new InstantEnchantParticle();
case "dripwater":
return new WaterDripParticle($pos);
return new WaterDripParticle();
case "driplava":
return new LavaDripParticle($pos);
return new LavaDripParticle();
case "townaura":
case "spore":
return new SporeParticle($pos);
return new SporeParticle();
case "portal":
return new PortalParticle($pos);
return new PortalParticle();
case "flame":
return new FlameParticle($pos);
return new FlameParticle();
case "lava":
return new LavaParticle($pos);
return new LavaParticle();
case "reddust":
return new RedstoneParticle($pos, $data ?? 1);
return new RedstoneParticle($data ?? 1);
case "snowballpoof":
return new ItemBreakParticle($pos, ItemFactory::get(Item::SNOWBALL));
return new ItemBreakParticle(ItemFactory::get(Item::SNOWBALL));
case "slime":
return new ItemBreakParticle($pos, ItemFactory::get(Item::SLIMEBALL));
return new ItemBreakParticle(ItemFactory::get(Item::SLIMEBALL));
case "itembreak":
if($data !== null and $data !== 0){
return new ItemBreakParticle($pos, ItemFactory::get($data));
return new ItemBreakParticle(ItemFactory::get($data));
}
break;
case "terrain":
if($data !== null and $data !== 0){
return new TerrainParticle($pos, BlockFactory::get($data));
return new TerrainParticle(BlockFactory::get($data));
}
break;
case "heart":
return new HeartParticle($pos, $data ?? 0);
return new HeartParticle($data ?? 0);
case "ink":
return new InkParticle($pos, $data ?? 0);
return new InkParticle($data ?? 0);
case "droplet":
return new RainSplashParticle($pos);
return new RainSplashParticle();
case "enchantmenttable":
return new EnchantmentTableParticle($pos);
return new EnchantmentTableParticle();
case "happyvillager":
return new HappyVillagerParticle($pos);
return new HappyVillagerParticle();
case "angryvillager":
return new AngryVillagerParticle($pos);
return new AngryVillagerParticle();
case "forcefield":
return new BlockForceFieldParticle($pos, $data ?? 0);
return new BlockForceFieldParticle($data ?? 0);
}
if(strpos($name, "iconcrack_") === 0){
$d = explode("_", $name);
if(count($d) === 3){
return new ItemBreakParticle($pos, ItemFactory::get((int) $d[1], (int) $d[2]));
return new ItemBreakParticle(ItemFactory::get((int) $d[1], (int) $d[2]));
}
}elseif(strpos($name, "blockcrack_") === 0){
$d = explode("_", $name);
if(count($d) === 2){
return new TerrainParticle($pos, BlockFactory::get($d[1] & 0xff, $d[1] >> 12));
return new TerrainParticle(BlockFactory::get($d[1] & 0xff, $d[1] >> 12));
}
}elseif(strpos($name, "blockdust_") === 0){
$d = explode("_", $name);
if(count($d) >= 4){
return new DustParticle($pos, $d[1] & 0xff, $d[2] & 0xff, $d[3] & 0xff, isset($d[4]) ? $d[4] & 0xff : 255);
return new DustParticle($d[1] & 0xff, $d[2] & 0xff, $d[3] & 0xff, isset($d[4]) ? $d[4] & 0xff : 255);
}
}

View File

@ -108,7 +108,7 @@ class Painting extends Entity{
//non-living entities don't have a way to create drops generically yet
$this->level->dropItem($this, ItemFactory::get(Item::PAINTING));
}
$this->level->addParticle(new DestroyBlockParticle($this->add(0.5, 0.5, 0.5), BlockFactory::get(Block::PLANKS)));
$this->level->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(BlockFactory::get(Block::PLANKS)));
}
protected function recalculateBoundingBox() : void{

View File

@ -35,7 +35,7 @@ class Egg extends Throwable{
protected function onHit(ProjectileHitEvent $event) : void{
for($i = 0; $i < 6; ++$i){
$this->level->addParticle(new ItemBreakParticle($this, ItemFactory::get(Item::EGG)));
$this->level->addParticle($this, new ItemBreakParticle(ItemFactory::get(Item::EGG)));
}
}
}

View File

@ -31,7 +31,7 @@ class Snowball extends Throwable{
protected function onHit(ProjectileHitEvent $event) : void{
for($i = 0; $i < 6; ++$i){
$this->level->addParticle(new SnowballPoofParticle($this));
$this->level->addParticle($this, new SnowballPoofParticle());
}
}
}

View File

@ -256,7 +256,7 @@ class Explosion{
$pk->records = $send;
$this->level->broadcastPacketToViewers($source, $pk);
$this->level->addParticle(new HugeExplodeSeedParticle($source));
$this->level->addParticle($source, new HugeExplodeSeedParticle());
$this->level->broadcastLevelSoundEvent($source, LevelSoundEventPacket::SOUND_EXPLODE);
return true;

View File

@ -466,15 +466,15 @@ class Level implements ChunkManager, Metadatable{
}
}
public function addParticle(Particle $particle, array $players = null){
$pk = $particle->encode();
public function addParticle(Vector3 $pos, Particle $particle, array $players = null){
$pk = $particle->encode($pos);
if(!is_array($pk)){
$pk = [$pk];
}
if(!empty($pk)){
if($players === null){
foreach($pk as $e){
$this->broadcastPacketToViewers($particle, $e);
$this->broadcastPacketToViewers($pos, $e);
}
}else{
$this->server->broadcastPackets($players, $pk);
@ -1761,7 +1761,7 @@ class Level implements ChunkManager, Metadatable{
private function destroyBlockInternal(Block $target, Item $item, ?Player $player = null, bool $createParticles = false) : void{
if($createParticles){
$this->addParticle(new DestroyBlockParticle($target->add(0.5, 0.5, 0.5), $target));
$this->addParticle($target->add(0.5, 0.5, 0.5), new DestroyBlockParticle($target));
}
$target->onBreak($item, $player);

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class AngryVillagerParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_VILLAGER_ANGRY);
public function __construct(){
parent::__construct(Particle::TYPE_VILLAGER_ANGRY);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class BlockForceFieldParticle extends GenericParticle{
public function __construct(Vector3 $pos, int $data = 0){
parent::__construct($pos, Particle::TYPE_BLOCK_FORCE_FIELD, $data); //TODO: proper encode/decode of data
public function __construct(int $data = 0){
parent::__construct(Particle::TYPE_BLOCK_FORCE_FIELD, $data); //TODO: proper encode/decode of data
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class BubbleParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_BUBBLE);
public function __construct(){
parent::__construct(Particle::TYPE_BUBBLE);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class CriticalParticle extends GenericParticle{
public function __construct(Vector3 $pos, int $scale = 2){
parent::__construct($pos, Particle::TYPE_CRITICAL, $scale);
public function __construct(int $scale = 2){
parent::__construct(Particle::TYPE_CRITICAL, $scale);
}
}

View File

@ -32,15 +32,14 @@ class DestroyBlockParticle extends Particle{
/** @var int */
protected $data;
public function __construct(Vector3 $pos, Block $b){
parent::__construct($pos->x, $pos->y, $pos->z);
public function __construct(Block $b){
$this->data = $b->getRuntimeId();
}
public function encode(){
public function encode(Vector3 $pos){
$pk = new LevelEventPacket;
$pk->evid = LevelEventPacket::EVENT_PARTICLE_DESTROY;
$pk->position = $this->asVector3();
$pk->position = $pos;
$pk->data = $this->data;
return $pk;

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class DustParticle extends GenericParticle{
public function __construct(Vector3 $pos, int $r, int $g, int $b, int $a = 255){
parent::__construct($pos, Particle::TYPE_DUST, (($a & 0xff) << 24) | (($r & 0xff) << 16) | (($g & 0xff) << 8) | ($b & 0xff));
public function __construct(int $r, int $g, int $b, int $a = 255){
parent::__construct(Particle::TYPE_DUST, (($a & 0xff) << 24) | (($r & 0xff) << 16) | (($g & 0xff) << 8) | ($b & 0xff));
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class EnchantParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_MOB_SPELL);
public function __construct(){
parent::__construct(Particle::TYPE_MOB_SPELL);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class EnchantmentTableParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_ENCHANTMENT_TABLE);
public function __construct(){
parent::__construct(Particle::TYPE_ENCHANTMENT_TABLE);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class EntityFlameParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_MOB_FLAME);
public function __construct(){
parent::__construct(Particle::TYPE_MOB_FLAME);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class ExplodeParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_EXPLODE);
public function __construct(){
parent::__construct(Particle::TYPE_EXPLODE);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class FlameParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_FLAME);
public function __construct(){
parent::__construct(Particle::TYPE_FLAME);
}
}

View File

@ -43,12 +43,10 @@ class FloatingTextParticle extends Particle{
protected $invisible = false;
/**
* @param Vector3 $pos
* @param string $text
* @param string $title
* @param string $text
* @param string $title
*/
public function __construct(Vector3 $pos, string $text, string $title = ""){
parent::__construct($pos->x, $pos->y, $pos->z);
public function __construct(string $text, string $title = ""){
$this->text = $text;
$this->title = $title;
}
@ -77,7 +75,7 @@ class FloatingTextParticle extends Particle{
$this->invisible = $value;
}
public function encode(){
public function encode(Vector3 $pos){
$p = [];
if($this->entityId === null){
@ -102,7 +100,7 @@ class FloatingTextParticle extends Particle{
$pk->uuid = $uuid;
$pk->username = $name;
$pk->entityRuntimeId = $this->entityId;
$pk->position = $this->asVector3(); //TODO: check offset
$pk->position = $pos; //TODO: check offset
$pk->item = ItemFactory::get(Item::AIR, 0, 0);
$flags = (

View File

@ -32,16 +32,15 @@ class GenericParticle extends Particle{
/** @var int */
protected $data;
public function __construct(Vector3 $pos, int $id, int $data = 0){
parent::__construct($pos->x, $pos->y, $pos->z);
public function __construct(int $id, int $data = 0){
$this->id = $id & 0xFFF;
$this->data = $data;
}
public function encode(){
public function encode(Vector3 $pos){
$pk = new LevelEventPacket;
$pk->evid = LevelEventPacket::EVENT_ADD_PARTICLE_MASK | $this->id;
$pk->position = $this->asVector3();
$pk->position = $pos;
$pk->data = $this->data;
return $pk;

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class HappyVillagerParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_VILLAGER_HAPPY);
public function __construct(){
parent::__construct(Particle::TYPE_VILLAGER_HAPPY);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class HeartParticle extends GenericParticle{
public function __construct(Vector3 $pos, int $scale = 0){
parent::__construct($pos, Particle::TYPE_HEART, $scale);
public function __construct(int $scale = 0){
parent::__construct(Particle::TYPE_HEART, $scale);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class HugeExplodeParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_HUGE_EXPLODE);
public function __construct(){
parent::__construct(Particle::TYPE_HUGE_EXPLODE);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class HugeExplodeSeedParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_HUGE_EXPLODE_SEED);
public function __construct(){
parent::__construct(Particle::TYPE_HUGE_EXPLODE_SEED);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class InkParticle extends GenericParticle{
public function __construct(Vector3 $pos, int $scale = 0){
parent::__construct($pos, Particle::TYPE_INK, $scale);
public function __construct(int $scale = 0){
parent::__construct(Particle::TYPE_INK, $scale);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class InstantEnchantParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_MOB_SPELL_INSTANTANEOUS);
public function __construct(){
parent::__construct(Particle::TYPE_MOB_SPELL_INSTANTANEOUS);
}
}

View File

@ -24,10 +24,9 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
class ItemBreakParticle extends GenericParticle{
public function __construct(Vector3 $pos, Item $item){
parent::__construct($pos, Particle::TYPE_ITEM_BREAK, ($item->getId() << 16) | $item->getDamage());
public function __construct(Item $item){
parent::__construct(Particle::TYPE_ITEM_BREAK, ($item->getId() << 16) | $item->getDamage());
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class LavaDripParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_DRIP_LAVA);
public function __construct(){
parent::__construct(Particle::TYPE_DRIP_LAVA);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class LavaParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_LAVA);
public function __construct(){
parent::__construct(Particle::TYPE_LAVA);
}
}

View File

@ -32,16 +32,15 @@ class MobSpawnParticle extends Particle{
/** @var int */
protected $height;
public function __construct(Vector3 $pos, int $width = 0, int $height = 0){
parent::__construct($pos->x, $pos->y, $pos->z);
public function __construct(int $width = 0, int $height = 0){
$this->width = $width;
$this->height = $height;
}
public function encode(){
public function encode(Vector3 $pos){
$pk = new LevelEventPacket;
$pk->evid = LevelEventPacket::EVENT_PARTICLE_SPAWN;
$pk->position = $this->asVector3();
$pk->position = $pos;
$pk->data = ($this->width & 0xff) + (($this->height & 0xff) << 8);
return $pk;

View File

@ -26,7 +26,7 @@ namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\DataPacket;
abstract class Particle extends Vector3{
abstract class Particle{
public const TYPE_BUBBLE = 1;
public const TYPE_CRITICAL = 2;
@ -74,8 +74,10 @@ abstract class Particle extends Vector3{
public const TYPE_FOOD = 44;
/**
* @param Vector3 $pos
*
* @return DataPacket|DataPacket[]
*/
abstract public function encode();
abstract public function encode(Vector3 $pos);
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class PortalParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_PORTAL);
public function __construct(){
parent::__construct(Particle::TYPE_PORTAL);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class RainSplashParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_RAIN_SPLASH);
public function __construct(){
parent::__construct(Particle::TYPE_RAIN_SPLASH);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class RedstoneParticle extends GenericParticle{
public function __construct(Vector3 $pos, int $lifetime = 1){
parent::__construct($pos, Particle::TYPE_REDSTONE, $lifetime);
public function __construct(int $lifetime = 1){
parent::__construct(Particle::TYPE_REDSTONE, $lifetime);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class SmokeParticle extends GenericParticle{
public function __construct(Vector3 $pos, int $scale = 0){
parent::__construct($pos, Particle::TYPE_SMOKE, $scale);
public function __construct(int $scale = 0){
parent::__construct(Particle::TYPE_SMOKE, $scale);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class SnowballPoofParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, self::TYPE_SNOWBALL_POOF, 0);
public function __construct(){
parent::__construct(self::TYPE_SNOWBALL_POOF, 0);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class SplashParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_WATER_SPLASH);
public function __construct(){
parent::__construct(Particle::TYPE_WATER_SPLASH);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class SporeParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_TOWN_AURA);
public function __construct(){
parent::__construct(Particle::TYPE_TOWN_AURA);
}
}

View File

@ -24,10 +24,9 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
class TerrainParticle extends GenericParticle{
public function __construct(Vector3 $pos, Block $b){
parent::__construct($pos, Particle::TYPE_TERRAIN, $b->getRuntimeId());
public function __construct(Block $b){
parent::__construct(Particle::TYPE_TERRAIN, $b->getRuntimeId());
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class WaterDripParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_DRIP_WATER);
public function __construct(){
parent::__construct(Particle::TYPE_DRIP_WATER);
}
}

View File

@ -23,10 +23,8 @@ declare(strict_types=1);
namespace pocketmine\level\particle;
use pocketmine\math\Vector3;
class WaterParticle extends GenericParticle{
public function __construct(Vector3 $pos){
parent::__construct($pos, Particle::TYPE_WATER_WAKE);
public function __construct(){
parent::__construct(Particle::TYPE_WATER_WAKE);
}
}