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

Creating a new entity

Comments in 'Plugin Development' started by Tethered_, Feb 1, 2015.

  1. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    I'm trying to create an NPC which I call FakeHuman (extension of Human) and I've registered the FakeHuman class as an entity correctly, but how do I create a new "empty" player?
  2. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Take a look at Specter :3
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No! Specter registers a real player. It is not an NPC. It is just like a player joined from console.
    Look at SlapIt instead. Although it doesn't work yet, it has the correct codebase for it.
    iksaku likes this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you do like specter, PocketMine will try to prepare and send chunks (internally though). Server has to process one more player. Plugins think that there is one more player.

    Try using $level->addEntity($human)
    Tethered_ likes this.
  5. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    What are the parameters $chunk and $nbt and what do I send them?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Tethered_ and iJoshuaHD like this.
  7. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    Yeah I've tried using this, but what exactly IS an nbt?
  8. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    So you're making a plugin like citizen in Bukkit?
  9. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    No I'm going for something more like a statue-type thing
  10. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    oi
    c
  11. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Like LifeBoat SkyWars? I see statues that showcase kits there.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What do you think if you join us to work on SlapIt instead?
    Tethered_ likes this.
  13. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    Sounds good! Still though, two questions:

    1. If I want to spawn a new entity at a specific xyz coordinate, how do I set up $level->addEntity(), because if I want to store a new Human (for example) in a variable, I would do $human = new Human(), but it asks for parameters of $chunk and $nbt

    2. What is nbt?
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $nbt is an NBT Compound object that stores the data of the entity. Look at SlapIt for example. NBT is a data format by Mojang to store Minecraft data, but anyway, it is like an array in this case.
    P.S. maybe what you want to do will be covered in SlapIt?

    For example of $nbt, read https://github.com/LegendOfMCPE/SlapIt/blob/master/src/slapit/entity/SlappableHuman.php#L33-61
    For example of $chunk, read https://github.com/LegendOfMCPE/SlapIt/blob/master/src/slapit/entity/SlappableHuman.php#L68
  15. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    I can't seem to make the Entity visible...

    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args) {
            if(
    strtolower($command->getName('a'))) {
                
    $level $sender->getPlayer()->getLevel();
                
    $pos $sender->getPlayer()->getPosition();
               
                
    $fakePlayer FakePlayer::cmdCreate($pos);
               
    $level->addEntity($fakePlayer); //runs without error but does not add visible entity
                         
                
    $fakerPlayer = new FakePlayer($pos->getLevel()->getChunk($pos->getFloorX() >> 4$pos->getFloorZ() >> 4true), FakePlayer::getNBT($pos));
                
    $level->addEntity($fakerPlayer); //same as above
               
               
            
    }
       
        }
  16. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    Looking at it again, it appears the FakePlayer entity was created and spawned, but is just not there...
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I'm not sure. It works in LegionPE shops-rewrite-2, but I spawn the dummy when the chunk is loaded, and kill/despawn when the chunk is unloaded.
  18. Sergey_D
    Offline

    Sergey_D Active Member

    Joined:
    Jan 19, 2014
    Posts:
    75
    Minecraft User:
    CLILLZ
    You can use network packets for creating a fake entities
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, but in that way, you must use DataPacketReceiveEvent to listen to interact packet on your entities because PocketMine won't let you know about them. Then every DataPacketReceiveEvent handler lags the server a bit more because it's called thousands times a second.
    So why don't we just use the PocketMine API?
  20. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    Here's the nbt that I pass to the FakePlayer btw if that helps. I took out the optional args from SlapIt

    PHP:
    public static function getNBT(Position $pos){
        
    $pos = new Location($pos->x$pos->y$pos->z0.00.0$pos->getLevel());
        
    $nbt = new Compound;
        
    $nbt->NameTag = new String("Troll");
        
    $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", [new Compound(false, [
                new 
    Short("id"0),
                new 
    Short("Damage"0),
                new 
    Byte("Count"0),
                new 
    Byte("Slot"9),
                new 
    Byte("TrueSlot"9)
        ])]);
        return 
    $nbt;

Share This Page

Advertisement