Tile NBT usage enhancements (#1259)

* Do not create new NBT objects on Tile::getSpawnCompound()

* PocketMine's string formatting

* Remove more useless array indices and create lesser new NBT objects.

* Remove unused imports and type-hint Sign::setText() params

* Do not mess with Sign::setText() params due to #1204

* Fix formatting

* Make getSpawnCompound() final and add abstract addAdditionalSpawnData()

* Make the same changes for Bed tile

* Fix a missing "->" and remove some unneeded int casting.
This commit is contained in:
Muqsit Rayyan
2017-08-06 17:05:37 +05:30
committed by Dylan K. Taylor
parent 3fdbcee10f
commit 7d3fca83f0
11 changed files with 107 additions and 165 deletions

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\tile;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
class EnchantTable extends Spawnable implements Nameable{
@ -47,18 +46,9 @@ class EnchantTable extends Spawnable implements Nameable{
$this->namedtag->CustomName = new StringTag("CustomName", $str);
}
public function getSpawnCompound() : CompoundTag{
$c = new CompoundTag("", [
new StringTag("id", Tile::ENCHANT_TABLE),
new IntTag("x", (int) $this->x),
new IntTag("y", (int) $this->y),
new IntTag("z", (int) $this->z)
]);
public function addAdditionalSpawnData(CompoundTag $nbt){
if($this->hasName()){
$c->CustomName = $this->namedtag->CustomName;
$nbt->CustomName = $this->namedtag->CustomName;
}
return $c;
}
}