Skip to content

Create Entity Attributes Event

Maksym Uimanov edited this page Feb 12, 2026 · 1 revision

Create Entity Attributes Event

The @CreateEntityAttributes annotation is used to automatically register entity attributes for custom entities during mod initialization. This annotation eliminates the need for manual attribute registration by programmatically mapping attribute builders to specific entity types.

Responsibilities / Purpose

  • Automates attribute registration: Registers entity attributes without manual event handling
  • Maps entities to attributes: Links entity types to their attribute configurations
  • Integrates with initialization: Works seamlessly with Temporal API's initialization system
  • Supports multiple entities: Allows one attribute method to serve multiple entity types

How it works

  1. Annotation processing: The framework scans methods annotated with @CreateEntityAttributes
  2. Method invocation: Invokes the annotated method to get the AttributeSupplier.Builder
  3. Entity mapping: Maps the attribute builder to specified entity type IDs
  4. Registration: Registers the attributes in the EntityAttributeEventHandler

Annotation Structure

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CreateEntityAttributes {
    String[] value();
}

Parameters

  • value (required): Array of entity type resource location strings to apply the attributes to

Usage Example

Basic Usage

public class ExampleEntity extends Turtle {
    public ExampleEntity(EntityType<? extends ExampleEntity> entityType, Level level) {
        super(entityType, level);
    }

    @NotNull
    @CreateEntityAttributes("example:example_entity")
    public static AttributeSupplier.Builder createAttributes() {
        return Mob.createMobAttributes()
                .add(Attributes.MAX_HEALTH, 20.0D)
                .add(Attributes.MOVEMENT_SPEED, 0.23D)
                .add(Attributes.ATTACK_DAMAGE, 3.0D);
    }
}

Multiple Entity Types

@NotNull
@CreateEntityAttributes({
    "example:example_entity",
    "example:example_entity_variant",
    "example:example_entity_boss"
})
public static AttributeSupplier.Builder createAttributes() {
    return Mob.createMobAttributes()
            .add(Attributes.MAX_HEALTH, 30.0D)
            .add(Attributes.MOVEMENT_SPEED, 0.25D)
            .add(Attributes.ATTACK_DAMAGE, 5.0D)
            .add(Attributes.ARMOR, 2.0D);
}

Method Requirements

The annotated method must follow these requirements:

Return Type

  • Required: AttributeSupplier.Builder

Modifiers

  • Required: public static
  • Optional: @NotNull (recommended for null safety)

Method Signature

public static AttributeSupplier.Builder createAttributes()

When to use

  • Custom entities: Any custom entity that needs specific attributes
  • Entity variants: Multiple entity types sharing the same attributes
  • Boss entities: Special entities with enhanced stats
  • Modded mobs: Replacing or extending vanilla entity attributes
  • Balanced gameplay: Ensuring proper attribute balance for custom mobs

Extension Points

The annotation system integrates with Temporal API's metadata processing:

  • Automatic registration: No manual event registration required
  • Multiple entity support: One method can serve multiple entity types
  • Strategy pattern: Uses CreateEntityAttributesStrategy for processing
  • Event handler integration: Works with EntityAttributeEventHandler
  • Reflection-based: Uses reflection to invoke attribute methods

The annotation maps to the CreateEntityAttributesStrategy that handles the attribute registration logic, allowing for easy extension and customization of the entity attribute system.

Clone this wiki locally