Interface EntityInjection.Builder<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
All Superinterfaces:
AbstractBuilder<EntityInjection<M,E>>
Enclosing interface:
EntityInjection<M extends net.minecraft.world.entity.Entity,E extends Entity>

public static sealed interface EntityInjection.Builder<M extends net.minecraft.world.entity.Entity,E extends Entity> extends AbstractBuilder<EntityInjection<M,E>>
A builder used to configure and construct an EntityInjection.
  • Method Details

    • getKey

      Key getKey()
      Gets the entity key.
      Returns:
      the key
    • getEntityClass

      Class<M> getEntityClass()
      Gets the entity class.
      Returns:
      the class
    • getEntityFactory

      net.minecraft.world.entity.EntityType.EntityFactory<M> getEntityFactory()
      Gets the entity factory.
      Returns:
      the factory
    • getConvertFunction

      ConvertFunction<M,E> getConvertFunction()
      Gets the craft entity factory.
      Returns:
      the factory
    • setMobCategory

      EntityInjection.Builder<M,E> setMobCategory(net.minecraft.world.entity.MobCategory category)
      Sets the mob category of the entity.

      Defaults to: MobCategory.MISC.

      Parameters:
      category - the mob category
      Returns:
      this builder
    • getMobCategory

      net.minecraft.world.entity.MobCategory getMobCategory()
      Gets the mob category.
      Returns:
      the category
    • setTypeCustomizer

      EntityInjection.Builder<M,E> setTypeCustomizer(Consumer<net.minecraft.world.entity.EntityType.Builder<M>> typeBuilder)
      Sets a customizer for the entity type builder.

      For example, to define passenger attachments use: EntityType.Builder.passengerAttachments(Vec3...).

      Defaults to: an empty Consumer.

      Parameters:
      typeBuilder - the builder customizer
      Returns:
      this builder
    • getTypeCustomizer

      Consumer<net.minecraft.world.entity.EntityType.Builder<M>> getTypeCustomizer()
      Gets the type builder customizer.
      Returns:
      the builder consumer
    • setDefaultAttributes

      EntityInjection.Builder<M,E> setDefaultAttributes(net.minecraft.world.entity.ai.attributes.AttributeSupplier attributes)
      Sets the default attributes for this entity. Only valid for entities extending LivingEntity.

      Defaults to: LivingEntity.createLivingAttributes() if this entity is a LivingEntity otherwise to null.

      Parameters:
      attributes - the attributes
      Returns:
      this builder
      Throws:
      UnsupportedOperationException - if the entity is not a LivingEntity
      See Also:
      • AttributeSupplier.Builder
    • setDefaultAttributes

      default EntityInjection.Builder<M,E> setDefaultAttributes(net.minecraft.world.entity.ai.attributes.AttributeSupplier.Builder builder)
      Sets the default attributes for this entity. Only valid for entities extending LivingEntity.

      Defaults to: LivingEntity.createLivingAttributes() if this entity is a LivingEntity otherwise to null.

      Parameters:
      builder - the builder used to construct the attributes
      Returns:
      this builder
      Throws:
      UnsupportedOperationException - if the entity is not a LivingEntity
      See Also:
      • AttributeSupplier.Builder
    • getDefaultAttributes

      @Nullable net.minecraft.world.entity.ai.attributes.AttributeSupplier getDefaultAttributes()
      Gets the attribute supplier, or null if this entity is not a LivingEntity.
      Returns:
      the attributes or null
    • setVariants

      Replaces all entity variants providing models for this entity injection with the given collection.

      This operation discards any previously added variants, whether added via this or other methods. The order of variants in the provided collection matters: the default variant chosen by a spawning entity will be the first variant in this collection.

      The collection must not contain variants with duplicate IDs. If duplicates exist, they will be silently eliminated with undefined behavior.

      Defaults to: no variants

      Parameters:
      variants - the collection of unbound entity variants to set
      Returns:
      this builder
      See Also:
    • addVariant

      Adds a single entity variant providing a model to this entity injection.

      If this is the first variant added, it will be used as the default variant when a spawning entity is choosing a model.

      If a variant with the same ID already exists, this method will ignore the new variant silently.

      Parameters:
      variant - the unbound entity variant to add
      Returns:
      this builder
      See Also:
    • addVariants

      default EntityInjection.Builder<M,E> addVariants(Collection<UnboundEntityVariant> variants)
      Adds a collection of entity variants providing models to this entity injection.

      The order of variants in the collection matters: if this is the first time variants are added, the first element will be used as the default variant when a spawning entity is choosing a variant.

      Variants with IDs that duplicate existing variants in the injection will be ignored. If there are duplicate IDs within the provided collection itself, the first variant encountered with that ID will be prioritized.

      Parameters:
      variants - the collection of unbound entity variants to add
      Returns:
      this builder
      See Also:
    • addVariants

      Adds two or more entity variants providing models to this entity injection.

      The order of variants matters: if this is the first time variants are added, the first argument will be the default variant selected when a spawning entity is choosing a model.

      Variants with duplicate IDs compared to already added variants will be ignored. For duplicates within the arguments themselves, the first variant with the ID will be prioritized.

      Parameters:
      first - the first unbound entity variant to add
      second - the second unbound entity variant to add
      rest - additional unbound entity variants to add
      Returns:
      this builder
      See Also:
    • getVariants

      @Unmodifiable Set<UnboundEntityVariant> getVariants()
      Returns an unmodifiable set of entity variants added to this entity injection.

      The returned set preserves the order in which variants were added.

      Returns:
      an unmodifiable, ordered set of added entity variants
    • setVariantRule

      EntityInjection.Builder<M,E> setVariantRule(VariantRule variantRule)
      Sets the VariantRule responsible for picking the BoundEntityVariant when this entity spawns into the world.

      Defaults to: VariantRule.first()

      Parameters:
      variantRule - the variant rule
      Returns:
      this builder
    • setComputedVariantRule

      default EntityInjection.Builder<M,E> setComputedVariantRule(Supplier<VariantRule> variantRuleSupplier)
      Computes and then sets the VariantRule responsible for picking the BoundEntityVariant when this entity spawns into the world.

      This method may be useful when additional logic needs to run before returning the variant rule.

      Defaults to: VariantRule.first()

      Parameters:
      variantRuleSupplier - the supplier providing the variant rule
      Returns:
      this builder
    • setDisplayNames

      EntityInjection.Builder<M,E> setDisplayNames(Map<Locale,Component> displayNames)
      Sets the display name Components for the injected entity, mapped by Locale.
      Parameters:
      displayNames - a map of locales to display name components
      Returns:
      this builder
    • setDisplayName

      EntityInjection.Builder<M,E> setDisplayName(Locale locale, Component displayName)
      Sets the display name Component for the injected entity for a specific Locale.
      Parameters:
      locale - the locale for which the display name component is being set
      displayName - the component to be used as the display name
      Returns:
      this builder
    • setDisplayName

      default EntityInjection.Builder<M,E> setDisplayName(Locale locale, String displayName)
      Sets the display name for the specified Locale.
      Parameters:
      locale - the locale for which the display name is being set
      displayName - the display name to set
      Returns:
      this builder
    • setDisplayName

      default EntityInjection.Builder<M,E> setDisplayName(Component displayName)
      Sets the display name Component for the Locale.US locale.
      Parameters:
      displayName - the display name component to set
      Returns:
      this builder
    • setDisplayName

      default EntityInjection.Builder<M,E> setDisplayName(String displayName)
      Sets the display name for the Locale.US locale.
      Parameters:
      displayName - the display name to set
      Returns:
      this builder
    • 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 for this entity.
      Returns:
      the variant rule
    • setSpawnRule

      EntityInjection.Builder<M,E> setSpawnRule(SpawnRule spawnRule)
      Sets the SpawnRule responsible for choosing in which biomes, how often and in what group sizes this entity naturally spawns.

      Defaults to: SpawnRule.never()

      Parameters:
      spawnRule - the spawn rule for this entity
      Returns:
      this builder
    • 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
    • setComputedSpawnRule

      default EntityInjection.Builder<M,E> setComputedSpawnRule(Supplier<SpawnRule> spawnRuleSupplier)
      Computes and then sets the SpawnRule responsible for choosing in which biomes, how often and in what group sizes this entity naturally spawns.

      This method may be useful when additional logic needs to run before returning the spawn rule.

      Defaults to: SpawnRule.never()

      Parameters:
      spawnRuleSupplier - the supplier providing the spawn rule
      Returns:
      this builder
    • build

      EntityInjection<M,E> build()
      Builds the EntityInjection instance.
      Specified by:
      build in interface AbstractBuilder<M extends net.minecraft.world.entity.Entity>
      Returns:
      the built entity injection instance
      Throws:
      IllegalArgumentException - if the entity is a living entity and no attributes were provided