Skip to main content

Particles and Emitters

Particles are two-dimensional, usually uniformly accelerated, bodies in game space. They are emitted during interactions with blocks, from blocks themselves during their operation, destruction of tools and much, much, much more. Emitters determine "sources"; those places relative to which particles will, for example, move. Emitters allow you to redefine linear accelerations of emitted particles, significantly expanding the scope of their application.

We will start with using a global emitter, consider contexts of using new emitter systems and delve into a little mathematics together with previously studied game objects.

Global Emitter — and you don't need more

Believe me, in most cases, the global emitter will be quite enough. You will not need to create your own if particles remain purely linear or even static. Most particles in the game appear once and disappear after a short period of time. For example, redstone dust or the environment of nether biomes. The lack of conditions for their existence allows achieving simultaneous display of a large number of particles without lag.

First of all, it is important to understand that particles like other renders remain purely client-side. So our task as modders is to ensure either sending packets for their display or using client events for this purpose. Before considering examples, let's determine the use of a global emitter.

Particles.addParticle(<numeric_particle_identifier>, <x>, <y>, <z>, <x_acceleration>, <y_acceleration>, <z_acceleration>, <particle_variation>);
Particles.addFarParticle(<numeric_particle_identifier>, <x>, <y>, <z>, <x_acceleration>, <y_acceleration>, <z_acceleration>, <particle_variation>);

That is, all particle emission boils down to specifying an identifier, starting point and linear acceleration. Variation in some cases determines the size of the particle, in some, for example, whether the particle is inverted. For notes above a jukebox, variation determines its color, these are in-game particles. Some particles have their own acceleration in addition to what we can specify here. For example, fire particles move and change size independently of input acceleration, this is again highly specific to certain types. Try experimenting with them in the game yourself.

We have repeatedly used the first function in past examples. The second one is a complete copy of the first, with the slight exception that a blur shader is additionally applied to the second.

Acceleration Patterns

Individual particles by themselves are quite insignificant, a player may even find it difficult to notice them. Usually a whole bunch of particles are involved to indicate the operation of something. We will use the World of Magical Art code to define some basic shapes that can be created using particles:

const effectExplode = function(type, x, y, z, power, count) {
count ? null : count = 25;
power ? null : power = 0.3;\n
for (let i = 0; i < count; i++) {
Particles.addParticle(type, x + 0.5, y + 0.5, z + 0.5, (Math.random() - 0.5) * power, (Math.random() - 0.5) * power, (Math.random() - 0.5) * power, 0);
}
};

Most mods interact with particles one way or another, a few more similar examples can be found, for example, in Ancient Wonders. A bit more geometry is used there, allowing you to finely tune the behavior of particles. For now, we will stop only at using the options above.

Attaching to Objects

Not implemented yet
Visit this page slightly later, here will appear what you've assuming to be. Or just make contribution to this page creation, it helpful for everyone!