mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 23:29:54 +00:00
Item: optimise serializeCompoundTag() a little
This commit is contained in:
parent
a77fc8109f
commit
674b65f789
@ -353,30 +353,35 @@ class Item implements \JsonSerializable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function serializeCompoundTag(CompoundTag $tag) : void{
|
protected function serializeCompoundTag(CompoundTag $tag) : void{
|
||||||
$display = $tag->getCompoundTag(self::TAG_DISPLAY) ?? new CompoundTag();
|
$display = $tag->getCompoundTag(self::TAG_DISPLAY);
|
||||||
|
|
||||||
$this->hasCustomName() ?
|
if($this->customName !== ""){
|
||||||
$display->setString(self::TAG_DISPLAY_NAME, $this->getCustomName()) :
|
$display ??= new CompoundTag();
|
||||||
$display->removeTag(self::TAG_DISPLAY_NAME);
|
$display->setString(self::TAG_DISPLAY_NAME, $this->customName);
|
||||||
|
}else{
|
||||||
|
$display?->removeTag(self::TAG_DISPLAY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
if(count($this->lore) > 0){
|
if(count($this->lore) > 0){
|
||||||
$loreTag = new ListTag();
|
$loreTag = new ListTag();
|
||||||
foreach($this->lore as $line){
|
foreach($this->lore as $line){
|
||||||
$loreTag->push(new StringTag($line));
|
$loreTag->push(new StringTag($line));
|
||||||
}
|
}
|
||||||
|
$display ??= new CompoundTag();
|
||||||
$display->setTag(self::TAG_DISPLAY_LORE, $loreTag);
|
$display->setTag(self::TAG_DISPLAY_LORE, $loreTag);
|
||||||
}else{
|
}else{
|
||||||
$display->removeTag(self::TAG_DISPLAY_LORE);
|
$display?->removeTag(self::TAG_DISPLAY_LORE);
|
||||||
}
|
}
|
||||||
$display->count() > 0 ?
|
$display !== null && $display->count() > 0 ?
|
||||||
$tag->setTag(self::TAG_DISPLAY, $display) :
|
$tag->setTag(self::TAG_DISPLAY, $display) :
|
||||||
$tag->removeTag(self::TAG_DISPLAY);
|
$tag->removeTag(self::TAG_DISPLAY);
|
||||||
|
|
||||||
if($this->hasEnchantments()){
|
if(count($this->enchantments) > 0){
|
||||||
$ench = new ListTag();
|
$ench = new ListTag();
|
||||||
foreach($this->getEnchantments() as $enchantmentInstance){
|
$enchantmentIdMap = EnchantmentIdMap::getInstance();
|
||||||
|
foreach($this->enchantments as $enchantmentInstance){
|
||||||
$ench->push(CompoundTag::create()
|
$ench->push(CompoundTag::create()
|
||||||
->setShort(self::TAG_ENCH_ID, EnchantmentIdMap::getInstance()->toId($enchantmentInstance->getType()))
|
->setShort(self::TAG_ENCH_ID, $enchantmentIdMap->toId($enchantmentInstance->getType()))
|
||||||
->setShort(self::TAG_ENCH_LVL, $enchantmentInstance->getLevel())
|
->setShort(self::TAG_ENCH_LVL, $enchantmentInstance->getLevel())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -385,8 +390,8 @@ class Item implements \JsonSerializable{
|
|||||||
$tag->removeTag(self::TAG_ENCH);
|
$tag->removeTag(self::TAG_ENCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
($blockData = $this->getCustomBlockData()) !== null ?
|
$this->blockEntityTag !== null ?
|
||||||
$tag->setTag(self::TAG_BLOCK_ENTITY_TAG, clone $blockData) :
|
$tag->setTag(self::TAG_BLOCK_ENTITY_TAG, clone $this->blockEntityTag) :
|
||||||
$tag->removeTag(self::TAG_BLOCK_ENTITY_TAG);
|
$tag->removeTag(self::TAG_BLOCK_ENTITY_TAG);
|
||||||
|
|
||||||
if(count($this->canPlaceOn) > 0){
|
if(count($this->canPlaceOn) > 0){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user