Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[1.5] Spawning a Human NPC

Comments in 'Plugin Development' started by Samueljh1, Apr 24, 2015.

  1. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Hi, I keep getting this error now, when I update my pocket mine to 1.5:

    PHP:
    [CRITICALCould not tick level "****Lobby"Human must have a valid skin set
    I know why its happening, but I don't know how to solve it.

    Here is my Code:

    PHP:
    public function spawnPlayer($lev$X,$Y,$Z$name "[Free]",$he,$ch,$le,$bo,$yaw,$pitchVector3 $motion null){

        
    $nbt = new Compound;

            if(
    $name == null$name "[Free]";
         
        
    //$motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;

        
    $motion = new Vector3(0,0,0);

            
    $nbt->Pos = new Enum("Pos", [
             
               new 
    Double(""$X),
               new 
    Double(""$Y),
               new 
    Double(""$Z)
             
            ]);

            
    $nbt->Motion = new Enum("Motion", [
             
               new 
    Double(""$motion->x),
               new 
    Double(""$motion->y),
               new 
    Double(""$motion->z)
             
            ]);
         
            
    $nbt->Rotation = new Enum("Rotation", [
             
                new 
    Float(""$yaw),
                new 
    Float(""$pitch)
             
            ]);
         
            
    $nbt->Health = new Short("Health"5);
         
            
    $nbt->Inventory = new Enum("Inventory", []);
         
            
    $nbt->NameTag = new String("name",$name);

            
    $nbt->Skin = new String("skin",$this->getDataFolder() . "char.png");
         
            
    /*## ERROR Happens Here! ## */ $itemEntity Entity::createEntity("Human"$lev->getChunk($X >> 4$Z >> 4),$nbt);
         
          
    /*Error before this is called */ $itemEntity->setSkin($this->getDataFolder() . "char.png");

            
    $Inv $itemEntity->getInventory();

            
    $Inv->setHelmet(Item::get($he));
            
    $Inv->setChestplate(Item::get($ch));
            
    $Inv->setLeggings(Item::get($le));
            
    $Inv->setBoots(Item::get($bo));
         
            
    //if($name != "[Free]"){$itemEntity->setSkin($name);}else{$itemEntity->setSkin("Steve");}
         
            
    $itemEntity->spawnToAll();
         
            
    array_push($this->npcs,$itemEntity);
           
        }
    I've tried everything, from just a player name, to a skin path. I can't get it to work. Is the name of my NBT incorrect?

    Thanks! :D
  2. MCPEGamerJPatPM
    Offline

    MCPEGamerJPatPM New Member

    Joined:
    Apr 18, 2015
    Posts:
    6
    Minecraft User:
    MCPEGamerJP
    Thats weird. You selected all the details eg. skin. Maybe there is something wrong in the code (such as spelling mistakes) which might not recognize on pc.
    Hope this helps
  3. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You need to be running MCPE 0.11
  4. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    your setSkin method is very wrong. you cant just load a skin image format on it.
    try this: $itemEntity->setSkin(str_repeat("\x00", 64 * 32 * 4), false);

    if you want to add a skin, you somehow need to dump the skin and load from their.
    Last edited: Apr 24, 2015
    Hua_rong and Falk like this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Skin should be a buffer of length 64*32*4 or 64*64*4, not the path to a file, nor a player's name, nor the content from a PNG file. It is simply a string of bytes containing the RGBA (or ARGB? I am not sure) bitmap of the human.
    You must set it every time the chunk of the human is loaded, otherwise it won't work.
    Legion PE for 0.11.0 (pe.legionpvp.eu:19133) spawns humans with the skin str_repeat("\x80", 64*32*4) in the PvP world. If you join to see it, you would find humans with the skin as gray color, because players are spawned with the skin bitmap full of #808080 pixels, making it completely gray.
    I am not sure about the order of the bitmap (like from horizontal to vertical or what), but you can try sending different combinations. If you succeeded finding out the order of the buffer, tell me the result please :)
    What the? NBT has nothing to do with skins at all!
    MobileCrafter likes this.
  6. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    updated the code above for my mistake xD
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Update: I told @shoghicp about skins not being saved in NBT, and he asked me to create an issue (because it will not work when the chunk is reloaded). So expect it getting fixed soon.
    MobileCrafter likes this.
  8. MCPEGamerJPatPM
    Offline

    MCPEGamerJPatPM New Member

    Joined:
    Apr 18, 2015
    Posts:
    6
    Minecraft User:
    MCPEGamerJP
    aliuly, PocketMine 1.5 ONLY Runs 0.11.0 MCPE. Please do not reply unless you have any suggestions on how it can be solved or it will be considered spam. Thanks
  9. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    His suggestion was actually very useful and diagnosed the problem correctly. They were spawning a client as if it were a 0.10 client (i.e. without a skin). Both of your posts, on the other hand, are very reminiscent of spam. You should check yourself before criticizing others.

    (Yes, I get that this is off topic, you don't need to point that out)
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The bug I mentioned has been fixed here.
    Now, you can use this:
    PHP:
    $nbt->Skin = new Compound("Skin", [
      
    "Data" => new String("Data" => $aStringFilledWithBytesRepresentingTheRGBAMapOfTheSkin),
      
    "Slim" => new Byte($oneIfSlimOrZeroIfNotSlim)
    ]);
  11. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Do you mean

    PHP:
    $nbt->Skin = new Compound("Skin", [

    "Data" => new String("Data"$aStringFilledWithBytesRepresentingTheRGBAMapOfTheSkin),
    "Slim" => new Byte($oneIfSlimOrZeroIfNotSlim)

    ]);

    ?
    Last edited: Apr 25, 2015
  12. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    How do you get an RGB map of an image?!
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is different?
    Though, sorry, it should be new Byte("Slim", $oneOrZero) instead.
    I am not sure how the RGBA map is ordered.
    Like
    Code:
    abcd
    efgh
    ijkl
    mnop
    Whether it is abcdefgh... or aeimbfjn... I don't know. I just know that for one pixel #ABCDEF, it is represented by "\xab\xcd\xef\x80", where the first three bytes/characters are the red/green/blue colors and the fourth byte is probably unused (I don't know others, but I know \x80 works"). Don't ask me how to convert PNG into it though, because:
    1. Pocketmkne PHP distribution doesn't necessarily have the GD extension, so it may be hard to read a PNG file.
    2. If it is your own private plugin, why do you even need to make it read PNG instead of hardcoding the buffer into the plugin, or read raw contents from a file?
  14. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Its a leaderboard system with NPCs for my skywars server
  15. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Wait, how would i represent #FF0000 in the rgb map? or R: 255 G: 0 B: 0 ?
  16. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    @PEMapModder Look what I found: If i do this:
    PHP:
    "Data" => new String("Data"str_repeat("\xFF"32*16*2) . str_repeat("\xFF"32*16*2) . str_repeat("\xFF"32*16*2) . str_repeat("\xFF"32*16*2) . str_repeat("\x80"32*16*2) . str_repeat("\x80"32*16*2) . str_repeat("\x80"32*16*2) . str_repeat("\x80"32*16*2)),
    The head is white, and the body is gray!
    PEMapModder likes this.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    "\xFF\x00\x00\x00" for one pixel
    Use str_repeat() with it to fill it up.
  18. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    So how would you convert something like R: 5 G: 10 B: 15 ? I'm quite confused with the conversion
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    "\x05\x0A\x0F\x00"
  20. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Could you make a mini function for me that converts the red, green and blue values given; to a string like that? If you do, I will be able to finish my image to rgb map converter - which will let us convert an image into what pocketmine would read as a skin!!!
    Last edited: Apr 25, 2015

Share This Page

Advertisement