User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

These pages will help you setup a productive development environment and semi-automated releases.

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:particles

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

tutorial/particles.txt · Last modified: 2021/09/09 20:49 (external edit)