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. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Including the PocketMine-MP logo :p
  2. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Yess :rolleyes:
  3. Rendum
    Offline

    Rendum New Member

    Joined:
    Mar 9, 2015
    Posts:
    3
    Minecraft User:
    Rendum
    when?! I never saw them...
  4. shoghicp
    Offline

    shoghicp Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    433
    Plugins:
    14
    Minecraft User:
    shoghicp
    The default PHP binaries include GD2 with PNG support now
    aliuly likes this.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  6. VonHirst
    Offline

    VonHirst Active Member

    Joined:
    Aug 26, 2014
    Posts:
    50
    you guys know how to get a handle to the default steve skin? I'm creating a PlayerPacket.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think you need to hardcode it. There isn't such thing in PocketMine.
    Why create PlayerPacket?
  8. VonHirst
    Offline

    VonHirst Active Member

    Joined:
    Aug 26, 2014
    Posts:
    50
    Cool thanks. I use mcg's statue plugin on my server and i'm patching it for 1.5. For now i'm setting the skin to the login player's skin, so he sees his skin on the statues, which is pretty cool actually :p
    PEMapModder likes this.
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    That is cool! Is it private?
  10. VonHirst
    Offline

    VonHirst Active Member

    Joined:
    Aug 26, 2014
    Posts:
    50
    The server? No it's public. pvp.pigraid.com. I'm still at 1.4 today, but moving up to 1.5 this weekend. I'm a bit nervous how it's going to go, i'm hearing some ppl say 1.5 is ready, but seeing all the issues about CPU & Memory on github is scary, I guess I'll find out this weekend!
    PEMapModder likes this.
  11. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Izs it possible that you release your patched mcg76's statue plugin?
  12. VonHirst
    Offline

    VonHirst Active Member

    Joined:
    Aug 26, 2014
    Posts:
    50
    Sure no problem, does he have it on github? I don't think he does.
  13. VonHirst
    Offline

    VonHirst Active Member

    Joined:
    Aug 26, 2014
    Posts:
    50
    Just ping me next week after I upgrade to 1.5 and i'll send you the src.
  14. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    why this crashes the MCPE when i join?
    PHP:
    public function spawnPlayer(Player $p$pos$userName$itemId$slots) {
            
    $pk = new AddPlayerPacket ();
            
    $pk->clientID 0;
            
    $pk->username $userName;
            
    $pk->eid $p->getId ();
            
    $pk->$pos->x;
            
    $pk->$pos->y;
            
    $pk->$pos->z;
            
    $pk->yaw $p->yaw;
            
    $pk->pitch $p->pitch;
            
    $pk->item $itemId;
            
    $pk->meta 0;
            
    $pk->slim false;
            
    $pk->skin 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);
            
    $pk->metadata = [ ];
            
    $p->dataPacket $pk );
            
    Server::broadcastPacket ($p->getViewers(), $pk );
          
            
    $p->addEntityMotion $p->getId (), 0290);      
            if (
    $slots != null) {
                
    $pk = new PlayerArmorEquipmentPacket ();
                
    $pk->eid $p->getId ();
                
    $pk->slots $slots;
                
    $pk->encode ();
                
    $pk->isEncoded true;
                
    $p->dataPacket $pk );
                
    Server::broadcastPacket ($p->getViewers(), $pk );
            }
        }
  15. VonHirst
    Offline

    VonHirst Active Member

    Joined:
    Aug 26, 2014
    Posts:
    50
    ClientID & eid. You have to get the next one in the series in 1.5 I don't have the code in front of me now or I'd post it here. Look how it's being generated in the pocketmine codebase. Just get it once at the top of the function and use it downstream.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why $p->dataPacket then Server::broadcastPacket?
  17. VonHirst
    Offline

    VonHirst Active Member

    Joined:
    Aug 26, 2014
    Posts:
    50
    Yes, good point PE. mcg76 originally had that duplicated in the code. Creeper remove the broadcast's you don't need them.
  18. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    OK and skin format is good?
  19. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    PHP:

    $player
    ->getSkinData()

    ?
    Legoboy0215 and Creeperface like this.
  20. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i tried to create normal entity but server still say Human must have bvalid skin set
    PHP:
    public static function getNBT(Position $pos$name){
        
    $pos = new Location($pos->x$pos->y$pos->z0.00.0$pos->getLevel());
        
    $nbt = new Compound;
        
    $nbt->NameTag = new String($name);
        
    $nbt->Pos = new Enum("Pos", [
                new 
    Double(0$pos->x),
                new 
    Double(1$pos->y),
                new 
    Double(2$pos->z),
        ]);
        
    $nbt->Motion = new Enum("Motion", [
                new 
    Double(00.0),
                new 
    Double(10.0),
                new 
    Double(20.0),
        ]);
        
    $nbt->Rotation = new Enum("Rotation", [
                new 
    Float(0$pos->yaw),
                new 
    Float(1$pos->pitch)
        ]);
        
    $nbt->FallDistance = new Float("FallDistance"0.0);
        
    $nbt->Fire = new Short("Fire"0);
        
    $nbt->Air = new Short("Air"0);
        
    //$nbt->OnGround = new Byte("OnGround", 1);
        //$nbt->Invulnerable = new Byte("Invulnerable", 1);
        
    $nbt->Health = new Short("Health"20);
        
    $nbt->Inventory = new Enum("Inventory", []);
        
    $nbt->Skin = new Compound("Skin", [

    "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)),
    "Slim" => new Byte(0)

    ]);
        return 
    $nbt;
        }

    public function 
    spawnNPC(){
            
    $level $this->getServer()->getLevelByName("flat");
            
    $entity Entity::createEntity("Human"$level->getChunk(13 >> 4, -16 >> 4), $this->getNBT(new Position(136, -16), "CreeperFace"));
            
    $entity->spawnToAll();
    }

Share This Page

Advertisement