Table of Contents

Adding Particles

Particles are textures used for special events and additional VFX. They are used on explosions, torches, dripping water and more!

Adding Simple Particles

Simple Particles might only use Minecraft's own particle Factories. This means all behavior must be equal to an already-existing particle in vanilla. For this example, we'll do a green-variant of FlameParticle - the particle used for the top of torches.

Initial register

First, register your particle in your ModInitializer:

  1. public class ExampleMod implements ModInitializer {
  2.  
  3. // instance of our particle
  4. public static final DefaultParticleType GREEN_FLAME = FabricParticleTypes.simple();
  5.  
  6. @Override
  7. public void onInitialize() {
  8. Registry.register(Registry.PARTICLE_TYPE, new Identifier("modid", "green_flame"), GREEN_FLAME);
  9. }
  10.  
  11. }

Client-side register

Now, we need to register it client-side. Create a class that implements ClientModInitializer (if one does not exist already):

  1. public class ExampleModClient implements ClientModInitializer {
  2.  
  3. @Override
  4. public void onInitializeClient() {
  5. /* Adds our particle textures to vanilla's Texture Atlas so it can be shown properly.
  6.   * Modify the namespace and particle id accordingly.
  7.   *
  8.   * This is only used if you plan to add your own textures for the particle. Otherwise, remove this.*/
  9. ClientSpriteRegistryCallback.event(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE).register(((atlasTexture, registry) -> {
  10. registry.register(new Identifier("modid", "particle/green_flame"));
  11. }));
  12.  
  13. /* Registers our particle client-side.
  14.   * First argument is our particle's instance, created previously on ExampleMod.
  15.   * Second argument is the particle's factory. The factory controls how the particle behaves.
  16.   * In this example, we'll use FlameParticle's Factory.*/
  17. ParticleFactoryRegistry.getInstance().register(ExampleMod.GREEN_FLAME, FlameParticle.Factory::new);
  18. }
  19.  
  20. }

Model & Texture

Our particle is now properly implemented… code-wise. Before starting the game, you'll need to create two files: the particle's model and texture.

src/main/resources/assets/modid/particles/green_flame.json
{
  "textures": [
    "modid:green_flame"
  ]
}

This will tell Minecraft which textures are used for our particle. Since we're using FlameParticle's Factory, we'll use only one particle, just as the former. TIP: you can use Minecraft's own textures!

Now, add your particle's textures to the following path:

src/main/resources/assets/modid/textures/particle/

Recommended texture size is 16×16 pixels.

If you did everything correctly, your particle should now work flawlessly! You might test it using the command /particle modid:green_flame ~ ~ ~.

Adding Complex Particles

WIP

The sourcecode for this tutorial is available here: ParticleExampleMod