From 4a5ff32d2ebe6a3c8365dcb0eb041d12cd329b2d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 11 Jul 2018 19:45:48 +0100 Subject: [PATCH] hacks for NPC and floating text I didn't think mojang could break this fucking game any worse --- src/pocketmine/entity/Human.php | 15 +++++++++++- .../level/particle/FloatingTextParticle.php | 23 +++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index a58d64ac1..1873c08a6 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -49,7 +49,9 @@ use pocketmine\network\mcpe\protocol\AddPlayerPacket; use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; +use pocketmine\network\mcpe\protocol\PlayerListPacket; use pocketmine\network\mcpe\protocol\PlayerSkinPacket; +use pocketmine\network\mcpe\protocol\types\PlayerListEntry; use pocketmine\Player; use pocketmine\utils\UUID; @@ -798,6 +800,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ throw new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set"); } + if(!($this instanceof Player)){ + /* we don't use Server->updatePlayerListData() because that uses batches, which could cause race conditions in async compression mode */ + $pk = new PlayerListPacket(); + $pk->type = PlayerListPacket::TYPE_ADD; + $pk->entries = [PlayerListEntry::createAdditionEntry($this->uuid, $this->id, $this->getName(), $this->getName(), 0, $this->skin)]; + $player->dataPacket($pk); + } + $pk = new AddPlayerPacket(); $pk->uuid = $this->getUniqueId(); $pk->username = $this->getName(); @@ -816,7 +826,10 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $this->armorInventory->sendContents($player); if(!($this instanceof Player)){ - $this->sendSkin([$player]); + $pk = new PlayerListPacket(); + $pk->type = PlayerListPacket::TYPE_REMOVE; + $pk->entries = [PlayerListEntry::createRemovalEntry($this->uuid)]; + $player->dataPacket($pk); } } diff --git a/src/pocketmine/level/particle/FloatingTextParticle.php b/src/pocketmine/level/particle/FloatingTextParticle.php index f9e460388..f393d22eb 100644 --- a/src/pocketmine/level/particle/FloatingTextParticle.php +++ b/src/pocketmine/level/particle/FloatingTextParticle.php @@ -29,8 +29,9 @@ use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\AddPlayerPacket; -use pocketmine\network\mcpe\protocol\PlayerSkinPacket; +use pocketmine\network\mcpe\protocol\PlayerListPacket; use pocketmine\network\mcpe\protocol\RemoveEntityPacket; +use pocketmine\network\mcpe\protocol\types\PlayerListEntry; use pocketmine\utils\UUID; class FloatingTextParticle extends Particle{ @@ -89,9 +90,17 @@ class FloatingTextParticle extends Particle{ } if(!$this->invisible){ + $uuid = UUID::fromRandom(); + $name = $this->title . ($this->text !== "" ? "\n" . $this->text : ""); + + $add = new PlayerListPacket(); + $add->type = PlayerListPacket::TYPE_ADD; + $add->entries = [PlayerListEntry::createAdditionEntry($uuid, $this->entityId, $name, $name, 0, new Skin("Standard_Custom", str_repeat("\x00", 8192)))]; + $p[] = $add; + $pk = new AddPlayerPacket(); - $pk->uuid = $uuid = UUID::fromRandom(); - $pk->username = $this->title . ($this->text !== "" ? "\n" . $this->text : ""); + $pk->uuid = $uuid; + $pk->username = $name; $pk->entityRuntimeId = $this->entityId; $pk->position = $this->asVector3(); //TODO: check offset $pk->item = ItemFactory::get(Item::AIR, 0, 0); @@ -106,10 +115,10 @@ class FloatingTextParticle extends Particle{ $p[] = $pk; - $skinPk = new PlayerSkinPacket(); - $skinPk->uuid = $uuid; - $skinPk->skin = new Skin("Standard_Custom", str_repeat("\x00", 8192)); - $p[] = $skinPk; + $remove = new PlayerListPacket(); + $remove->type = PlayerListPacket::TYPE_REMOVE; + $remove->entries = [PlayerListEntry::createRemovalEntry($uuid)]; + $p[] = $remove; } return $p;