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

Solved Skin can not be changed

Discussion in 'Development' started by yuko fuyutsuki, Apr 21, 2018.

  1. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    Summary:
    I attempted to change the skin using Player->setSkin(), Player->sendSkin(), but the skin size does not become either 8KiB or 16KiB.
    I wrote the following code, but it does not work.
    PHP:
    // On PlayerJoinEvent
    $data base64_encode(file_get_contents($this->getDataFolder()."Steve.png"));
    $skin = new Skin("Standard_Custom"$data);
    $p $e->getPlayer();
    $p->setSkin($skin);
    $p->sendSkin($this->getServer()->getOnlinePlayers());
     
  2. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    That is not the correct way to read the skin's data.
    The right way would be:
    PHP:
    $image imagecreatefrompng($this->getDataFolder() . "Steve.png");
    $data '';
    for (
    $y 0$height imagesy($image); $y $height$y++) {
        for (
    $x 0$width imagesx($image); $x $width$x++) {
            
    $color imagecolorat($image$x$y);
            
    $data .= pack("c", ($color >> 16) & 0xFF//red
                
    pack("c", ($color >> 8) & 0xFF//green
                
    pack("c"$color 0xFF//blue
                
    pack("c"0xFF); //alpha
        
    }
    }
    But you need the GD extension for that. For windows, you'll only need to enable it in php.ini, but for linux I still don't know, was trying to figure out myself.
     
    yuko fuyutsuki likes this.
  3. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    Thx :D
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    for linux you just need to recompile php using php-build-scripts with the -g flag. https://github.com/pmmp/php-build-scripts
     
  5. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Thanks. Actually I have seen this, but never tried it.
     
    yuko fuyutsuki likes this.
  6. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    The skin was changed, but the skins were not loaded properly, and a part or all was discolored black.
     
  7. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    Can you please send a screenshot and your "Steve.png" file? I do suspect what may be the problem here, but I want to be sure.
     
    yuko fuyutsuki likes this.
  8. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    Steve.png
    Steve.png
     
  9. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    ScreenShot:
    タイトルなし.jpg
     
  10. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    As I thought, the problem here is the alpha channel. The second layer gets completely opaque, but without color.
    So the correct code will be:
    PHP:
    $image imagecreatefrompng($this->getDataFolder() . "Steve.png");
    $data '';
    for (
    $y 0$height imagesy($image); $y $height$y++) {
        for (
    $x 0$width imagesx($image); $x $width$x++) {
            
    $color imagecolorat($image$x$y);
            
    $data .= pack("c", ($color >> 16) & 0xFF//red
                
    pack("c", ($color >> 8) & 0xFF//green
                
    pack("c"$color 0xFF//blue
                
    pack("c"255 - (($color 0x7F000000) >> 23)); //alpha
        
    }
    }
     
  11. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
    It worked!! thx!!
     
    Tee7even likes this.
  12. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Does it for any skin or only steve
     
  13. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    It does work for any skin. If used right of course.
     
    xXNiceAssassinlo YT likes this.
  14. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Thx
     
  15. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
                $skin imagecreatefrompng(Core::getDataFolder() . "Steve.png");
                
    $data '';
                for(
    $y 0$height imagesy($skin); $y $height$y++){
                    
    $color imagecolorat($skin$x$y);
                    
    $data .= 
                    
    pack("c", ($color >> 16) & 0xFF) . 
                    
    pack("c", ($color >> 8) & 0xFF) . 
                    
    pack("c"$color 0xFF) . 
                    
    pack("c"255 - (($color 0x7F000000) >> 23));
                }
                
    $player->setSkin($skin);
    [/php]
    Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'ExonCore v1.0.0': Call to undefined function ExonCore\events\imagecreatefrompng() on ExonCore\events\JoinSystemEvent
    [16:50:36] [Server thread/CRITICAL]: Error: "Call to undefined function ExonCore\events\imagecreatefrompng()" (EXCEPTION) in "ExonPECore-master/src/ExonCore/events/JoinSystemEvent" at line 43
     
  16. yuko fuyutsuki

    yuko fuyutsuki Slime

    Messages:
    77
    GitHub:
    fuyutsuki
     
    corytortoise and Tee7even like this.
  17. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    This:
    Moreover, that code that you've pasted here won't work, since you've left out the X loop for some reason.
     
    Lolipop78709 likes this.
  18. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Code:
    ;Custom PocketMine-MP php.ini file
    display_errors=1
    display_startup_errors=1
    error_reporting=-1
    zend.assertions=-1
    phar.readonly=0
    extension_dir=ext
    extension=php_pthreads.dll
    extension=php_openssl.dll
    extension=php_pocketmine_chunkutils.dll
    extension=php_igbinary.dll
    extension=php_ds.dll
    igbinary.compact_strings=0
    ;zend_extension=php_opcache.dll
    ;The following extensions are included as shared extensions (DLLs) but disabled by default as they are optional. Uncomment the ones you want to enable.
    ;extension=php_gd2.dll
    ;extension=php_mysqli.dll
    extension=php_sqlite3.dll
     
  19. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    remove ; in this line
     
  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.