Skip to content

Register ParticleProvider Event

Maksym Uimanov edited this page Feb 12, 2026 · 2 revisions

Register ParticleProvider Event

The @RegisterParticleProvider annotation provides a declarative way to register particle providers for custom particle types. This annotation automatically handles the registration of particle providers with Minecraft's particle system during the particle provider registration phase, eliminating the need for manual event handler registration.

Responsibilities / Purpose

The @RegisterParticleProvider annotation is responsible for:

  • Automatically registering particle providers for custom particle types
  • Managing the relationship between particle types and their corresponding providers
  • Eliminating manual event handler registration for particle setup
  • Ensuring proper instantiation of particle providers with required SpriteSet parameter
  • Handling the reflection-based instantiation of particle provider classes

How it works

The Register Particle Provider system operates through the following process:

  1. Field Scanning: The annotation processor scans fields annotated with @RegisterParticleProvider
  2. Particle Type Extraction: The strategy extracts the ParticleType from the annotated field
  3. Provider Class Resolution: The specified provider class is obtained from the annotation value
  4. Constructor Preparation: The strategy locates the provider constructor that accepts a SpriteSet parameter
  5. Registration Queue: A registration consumer is added to the queue in RegisterParticleProvidersEventHandler
  6. Event Processing: During RegisterParticleProvidersEvent, the provider is instantiated and registered

The annotation is processed within the RegisterParticleProvidersEventHandlerAnnotationProcessorAdapter scope, ensuring execution at the correct time in the particle system initialization lifecycle.

How to use / Configure

Basic Usage

Apply the annotation to your particle type field, specifying the provider class:

public final class ExampleParticleTypes {
    private static final ParticleTypeFactory PARTICLE_TYPE_FACTORY = InjectionPool.getFromInstance(ParticleTypeFactory.class);

    @RegisterParticleProvider(ExampleParticle.Provider.class)
    @GenerateParticleSpriteSet(id = "example:example", count = 6)
    public static final DeferredHolder<ParticleType<?>, ParticleType<SimpleParticleType>> EXAMPLE_PARTICLE_TYPE = 
        PARTICLE_TYPE_FACTORY.create("example", true);
}

Particle Provider Implementation

Create a particle provider class that extends or implements the appropriate particle provider interface:

public class ExampleParticle extends SimpleParticle {
    protected ExampleParticle(ClientLevel level, double x, double y, double z, 
                              double xSpeed, double ySpeed, double zSpeed, SpriteSet spriteSet) {
        super(level, x, y, z, xSpeed, ySpeed, zSpeed, spriteSet);
        this.friction = 0.96F;
        this.speedUpWhenYMotionIsBlocked = true;
        this.quadSize *= 0.75F;
        this.hasPhysics = false;
    }

    @Override
    @NotNull
    public ParticleRenderType getRenderType() {
        return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
    }

    public static class Provider extends SimpleParticle.Provider {
        public Provider(SpriteSet spriteSet) {
            super(spriteSet);
        }

        @Override
        public Particle createParticle(@NotNull SimpleParticleType simpleParticleType, 
                                      @NotNull ClientLevel clientLevel, 
                                      double x, double y, double z, 
                                      double xSpeed, double ySpeed, double zSpeed, 
                                      SpriteSet spriteSet) {
            ExampleParticle particle = new ExampleParticle(clientLevel, x, y, z, xSpeed, ySpeed, zSpeed, spriteSet);
            particle.setAlpha(1.0F);
            particle.setParticleSpeed(xSpeed * 0.25D, ySpeed * 0.25D, zSpeed * 0.25D);
            particle.setLifetime(clientLevel.random.nextInt(6) + 6);
            return particle;
        }
    }
}

Annotation Parameters

  • value (Class extends ParticleProvider>>): The particle provider class that will be instantiated and registered

Requirements

The particle provider class must:

  • Implement or extend ParticleProvider<?>
  • Have a constructor that accepts a SpriteSet parameter
  • Be accessible (public or package-private with appropriate access)

Extension / Customization Points

The Register Particle Provider system can be extended by:

  1. Custom Particle Types: Create new particle types with custom behavior
  2. Complex Providers: Implement sophisticated particle providers with custom rendering logic
  3. Particle Variants: Register multiple providers for different particle variants
  4. Custom Factories: Use different particle type factories for specialized particle creation

When to use

Use @RegisterParticleProvider when:

  • Creating custom particle types that need provider registration
  • You want to eliminate manual event handler registration for particles
  • You need to ensure proper timing of particle provider registration
  • You want to follow a declarative approach to particle system setup
  • Your particle provider requires a SpriteSet constructor parameter

Clone this wiki locally