Added experimental particles

This commit is contained in:
Shoghi Cervantes 2015-03-18 08:51:38 +01:00
parent 8169803bb4
commit c00370cfbf
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
7 changed files with 241 additions and 4 deletions

View File

@ -24,4 +24,9 @@ namespace pocketmine\entity;
class Wolf extends Animal implements Tameable{ class Wolf extends Animal implements Tameable{
const NETWORK_ID = 14;
public function getName(){
return "Wolf";
}
} }

View File

@ -371,7 +371,14 @@ class Level implements ChunkManager, Metadatable{
public function addParticle(Particle $particle){ public function addParticle(Particle $particle){
$pk = $particle->encode(); $pk = $particle->encode();
if($pk !== null){ if($pk !== null){
Server::broadcastPacket($this->getUsingChunk($particle->x >> 4, $particle->z >> 4), $pk); if(!is_array($pk)){
Server::broadcastPacket($this->getUsingChunk($particle->x >> 4, $particle->z >> 4), $pk);
}else{
$players = $this->getUsingChunk($particle->x >> 4, $particle->z >> 4);
foreach($pk as $p){
Server::broadcastPacket($players, $p);
}
}
} }
} }
@ -1335,6 +1342,8 @@ class Level implements ChunkManager, Metadatable{
$target = $this->getBlock($vector); $target = $this->getBlock($vector);
$block = $target->getSide($face); $block = $target->getSide($face);
$this->addParticle(new \pocketmine\level\particle\FloatingTextParticle($target->add(0.5, 1.5, 0.5), "TESTTTTT\nSssass"));
if($block->y > 127 or $block->y < 0){ if($block->y > 127 or $block->y < 0){
return false; return false;
} }

View File

@ -0,0 +1,90 @@
<?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/
*
*
*/
namespace pocketmine\level\particle;
use pocketmine\entity\Entity;
use pocketmine\entity\Wolf;
use pocketmine\math\Vector3;
use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\AddMobPacket;
use pocketmine\network\protocol\AddPlayerPacket;
use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\RemovePlayerPacket;
use pocketmine\network\protocol\SetEntityDataPacket;
class FloatingTextParticle extends Particle{
//TODO: HACK!
protected $text;
protected $title;
protected $entityId;
public function __construct(Vector3 $pos, $text, $title = ""){
parent::__construct($pos->x, $pos->y, $pos->z);
$this->text = $text;
$this->title = $title;
}
public function setText($text){
$this->text = $text;
}
public function setTitle($title){
$this->title = $title;
}
public function encode(){
$p = [];
if($this->entityId === null){
$this->entityId = bcadd("1095216660480", mt_rand(0, 0x7fffffff)); //No conflict with other things
}else{
$pk0 = new RemovePlayerPacket();
$pk0->eid = $this->entityId;
$pk0->clientID = $this->entityId;
$p[] = $pk0;
}
$pk = new AddPlayerPacket();
$pk->eid = $this->entityId;
$pk->username = $this->title . "\n" . $this->text;
$pk->clientID = $this->entityId;
$pk->x = $this->x;
$pk->y = $this->y - 2;
$pk->z = $this->z;
$pk->yaw = 0;
$pk->pitch = 0;
$pk->item = 0;
$pk->meta = 0;
$pk->metadata = [
Entity::DATA_FLAGS => [Entity::DATA_TYPE_BYTE, 1 << Entity::DATA_FLAG_INVISIBLE],
Entity::DATA_AIR => [Entity::DATA_TYPE_SHORT, 300],
Entity::DATA_SHOW_NAMETAG => [Entity::DATA_TYPE_BYTE, 1]
];
$p[] = $pk;
return $pk;
}
}

View File

@ -0,0 +1,63 @@
<?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/
*
*
*/
namespace pocketmine\level\particle;
use pocketmine\entity\Entity;
use pocketmine\entity\Wolf;
use pocketmine\math\Vector3;
use pocketmine\network\protocol\AddMobPacket;
use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\network\protocol\RemoveEntityPacket;
class HearthParticle extends Particle{
//TODO: HACK!
//TODO: needs more testing!
public function __construct(Vector3 $pos){
parent::__construct($pos->x, $pos->y, $pos->z);
}
public function encode(){
$entityId = bcadd("1095216660480", mt_rand(0, 0x7fffffff)); //No conflict with other things
$pk = new AddMobPacket();
$pk->eid = $entityId;
$pk->type = Wolf::NETWORK_ID;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->pitch = 0;
$pk->yaw = 0;
$pk->metadata = [
Entity::DATA_FLAGS => [Entity::DATA_TYPE_BYTE, 1 << Entity::DATA_FLAG_INVISIBLE],
Entity::DATA_AIR => [Entity::DATA_TYPE_SHORT, 300]
];
$pk2 = new EntityEventPacket();
$pk2->eid = $entityId;
$pk2->event = 7;
$pk3 = new RemoveEntityPacket();
$pk3->eid = $entityId;
return [$pk, $pk2, $pk3];
}
}

View File

@ -27,7 +27,7 @@ use pocketmine\network\protocol\DataPacket;
abstract class Particle extends Vector3{ abstract class Particle extends Vector3{
/** /**
* @return DataPacket * @return DataPacket|DataPacket[]
*/ */
abstract public function encode(); abstract public function encode();

View File

@ -0,0 +1,72 @@
<?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/
*
*
*/
namespace pocketmine\level\particle;
use pocketmine\entity\Entity;
use pocketmine\entity\Wolf;
use pocketmine\math\Vector3;
use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\AddMobPacket;
use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\network\protocol\RemoveEntityPacket;
use pocketmine\network\protocol\SetEntityDataPacket;
class WaterParticle extends Particle{
//TODO: HACK!
protected $angle;
public function __construct(Vector3 $pos, $angle = 0){
parent::__construct($pos->x, $pos->y, $pos->z);
$this->angle = $angle;
}
public function encode(){
$entityId = bcadd("1095216660480", mt_rand(0, 0x7fffffff)); //No conflict with other things
$pk = new AddEntityPacket();
$pk->eid = $entityId;
$pk->type = 77;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->did = 0;
$pk2 = new SetEntityDataPacket();
$pk2->eid = $entityId;
$pk2->metadata = [
Entity::DATA_FLAGS => [Entity::DATA_TYPE_BYTE, 1 << Entity::DATA_FLAG_INVISIBLE],
Entity::DATA_AIR => [Entity::DATA_TYPE_SHORT, 300],
2 => [Entity::DATA_TYPE_FLOAT, $this->x],
4 => [Entity::DATA_TYPE_FLOAT, $this->z],
8 => [Entity::DATA_TYPE_FLOAT, $this->angle]
];
$pk3 = new EntityEventPacket();
$pk3->eid = $entityId;
$pk3->event = 12;
$pk4 = new RemoveEntityPacket();
$pk4->eid = $entityId;
return [$pk, $pk2, $pk3, $pk4];
}
}

View File

@ -80,7 +80,6 @@ class Binary{
/** /**
* Writes a coded metadata string * Writes a coded metadata string
* TODO: Replace and move this to entity
* *
* @param array $data * @param array $data
* *
@ -128,7 +127,6 @@ class Binary{
/** /**
* Reads a metadata coded string * Reads a metadata coded string
* TODO: Change
* *
* @param $value * @param $value
* @param bool $types * @param bool $types