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

@ -28,8 +28,6 @@ use pocketmine\level\Level;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
class ItemFrame extends Spawnable{
@ -71,7 +69,7 @@ class ItemFrame extends Spawnable{
}
public function setItemRotation(int $rotation){
$this->namedtag->ItemRotation = new ByteTag("ItemRotation", $rotation);
$this->namedtag->ItemRotation->setValue($rotation);
$this->onChanged();
}
@ -80,23 +78,17 @@ class ItemFrame extends Spawnable{
}
public function setItemDropChance(float $chance){
$this->namedtag->ItemDropChance = new FloatTag("ItemDropChance", $chance);
$this->namedtag->ItemDropChance->setValue($chance);
$this->onChanged();
}
public function getSpawnCompound() : CompoundTag{
$tag = new CompoundTag("", [
new StringTag("id", Tile::ITEM_FRAME),
new IntTag("x", (int) $this->x),
new IntTag("y", (int) $this->y),
new IntTag("z", (int) $this->z),
$this->namedtag->ItemDropChance,
$this->namedtag->ItemRotation,
]);
public function addAdditionalSpawnData(CompoundTag $nbt){
$nbt->ItemDropChance = $this->namedtag->ItemDropChance;
$nbt->ItemRotation = $this->namedtag->ItemRotation;
if($this->hasItem()){
$tag->Item = $this->namedtag->Item;
$nbt->Item = $this->namedtag->Item;
}
return $tag;
}
}