Create custom entity api 4

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

  1. FresherGAMING

    FresherGAMING Spider Jockey

    Messages:
    42
    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:
    29
    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:
    29
    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:
    42
    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:
    42
    GitHub:
    FresherGAMING
  6. hafy

    hafy Creeper

    Messages:
    3
    yes I also asked that
     
  7. Abininda13

    Abininda13 Spider

    Messages:
    13
    I think Ik But I think I will tell after some time
     
  8. BOFOIII

    BOFOIII Spider

    Messages:
    8
    GitHub:
    BOFOII
    I won't give an example code, but you can manipulate x y z on break block event, take position/location. you can add x y z as you like. all available in that class. what about after manipulating?. you just need to pass the first parameter (if I'm not mistaken) with the location you've manipulated
     

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.