Moved network ids to constants, improved some entity methods, more performance

This commit is contained in:
Shoghi Cervantes 2015-05-30 23:59:24 +02:00
parent 32680843fa
commit 9e14435dbb
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
58 changed files with 197 additions and 436 deletions

View File

@ -159,8 +159,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
protected $sendIndex = 0;
protected $moveToSend = [];
protected $motionToSend = [];
protected $moveToSend;
protected $motionToSend;
/** @var Vector3 */
public $speed = null;
@ -502,11 +502,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->spawnThreshold = (int) $this->server->getProperty("chunk-sending.spawn-threshold", 56);
$this->spawnPosition = null;
$this->gamemode = $this->server->getGamemode();
$this->setLevel($this->server->getDefaultLevel(), true);
$this->setLevel($this->server->getDefaultLevel());
$this->viewDistance = $this->server->getViewDistance();
$this->newPosition = new Vector3(0, 0, 0);
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->motionToSend = new SetEntityMotionPacket();
$this->moveToSend = new MoveEntityPacket();
$this->motionToSend->setChannel(Network::CHANNEL_MOVEMENT);
$this->moveToSend->setChannel(Network::CHANNEL_MOVEMENT);
$this->uuid = Utils::dataToUUID($ip, $port, $clientID);
$this->creationTime = microtime(true);
@ -1168,11 +1173,40 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
public function addEntityMotion($entityId, $x, $y, $z){
$this->motionToSend[$entityId] = [$entityId, $x, $y, $z];
$this->motionToSend->entities[$entityId] = [$entityId, $x, $y, $z];
}
public function addEntityMovement($entityId, $x, $y, $z, $yaw, $pitch, $headYaw = null){
$this->moveToSend[$entityId] = [$entityId, $x, $y, $z, $yaw, $headYaw === null ? $yaw : $headYaw, $pitch];
$this->moveToSend->entities[$entityId] = [$entityId, $x, $y, $z, $yaw, $headYaw === null ? $yaw : $headYaw, $pitch];
}
public function setDataProperty($id, $type, $value){
if(parent::setDataProperty($id, $type, $value)){
$this->sendData([$this], [$id => $this->dataProperties[$id]]);
return true;
}
return false;
}
protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){
if(!$this->onGround or $movY != 0){
$bb = clone $this->boundingBox;
$bb->maxY = $bb->minY + 0.5;
$bb->minY -= 1;
if(count($this->level->getCollisionBlocks($bb, true)) > 0){
$this->onGround = true;
}else{
$this->onGround = false;
}
}
$this->isCollided = $this->onGround;
}
protected function checkBlockCollision(){
foreach($this->getBlocksAround() as $block){
$block->onEntityCollide($this);
}
}
protected function checkNearEntities($tickDiff){
@ -1418,7 +1452,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}else{
if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and $this->getDataProperty(self::DATA_NO_AI) !== 1){
$expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks));
$diff = sqrt(abs($this->speed->y - $expectedVelocity));
$diff = ($this->speed->y - $expectedVelocity) ** 2;
if(!$this->hasEffect(Effect::JUMP) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){
if($this->inAirTicks < 100){
@ -1442,19 +1476,17 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->sendNextChunk();
}
if(count($this->moveToSend) > 0){
$pk = new MoveEntityPacket();
$pk->entities = $this->moveToSend;
$this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT));
$this->moveToSend = [];
if(count($this->moveToSend->entities) > 0){
$this->dataPacket($this->moveToSend);
$this->moveToSend->entities = [];
$this->moveToSend->isEncoded = false;
}
if(count($this->motionToSend) > 0){
$pk = new SetEntityMotionPacket();
$pk->entities = $this->motionToSend;
$this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT));
$this->motionToSend = [];
if(count($this->motionToSend->entities) > 0){
$this->dataPacket($this->motionToSend);
$this->motionToSend->entities = [];
$this->motionToSend->isEncoded = false;
}
if(count($this->batchedPackets) > 0){
@ -1496,7 +1528,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return;
}
if($packet->pid() === ProtocolInfo::BATCH_PACKET){
if($packet::NETWORK_ID === ProtocolInfo::BATCH_PACKET){
/** @var BatchPacket $packet */
$this->server->getNetwork()->processBatch($packet, $this);
return;
@ -1507,7 +1539,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return;
}
switch($packet->pid()){
switch($packet::NETWORK_ID){
case ProtocolInfo::LOGIN_PACKET:
if($this->loggedIn){
break;
@ -3097,7 +3129,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->resetFallDistance();
$this->orderChunks();
$this->nextChunkOrderRun = 0;
$this->newPosition = null;
}

View File

@ -1408,7 +1408,7 @@ class Server{
public function addOp($name){
$this->operators->set(strtolower($name), true);
if(($player = $this->getPlayerExact($name)) instanceof Player){
if(($player = $this->getPlayerExact($name)) !== null){
$player->recalculatePermissions();
}
$this->operators->save(true);
@ -1420,7 +1420,7 @@ class Server{
public function removeOp($name){
$this->operators->remove(strtolower($name));
if(($player = $this->getPlayerExact($name)) instanceof Player){
if(($player = $this->getPlayerExact($name)) !== null){
$player->recalculatePermissions();
}
$this->operators->save();

View File

@ -129,6 +129,9 @@ abstract class Entity extends Location implements Metadatable{
protected $lastDamageCause = null;
/** @var Block[] */
private $blocksAround = [];
public $lastX = null;
public $lastY = null;
public $lastZ = null;
@ -198,6 +201,7 @@ abstract class Entity extends Location implements Metadatable{
/** @var \pocketmine\event\TimingsHandler */
protected $timings;
protected $isPlayer = false;
public function __construct(FullChunk $chunk, Compound $nbt){
@ -207,6 +211,8 @@ abstract class Entity extends Location implements Metadatable{
$this->timings = Timings::getEntityTimings($this);
$this->isPlayer = $this instanceof Player;
$this->temporalVector = new Vector3();
if($this->eyeHeight === null){
@ -537,7 +543,7 @@ abstract class Entity extends Location implements Metadatable{
* @param array $data Properly formatted entity data, defaults to everything
*/
public function sendData($player, array $data = null){
if($player instanceof Player){
if(!is_array($player)){
$player = [$player];
}
@ -757,13 +763,13 @@ abstract class Entity extends Location implements Metadatable{
Timings::$timerEntityBaseTick->startTiming();
//TODO: check vehicles
$this->blocksAround = null;
$this->justCreated = false;
$isPlayer = $this instanceof Player;
if(!$this->isAlive()){
$this->removeAllEffects();
$this->despawnFromAll();
if(!$isPlayer){
if(!$this->isPlayer){
$this->close();
}
@ -844,12 +850,10 @@ abstract class Entity extends Location implements Metadatable{
$this->lastYaw = $this->yaw;
$this->lastPitch = $this->pitch;
if(!($this instanceof Player)){
foreach($this->hasSpawned as $player){
$player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw);
}
}
}
if($diffMotion > 0.0025 or ($diffMotion > 0.0001 and $this->getMotion()->lengthSquared() <= 0.0001)){ //0.05 ** 2
$this->lastMotionX = $this->motionX;
@ -859,12 +863,6 @@ abstract class Entity extends Location implements Metadatable{
foreach($this->hasSpawned as $player){
$player->addEntityMotion($this->id, $this->motionX, $this->motionY, $this->motionZ);
}
if($this instanceof Player){
$this->motionX = 0;
$this->motionY = 0;
$this->motionZ = 0;
}
}
}
@ -893,7 +891,7 @@ abstract class Entity extends Location implements Metadatable{
++$this->deadTicks;
if($this->deadTicks >= 10){
$this->despawnFromAll();
if(!($this instanceof Player)){
if(!$this->isPlayer){
$this->close();
}
}
@ -1076,11 +1074,9 @@ abstract class Entity extends Location implements Metadatable{
Timings::$entityMoveTimer->startTiming();
$axisalignedbb = clone $this->boundingBox;
$newBB = $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz);
$list = $this->level->getCollisionCubes($this, $newBB->grow(-0.01, -0.01, -0.01), false);
$list = $this->level->getCollisionCubes($this, $newBB, false);
if(count($list) === 0){
$this->boundingBox = $newBB;
@ -1119,7 +1115,7 @@ abstract class Entity extends Location implements Metadatable{
if($this->keepMovement){
$this->boundingBox->offset($dx, $dy, $dz);
$this->setPosition($this->temporalVector->setComponents(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2));
$this->onGround = $this instanceof Player ? true : false;
$this->onGround = $this->isPlayer ? true : false;
return true;
}else{
@ -1243,24 +1239,7 @@ abstract class Entity extends Location implements Metadatable{
$this->checkChunks();
if($this instanceof Player){
if(!$this->onGround or $movY != 0){
$bb = clone $this->boundingBox;
$bb->maxY = $bb->minY + 0.5;
$bb->minY -= 1;
if(count($this->level->getCollisionBlocks($bb)) > 0){
$this->onGround = true;
}else{
$this->onGround = false;
}
}
$this->isCollided = $this->onGround;
}else{
$this->isCollidedVertically = $movY != $dy;
$this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz);
$this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
$this->onGround = ($movY != $dy and $movY < 0);
}
$this->checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz);
$this->updateFallState($dy, $this->onGround);
if($movX != $dx){
@ -1284,32 +1263,48 @@ abstract class Entity extends Location implements Metadatable{
}
}
protected function checkBlockCollision(){
$minX = Math::floorFloat($this->boundingBox->minX + 0.001);
$minY = Math::floorFloat($this->boundingBox->minY + 0.001);
$minZ = Math::floorFloat($this->boundingBox->minZ + 0.001);
$maxX = Math::ceilFloat($this->boundingBox->maxX - 0.001);
$maxY = Math::ceilFloat($this->boundingBox->maxY - 0.001);
$maxZ = Math::ceilFloat($this->boundingBox->maxZ - 0.001);
protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){
$this->isCollidedVertically = $movY != $dy;
$this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz);
$this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically);
$this->onGround = ($movY != $dy and $movY < 0);
}
$vector = new Vector3(0, 0, 0);
$v = new Vector3(0, 0, 0);
public function getBlocksAround(){
if($this->blocksAround === null){
$minX = Math::floorFloat($this->boundingBox->minX);
$minY = Math::floorFloat($this->boundingBox->minY);
$minZ = Math::floorFloat($this->boundingBox->minZ);
$maxX = Math::ceilFloat($this->boundingBox->maxX);
$maxY = Math::ceilFloat($this->boundingBox->maxY);
$maxZ = Math::ceilFloat($this->boundingBox->maxZ);
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
for($v->y = $minY; $v->y <= $maxY; ++$v->y){
$block = $this->level->getBlock($v);
$this->blocksAround = [];
for($z = $minZ; $z <= $maxZ; ++$z){
for($x = $minX; $x <= $maxX; ++$x){
for($y = $minY; $y <= $maxY; ++$y){
$block = $this->level->getBlock($this->temporalVector->setComponents($x, $y, $z));
if($block->hasEntityCollision()){
$this->blocksAround[] = $block;
}
}
}
}
}
return $this->blocksAround;
}
protected function checkBlockCollision(){
$vector = new Vector3(0, 0, 0);
foreach($this->getBlocksAround() as $block){
$block->onEntityCollide($this);
if(!($this instanceof Player)){
$block->addVelocityToEntity($this, $vector);
}
}
}
}
}
if(!($this instanceof Player) and $vector->lengthSquared() > 0){
if($vector->lengthSquared() > 0){
$vector = $vector->normalize();
$d = 0.014;
$this->motionX += $vector->x * $d;
@ -1508,21 +1503,19 @@ abstract class Entity extends Location implements Metadatable{
* @param int $id
* @param int $type
* @param mixed $value
*
* @return bool
*/
public function setDataProperty($id, $type, $value){
if($this->getDataProperty($id) !== $value){
$this->dataProperties[$id] = [$type, $value];
$targets = $this->hasSpawned;
if($this instanceof Player){
if(!$this->spawned){
return;
}
$targets[] = $this;
$this->sendData($this->hasSpawned, [$id => $this->dataProperties[$id]]);
return true;
}
$this->sendData($targets, [$id => $this->dataProperties[$id]]);
}
return false;
}
/**

View File

@ -115,7 +115,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function getDrops(){
$drops = [];
if($this->inventory instanceof PlayerInventory){
if($this->inventory !== null){
foreach($this->inventory->getContents() as $item){
$drops[] = $item;
}
@ -128,7 +128,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
parent::saveNBT();
$this->namedtag->Inventory = new Enum("Inventory", []);
$this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
if($this->inventory instanceof PlayerInventory){
if($this->inventory !== null){
for($slot = 0; $slot < 9; ++$slot){
$hotbarSlot = $this->inventory->getHotbarSlotIndex($slot);
if($hotbarSlot !== -1){

View File

@ -76,10 +76,8 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{
* @param Player $player
*/
public function setPlayer(Player $player){
if($player instanceof Player){
$this->player = $player;
}
}
public function getFormat(){
return $this->format;

View File

@ -988,10 +988,11 @@ class Level implements ChunkManager, Metadatable{
/**
* @param AxisAlignedBB $bb
* @param bool $targetFirst
*
* @return Block[]
*/
public function getCollisionBlocks(AxisAlignedBB $bb){
public function getCollisionBlocks(AxisAlignedBB $bb, $targetFirst = false){
$minX = Math::floorFloat($bb->minX);
$minY = Math::floorFloat($bb->minY);
$minZ = Math::floorFloat($bb->minZ);
@ -1001,6 +1002,18 @@ class Level implements ChunkManager, Metadatable{
$collides = [];
if($targetFirst){
for($z = $minZ; $z <= $maxZ; ++$z){
for($x = $minX; $x <= $maxX; ++$x){
for($y = $minY; $y <= $maxY; ++$y){
$block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z));
if($block->getId() !== 0 and $block->collidesWithBB($bb)){
return [$block];
}
}
}
}
}else{
for($z = $minZ; $z <= $maxZ; ++$z){
for($x = $minX; $x <= $maxX; ++$x){
for($y = $minY; $y <= $maxY; ++$y){
@ -1011,6 +1024,8 @@ class Level implements ChunkManager, Metadatable{
}
}
}
}
return $collides;
}

View File

@ -220,7 +220,7 @@ class Network{
try{
while($offset < $len){
if(($pk = $this->getPacket(ord($str{$offset++}))) !== null){
if($pk->pid() === Info::BATCH_PACKET){
if($pk::NETWORK_ID === Info::BATCH_PACKET){
throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket");
}
$pk->setBuffer($str, $offset);

View File

@ -25,7 +25,6 @@ use pocketmine\event\player\PlayerCreationEvent;
use pocketmine\network\protocol\DataPacket;
use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\network\protocol\Info;
use pocketmine\network\protocol\UnknownPacket;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\MainLogger;
@ -136,9 +135,11 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
try{
if($packet->buffer !== ""){
$pk = $this->getPacket($packet->buffer);
if($pk !== null){
$pk->decode();
$this->players[$identifier]->handleDataPacket($pk);
}
}
}catch(\Exception $e){
if(\pocketmine\DEBUG > 1 and isset($pk)){
$logger = $this->server->getLogger();
@ -216,7 +217,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
$pk = $packet->__encapsulatedPacket;
}
if(!$immediate and !$needACK and $packet->pid() !== ProtocolInfo::BATCH_PACKET
if(!$immediate and !$needACK and $packet::NETWORK_ID !== ProtocolInfo::BATCH_PACKET
and Network::$BATCH_THRESHOLD >= 0
and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD){
$this->server->batchPackets([$player], [$packet], true, $packet->getChannel());
@ -251,8 +252,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{
$pid = ord($buffer{0});
if(($data = $this->network->getPacket($pid)) === null){
$data = new UnknownPacket();
$data->packetID = $pid;
return null;
}
$data->setBuffer($buffer, 1);

View File

@ -29,8 +29,7 @@ use pocketmine\utils\Binary;
#endif
class AddEntityPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::ADD_ENTITY_PACKET;
public $eid;
public $type;
@ -45,10 +44,6 @@ class AddEntityPacket extends DataPacket{
public $metadata;
public $links = [];
public function pid(){
return Info::ADD_ENTITY_PACKET;
}
public function decode(){
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class AddItemEntityPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::ADD_ITEM_ENTITY_PACKET;
public $eid;
public $item;
@ -37,10 +36,6 @@ class AddItemEntityPacket extends DataPacket{
public $speedY;
public $speedZ;
public function pid(){
return Info::ADD_ITEM_ENTITY_PACKET;
}
public function decode(){
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class AddPaintingPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::ADD_PAINTING_PACKET;
public $eid;
public $x;
@ -35,10 +34,6 @@ class AddPaintingPacket extends DataPacket{
public $direction;
public $title;
public function pid(){
return Info::ADD_PAINTING_PACKET;
}
public function decode(){
}

View File

@ -29,10 +29,7 @@ use pocketmine\utils\Binary;
#endif
class AddPlayerPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::ADD_PLAYER_PACKET;
public $clientID;
public $username;
@ -52,10 +49,6 @@ class AddPlayerPacket extends DataPacket{
public $slim = false;
public $skin = null;
public function pid(){
return Info::ADD_PLAYER_PACKET;
}
public function decode(){
}

View File

@ -25,15 +25,10 @@ namespace pocketmine\network\protocol;
class AdventureSettingsPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::ADVENTURE_SETTINGS_PACKET;
public $flags;
public function pid(){
return Info::ADVENTURE_SETTINGS_PACKET;
}
public function decode(){
}

View File

@ -25,16 +25,11 @@ namespace pocketmine\network\protocol;
class AnimatePacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::ANIMATE_PACKET;
public $action;
public $eid;
public function pid(){
return Info::ANIMATE_PACKET;
}
public function decode(){
$this->action = $this->getByte();
$this->eid = $this->getLong();

View File

@ -25,15 +25,10 @@ namespace pocketmine\network\protocol;
class BatchPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::BATCH_PACKET;
public $payload;
public function pid(){
return Info::BATCH_PACKET;
}
public function decode(){
$size = $this->getInt();
$this->payload = $this->get($size);

View File

@ -25,15 +25,10 @@ namespace pocketmine\network\protocol;
class ContainerClosePacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::CONTAINER_CLOSE_PACKET;
public $windowid;
public function pid(){
return Info::CONTAINER_CLOSE_PACKET;
}
public function decode(){
$this->windowid = $this->getByte();
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class ContainerOpenPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::CONTAINER_OPEN_PACKET;
public $windowid;
public $type;
@ -35,10 +34,6 @@ class ContainerOpenPacket extends DataPacket{
public $y;
public $z;
public function pid(){
return Info::CONTAINER_OPEN_PACKET;
}
public function decode(){
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class ContainerSetContentPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::CONTAINER_SET_CONTENT_PACKET;
const SPECIAL_INVENTORY = 0;
const SPECIAL_ARMOR = 0x78;
@ -37,10 +36,6 @@ class ContainerSetContentPacket extends DataPacket{
public $slots = [];
public $hotbar = [];
public function pid(){
return Info::CONTAINER_SET_CONTENT_PACKET;
}
public function clean(){
$this->slots = [];
$this->hotbar = [];

View File

@ -25,17 +25,12 @@ namespace pocketmine\network\protocol;
class ContainerSetDataPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::CONTAINER_SET_DATA_PACKET;
public $windowid;
public $property;
public $value;
public function pid(){
return Info::CONTAINER_SET_DATA_PACKET;
}
public function decode(){
}

View File

@ -26,18 +26,13 @@ namespace pocketmine\network\protocol;
use pocketmine\item\Item;
class ContainerSetSlotPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::CONTAINER_SET_SLOT_PACKET;
public $windowid;
public $slot;
/** @var Item */
public $item;
public function pid(){
return Info::CONTAINER_SET_SLOT_PACKET;
}
public function decode(){
$this->windowid = $this->getByte();
$this->slot = $this->getShort();

View File

@ -32,19 +32,23 @@ use pocketmine\item\Item;
abstract class DataPacket extends \stdClass{
private $offset = 0;
const NETWORK_ID = 0;
public $offset = 0;
public $buffer = "";
public $isEncoded = false;
private $channel = 0;
abstract public function pid();
public function pid(){
return $this::NETWORK_ID;
}
abstract public function encode();
abstract public function decode();
protected function reset(){
$this->buffer = chr($this->pid());
$this->buffer = chr($this::NETWORK_ID);
$this->offset = 0;
}

View File

@ -25,15 +25,10 @@ namespace pocketmine\network\protocol;
class DisconnectPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::DISCONNECT_PACKET;
public $message;
public function pid(){
return Info::DISCONNECT_PACKET;
}
public function decode(){
$this->message = $this->getString();
}

View File

@ -25,17 +25,12 @@ namespace pocketmine\network\protocol;
class DropItemPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::DROP_ITEM_PACKET;
public $eid;
public $unknown;
public $item;
public function pid(){
return Info::DROP_ITEM_PACKET;
}
public function decode(){
$this->eid = $this->getLong();
$this->unknown = $this->getByte();

View File

@ -25,6 +25,7 @@ namespace pocketmine\network\protocol;
class EntityEventPacket extends DataPacket{
const NETWORK_ID = Info::ENTITY_EVENT_PACKET;
const HURT_ANIMATION = 2;
const DEATH_ANIMATION = 3;
@ -42,16 +43,9 @@ class EntityEventPacket extends DataPacket{
const AMBIENT_SOUND = 16;
const RESPAWN = 17;
public static $pool = [];
public static $next = 0;
public $eid;
public $event;
public function pid(){
return Info::ENTITY_EVENT_PACKET;
}
public function decode(){
$this->eid = $this->getLong();
$this->event = $this->getByte();

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class ExplodePacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::EXPLODE_PACKET;
public $x;
public $y;
@ -34,10 +33,6 @@ class ExplodePacket extends DataPacket{
public $radius;
public $records = [];
public function pid(){
return Info::EXPLODE_PACKET;
}
public function clean(){
$this->records = [];
return parent::clean();

View File

@ -25,17 +25,12 @@ namespace pocketmine\network\protocol;
class FullChunkDataPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::FULL_CHUNK_DATA_PACKET;
public $chunkX;
public $chunkZ;
public $data;
public function pid(){
return Info::FULL_CHUNK_DATA_PACKET;
}
public function decode(){
}

View File

@ -25,15 +25,10 @@ namespace pocketmine\network\protocol;
class HurtArmorPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::HURT_ARMOR_PACKET;
public $health;
public function pid(){
return Info::HURT_ARMOR_PACKET;
}
public function decode(){
}

View File

@ -25,17 +25,12 @@ namespace pocketmine\network\protocol;
class InteractPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::INTERACT_PACKET;
public $action;
public $eid;
public $target;
public function pid(){
return Info::INTERACT_PACKET;
}
public function decode(){
$this->action = $this->getByte();
$this->target = $this->getLong();

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class LevelEventPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::LEVEL_EVENT_PACKET;
public $evid;
public $x;
@ -34,10 +33,6 @@ class LevelEventPacket extends DataPacket{
public $z;
public $data;
public function pid(){
return Info::LEVEL_EVENT_PACKET;
}
public function decode(){
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class LoginPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::LOGIN_PACKET;
public $username;
public $protocol1;
@ -36,10 +35,6 @@ class LoginPacket extends DataPacket{
public $slim = false;
public $skin = null;
public function pid(){
return Info::LOGIN_PACKET;
}
public function decode(){
$this->username = $this->getString();
$this->protocol1 = $this->getInt();

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class MobEffectPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::MOB_EFFECT_PACKET;
const EVENT_ADD = 1;
const EVENT_MODIFY = 2;
@ -39,10 +38,6 @@ class MobEffectPacket extends DataPacket{
public $particles = true;
public $duration;
public function pid(){
return Info::MOB_EFFECT_PACKET;
}
public function decode(){
}

View File

@ -25,18 +25,13 @@ namespace pocketmine\network\protocol;
class MoveEntityPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::MOVE_ENTITY_PACKET;
// eid, x, y, z, yaw, pitch
/** @var array[] */
public $entities = [];
public function pid(){
return Info::MOVE_ENTITY_PACKET;
}
public function clean(){
$this->entities = [];
return parent::clean();

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class MovePlayerPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::MOVE_PLAYER_PACKET;
public $eid;
public $x;
@ -38,10 +37,6 @@ class MovePlayerPacket extends DataPacket{
public $mode = 0;
public $onGround;
public function pid(){
return Info::MOVE_PLAYER_PACKET;
}
public function clean(){
$this->teleport = false;
return parent::clean();

View File

@ -25,21 +25,15 @@ namespace pocketmine\network\protocol;
class PlayStatusPacket extends DataPacket{
const NETWORK_ID = Info::PLAY_STATUS_PACKET;
const LOGIN_SUCCESS = 0;
const LOGIN_FAILED_CLIENT = 1;
const LOGIN_FAILED_SERVER = 2;
const PLAYER_SPAWN = 3;
public static $pool = [];
public static $next = 0;
public $status;
public function pid(){
return Info::PLAY_STATUS_PACKET;
}
public function decode(){
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class PlayerActionPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::PLAYER_ACTION_PACKET;
public $eid;
public $action;
@ -35,10 +34,6 @@ class PlayerActionPacket extends DataPacket{
public $z;
public $face;
public function pid(){
return Info::PLAYER_ACTION_PACKET;
}
public function decode(){
$this->eid = $this->getLong();
$this->action = $this->getInt();

View File

@ -25,16 +25,11 @@ namespace pocketmine\network\protocol;
class PlayerArmorEquipmentPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::PLAYER_ARMOR_EQUIPMENT_PACKET;
public $eid;
public $slots = [];
public function pid(){
return Info::PLAYER_ARMOR_EQUIPMENT_PACKET;
}
public function decode(){
$this->eid = $this->getLong();
$this->slots[0] = $this->getByte();

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class PlayerEquipmentPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::PLAYER_EQUIPMENT_PACKET;
public $eid;
public $item;
@ -34,10 +33,6 @@ class PlayerEquipmentPacket extends DataPacket{
public $slot;
public $selectedSlot;
public function pid(){
return Info::PLAYER_EQUIPMENT_PACKET;
}
public function decode(){
$this->eid = $this->getLong();
$this->item = $this->getShort();

View File

@ -25,18 +25,13 @@ namespace pocketmine\network\protocol;
class RemoveBlockPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::REMOVE_BLOCK_PACKET;
public $eid;
public $x;
public $y;
public $z;
public function pid(){
return Info::REMOVE_BLOCK_PACKET;
}
public function decode(){
$this->eid = $this->getLong();
$this->x = $this->getInt();

View File

@ -25,15 +25,10 @@ namespace pocketmine\network\protocol;
class RemoveEntityPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::REMOVE_ENTITY_PACKET;
public $eid;
public function pid(){
return Info::REMOVE_ENTITY_PACKET;
}
public function decode(){
}

View File

@ -25,16 +25,11 @@ namespace pocketmine\network\protocol;
class RemovePlayerPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::REMOVE_PLAYER_PACKET;
public $eid;
public $clientID;
public function pid(){
return Info::REMOVE_PLAYER_PACKET;
}
public function decode(){
}

View File

@ -25,17 +25,12 @@ namespace pocketmine\network\protocol;
class RespawnPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::RESPAWN_PACKET;
public $x;
public $y;
public $z;
public function pid(){
return Info::RESPAWN_PACKET;
}
public function decode(){
$this->x = $this->getFloat();
$this->y = $this->getFloat();

View File

@ -25,15 +25,10 @@ namespace pocketmine\network\protocol;
class SetDifficultyPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::SET_DIFFICULTY_PACKET;
public $difficulty;
public function pid(){
return Info::SET_DIFFICULTY_PACKET;
}
public function decode(){
$this->difficulty = $this->getInt();
}

View File

@ -29,16 +29,11 @@ use pocketmine\utils\Binary;
#endif
class SetEntityDataPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::SET_ENTITY_DATA_PACKET;
public $eid;
public $metadata;
public function pid(){
return Info::SET_ENTITY_DATA_PACKET;
}
public function decode(){
}

View File

@ -25,17 +25,12 @@ namespace pocketmine\network\protocol;
class SetEntityLinkPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::SET_ENTITY_LINK_PACKET;
public $from;
public $to;
public $type;
public function pid(){
return Info::SET_ENTITY_LINK_PACKET;
}
public function decode(){
}

View File

@ -25,18 +25,13 @@ namespace pocketmine\network\protocol;
class SetEntityMotionPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::SET_ENTITY_MOTION_PACKET;
// eid, motX, motY, motZ
/** @var array[] */
public $entities = [];
public function pid(){
return Info::SET_ENTITY_MOTION_PACKET;
}
public function clean(){
$this->entities = [];
return parent::clean();

View File

@ -25,15 +25,10 @@ namespace pocketmine\network\protocol;
class SetHealthPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::SET_HEALTH_PACKET;
public $health;
public function pid(){
return Info::SET_HEALTH_PACKET;
}
public function decode(){
$this->health = $this->getInt();
}

View File

@ -25,17 +25,12 @@ namespace pocketmine\network\protocol;
class SetSpawnPositionPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::SET_SPAWN_POSITION_PACKET;
public $x;
public $z;
public $y;
public function pid(){
return Info::SET_SPAWN_POSITION_PACKET;
}
public function decode(){
}

View File

@ -27,16 +27,11 @@ namespace pocketmine\network\protocol;
use pocketmine\level\Level;
class SetTimePacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::SET_TIME_PACKET;
public $time;
public $started = true;
public function pid(){
return Info::SET_TIME_PACKET;
}
public function decode(){
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class StartGamePacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::START_GAME_PACKET;
public $seed;
public $generator;
@ -39,10 +38,6 @@ class StartGamePacket extends DataPacket{
public $y;
public $z;
public function pid(){
return Info::START_GAME_PACKET;
}
public function decode(){
}

View File

@ -25,16 +25,11 @@ namespace pocketmine\network\protocol;
class TakeItemEntityPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::TAKE_ITEM_ENTITY_PACKET;
public $target;
public $eid;
public function pid(){
return Info::TAKE_ITEM_ENTITY_PACKET;
}
public function decode(){
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class TextPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::TEXT_PACKET;
const TYPE_RAW = 0;
const TYPE_CHAT = 1;
@ -39,10 +38,6 @@ class TextPacket extends DataPacket{
public $message;
public $parameters = [];
public function pid(){
return Info::TEXT_PACKET;
}
public function decode(){
$this->type = $this->getByte();
switch($this->type){

View File

@ -25,18 +25,13 @@ namespace pocketmine\network\protocol;
class TileEntityDataPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::TILE_ENTITY_DATA_PACKET;
public $x;
public $y;
public $z;
public $namedtag;
public function pid(){
return Info::TILE_ENTITY_DATA_PACKET;
}
public function decode(){
$this->x = $this->getInt();
$this->y = $this->getByte();

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class TileEventPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::TILE_EVENT_PACKET;
public $x;
public $y;
@ -34,10 +33,6 @@ class TileEventPacket extends DataPacket{
public $case1;
public $case2;
public function pid(){
return Info::TILE_EVENT_PACKET;
}
public function decode(){
}

View File

@ -1,46 +0,0 @@
<?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\network\protocol;
#include <rules/DataPacket.h>
class UnknownPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
public $packetID = -1;
public function pid(){
return $this->packetID;
}
public function decode(){
}
public function encode(){
}
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class UpdateBlockPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::UPDATE_BLOCK_PACKET;
const FLAG_NONE = 0b0000;
const FLAG_NEIGHBORS = 0b0001;
@ -39,10 +38,6 @@ class UpdateBlockPacket extends DataPacket{
public $records = []; //x, z, y, blockId, blockData, flags
public function pid(){
return Info::UPDATE_BLOCK_PACKET;
}
public function decode(){
}

View File

@ -25,8 +25,7 @@ namespace pocketmine\network\protocol;
class UseItemPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
const NETWORK_ID = Info::USE_ITEM_PACKET;
public $x;
public $y;
@ -42,10 +41,6 @@ class UseItemPacket extends DataPacket{
public $posY;
public $posZ;
public function pid(){
return Info::USE_ITEM_PACKET;
}
public function decode(){
$this->x = $this->getInt();
$this->y = $this->getInt();

@ -1 +1 @@
Subproject commit 675c7b0c98645c1c63505bcb94e8556412124e67
Subproject commit 88c47ff3eca89dd369c9a4d575d40a777bda4ac8

@ -1 +1 @@
Subproject commit 0bea1c5d4003a3d0a8a38a9c2192bf9dcfc26f46
Subproject commit d59c0f673455f02b2620853f3fa6290d63ffd960