Set skin to an entity

Discussion in 'Development' started by IvanCraft623, Oct 17, 2020.

  1. IvanCraft623

    IvanCraft623 Spider Jockey

    Messages:
    42
    GitHub:
    IvanCraft623
    I am trying to put a skin to an npc but I could not.

    Error:
    Code:
    ErrorException: "Declaration of BedWars\game\entity\villager::setSkin(BedWars\game\entity\Skin $skin): void should be compatible with pocketmine\entity\Human::setSkin(pocketmine\entity\Skin $skin): void" (EXCEPTION) in "plugins/BedWars_v1/src/BedWars/game/entity/villager" at line 75
    Code:
    Game:
    PHP:
        private function initShops() : void{
            foreach(
    $this->teamInfo as $team => $info){
                
    $shopPos Utils::stringToVector(":"$info['shopPos']);
                
    $rotation explode(":"$info['shopPos']);

                
    $nbt Entity::createBaseNBT($shopPos->add(0.500.5), null$rotation[3], $rotation[4]);
                
    $path Server::getInstance()->getDataPath() . "plugin_data/BedWars/skins/villager.png";
                
    $skin Utils::getSkinFromFile($path);
                
    $entity = new villager($this->plugin->getServer()->getLevelByName($this->worldName), $nbt);
                
    $nbt->setTag(new CompoundTag('Skin', [
                    new 
    StringTag('Data'$skin->getSkinData()),
                    new 
    StringTag('Name''Standard_CustomSlim'),
                    new 
    StringTag('GeometryName''geometry.player.villager'),
                    new 
    ByteArrayTag('GeometryData'villager::GEOMETRY)]));
                
    $entity->setNameTag(TextFormat::AQUA "ITEM SHOP\n" TextFormat::BOLD TextFormat::YELLOW "TAP TO USE");
                
    $entity->setNameTagAlwaysVisible(true);
                
    $entity->spawnToAll();

                
    $this->npcs[$entity->getId()] = [$team'shop'];
        }
    villager:
    PHP:
    <?php
    declare(strict_types=1);

    namespace 
    BedWars\game\entity;

    use 
    pocketmine\entity\Human;
    use 
    pocketmine\entity\object\ItemEntity;
    use 
    pocketmine\entity\Skin;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\nbt\tag\CompoundTag;

    class 
    villager extends Human {

        public const 
    GEOMETRY '{
            "geometry.player.villager":{
                "texturewidth": 64,
                "textureheight": 64,
                "visible_bounds_width": 2,
                "visible_bounds_height": 2,
                "visible_bounds_offset": [0, 1, 0],
                "bones": [
                    {
                        "name": "head",
                        "pivot": [0, 24, 0],
                        "mirror": true,
                        "cubes": [
                            {"origin": [-4, 24, -4], "size": [8, 10, 8], "uv": [0, 0]},
                        {"origin": [-1, 23, -6], "size": [2, 4, 2], "uv": [24, 0]}
                        ]
                    },
                    {
                        "name": "body",
                        "pivot": [0, 24, 0],
                        "mirror": true,
                        "cubes": [
                            {"origin": [-4, 12, -3], "size": [8, 12, 6], "uv": [16, 20]},
                            {"origin": [-4, 6, -3], "size": [8, 18, 6], "uv": [0, 38], "inflate": 0.5}
                        ]
                    },
                    {
                        "name": "jacket",
                        "parent": "body",
                        "pivot": [0, 24, 0],
                        "rotation": [-40, 0, 0],
                        "mirror": true,
                        "cubes": [
                            {"origin": [-4, 16, -1], "size": [8, 4, 4], "uv": [40, 38]},
                            {"origin": [4, 16, -1], "size": [4, 8, 4], "uv": [44, 22]},
                            {"origin": [-8, 16, -1], "size": [4, 8, 4], "uv": [44, 22]}
                        ]
                    },
                    {
                        "name": "leftLeg",
                        "pivot": [2, 12, 0],
                        "mirror": true,
                        "cubes": [
                            {"origin": [0, 0, -2], "size": [4, 12, 4], "uv": [0, 22]}
                        ]
                    },
                    {
                        "name": "rightLeg",
                        "pivot": [-2, 12, 0],
                        "mirror": true,
                        "cubes": [
                            {"origin": [-4, 0, -2], "size": [4, 12, 4], "uv": [0, 22]}
                        ]
                    }
                ]
            }
        }'
    ;

        public function 
    setSkin(Skin $skin) : void{
            
    parent::setSkin(new Skin($skin->getSkinId(), $skin->getSkinData(), '''geometry.player.villager'self::GEOMETRY));
        }
    }
     
  2. IvanCraft623

    IvanCraft623 Spider Jockey

    Messages:
    42
    GitHub:
    IvanCraft623
  3. IvanCraft623

    IvanCraft623 Spider Jockey

    Messages:
    42
    GitHub:
    IvanCraft623
    Someone?... :c
     

Share This Page

  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.