Create custom entity api 4

Discussion in 'Development' started by FresherGAMING, Apr 30, 2022.

  1. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    41
    GitHub:
    FresherGAMING
    Hi, so I want to create a custom entity, but I still have no idea about creating it. I've search on the other forum but what I found is still on api 3 while I want for the api 4. It would be great if someone can help me to make this possible, cuz I need it to my server, thank you
     
  2. GamingFR91

    GamingFR91 Spider Jockey

    Messages:
    27
    GitHub:
    kanekilechomeur
    You have to create a new class that extends on Living, and register it with the Main
     
  3. GamingFR91

    GamingFR91 Spider Jockey

    Messages:
    27
    GitHub:
    kanekilechomeur
    ----------------------------------------------------------

    here is an example if you want:
    -----------------------------------------------------------

    PHP:
    <?php

    namespace NewEntity;

    use 
    pocketmine\data\bedrock\EntityLegacyIds;
    use 
    pocketmine\entity\EntitySizeInfo;
    use 
    pocketmine\entity\Living;


    Class 
    NewEntity extends Living{

        protected function 
    getInitialSizeInfo(): EntitySizeInfo
        
    {
            return new 
    EntitySizeInfo(1.80.6);
        }

        public static function 
    getNetworkTypeId(): string
        
    {
            
    //replace it by the entity that you want
            
    return EntityLegacyIds::ARMOR_STAND;
        }

        public function 
    getName(): string
        
    {
            return 
    "Armor Stand";
        }

        public function 
    getDrops(): array
        {
            return [];
        }

        public function 
    getXpDropAmount(): int
        
    {
            return 
    2;
        }

    }
     
    Last edited: May 1, 2022
  4. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    41
    GitHub:
    FresherGAMING
    Now, how to summon the entity ?
    for example, when you break any block, the entities appeared 5 blocks in front of you
     
  5. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    41
    GitHub:
    FresherGAMING

Share This Page

  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.