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

NPC creating - crash client

Discussion in 'Development' started by Error202, Apr 18, 2019.

  1. Error202

    Error202 Spider Jockey

    Messages:
    39
    Why does the client crash if I create NPC in the following way?

    Server work perfectly, no log, no errors and NPC placed correct

    PHP:
    $position '[some position]';

    $skin_file $plugin->getDataFolder() . '/skins/invisible/invisible.png';
            
    $img = @imagecreatefrompng($skin_file);
            
    $skinbytes "";
            
    $s = (int)@getimagesize($skin_file)[1];
            for(
    $y 0$y $s$y++){
                for(
    $x 0$x 64$x++){
                    
    $colorat = @imagecolorat($img$x$y);
                    
    $a = ((~((int)($colorat >> 24))) << 1) & 0xff;
                    
    $r = ($colorat >> 16) & 0xff;
                    
    $g = ($colorat >> 8) & 0xff;
                    
    $b $colorat 0xff;
                    
    $skinbytes .= chr($r) . chr($g) . chr($b) . chr($a);
                }
            }
            @
    imagedestroy($img);

            
    $nbt Entity::createBaseNBT($positionnull$yaw$pitch);
            
    $nbt->setShort("Health"20);
            
    $nbt->setString("MenuName""");
            
    $nbt->setString("CustomName""NPC");

            
    $nbt->setTag(new CompoundTag("Skin", [
                new 
    StringTag("Name""Invisible"),
                new 
    ByteArrayTag("Data"$skinbytes),
                new 
    ByteArrayTag("CapeData"''),
                new 
    StringTag("GeometryName"''),
                new 
    ByteArrayTag("GeometryData"'')
            ]));

            
    $npc Entity::createEntity("NpcHuman"$position->getLevel(), $nbt);

            
    $npc->setNameTag('NPC');
            
    $npc->setNameTagVisible(true);
            
    $npc->setPosition($position);
            
    $npc->setRotation($yaw$pitch);
            
    $npc->spawnToAll();
            
     
  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.