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

@ -77,7 +77,24 @@ abstract class Spawnable extends Tile{
/**
* @return CompoundTag
*/
abstract public function getSpawnCompound() : CompoundTag;
final public function getSpawnCompound() : CompoundTag{
$nbt = new CompoundTag("", [
$this->namedtag->id,
$this->namedtag->x,
$this->namedtag->y,
$this->namedtag->z
]);
$this->addAdditionalSpawnData($nbt);
return $nbt;
}
/**
* An extension to getSpawnCompound() for
* further modifying the generic tile NBT.
*
* @param CompoundTag $nbt
*/
abstract public function addAdditionalSpawnData(CompoundTag $nbt);
/**
* Called when a player updates a block entity's NBT data