Interface EntityInjection<M extends net.minecraft.world.entity.Entity,E extends Entity>

Type Parameters:
M - the type of the Minecraft entity being injected
E - the type of the Bukkit entity the Minecraft entity can be converted to

public sealed interface EntityInjection<M extends net.minecraft.world.entity.Entity,E extends Entity>
Represents all necessary metadata and configuration for injecting a custom 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:
  • Method Details

    • getKey

      Key getKey()
      Returns the unique key representing this entity type.
      Returns:
      the namespaced key
    • getEntityClass

      Class<M> 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 type EntityInjection into a Bukkit entity of type EntityInjection.
      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

      Consumer<net.minecraft.world.entity.EntityType.Builder<M>> 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. Returns null if the entity does not extend LivingEntity and therefore does not have attributes.
      Returns:
      the attribute supplier or null
    • getModelPrefix

      default String 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:

      bestium.<key_namespace>.<key_value>
      where slashes in the key's value are replaced with dots.

      This prefix is used to construct full model names for the entity's variants. For example, if the prefix is

      bestium.my_plugin.capybara
      the full variant model name might be:
      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

      @Unmodifiable Map<Locale,Component> getDisplayNames()
      Returns a map of display names, where each Locale corresponds to a Component that serves as the display name.
      Returns:
      an unmodifiable map of locales to display name components
    • getDisplayName

      default @Nullable Component getDisplayName(Locale locale)
      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 the VariantRule 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 the SpawnRule 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 synthetic EntityType 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 this EntityInjection 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 new EntityInjection.Builder for constructing an EntityInjection.

      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 like EntityType.PIG or EntityType.PIG.
      • If your entity extends Monster, use a type like EntityType.ZOMBIE.
      • If your entity is non-living (e.g., a custom minecart), you MUST NOT use a living backing type, and vice versa.
      Incorrectly pairing a living and non-living type will disconnect clients.

      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 injected
      E - the type of the Bukkit entity the Minecraft entity can be converted to
      Parameters:
      key - a namespaced key such as my_plugin:my_custom_entity
      entityClass - the class representing your custom entity
      entityFactory - the factory used to instantiate the entity (usually CustomEntityClass::new)
      convertFunction - the factory used to create a Bukkit representation of this entity (e.g., CraftAnimals::new)
      backingType - the backing vanilla EntityType used for network communication
      Returns:
      a new builder instance
      See Also: