Particles are textures used for special events and additional VFX. They are used on explosions, torches, dripping water and more!
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.
First, register your particle in your ModInitializer
:
public class ExampleMod implements ModInitializer { // instance of our particle public static final DefaultParticleType GREEN_FLAME = FabricParticleTypes.simple(); @Override public void onInitialize() { } }
Now, we need to register it client-side. Create a class that implements ClientModInitializer
(if one does not exist already):
public class ExampleModClient implements ClientModInitializer { @Override public void onInitializeClient() { /* Adds our particle textures to vanilla's Texture Atlas so it can be shown properly. * Modify the namespace and particle id accordingly. * * This is only used if you plan to add your own textures for the particle. Otherwise, remove this.*/ ClientSpriteRegistryCallback.event(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE).register(((atlasTexture, registry) -> { registry.register(new Identifier("modid", "particle/green_flame")); })); /* Registers our particle client-side. * First argument is our particle's instance, created previously on ExampleMod. * Second argument is the particle's factory. The factory controls how the particle behaves. * In this example, we'll use FlameParticle's Factory.*/ ParticleFactoryRegistry.getInstance().register(ExampleMod.GREEN_FLAME, FlameParticle.Factory::new); } }
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.
{ "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 ~ ~ ~
.
WIP
The sourcecode for this tutorial is available here: ParticleExampleMod