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

No pig spawn on command

Discussion in 'Development' started by Robertcc19, Jan 1, 2017.

  1. Robertcc19

    Robertcc19 Silverfish

    Messages:
    18
    After a few hours of reading through the api docs and PMMP source I am unsure wh I am not getting a pig to spawn when I run my command

    PHP:
    <?php

    namespace robertcc19\spawnanimals;
        use 
    pocketmine\level\format\FullChunk;
        use 
    pocketmine\plugin\PluginBase;
        use 
    pocketmine\command\Command;
        use 
    pocketmine\command\CommandSender;
        use 
    pocketmine\command\CommandExecutor;
        use 
    pocketmine\entity\Entity;
        use 
    pocketmine\entity\Pig;
        use 
    pocketmine\level\Level;
        use 
    pocketmine\level\Position;
        use 
    pocketmine\math\Vector3;
        use 
    pocketmine\nbt\NBT;
        use 
    pocketmine\nbt\tag\ByteTag;
        use 
    pocketmine\nbt\tag\CompoundTag;
        use 
    pocketmine\nbt\tag\DoubleTag;
        use 
    pocketmine\nbt\tag\FloatTag;
        use 
    pocketmine\nbt\tag\IntTag;
        use 
    pocketmine\nbt\tag\ListTag;
        use 
    pocketmine\nbt\tag\ShortTag;
        use 
    pocketmine\nbt\tag\StringTag;
        use 
    pocketmine\entity\Villager;
        use 
    pocketmine\event\Listener;
        use 
    pocketmine\Player;
        use 
    pocketmine\Server;
        use 
    pocketmine\event\player\PlayerJoinEvent;





       class 
    AnimalSpawn extends PluginBase implements Listener
       
    {


           
    /**
            * @param CommandSender $sender
            * @param Command $command
            * @param string $label
            * @param array $args
            * @return bool
            */
           
    public function onCommand(CommandSender $senderCommand $command$label, array $args)
           {
               if (
    strtolower($command->getName()) === "vc") {
               if (
    $sender instanceof Player) {
                   if (
    count($args) === 1) {
                       
    $name $args[0];
                       
    $player $this->getServer()->getPlayer($name);
                       
    $nbt = new CompoundTag ("", [
                           
    "Pos" => new ListTag("Pos", [
                               new 
    DoubleTag(""$player->x),
                               new 
    DoubleTag(""$player->y),
                               new 
    DoubleTag(""$player->z)
                           ]),
                           
    "Motion" => new ListTag ("Motion", [
                               new 
    DoubleTag(""0),
                               new 
    DoubleTag(""0),
                               new 
    DoubleTag(""0)
                           ]),
                           
    "Rotation" => new ListTag("Rotation", [
                               new 
    FloatTag(""90),
                               new 
    FloatTag(""90)
                           ])
                       ]);
                       
    $youranimal Entity::createEntity(Pig::NETWORK_ID$player->chunk$nbt);
                       
    $youranimal->spawnToAll();

                   }

                   }
               }
           }
       }

    ?>
    I am getting this error
    Class pocketmine\entity\Pig contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (pocketmine\entity\Living::getName)
     
    Last edited: Jan 1, 2017
  2. Robertcc19

    Robertcc19 Silverfish

    Messages:
    18
    I am a bit confused by why the world does not spawn animals on it's own or why spawn eggs do not work but I would like to get this plugin working
    Any help would be appreciated!
     
  3. SuperDude36

    SuperDude36 Spider Jockey

    Messages:
    26
    GitHub:
    superdude36
    Doesn't PMMP have /summon Pig ~ ~ ~ ?
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    No
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    well we dont support forks so idk either ¯\_(ツ)_/¯
     
    HimbeersaftLP likes this.
  6. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Entity's aren't implemented properly into PocketMine and won't be until some time after the core rewrite. If you want to spawn an entity your best bet would be to create your own class that extends an existing entity. In your case you'd want to extend the pocketmine\entity\Pig class:

    PHP:
    <?php

    namespace your\plugin\namespace;

    use 
    pocketmine\entity\Pig;

    class 
    MyPig extends Pig {

        
    // fix the abstract class error
        
    public function getName() {
            return 
    "Pig";
        }

    }

    You also need to register your entity so the server knows what class to use when you spawn it, I'd suggest doing this in your PluginBase::onEnable method:

    PHP:
    public function onEnable(){
        
    pocketmine/entity/Entity::registerEntity(MyPig::class, true);
    }
    Now you can spawn your entity:
    PHP:
    $pig Entity::createEntity("MyPig"Level::getChunk($x >> 4$z >> 4), $nbt);
    if(
    $pig instanceof MyPig){
        
    $pig->spawnToAll();
    }else{
        
    $pig->kill();
    }
    Also, don't close your .php files with closing tags in plugins (?>) as it's bad practice and may cause unexpected behaviour.
     
    Last edited: Jan 11, 2017
  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.