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 interfaceEntityInjection.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.Builderfor 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 typeEntityInjectioninto a Bukkit entity of typeEntityInjection.@Nullable net.minecraft.world.entity.ai.attributes.AttributeSupplierReturns 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.MobCategoryReturns the category of the entity.default StringReturns the model name prefix used for entity variants bound to this injection.net.minecraft.world.entity.EntityType<M> Returns the syntheticEntityTypecreated and used internally by Bestium.Returns theSpawnRuleresponsible 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 theVariantRuleresponsible 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 typeEntityInjectioninto 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. Returnsnullif the entity does not extendLivingEntityand 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.capybarabestium.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 eachLocalecorresponds to aComponentthat 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
nullif no display name for provided locale was set
-
getVariantRule
VariantRule getVariantRule()Returns theVariantRuleresponsible for choosing the variant for this entity when in spawns into the world.- Returns:
- the variant rule for this entity
-
getSpawnRule
SpawnRule getSpawnRule()Returns theSpawnRuleresponsible 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 syntheticEntityTypecreated 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 thisEntityInjectionwas 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.Builderfor constructing anEntityInjection.Choosing the correct
backingTypeis 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
backingTypeshould be as hierarchically close as possible to your custom entity. For example:- If your entity extends
Animal, use a backing type likeEntityType.PIGorEntityType.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
backingTypecan 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_entityentityClass- 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 vanillaEntityTypeused for network communication- Returns:
- a new builder instance
- See Also:
- If your entity extends
-