Interface EntityInjection<M extends net.minecraft.world.entity.Entity,E extends Entity>
- Type Parameters:
M
- the type of the Minecraft entity being injectedE
- the type of the Bukkit entity the Minecraft entity can be converted to
Entity
into the game.
Created using builder(Key, Class, EntityType.EntityFactory, ConvertFunction, EntityType)
.
After an instance is created, it can be injected into the server runtime using EntityInjector.register(Supplier)
)}.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
EntityInjection.Builder<M extends net.minecraft.world.entity.Entity,
E extends Entity> A builder used to configure and construct anEntityInjection
. -
Method Summary
Modifier and TypeMethodDescriptionstatic <M extends net.minecraft.world.entity.Entity,
E extends Entity>
EntityInjection.Builder<M, E> builder
(Key key, Class<M> entityClass, net.minecraft.world.entity.EntityType.EntityFactory<M> entityFactory, ConvertFunction<M, E> convertFunction, net.minecraft.world.entity.EntityType<?> backingType) Creates a newEntityInjection.Builder
for constructing anEntityInjection
.net.minecraft.world.entity.EntityType
<?> Returns the backing Minecraft entity type used for client-side rendering and hitbox size.Returns the function that converts the Minecraft entity of typeEntityInjection
into a Bukkit entity of typeEntityInjection
.@Nullable net.minecraft.world.entity.ai.attributes.AttributeSupplier
Returns the attribute supplier used to define default attributes for this entity.getDisplayName
(Locale locale) Retrieves the display name of this entity for the specified locale.Returns the class of the custom entity.net.minecraft.world.entity.EntityType.EntityFactory
<M> Returns the factory used to create new instances of this entity.getKey()
Returns the unique key representing this entity type.net.minecraft.world.entity.MobCategory
Returns the category of the entity.default String
Returns the model name prefix used for entity variants bound to this injection.net.minecraft.world.entity.EntityType
<M> Returns the syntheticEntityType
created and used internally by Bestium.Returns theSpawnRule
responsible for choosing in which biomes, how often and in what group sizes this entity naturally spawns.Returns the type builder customizer used to modify entity properties.Returns theVariantRule
responsible for choosing the variant for this entity when in spawns into the world.@Unmodifiable Map
<String, BoundEntityVariant> Returns the model variants associated with this entity injection.
-
Method Details
-
getKey
Key getKey()Returns the unique key representing this entity type.- Returns:
- the namespaced key
-
getEntityClass
Returns the class of the custom entity.- Returns:
- the entity class
-
getEntityFactory
net.minecraft.world.entity.EntityType.EntityFactory<M> getEntityFactory()Returns the factory used to create new instances of this entity.- Returns:
- the entity factory
-
getConvertFunction
ConvertFunction<M,E> getConvertFunction()Returns the function that converts the Minecraft entity of typeEntityInjection
into a Bukkit entity of typeEntityInjection
.- Returns:
- the convert function
-
getBackingType
net.minecraft.world.entity.EntityType<?> getBackingType()Returns the backing Minecraft entity type used for client-side rendering and hitbox size.- Returns:
- the backing type
-
getMobCategory
net.minecraft.world.entity.MobCategory getMobCategory()Returns the category of the entity.- Returns:
- the mob category
-
getTypeCustomizer
Returns the type builder customizer used to modify entity properties.- Returns:
- the builder customizer
-
getDefaultAttributes
@Nullable net.minecraft.world.entity.ai.attributes.AttributeSupplier getDefaultAttributes()Returns the attribute supplier used to define default attributes for this entity. Returnsnull
if the entity does not extendLivingEntity
and therefore does not have attributes.- Returns:
- the attribute supplier or
null
-
getModelPrefix
Returns the model name prefix used for entity variants bound to this injection.The returned string is based on the entity's Bestium
Key
, with the format:
where slashes in the key's value are replaced with dots.bestium.<key_namespace>.<key_value>
This prefix is used to construct full model names for the entity's variants. For example, if the prefix is
the full variant model name might be:bestium.my_plugin.capybara
bestium.my_plugin.capybara.cold
- Returns:
- the variant model prefix for this entity
- See Also:
-
getVariants
@Unmodifiable Map<String,BoundEntityVariant> getVariants()Returns the model variants associated with this entity injection.The returned map preserves the insertion order of the variants. Keys are the entity variant IDs, and values are the corresponding bound variants.
- Returns:
- an unmodifiable, insertion-ordered map of bound entity variants
-
getDisplayNames
Returns a map of display names, where eachLocale
corresponds to aComponent
that serves as the display name.- Returns:
- an unmodifiable map of locales to display name components
-
getDisplayName
Retrieves the display name of this entity for the specified locale.- Parameters:
locale
- the locale for which the display name should be retrieved- Returns:
- the display name entity, or
null
if no display name for provided locale was set
-
getVariantRule
VariantRule getVariantRule()Returns theVariantRule
responsible for choosing the variant for this entity when in spawns into the world.- Returns:
- the variant rule for this entity
-
getSpawnRule
SpawnRule getSpawnRule()Returns theSpawnRule
responsible for choosing in which biomes, how often and in what group sizes this entity naturally spawns.- Returns:
- the spawn rule for this entity
-
getRealType
net.minecraft.world.entity.EntityType<M> getRealType()Returns the syntheticEntityType
created and used internally by Bestium.Warning: This type is not safe to send to the client, as it is not recognized by vanilla clients and may cause packet errors or disconnections.
- Returns:
- the real entity type
- Throws:
IllegalStateException
- if thisEntityInjection
was not yet injected into the runtime- See Also:
-
builder
static <M extends net.minecraft.world.entity.Entity,E extends Entity> EntityInjection.Builder<M,E> builder(Key key, Class<M> entityClass, net.minecraft.world.entity.EntityType.EntityFactory<M> entityFactory, ConvertFunction<M, E> convertFunction, net.minecraft.world.entity.EntityType<?> backingType) Creates a newEntityInjection.Builder
for constructing anEntityInjection
.Choosing the correct
backingType
is critical. This is the entity type that will be sent to the client over the network protocol. If you choose an incompatible or distant type, it may lead to serious issues, including players being kicked with a "Network Protocol Error".The
backingType
should be as hierarchically close as possible to your custom entity. For example:- If your entity extends
Animal
, use a backing type likeEntityType.PIG
orEntityType.PIG
. - If your entity extends
Monster
, use a type likeEntityType.ZOMBIE
. - If your entity is non-living (e.g., a custom minecart), you MUST NOT use a living backing type, and vice versa.
The
backingType
can be changed after registration, changing all already spawned-in entities.For more guidance on choosing a convert function and backing type, visit the documentation.
- Type Parameters:
M
- the type of the Minecraft entity being injectedE
- the type of the Bukkit entity the Minecraft entity can be converted to- Parameters:
key
- a namespaced key such asmy_plugin:my_custom_entity
entityClass
- the class representing your custom entityentityFactory
- the factory used to instantiate the entity (usuallyCustomEntityClass::new
)convertFunction
- the factory used to create a Bukkit representation of this entity (e.g.,CraftAnimals::new
)backingType
- the backing vanillaEntityType
used for network communication- Returns:
- a new builder instance
- See Also:
- If your entity extends
-