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

NBT

Comments in 'Plugin Development' started by Bluplayz, Feb 3, 2016.

  1. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    Can anyone tutorial me how did i can create a Entity like a player or an mob , i dont understand the nbt thing what it is and why "nbt", please a code and comment them xD that would be nice ^^
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Look in the slapper plugin. It helps.
    applqpak and Bluplayz like this.
  3. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    And My Tnt Plugin :)
    It helps.
    applqpak and Bluplayz like this.
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Just look at the Entity.php in the pocketmine source code, or even the slapper plugin.
    Anyways, this is how to spawn an entity:
    PHP:
    public static function createEntity($typePosition $source, ...$args){
            
    $chunk $source->getLevel()->getChunk($source->>> 4$source->>> 4true);
            if(
    $chunk == null) return null;
            if(!
    $chunk->isLoaded()) $chunk->load();
            if(!
    $chunk->isGenerated()) $chunk->setGenerated();
            if(!
    $chunk->isPopulated()) $chunk->setPopulated();
            
    $nbt = new Compound("", [
                
    "Pos" => new Enum("Pos", [
                    new 
    Double(""$source->x),
                    new 
    Double(""$source->y),
                    new 
    Double(""$source->z)
                ]),
                
    "Motion" => new Enum("Motion", [
                    new 
    Double(""0),
                    new 
    Double(""0),
                    new 
    Double(""0)
                ]),
                
    "Rotation" => new Enum("Rotation", [
                    new 
    Float(""$source instanceof Location $source->yaw 0),
                    new 
    Float(""$source instanceof Location $source->pitch 0)
                ]),
            ]);
            
    $keys array_keys(self::$knownEntities);
            foreach(
    $keys as $c => $name){
                if(
    strtolower($type) == strtolower($name)){
                    
    $type $name;
                    break;
                }
            }
            if(isset(
    self::$knownEntities[$type])){
                
    $class self::$knownEntities[$type];
                
    /** @var BaseEntity $entity */
                
    $entity =  new $class($chunk$nbt, ...$args);
                if(
    $entity != null && $entity->isCreated()) $entity->spawnToAll();
                return 
    $entity;
            }else{
                
    $entity Entity::createEntity($type$chunk$nbt, ...$args);
                if(
    $entity != null$entity->spawnToAll();
                return 
    $entity;
            }
        }
    applqpak likes this.
  5. Bluplayz
    Offline

    Bluplayz Active Member

    Joined:
    Aug 20, 2015
    Posts:
    74
    Minecraft User:
    Bluplayz
    Hmm nice but can i use AS type a Human? So a statue? Of a player ?
  6. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Yes

Share This Page

Advertisement