mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
Tiles no longer store their NBT at runtime
This is a significant breaking change for anything utilizing Tiles as they now do not store their NBT at runtime anymore. This is another step in the process of ridding PocketMine-MP of runtime NBT. It can be noticed that all tiles are now using class fields to store properties instead of NBT, which is much faster, uses less memory and is also more concise when written in code. Highlights: - Tile->namedtag has been removed. - Tile->saveNBT() now accepts a CompoundTag() parameter. Typically it's expected that this will be fed a newly-created CompoundTag (this part may be improved in the future). - New internal methods Tile->readSaveData() and Tile->writeSaveData() have been added. Instead of overriding __construct() and saveNBT() to load and save properties from NBT, you should now implement these methods instead. This is not final and will see further changes before it's done.
This commit is contained in:
parent
a22e5616f6
commit
fa21cd96c5
@ -456,8 +456,8 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
$tiles = [];
|
$tiles = [];
|
||||||
foreach($chunk->getTiles() as $tile){
|
foreach($chunk->getTiles() as $tile){
|
||||||
if(!$tile->isClosed()){
|
if(!$tile->isClosed()){
|
||||||
$tile->saveNBT();
|
$tile->saveNBT($tileTag = new CompoundTag());
|
||||||
$tiles[] = $tile->namedtag;
|
$tiles[] = $tileTag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->writeTags($tiles, $index . self::TAG_BLOCK_ENTITY);
|
$this->writeTags($tiles, $index . self::TAG_BLOCK_ENTITY);
|
||||||
|
@ -75,8 +75,8 @@ class Anvil extends McRegion{
|
|||||||
|
|
||||||
$tiles = [];
|
$tiles = [];
|
||||||
foreach($chunk->getTiles() as $tile){
|
foreach($chunk->getTiles() as $tile){
|
||||||
$tile->saveNBT();
|
$tile->saveNBT($tileTag = new CompoundTag());
|
||||||
$tiles[] = $tile->namedtag;
|
$tiles[] = $tileTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
|
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
|
||||||
|
@ -94,8 +94,8 @@ class McRegion extends BaseLevelProvider{
|
|||||||
|
|
||||||
$tiles = [];
|
$tiles = [];
|
||||||
foreach($chunk->getTiles() as $tile){
|
foreach($chunk->getTiles() as $tile){
|
||||||
$tile->saveNBT();
|
$tile->saveNBT($tileTag = new CompoundTag());
|
||||||
$tiles[] = $tile->namedtag;
|
$tiles[] = $tileTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
|
$nbt->setTag(new ListTag("TileEntities", $tiles, NBT::TAG_Compound));
|
||||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\tile;
|
namespace pocketmine\tile;
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
@ -107,19 +106,16 @@ class Banner extends Spawnable implements Nameable{
|
|||||||
*/
|
*/
|
||||||
private $patterns;
|
private $patterns;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
$this->baseColor = $nbt->getInt(self::TAG_BASE, self::COLOR_BLACK, true);
|
$this->baseColor = $nbt->getInt(self::TAG_BASE, self::COLOR_BLACK, true);
|
||||||
$this->patterns = $nbt->getListTag(self::TAG_PATTERNS) ?? new ListTag(self::TAG_PATTERNS);
|
$this->patterns = $nbt->getListTag(self::TAG_PATTERNS) ?? new ListTag(self::TAG_PATTERNS);
|
||||||
$nbt->removeTag(self::TAG_BASE, self::TAG_PATTERNS);
|
|
||||||
$this->loadName($nbt);
|
$this->loadName($nbt);
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
parent::saveNBT();
|
$nbt->setInt(self::TAG_BASE, $this->baseColor);
|
||||||
$this->namedtag->setInt(self::TAG_BASE, $this->baseColor);
|
$nbt->setTag($this->patterns);
|
||||||
$this->namedtag->setTag($this->patterns);
|
$this->saveName($nbt);
|
||||||
$this->saveName($this->namedtag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
public function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
||||||
|
@ -25,7 +25,6 @@ namespace pocketmine\tile;
|
|||||||
|
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
@ -35,13 +34,6 @@ class Bed extends Spawnable{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
private $color = 14; //default to old red
|
private $color = 14; //default to old red
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
|
||||||
$this->color = $nbt->getByte(self::TAG_COLOR, 14, true);
|
|
||||||
$nbt->removeTag(self::TAG_COLOR);
|
|
||||||
|
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getColor() : int{
|
public function getColor() : int{
|
||||||
return $this->color;
|
return $this->color;
|
||||||
}
|
}
|
||||||
@ -51,13 +43,16 @@ class Bed extends Spawnable{
|
|||||||
$this->onChanged();
|
$this->onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
|
$this->color = $nbt->getByte(self::TAG_COLOR, 14, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
$nbt->setByte(self::TAG_COLOR, $this->color);
|
$nbt->setByte(self::TAG_COLOR, $this->color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
public function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
||||||
parent::saveNBT();
|
$nbt->setByte(self::TAG_COLOR, $this->color);
|
||||||
$this->namedtag->setByte(self::TAG_COLOR, $this->color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function createAdditionalNBT(CompoundTag $nbt, Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : void{
|
protected static function createAdditionalNBT(CompoundTag $nbt, Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : void{
|
||||||
|
@ -26,7 +26,6 @@ namespace pocketmine\tile;
|
|||||||
use pocketmine\inventory\ChestInventory;
|
use pocketmine\inventory\ChestInventory;
|
||||||
use pocketmine\inventory\DoubleChestInventory;
|
use pocketmine\inventory\DoubleChestInventory;
|
||||||
use pocketmine\inventory\InventoryHolder;
|
use pocketmine\inventory\InventoryHolder;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
|
|
||||||
@ -50,19 +49,26 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
|
|||||||
/** @var int|null */
|
/** @var int|null */
|
||||||
private $pairZ;
|
private $pairZ;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag(self::TAG_PAIRX, IntTag::class) and $nbt->hasTag(self::TAG_PAIRZ, IntTag::class)){
|
if($nbt->hasTag(self::TAG_PAIRX, IntTag::class) and $nbt->hasTag(self::TAG_PAIRZ, IntTag::class)){
|
||||||
$this->pairX = $nbt->getInt(self::TAG_PAIRX);
|
$this->pairX = $nbt->getInt(self::TAG_PAIRX);
|
||||||
$this->pairZ = $nbt->getInt(self::TAG_PAIRZ);
|
$this->pairZ = $nbt->getInt(self::TAG_PAIRZ);
|
||||||
}
|
}
|
||||||
$nbt->removeTag(self::TAG_PAIRX, self::TAG_PAIRZ);
|
|
||||||
$this->loadName($nbt);
|
$this->loadName($nbt);
|
||||||
|
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
|
|
||||||
$this->inventory = new ChestInventory($this);
|
$this->inventory = new ChestInventory($this);
|
||||||
$this->loadItems($this->namedtag);
|
$this->loadItems($nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
|
if($this->isPaired()){
|
||||||
|
$nbt->setInt(self::TAG_PAIRX, $this->pairX);
|
||||||
|
$nbt->setInt(self::TAG_PAIRZ, $this->pairZ);
|
||||||
|
}else{
|
||||||
|
$nbt->removeTag(self::TAG_PAIRX, self::TAG_PAIRZ);
|
||||||
|
}
|
||||||
|
$this->saveName($nbt);
|
||||||
|
$this->saveItems($nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close() : void{
|
public function close() : void{
|
||||||
@ -81,18 +87,6 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
|
||||||
parent::saveNBT();
|
|
||||||
if($this->isPaired()){
|
|
||||||
$this->namedtag->setInt(self::TAG_PAIRX, $this->pairX);
|
|
||||||
$this->namedtag->setInt(self::TAG_PAIRZ, $this->pairZ);
|
|
||||||
}else{
|
|
||||||
$this->namedtag->removeTag(self::TAG_PAIRX, self::TAG_PAIRZ);
|
|
||||||
}
|
|
||||||
$this->saveItems($this->namedtag);
|
|
||||||
$this->saveName($this->namedtag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ChestInventory|DoubleChestInventory
|
* @return ChestInventory|DoubleChestInventory
|
||||||
*/
|
*/
|
||||||
|
@ -23,20 +23,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\tile;
|
namespace pocketmine\tile;
|
||||||
|
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
|
||||||
|
|
||||||
class EnchantTable extends Spawnable implements Nameable{
|
class EnchantTable extends Spawnable implements Nameable{
|
||||||
use NameableTrait;
|
use NameableTrait{
|
||||||
|
loadName as readSaveData;
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
saveName as writeSaveData;
|
||||||
$this->loadName($nbt);
|
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function saveNBT() : void{
|
|
||||||
parent::saveNBT();
|
|
||||||
$this->saveName($this->namedtag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,14 @@ use pocketmine\nbt\tag\CompoundTag;
|
|||||||
|
|
||||||
class EnderChest extends Spawnable{
|
class EnderChest extends Spawnable{
|
||||||
|
|
||||||
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
public function addAdditionalSpawnData(CompoundTag $nbt) : void{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ namespace pocketmine\tile;
|
|||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
|
||||||
class FlowerPot extends Spawnable{
|
class FlowerPot extends Spawnable{
|
||||||
@ -35,17 +34,13 @@ class FlowerPot extends Spawnable{
|
|||||||
/** @var Item */
|
/** @var Item */
|
||||||
private $item;
|
private $item;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
//TODO: check PC format
|
|
||||||
$this->item = ItemFactory::get($nbt->getShort(self::TAG_ITEM, 0, true), $nbt->getInt(self::TAG_ITEM_DATA, 0, true), 1);
|
$this->item = ItemFactory::get($nbt->getShort(self::TAG_ITEM, 0, true), $nbt->getInt(self::TAG_ITEM_DATA, 0, true), 1);
|
||||||
$nbt->removeTag(self::TAG_ITEM, self::TAG_ITEM_DATA);
|
|
||||||
|
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
$this->namedtag->setShort(self::TAG_ITEM, $this->item->getId());
|
$nbt->setShort(self::TAG_ITEM, $this->item->getId());
|
||||||
$this->namedtag->setInt(self::TAG_ITEM_DATA, $this->item->getDamage());
|
$nbt->setInt(self::TAG_ITEM_DATA, $this->item->getDamage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canAddItem(Item $item) : bool{
|
public function canAddItem(Item $item) : bool{
|
||||||
|
@ -56,6 +56,13 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
|||||||
private $maxTime;
|
private $maxTime;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
public function __construct(Level $level, CompoundTag $nbt){
|
||||||
|
parent::__construct($level, $nbt);
|
||||||
|
if($this->burnTime > 0){
|
||||||
|
$this->scheduleUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
$this->burnTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, 0, true));
|
$this->burnTime = max(0, $nbt->getShort(self::TAG_BURN_TIME, 0, true));
|
||||||
|
|
||||||
$this->cookTime = $nbt->getShort(self::TAG_COOK_TIME, 0, true);
|
$this->cookTime = $nbt->getShort(self::TAG_COOK_TIME, 0, true);
|
||||||
@ -70,14 +77,16 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
|||||||
|
|
||||||
$this->loadName($nbt);
|
$this->loadName($nbt);
|
||||||
|
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
$this->inventory = new FurnaceInventory($this);
|
$this->inventory = new FurnaceInventory($this);
|
||||||
$this->loadItems($this->namedtag);
|
$this->loadItems($nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
if($this->burnTime > 0){
|
$nbt->setShort(self::TAG_BURN_TIME, $this->burnTime);
|
||||||
$this->scheduleUpdate();
|
$nbt->setShort(self::TAG_COOK_TIME, $this->cookTime);
|
||||||
}
|
$nbt->setShort(self::TAG_MAX_TIME, $this->maxTime);
|
||||||
|
$this->saveName($nbt);
|
||||||
|
$this->saveItems($nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,16 +105,6 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
|
||||||
parent::saveNBT();
|
|
||||||
$this->namedtag->setShort(self::TAG_BURN_TIME, $this->burnTime);
|
|
||||||
$this->namedtag->setShort(self::TAG_COOK_TIME, $this->cookTime);
|
|
||||||
$this->namedtag->setShort(self::TAG_MAX_TIME, $this->maxTime);
|
|
||||||
|
|
||||||
$this->saveItems($this->namedtag);
|
|
||||||
$this->saveName($this->namedtag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return FurnaceInventory
|
* @return FurnaceInventory
|
||||||
*/
|
*/
|
||||||
|
@ -25,7 +25,6 @@ namespace pocketmine\tile;
|
|||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
|
||||||
class ItemFrame extends Spawnable{
|
class ItemFrame extends Spawnable{
|
||||||
@ -40,7 +39,7 @@ class ItemFrame extends Spawnable{
|
|||||||
/** @var float */
|
/** @var float */
|
||||||
private $itemDropChance;
|
private $itemDropChance;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
if(($itemTag = $nbt->getCompoundTag(self::TAG_ITEM)) !== null){
|
if(($itemTag = $nbt->getCompoundTag(self::TAG_ITEM)) !== null){
|
||||||
$this->item = Item::nbtDeserialize($itemTag);
|
$this->item = Item::nbtDeserialize($itemTag);
|
||||||
}else{
|
}else{
|
||||||
@ -48,16 +47,12 @@ class ItemFrame extends Spawnable{
|
|||||||
}
|
}
|
||||||
$this->itemRotation = $nbt->getByte(self::TAG_ITEM_ROTATION, 0, true);
|
$this->itemRotation = $nbt->getByte(self::TAG_ITEM_ROTATION, 0, true);
|
||||||
$this->itemDropChance = $nbt->getFloat(self::TAG_ITEM_DROP_CHANCE, 1.0, true);
|
$this->itemDropChance = $nbt->getFloat(self::TAG_ITEM_DROP_CHANCE, 1.0, true);
|
||||||
$nbt->removeTag(self::TAG_ITEM, self::TAG_ITEM_ROTATION, self::TAG_ITEM_DROP_CHANCE);
|
|
||||||
|
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
parent::saveNBT();
|
$nbt->setFloat(self::TAG_ITEM_DROP_CHANCE, $this->itemDropChance);
|
||||||
$this->namedtag->setFloat(self::TAG_ITEM_DROP_CHANCE, $this->itemDropChance);
|
$nbt->setByte(self::TAG_ITEM_ROTATION, $this->itemRotation);
|
||||||
$this->namedtag->setByte(self::TAG_ITEM_ROTATION, $this->itemRotation);
|
$nbt->setTag($this->item->nbtSerialize(-1, self::TAG_ITEM));
|
||||||
$this->namedtag->setTag($this->item->nbtSerialize(-1, self::TAG_ITEM));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasItem() : bool{
|
public function hasItem() : bool{
|
||||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\tile;
|
namespace pocketmine\tile;
|
||||||
|
|
||||||
use pocketmine\event\block\SignChangeEvent;
|
use pocketmine\event\block\SignChangeEvent;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
@ -37,7 +36,7 @@ class Sign extends Spawnable{
|
|||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
protected $text = ["", "", "", ""];
|
protected $text = ["", "", "", ""];
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
if($nbt->hasTag(self::TAG_TEXT_BLOB, StringTag::class)){ //MCPE 1.2 save format
|
if($nbt->hasTag(self::TAG_TEXT_BLOB, StringTag::class)){ //MCPE 1.2 save format
|
||||||
$this->text = array_pad(explode("\n", $nbt->getString(self::TAG_TEXT_BLOB)), 4, "");
|
$this->text = array_pad(explode("\n", $nbt->getString(self::TAG_TEXT_BLOB)), 4, "");
|
||||||
assert(count($this->text) === 4, "Too many lines!");
|
assert(count($this->text) === 4, "Too many lines!");
|
||||||
@ -51,17 +50,14 @@ class Sign extends Spawnable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
parent::saveNBT();
|
$nbt->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text));
|
||||||
$this->namedtag->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text));
|
|
||||||
|
|
||||||
for($i = 1; $i <= 4; ++$i){ //Backwards-compatibility
|
for($i = 1; $i <= 4; ++$i){ //Backwards-compatibility
|
||||||
$textKey = sprintf(self::TAG_TEXT_LINE, $i);
|
$textKey = sprintf(self::TAG_TEXT_LINE, $i);
|
||||||
$this->namedtag->setString($textKey, $this->getLine($i - 1));
|
$nbt->setString($textKey, $this->getLine($i - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\tile;
|
namespace pocketmine\tile;
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
@ -47,17 +46,14 @@ class Skull extends Spawnable{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
private $skullRotation;
|
private $skullRotation;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
protected function readSaveData(CompoundTag $nbt) : void{
|
||||||
$this->skullType = $nbt->getByte(self::TAG_SKULL_TYPE, self::TYPE_SKELETON, true);
|
$this->skullType = $nbt->getByte(self::TAG_SKULL_TYPE, self::TYPE_SKELETON, true);
|
||||||
$this->skullRotation = $nbt->getByte(self::TAG_ROT, 0, true);
|
$this->skullRotation = $nbt->getByte(self::TAG_ROT, 0, true);
|
||||||
$nbt->removeTag(self::TAG_SKULL_TYPE, self::TAG_ROT);
|
|
||||||
parent::__construct($level, $nbt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||||
parent::saveNBT();
|
$nbt->setByte(self::TAG_SKULL_TYPE, $this->skullType);
|
||||||
$this->namedtag->setByte(self::TAG_SKULL_TYPE, $this->skullType);
|
$nbt->setByte(self::TAG_ROT, $this->skullRotation);
|
||||||
$this->namedtag->setByte(self::TAG_ROT, $this->skullRotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setType(int $type){
|
public function setType(int $type){
|
||||||
|
@ -74,8 +74,6 @@ abstract class Tile extends Position{
|
|||||||
public $id;
|
public $id;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
public $closed = false;
|
public $closed = false;
|
||||||
/** @var CompoundTag */
|
|
||||||
public $namedtag;
|
|
||||||
/** @var Server */
|
/** @var Server */
|
||||||
protected $server;
|
protected $server;
|
||||||
/** @var TimingsHandler */
|
/** @var TimingsHandler */
|
||||||
@ -155,12 +153,12 @@ abstract class Tile extends Position{
|
|||||||
public function __construct(Level $level, CompoundTag $nbt){
|
public function __construct(Level $level, CompoundTag $nbt){
|
||||||
$this->timings = Timings::getTileEntityTimings($this);
|
$this->timings = Timings::getTileEntityTimings($this);
|
||||||
|
|
||||||
$this->namedtag = $nbt;
|
|
||||||
$this->server = $level->getServer();
|
$this->server = $level->getServer();
|
||||||
$this->name = "";
|
$this->name = "";
|
||||||
$this->id = Tile::$tileCount++;
|
$this->id = Tile::$tileCount++;
|
||||||
|
|
||||||
parent::__construct($this->namedtag->getInt(self::TAG_X), $this->namedtag->getInt(self::TAG_Y), $this->namedtag->getInt(self::TAG_Z), $level);
|
parent::__construct($nbt->getInt(self::TAG_X), $nbt->getInt(self::TAG_Y), $nbt->getInt(self::TAG_Z), $level);
|
||||||
|
$this->readSaveData($nbt);
|
||||||
|
|
||||||
$this->getLevel()->addTile($this);
|
$this->getLevel()->addTile($this);
|
||||||
}
|
}
|
||||||
@ -169,26 +167,31 @@ abstract class Tile extends Position{
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveNBT() : void{
|
/**
|
||||||
$this->namedtag->setString(self::TAG_ID, static::getSaveId());
|
* Reads additional data from the CompoundTag on tile creation.
|
||||||
$this->namedtag->setInt(self::TAG_X, $this->x);
|
*
|
||||||
$this->namedtag->setInt(self::TAG_Y, $this->y);
|
* @param CompoundTag $nbt
|
||||||
$this->namedtag->setInt(self::TAG_Z, $this->z);
|
*/
|
||||||
}
|
abstract protected function readSaveData(CompoundTag $nbt) : void;
|
||||||
|
|
||||||
public function getNBT() : CompoundTag{
|
/**
|
||||||
return $this->namedtag;
|
* Writes additional save data to a CompoundTag, not including generic things like ID and coordinates.
|
||||||
|
*
|
||||||
|
* @param CompoundTag $nbt
|
||||||
|
*/
|
||||||
|
abstract protected function writeSaveData(CompoundTag $nbt) : void;
|
||||||
|
|
||||||
|
public function saveNBT(CompoundTag $nbt) : void{
|
||||||
|
$nbt->setString(self::TAG_ID, static::getSaveId());
|
||||||
|
$nbt->setInt(self::TAG_X, $this->x);
|
||||||
|
$nbt->setInt(self::TAG_Y, $this->y);
|
||||||
|
$nbt->setInt(self::TAG_Z, $this->z);
|
||||||
|
$this->writeSaveData($nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCleanedNBT() : ?CompoundTag{
|
public function getCleanedNBT() : ?CompoundTag{
|
||||||
$this->saveNBT();
|
$this->writeSaveData($tag = new CompoundTag());
|
||||||
$tag = clone $this->namedtag;
|
return $tag->getCount() > 0 ? $tag : null;
|
||||||
$tag->removeTag(self::TAG_X, self::TAG_Y, self::TAG_Z, self::TAG_ID);
|
|
||||||
if($tag->getCount() > 0){
|
|
||||||
return $tag;
|
|
||||||
}else{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,8 +273,6 @@ abstract class Tile extends Position{
|
|||||||
$this->level->removeTile($this);
|
$this->level->removeTile($this);
|
||||||
$this->setLevel(null);
|
$this->setLevel(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->namedtag = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user