Hello, I am wondering how to create an entity and by that I mean how to spawn sheep, cows, pigs, and chickens at a certain coordinate. They do not need to move. As long as they can be killed and loot drops.
Here's an example for a Cow entity. You start off by creating an Animal entity class and specify it's network id. Network IDs alter how the entity looks like. P.S. A list of entity IDs can be found here. You will need to specify the entity's width and height too, you can get those values from the Minecraft wiki. For our case, it's 0.9 and 1.4 for a cow. Widths and heights alter the bounding box and the hitbox of the entity. It's also mandatory to specify a getName() method that returns a string. Also, you might want to use the Monster entity class instead of Animal class for hostile mobs like zombies. If you are unsure, use the Creature class — that's what I do, I may be doing it wrong but for now, it doesn't make much of a difference. PHP: use pocketmine\entity\Animal;class Cow extends Animal{ const NETWORK_ID = self::COW; //if you change this to SHEEP, it will look like sheep public $width = 0.9; public $height = 1.4; public function getName() : string{ return "Cow"; }} Now you will need to register the entity when you plugin gets enabled, using PHP: Entity::registerEntity(Cow::class); Once that has been done, you can spawn the cow using a spawn egg. If you want to spawn it through code, read the SpawnEgg source code to figure out how pocketmine does it. Kinda offtopic but do read the README, there are consequences for abusing font sizes AFAIK.
There's an error on class Cow extends animal{ which says some error about pocketmine/entity/Living::getName();
I think it's the best solution : PHP: $nbt = Entity::createBaseNBT($pos, null, $yaw, $pitch);$entity = Entity::createEntity("Cow", $level, $nbt);$entity->spawnToAll();
I use that : PHP: $nbt = Entity::createBaseNBT($pos, null, $yaw, $pitch);$entity = Entity::createEntity("Cow", $level, $nbt);$entity->spawnToAll();
Updated code. Thanks. Also DON'T use PureEntities as it's destroying half the purpose of your thread.
How would I be able to dmg an entity such as cow, sheep, pig, or chicken. But only those 4. I have my server to block any entity dmg in the main world. What could I add into the function to make it allow only the 4 entities to be damaged?