Spawning an entity
After you have injected your entity, you will likely want to spawn it in the world.
You can use the /summon
command (e.g. /summon my_plugin:capybara
), but you may also want to do this programmatically using the Bestium API.
To spawn an entity with the API, use:
Bestium.getEntityManager().spawn(Location, Class, EntitySpawnReason, CreatureSpawnEvent.SpawnReason, [Consumer])
Bestium.getEntityManager().spawn(Location, Class, EntitySpawnReason, CreatureSpawnEvent.SpawnReason, [Consumer]);
This method requires four parameters:
1. Location
Section titled “1. Location”The position where the entity should be spawned.
Location(world, 0.0, 64.0, 0.0)
new Location(world, 0.0, 64.0, 0.0)
2. Class
Section titled “2. Class”The class of the injected entity you want to spawn.
Capybara::class.java
Capybara.class
3. EntitySpawnReason
Section titled “3. EntitySpawnReason”The (NMS) reason for spawning the entity, stored in the entity data.
For example, when spawning via a command:
EntitySpawnReason.COMMAND
EntitySpawnReason.COMMAND
4. CreatureSpawnEvent.SpawnReason
Section titled “4. CreatureSpawnEvent.SpawnReason”The (Bukkit) spawn reason, used for Bukkit events.
For example, when spawning via a command:
CreatureSpawnEvent.SpawnReason.COMMAND
CreatureSpawnEvent.SpawnReason.COMMAND
5. Consumer
(optional)
Section titled “5. Consumer (optional)”A function that allows you to modify the entity just before it is spawned.
This is useful if you want to customize the entity, right after creation.