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: <?phpnamespace 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 $sender, Command $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)
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!
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: <?phpnamespace 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.