1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved How to set NPC's skin from sender skin?

Discussion in 'Development' started by Yexeed, Oct 30, 2017.

  1. Yexeed

    Yexeed Slime

    Messages:
    76
    The API changed and I dont actually know how to set NPC's skin from command sender. Server always throwing InvalidStateException: "Human must have a valid skin set".
    Code i tried to use:
    PHP:
    $nbt = new CompoundTag(""array_merge([
        new 
    ListTag("Pos", [
            new 
    DoubleTag("", -372 0.5),
            new 
    DoubleTag(""89),
            new 
    DoubleTag(""235 0.5)
        ]),
        new 
    ListTag("Motion", [
            new 
    DoubleTag(""0),
            new 
    DoubleTag(""0),
            new 
    DoubleTag(""0)
        ]),
        new 
    ListTag("Rotation", [
            new 
    FloatTag(""1),
            new 
    FloatTag(""4)
        ])
    ]));
    $npc Entity::createEntity("Human"$lvl$nbt);
    $skin $sender->getSkin();
    $npc->setSkin(new Skin($skin->getSkinId(), $skin->getSkinData(), $skin->getCapeData(), $skin->getGeometryName(), $skin->getGeometryData()));
    $npc->sendSkin($this->getServer()->getOnlinePlayers());
    $npc->spawnToAll();
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    $skin = clone $sender->getSkin();
    $npc->setSkin($skin);
     
  3. Yexeed

    Yexeed Slime

    Messages:
    76
    thanks alot. helped.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.