-
Notifications
You must be signed in to change notification settings - Fork 0
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.
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
The Register Particle Provider system operates through the following process:
-
Field Scanning: The annotation processor scans fields annotated with
@RegisterParticleProvider -
Particle Type Extraction: The strategy extracts the
ParticleTypefrom the annotated field - Provider Class Resolution: The specified provider class is obtained from the annotation value
-
Constructor Preparation: The strategy locates the provider constructor that accepts a
SpriteSetparameter -
Registration Queue: A registration consumer is added to the queue in
RegisterParticleProvidersEventHandler -
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.
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);
}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;
}
}
}- value (Class extends ParticleProvider>>): The particle provider class that will be instantiated and registered
The particle provider class must:
- Implement or extend
ParticleProvider<?> - Have a constructor that accepts a
SpriteSetparameter - Be accessible (public or package-private with appropriate access)
The Register Particle Provider system can be extended by:
- Custom Particle Types: Create new particle types with custom behavior
- Complex Providers: Implement sophisticated particle providers with custom rendering logic
- Particle Variants: Register multiple providers for different particle variants
- Custom Factories: Use different particle type factories for specialized particle creation
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
🚀 Getting Started
🧩 Core Concepts
⚙️ Data Generation
- ⚙️ Advancement
- ⚙️ Damage Type
- ⚙️ Chest Loot Modifier
- ⚙️ Recipe
- ⚙️ Sound
- ⚙️ Jukebox Song
- ⚙️ Enchantment
- ⚙️ Trim Material
- ⚙️ Trim Pattern
- ⚙️ Banner Pattern
- ⚙️ Painting Variant
- ⚙️ Particle Sprite Set
- ⚙️ Wolf Variant
- ⚙️ Item Model
- ⚙️ Block Model
- ⚙️ Block Loot Table
- ⚙️ Tag
- ⚙️ Language Translation
- ⚙️ World Feature
- ⚙️ Custom Properties
🚨 Events
🛠 Engine Layers
🧪 Resources
- 🧪 Examples