pocketmine\entity\Entity::saveNBT PHP Method

saveNBT() public method

public saveNBT ( )
    public function saveNBT()
    {
        if (!$this instanceof Player) {
            $this->namedtag->id = new StringTag("id", $this->getSaveId());
            if ($this->getNameTag() !== "") {
                $this->namedtag->CustomName = new StringTag("CustomName", $this->getNameTag());
                $this->namedtag->CustomNameVisible = new StringTag("CustomNameVisible", $this->isNameTagVisible());
            } else {
                unset($this->namedtag->CustomName);
                unset($this->namedtag->CustomNameVisible);
            }
        }
        $this->namedtag->Pos = new ListTag("Pos", [new DoubleTag(0, $this->x), new DoubleTag(1, $this->y), new DoubleTag(2, $this->z)]);
        $this->namedtag->Motion = new ListTag("Motion", [new DoubleTag(0, $this->motionX), new DoubleTag(1, $this->motionY), new DoubleTag(2, $this->motionZ)]);
        $this->namedtag->Rotation = new ListTag("Rotation", [new FloatTag(0, $this->yaw), new FloatTag(1, $this->pitch)]);
        $this->namedtag->FallDistance = new FloatTag("FallDistance", $this->fallDistance);
        $this->namedtag->Fire = new ShortTag("Fire", $this->fireTicks);
        $this->namedtag->Air = new ShortTag("Air", $this->getDataProperty(self::DATA_AIR));
        $this->namedtag->OnGround = new ByteTag("OnGround", $this->onGround == true ? 1 : 0);
        $this->namedtag->Invulnerable = new ByteTag("Invulnerable", $this->invulnerable == true ? 1 : 0);
        if (count($this->effects) > 0) {
            $effects = [];
            foreach ($this->effects as $effect) {
                $effects[$effect->getId()] = new CompoundTag($effect->getId(), ["Id" => new ByteTag("Id", $effect->getId()), "Amplifier" => new ByteTag("Amplifier", $effect->getAmplifier()), "Duration" => new IntTag("Duration", $effect->getDuration()), "Ambient" => new ByteTag("Ambient", 0), "ShowParticles" => new ByteTag("ShowParticles", $effect->isVisible() ? 1 : 0)]);
            }
            $this->namedtag->ActiveEffects = new ListTag("ActiveEffects", $effects);
        } else {
            unset($this->namedtag->ActiveEffects);
        }
    }

Usage Example

Example #1
0
 public function saveNBT()
 {
     parent::saveNBT();
     $this->namedtag->Item = NBT::putItemHelper($this->item);
     $this->namedtag->Health = new Short("Health", $this->getHealth());
     $this->namedtag->Age = new Short("Age", $this->age);
     $this->namedtag->PickupDelay = new Short("PickupDelay", $this->pickupDelay);
     if ($this->owner !== null) {
         $this->namedtag->Owner = new String("Owner", $this->owner);
     }
     if ($this->thrower !== null) {
         $this->namedtag->Thrower = new String("Thrower", $this->thrower);
     }
 }
All Usage Examples Of pocketmine\entity\Entity::saveNBT