mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 08:49:42 +00:00
LevelEventPacket: added create() to reduce boilerplate code
This commit is contained in:
parent
7333e7118e
commit
1bf0802275
@ -507,14 +507,10 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
* @param int $data
|
* @param int $data
|
||||||
*/
|
*/
|
||||||
public function broadcastLevelEvent(?Vector3 $pos, int $evid, int $data = 0){
|
public function broadcastLevelEvent(?Vector3 $pos, int $evid, int $data = 0){
|
||||||
$pk = new LevelEventPacket();
|
$pk = LevelEventPacket::create($evid, $data, $pos);
|
||||||
$pk->evid = $evid;
|
|
||||||
$pk->data = $data;
|
|
||||||
if($pos !== null){
|
if($pos !== null){
|
||||||
$pk->position = $pos->asVector3();
|
|
||||||
$this->broadcastPacketToViewers($pos, $pk);
|
$this->broadcastPacketToViewers($pos, $pk);
|
||||||
}else{
|
}else{
|
||||||
$pk->position = null;
|
|
||||||
$this->broadcastGlobalPacket($pk);
|
$this->broadcastGlobalPacket($pk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,6 @@ class DestroyBlockParticle implements Particle{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function encode(Vector3 $pos){
|
public function encode(Vector3 $pos){
|
||||||
$pk = new LevelEventPacket;
|
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DESTROY, $this->data, $pos);
|
||||||
$pk->evid = LevelEventPacket::EVENT_PARTICLE_DESTROY;
|
|
||||||
$pk->position = $pos;
|
|
||||||
$pk->data = $this->data;
|
|
||||||
|
|
||||||
return $pk;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,17 +50,13 @@ class DragonEggTeleportParticle implements Particle{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function encode(Vector3 $pos){
|
public function encode(Vector3 $pos){
|
||||||
$pk = new LevelEventPacket();
|
$data = ($this->zDiff < 0 ? 1 << 26 : 0) |
|
||||||
$pk->evid = LevelEventPacket::EVENT_PARTICLE_DRAGON_EGG_TELEPORT;
|
|
||||||
$pk->position = $pos;
|
|
||||||
$pk->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) |
|
||||||
(abs($this->xDiff) << 16) |
|
(abs($this->xDiff) << 16) |
|
||||||
(abs($this->yDiff) << 8) |
|
(abs($this->yDiff) << 8) |
|
||||||
abs($this->zDiff);
|
abs($this->zDiff);
|
||||||
|
|
||||||
return $pk;
|
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_DRAGON_EGG_TELEPORT, $data, $pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,6 @@ class GenericParticle implements Particle{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function encode(Vector3 $pos){
|
public function encode(Vector3 $pos){
|
||||||
$pk = new LevelEventPacket;
|
return LevelEventPacket::create(LevelEventPacket::EVENT_ADD_PARTICLE_MASK | $this->id, $this->data, $pos);
|
||||||
$pk->evid = LevelEventPacket::EVENT_ADD_PARTICLE_MASK | $this->id;
|
|
||||||
$pk->position = $pos;
|
|
||||||
$pk->data = $this->data;
|
|
||||||
|
|
||||||
return $pk;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,16 +33,12 @@ class MobSpawnParticle implements Particle{
|
|||||||
protected $height;
|
protected $height;
|
||||||
|
|
||||||
public function __construct(int $width = 0, int $height = 0){
|
public function __construct(int $width = 0, int $height = 0){
|
||||||
|
//TODO: bounds checks
|
||||||
$this->width = $width;
|
$this->width = $width;
|
||||||
$this->height = $height;
|
$this->height = $height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function encode(Vector3 $pos){
|
public function encode(Vector3 $pos){
|
||||||
$pk = new LevelEventPacket;
|
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_SPAWN, ($this->width & 0xff) | (($this->height & 0xff) << 8), $pos);
|
||||||
$pk->evid = LevelEventPacket::EVENT_PARTICLE_SPAWN;
|
|
||||||
$pk->position = $pos;
|
|
||||||
$pk->data = ($this->width & 0xff) + (($this->height & 0xff) << 8);
|
|
||||||
|
|
||||||
return $pk;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,6 @@ abstract class LevelEventSound implements Sound{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function encode(Vector3 $pos){
|
public function encode(Vector3 $pos){
|
||||||
$pk = new LevelEventPacket;
|
return LevelEventPacket::create($this->getLevelEventId(), (int) $this->pitch, $pos);
|
||||||
$pk->evid = $this->getLevelEventId();
|
|
||||||
$pk->position = $pos;
|
|
||||||
$pk->data = (int) $this->pitch;
|
|
||||||
|
|
||||||
return $pk;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,14 @@ class LevelEventPacket extends DataPacket implements ClientboundPacket{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
public $data;
|
public $data;
|
||||||
|
|
||||||
|
public static function create(int $evid, int $data, ?Vector3 $pos) : self{
|
||||||
|
$pk = new self;
|
||||||
|
$pk->evid = $evid;
|
||||||
|
$pk->data = $data;
|
||||||
|
$pk->position = $pos !== null ? $pos->asVector3() : null;
|
||||||
|
return $pk;
|
||||||
|
}
|
||||||
|
|
||||||
protected function decodePayload() : void{
|
protected function decodePayload() : void{
|
||||||
$this->evid = $this->getVarInt();
|
$this->evid = $this->getVarInt();
|
||||||
$this->position = $this->getVector3();
|
$this->position = $this->getVector3();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user