1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How do I go about spawning this..?

Discussion in 'Development' started by Indexfire, Sep 25, 2017.

  1. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Recently tried my hand at Mobs (a Wither):
    PHP:
    <?php

    namespace endermysteryteam\megawalls\entities;

    use 
    pocketmine\entity\Monster;
    use 
    pocketmine\network\mcpe\protocol\AddEntityPacket;
    use 
    pocketmine\Player;
    use 
    pocketmine\entity\ProjectileSource;

    abstract class 
    WitherEntity extends Monster implements ProjectileSource{
       
        const 
    NETWORK_ID 52;
        public 
    $width 0.9;
        public 
    $height 3.5;
       
        public function 
    spawnTo(Player $player){
            
    $pk = new AddEntityPacket();
            
    $pk->entityRuntimeId $this->getId();
            
    $pk->type WitherEntity::NETWORK_ID;
            
    $pk->$this->x;
            
    $pk->$this->y;
            
    $pk->$this->z;
            
    $pk->speedX $this->motionX;
            
    $pk->speedY $this->motionY;
            
    $pk->speedZ $this->motionZ;
            
    $pk->yaw $this->yaw;
            
    $pk->pitch $this->pitch;
            
    $pk->metadata $this->dataProperties;
            
    $player->dataPacket($pk);
            
    parent::spawnTo($player);
        }
       
        public static function 
    addWitherEntity(Location $posstring $name){
            
    $nbt = new CompoundTag;
            
    $nbt->Pos = new ListTag("Pos", [
                    new 
    DoubleTag(""$pos->x),
                    new 
    DoubleTag(""$pos->y),
                    new 
    DoubleTag(""$pos->z)
            ]);
            
    $nbt->Rotation = new ListTag("Rotation", [
                    new 
    FloatTag(""$pos->yaw),
                    new 
    FloatTag(""$pos->pitch)
            ]);
            
    $nbt->Health = new ShortTag("Health"600);
            
    $nbt->displayname $name;
            
    $chunk $player->chunk;
            if (!
    $chunk instanceof Chunk) {
                return;
            }
            
    $entity Entity::createEntity("Wither"$chunk$nbt);
            
    $entity->spawnToAll();
            
    $entity->saveNBT();
            
    $entity->setNamedTagVisible(true);
            
    $entity->setNamedTagAlwaysVisible(true);
            
    $entity->setNamedTag($nbt->displayname);
        }
       
    }

    ?>
    How would I spawn/register the Wither now?
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
  3. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
  4. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Didnt want the Wither to implement the drop loot and get name method lel

    Edit: crud just read the registerEntity method and it dosent accept abstract class

    Also what does the $force boolean do?
     
    Last edited: Sep 25, 2017
  5. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    You cannot construct abstract classes.

    Overwrites a previously registered entity if it has the same class name.
     
    artulloss and Muqsit like this.
  6. AshBull

    AshBull Spider Jockey

    Messages:
    31
    jasonwynn10 likes this.
  7. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    How do i spawn it and define custom behaviour though? This seems so much different than on Bukkit where NMS was so fun to mess with...

    Interestingly though, in the Entity class constructor, the EntitySpawnEvent is called, which must mean that spawning the mob you added via Plugin must have something to do with the constructor, just cant figure out what to do yet...
     
  8. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Oops :p

    PHP:
    $entity pocketmine\entity\Entity::create("WitherEntity"pocketmine/Server::getInstance()->getDefaultLevel(), new pocketmine\nbt\tag\CompoundTag("", [
        new 
    pocketmine\nbt\tag\ListTag("Pos", [
            new 
    pocketmine\nbt\tag\DoubleTag(""127),
            new 
    pocketmine\nbt\tag\DoubleTag(""80),
            new 
    pocketmine\nbt\tag\DoubleTag(""127),
        ],
        new 
    pocketmine\nbt\tag\ListTag("Motion", [
            new 
    pocketmine\nbt\tag\DoubleTag(""0),
            new 
    pocketmine\nbt\tag\DoubleTag(""0),
            new 
    pocketmine\nbt\tag\DoubleTag(""0),
        ],
        new 
    pocketmine\nbt\tag\ListTag("Rotation", [
            new 
    pocketmine\nbt\tag\FloatTag(""0.0),
            new 
    pocketmine\nbt\tag\FloatTag(""0.0),
        ],
    ]);
    $entity->spawnToAll();
     
    Indexfire likes this.
  9. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Actually would this work?
    PHP:
    <?php

    namespace endermysteryteam\megawalls\entities;

    use 
    pocketmine\entity\Monster;
    use 
    pocketmine\network\mcpe\protocol\AddEntityPacket;
    use 
    pocketmine\Player;
    use 
    pocketmine\entity\ProjectileSource;

    class 
    WitherEntity extends Monster implements ProjectileSource{
     
        const 
    NETWORK_ID 52;
        public 
    $width 0.9;
        public 
    $height 3.5;
     
        public function 
    spawnTo(Player $player){
            
    $pk = new AddEntityPacket();
            
    $pk->entityRuntimeId $this->getId();
            
    $pk->type WitherEntity::NETWORK_ID;
            
    $pk->$this->x;
            
    $pk->$this->y;
            
    $pk->$this->z;
            
    $pk->speedX $this->motionX;
            
    $pk->speedY $this->motionY;
            
    $pk->speedZ $this->motionZ;
            
    $pk->yaw $this->yaw;
            
    $pk->pitch $this->pitch;
            
    $pk->metadata $this->dataProperties;
            
    $player->dataPacket($pk);
            
    parent::spawnTo($player);
        }
     
        public static function 
    addWitherEntity(Location $posstring $name){
            
    $nbt = new CompoundTag;
            
    $nbt->Pos = new ListTag("Pos", [
                    new 
    DoubleTag(""$pos->x),
                    new 
    DoubleTag(""$pos->y),
                    new 
    DoubleTag(""$pos->z)
            ]);
            
    $nbt->Rotation = new ListTag("Rotation", [
                    new 
    FloatTag(""$pos->yaw),
                    new 
    FloatTag(""$pos->pitch)
            ]);
            
    $nbt->Health = new ShortTag("Health"600);
            
    $nbt->displayname $name;
            
    $chunk $player->chunk;
            if (!
    $chunk instanceof Chunk) {
                return;
            }
            
    $entity Entity::createEntity("WitherEntity"$chunk$nbt);
            
    $entity->spawnToAll();
            
    $entity->saveNBT();
            
    $entity->setNamedTagVisible(true);
            
    $entity->setNamedTagAlwaysVisible(true);
            
    $entity->setNamedTag($nbt->displayname);
        }
     
    }

    ?>
     
  10. AshBull

    AshBull Spider Jockey

    Messages:
    31
    Just a note, if you have the NETWORK_ID set to anything other than -1, spawn eggs with that same damage value will spawn your entity.
     
    Muqsit and Jack Noordhuis like this.
  11. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Try executing it.

    Entity::setNamedTagVisible(), Entity::setNamedTagAlwaysVisible() and Entity::setNamedTag() do not exist. You probably meant Entity::setNameTag*().
    Aside from that...
    • The chunk checking is unneeded.
    • The game doesn't listen to "displayname" tag, you can remove that unless you are using it (the game isn't using it). If you are implementing it, create a StringTag instance. I don't think that NBT key is gonna get saved.
     
    Last edited: Sep 27, 2017
    Indexfire likes this.
  12. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Just tried it and of course it wont work lmao

    Apparently pocketmine hates mobs
     
  13. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    The plugin literally crashed on startup registering the Wither didnt even have a chance
     
  14. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    If you are using alpha8 or 9 you need to update your code: newer API versions use Vector3 for Entity speed and motion, not x, y, z.
     
    Last edited: Sep 30, 2017
  15. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Err that was the code you gave me over half a year ago...
    Where doe?
     
    Last edited: Oct 1, 2017
  16. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Everywhere you set position or speed for an entity. If you set up your IDE correctly it should tell you that $pk->x doesn't exist, for example.
     
    jasonwynn10 likes this.
  17. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Dammit i guess Eclipse is a potato then

    (But no PHP IDE i seen so far ever corrects errors in code soo...)

    Edit: GitHub sure is handy
    PHP:
    public function spawnTo(Player $player){
            
    $pk = new AddEntityPacket();
            
    $pk->entityRuntimeId $this->getId();
            
    $pk->type Zombie::NETWORK_ID;
            
    $pk->position $this->asVector3();
            
    $pk->motion $this->getMotion();
            
    $pk->yaw $this->yaw;
            
    $pk->pitch $this->pitch;
            
    $pk->metadata $this->dataProperties;
            
    $player->dataPacket($pk);
            
    parent::spawnTo($player);
        }
     
  18. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    As long as you add pocketmine source code to your projects you'll be able to 'inspect', and you should see warnings on the page itself for errors like this in any decent IDE, such as PHPStorm, Eclipse and Netbeans.
     
    jasonwynn10 likes this.
  19. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    NetBeans didnt do shit when i added the pocketmine source it didnt even auto import from pocketmine lmao

    Eclipse is working better but even then its still a potato most of the time. Sure as heck dosent match the Java version of itself
     
  20. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Hmm...
     
  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.