From 70a7c4c55255d4a1bad10edac37e15ddecf96d95 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 18 May 2015 19:04:37 +0200 Subject: [PATCH] Added nametag saving --- src/pocketmine/entity/Entity.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index dbaebaf4e..0615a0e30 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -268,6 +268,13 @@ abstract class Entity extends Location implements Metadatable{ return $this->getDataProperty(self::DATA_NAMETAG); } + /** + * @return bool + */ + public function isNameTagVisible(){ + return $this->getDataProperty(self::DATA_SHOW_NAMETAG) > 0; + } + /** * @param string $name */ @@ -275,6 +282,13 @@ abstract class Entity extends Location implements Metadatable{ $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $name); } + /** + * @param bool $value + */ + public function setNameTagVisible($value = true){ + $this->setDataProperty(self::DATA_SHOW_NAMETAG, self::DATA_TYPE_BYTE, $value ? 1 : 0); + } + /** * @return Effect[] */ @@ -406,6 +420,8 @@ abstract class Entity extends Location implements Metadatable{ public function saveNBT(){ if(!($this instanceof Player)){ $this->namedtag->id = new String("id", $this->getSaveId()); + $this->namedtag->CustomName = new String("CustomName", $this->getNameTag()); + $this->namedtag->CustomNameVisible = new String("CustomNameVisible", $this->isNameTagVisible()); } $this->namedtag->Pos = new Enum("Pos", [ @@ -463,6 +479,12 @@ abstract class Entity extends Location implements Metadatable{ } } + + if(isset($this->namedtag->CustomName)){ + $this->setNameTag($this->namedtag["CustomName"]); + $this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0); + } + $this->scheduleUpdate(); }