Tile: Improved Nameable and NameableTrait to cut down code duplication

This commit is contained in:
Dylan K. Taylor
2018-06-02 15:17:32 +01:00
parent b6b0bbde18
commit 1bb0337420
6 changed files with 38 additions and 50 deletions

View File

@ -23,11 +23,6 @@ declare(strict_types=1);
namespace pocketmine\tile;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\Player;
class EnchantTable extends Spawnable implements Nameable{
use NameableTrait;
@ -37,16 +32,4 @@ class EnchantTable extends Spawnable implements Nameable{
public function getDefaultName() : string{
return "Enchanting Table";
}
public function addAdditionalSpawnData(CompoundTag $nbt) : void{
if($this->hasName()){
$nbt->setTag($this->namedtag->getTag("CustomName"));
}
}
protected static function createAdditionalNBT(CompoundTag $nbt, Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : void{
if($item !== null and $item->hasCustomName()){
$nbt->setString("CustomName", $item->getCustomName());
}
}
}