From df8e1e87024f3f70ee91d15d936fe48dbda08ec9 Mon Sep 17 00:00:00 2001 From: Intyre Date: Wed, 22 Jun 2016 00:08:52 +0200 Subject: [PATCH] Spawn unleashed, movement fixed and some Player DataProperty cleanup --- src/pocketmine/Player.php | 9 ++-- src/pocketmine/PocketMine.php | 2 +- src/pocketmine/entity/Entity.php | 14 ++++--- src/pocketmine/entity/Human.php | 2 +- src/pocketmine/level/Level.php | 14 +++++-- .../network/protocol/MoveEntityPacket.php | 41 ++++++++++--------- 6 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b6361213e2..53cbfa520b 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1207,9 +1207,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return []; } - public function setDataProperty($id, $type, $value){ - if(parent::setDataProperty($id, $type, $value)){ - $this->sendData($this, [$id => $this->dataProperties[$id]]); + public function setDataProperty($id, $type, $value, $send = true){ + if(parent::setDataProperty($id, $type, $value, $send)){ return true; } @@ -1618,7 +1617,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } } } - $this->setNameTag($this->username); $nbt = $this->server->getOfflinePlayerData($this->username); $this->playedBefore = ($nbt["lastPlayed"] - $nbt["firstPlayed"]) > 1; // microtime(true) - microtime(true) may have less than one millisecond difference @@ -1793,6 +1791,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->username = TextFormat::clean($packet->username); $this->displayName = $this->username; $this->iusername = strtolower($this->username); + $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false); if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ break; @@ -2204,7 +2203,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->setSneaking(false); $this->extinguish(); - $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300); + $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300, false); $this->deadTicks = 0; $this->noDamageTicks = 60; diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index b7bb32462b..634a2876c4 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -74,7 +74,7 @@ namespace pocketmine { const VERSION = "1.6dev"; const API_VERSION = "2.0.0"; - const CODENAME = "[REDACTED]"; + const CODENAME = "Unleashed"; const MINECRAFT_VERSION = "v0.15.0.0 alpha"; const MINECRAFT_VERSION_NETWORK = "0.15.0.0"; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index f80fe5bd2e..57d6f90cb3 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -73,8 +73,7 @@ abstract class Entity extends Location implements Metadatable{ const DATA_TYPE_STRING = 4; const DATA_TYPE_SLOT = 5; const DATA_TYPE_POS = 6; - const DATA_TYPE_ROTATION = 7; - const DATA_TYPE_LONG = 8; + const DATA_TYPE_LONG = 7; const DATA_FLAGS = 0; const DATA_AIR = 1; @@ -84,6 +83,7 @@ abstract class Entity extends Location implements Metadatable{ const DATA_POTION_COLOR = 7; const DATA_POTION_AMBIENT = 8; const DATA_NO_AI = 15; + const DATA_LINKED_EID = 23; const DATA_FLAG_ONFIRE = 0; @@ -117,6 +117,7 @@ abstract class Entity extends Location implements Metadatable{ self::DATA_SHOW_NAMETAG => [self::DATA_TYPE_BYTE, 1], self::DATA_SILENT => [self::DATA_TYPE_BYTE, 0], self::DATA_NO_AI => [self::DATA_TYPE_BYTE, 0], + self::DATA_LINKED_EID => [self::DATA_TYPE_LONG, -1], ]; public $passenger = null; @@ -254,7 +255,7 @@ abstract class Entity extends Location implements Metadatable{ if(!isset($this->namedtag->Air)){ $this->namedtag->Air = new ShortTag("Air", 300); } - $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"]); + $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"], false); if(!isset($this->namedtag->OnGround)){ $this->namedtag->OnGround = new ByteTag("OnGround", 0); @@ -1529,11 +1530,12 @@ abstract class Entity extends Location implements Metadatable{ * * @return bool */ - public function setDataProperty($id, $type, $value){ + public function setDataProperty($id, $type, $value, $send = true){ if($this->getDataProperty($id) !== $value){ $this->dataProperties[$id] = [$type, $value]; - - $this->sendData($this->hasSpawned, [$id => $this->dataProperties[$id]]); + if($send === true) { + $this->sendData($this->hasSpawned, [$id => $this->dataProperties[$id]]); + } return true; } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 7005a8d3d9..a33699d460 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -254,7 +254,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ protected function initEntity(){ $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false); - $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0]); + $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0], false); $this->inventory = new PlayerInventory($this); if($this instanceof Player){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 93e2300932..9f229452e6 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -715,9 +715,17 @@ class Level implements ChunkManager, Metadatable{ foreach($this->moveToSend as $index => $entry){ Level::getXZ($index, $chunkX, $chunkZ); - $pk = new MoveEntityPacket(); - $pk->entities = $entry; - $this->addChunkPacket($chunkX, $chunkZ, $pk); + foreach($entry as $e) { + $pk = new MoveEntityPacket(); + $pk->eid = $e[0]; + $pk->x = $e[1]; + $pk->y = $e[2]; + $pk->z = $e[3]; + $pk->yaw = $e[4]; + $pk->headYaw = $e[5]; + $pk->pitch = $e[6]; + $this->addChunkPacket($chunkX, $chunkZ, $pk); + } } $this->moveToSend = []; diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/protocol/MoveEntityPacket.php index 81a8afb83a..82eb8c65ee 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/protocol/MoveEntityPacket.php @@ -27,32 +27,33 @@ namespace pocketmine\network\protocol; class MoveEntityPacket extends DataPacket{ const NETWORK_ID = Info::MOVE_ENTITY_PACKET; - - // eid, x, y, z, yaw, pitch - /** @var array[] */ - public $entities = []; - - public function clean(){ - $this->entities = []; - return parent::clean(); - } + public $eid; + public $x; + public $y; + public $z; + public $yaw; + public $headYaw; + public $pitch; public function decode(){ - + $this->eid = $this->getLong(); + $this->x = $this->getFloat(); + $this->y = $this->getFloat(); + $this->z = $this->getFloat(); + $this->pitch = $this->getByte()*(360.0/256); + $this->yaw = $this->getByte()*(360.0/256); + $this->headYaw = $this->getByte()*(360.0/256); } public function encode(){ $this->reset(); - $this->putInt(count($this->entities)); - foreach($this->entities as $d){ - $this->putLong($d[0]); //eid - $this->putFloat($d[1]); //x - $this->putFloat($d[2]); //y - $this->putFloat($d[3]); //z - $this->putFloat($d[4]); //yaw - $this->putFloat($d[5]); //headYaw - $this->putFloat($d[6]); //pitch - } + $this->putLong($this->eid); + $this->putFloat($this->x); + $this->putFloat($this->y); + $this->putFloat($this->z); + $this->putByte($this->pitch/(360.0/256)); + $this->putByte($this->yaw/(360.0/256)); + $this->putByte($this->headYaw/(360.0/256)); } }