$x = $player->x; $y = $player->y; $z = $player->z; $position = new Position($x, $y, $z, $player->getLevel()); $nbtcr = Entity::createBaseNBT($position); $sc = Entity::createEntity(10, $level, $nbtcr, true); $sc->spawnTo($player);
See here how the other entities are registered: https://github.com/pmmp/PocketMine-...58eeae3/src/pocketmine/entity/Entity.php#L340
$x = $player->x; $y = $player->y; $z = $player->z; $position = new Position($x, $y, $z, $player->getLevel()); Entity::registerEntity(Chicken::class, false, ['Chicken', 'minecraft:Chicken']); $nbtcr = Entity::createBaseNBT($position); $sc = Entity::createEntity(Chicken, $level, $nbtcr, true); $sc->spawnTo($player); I added Entity::registerEntity(Chicken::class, false, ['Chicken', 'minecraft:Chicken']); but it doesn't work and says ReflectionException: "Class ms\Chicken does not exist" (-1) in "src/pocketmine/entity/Entity" at line 391
I made a new folder(src->chicken->CChicken.php) and I wrote <?php declare(strict_types=1); namespace ms\chicken; class CChicken extends ms { const TYPE_ID = 10; const HEIGHT = 0.7; } and I added "use chicken\CChicken;" in MS.php(src->ms->MS.php) but nothing happened. no crash.
"extends ms" why?! Take a look at the built-in entities: https://github.com/pmmp/PocketMine-...c20ef230dcadd33343b32c4/src/pocketmine/entity
I see it, but I don't know what to do now.. I'm plugin beginner, please help me more detail. then what should I edit?
Your class will need to inherit "Entity" (in this case "Animal" is probably the best choice). You will need to have basic understanding of OOP if you want to make a complex PocketMine plugin.
I edit MS.php like this(down) <?php namespace ms; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\item\ItemBlock; use pocketmine\item\Item; use pocketmine\level\Particle; use pocketmine\level\Position; use pocketmine\level\particle\FlameParticle; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\DoubleTag; use pocketmine\nbt\tag\FloatTag; use pocketmine\entity\Entity; use pocketmine\level\Level; use pocketmine\Player; use pocketmine\math\Vector3; use ms\CChicken; class MS extends PluginBase implements Listener{ const ENTITY_TYPES = "Chicken" public function onEnable(){ foreach (Chicekn as $className){ Entity::registerEntity($className, true); } $this->getServer()->getPluginManager()->registerEvents($this,$this); } public function Throwing(PlayerInteractEvent $event){ $player = $event->getPlayer(); $level = $player->getLevel(); if($event->getItem()->getId() == 280){ $nbt = new CompoundTag("", [ "Pos" => new ListTag("Pos", [ new DoubleTag("", $player->x), new DoubleTag("", $player->y + $player->getEyeHeight()), new DoubleTag("", $player->z) ]), "Motion" => new ListTag("Motion", [ new DoubleTag("", -sin($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI)), new DoubleTag("", -sin($player->pitch / 180 * M_PI)), new DoubleTag("", cos($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI)) ]), "Rotation" => new ListTag("Rotation", [ new FloatTag("", $player->yaw), new FloatTag("", $player->pitch) ]), ]); $x = $player->x; $y = $player->y; $z = $player->z; $position = new Position($x, $y, $z, $player->getLevel()); $nbtcr = Entity::createBaseNBT($position); $sc = Entity::createEntity(Chicken, $level, $nbtcr, true); $sc->spawnTo($player); and I edit CChicken.php like this(down) <?php declare(strict_types=1); namespace ms\chicken; class CChicken extends PluginBase { const TYPE_ID = 10; const HEIGHT = 0.7; } and There is no crash but still nothing happening, what's wrong??
Is there example plugin? I Iittle understanded about OOP, but still don't know how to solve this.. I want to just make spawning one chicken to me when I touch with stick... I edit MS.php <?php namespace ms; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\item\ItemBlock; use pocketmine\item\Item; use pocketmine\level\Particle; use pocketmine\level\Position; use pocketmine\level\particle\FlameParticle; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\DoubleTag; use pocketmine\nbt\tag\FloatTag; use pocketmine\entity\Entity; use pocketmine\level\Level; use pocketmine\Player; use pocketmine\math\Vector3; use chicken\CChicken; class MS extends PluginBase implements Listener{ const ENTITY_TYPES = "Chicken"; public function onEnable(){ foreach (ENTITY_TYPES as $className){ Entity::registerEntity($className, true); } $this->getServer()->getPluginManager()->registerEvents($this,$this); } public function Throwing(PlayerInteractEvent $event){ $player = $event->getPlayer(); $level = $player->getLevel(); if($event->getItem()->getId() == 280){ $nbt = new CompoundTag("", [ "Pos" => new ListTag("Pos", [ new DoubleTag("", $player->x), new DoubleTag("", $player->y + $player->getEyeHeight()), new DoubleTag("", $player->z) ]), "Motion" => new ListTag("Motion", [ new DoubleTag("", -sin($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI)), new DoubleTag("", -sin($player->pitch / 180 * M_PI)), new DoubleTag("", cos($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI)) ]), "Rotation" => new ListTag("Rotation", [ new FloatTag("", $player->yaw), new FloatTag("", $player->pitch) ]), ]); $x = $player->x; $y = $player->y; $z = $player->z; $position = new Position($x, $y, $z, $player->getLevel()); $nbtcr = Entity::createBaseNBT($position); $sc = Entity::createEntity(Chicken, $level, $nbtcr, true); $sc->spawnTo($player); and I edit CChicken.php <?php use pocketmine\entity\Animal; //declare(strict_types=1); namespace chicken; class CChicken extends Animal { const TYPE_ID = 10; const HEIGHT = 0.7; } It says "Use of undefined constant ENTITY_TYPES - assumed 'ENTITY_TYPES' (this will throw an Error in a future version of PHP)" (EXCEPTION) in "plugins/monster/src/ms/MS" at line 61