Skip to content

How to make a block that gives off particles in a Minecraft mod

Blocks show particles from animateTick (randomDisplayTick on 1.12.2), which the client calls now and then for blocks near the player, as torches do for their flame. Adding a particle with level.addParticle(ParticleTypes.FLAME, x, y, z, dx, dy, dz) shows it only to the player who sees it. For particles everyone sees, send them from the server with ServerLevel#sendParticles.

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Make a block class and override animateTick.
  2. Add a particle with level.addParticle(ParticleTypes.X, x, y, z, 0, 0.02, 0).
  3. Use the random source to spread them out and not add one every time.
  4. Register the block with your class.

The example uses these values. Change them in the code.

Setting In the example What it does
particle FLAME The vanilla particle it gives off.
chance 2 One in this many calls adds a particle (1: every time).

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Fabric and NeoForge 1.20.1 to 1.20.2, Forge 1.19 to 1.20.1

Section titled “Fabric and NeoForge 1.20.1 to 1.20.2, Forge 1.19 to 1.20.1”

Uses:

  • Block.animateTick
  • Level.addParticle
  • ParticleTypes
  • RandomSource

src/main/java/com/example/examplemod/block/EmberBlock.java

package com.example.examplemod.block;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
// Ember Block: gives off FLAME particles, drawn in the client of every player near it (animateTick).
public class EmberBlock extends Block {
public EmberBlock(BlockBehaviour.Properties properties) {
super(properties);
}
@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
if (random.nextInt(2) == 0) {
level.addParticle(ParticleTypes.FLAME, pos.getX() + random.nextDouble(), pos.getY() + 1.0D, pos.getZ() + random.nextDouble(),
0.0D, 0.02D, 0.0D);
}
}
}

It’s registered like any other block, as EmberBlock: see a new block.

Fabric and NeoForge 1.20.3 to 1.21.1, Fabric and NeoForge 1.21.2 to 26.2

Section titled “Fabric and NeoForge 1.20.3 to 1.21.1, Fabric and NeoForge 1.21.2 to 26.2”

Uses:

  • Block.animateTick
  • Level.addParticle
  • ParticleTypes
  • RandomSource

src/main/java/com/example/examplemod/block/EmberBlock.java

package com.example.examplemod.block;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
// Ember Block: gives off FLAME particles, drawn in the client of every player near it (animateTick).
public class EmberBlock extends Block {
public static final MapCodec<EmberBlock> CODEC = simpleCodec(EmberBlock::new);
public EmberBlock(BlockBehaviour.Properties properties) {
super(properties);
}
@Override
protected MapCodec<? extends Block> codec() {
return CODEC;
}
@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
if (random.nextInt(2) == 0) {
level.addParticle(ParticleTypes.FLAME, pos.getX() + random.nextDouble(), pos.getY() + 1.0D, pos.getZ() + random.nextDouble(),
0.0D, 0.02D, 0.0D);
}
}
}

It’s registered like any other block, as EmberBlock: see a new block.

Uses:

  • Block.animateTick
  • Level.addParticle
  • ParticleTypes
  • RandomSource

Since 26.3 a Block no longer has a codec: there is no CODEC field and no codec() method to write.

src/main/java/com/example/examplemod/block/EmberBlock.java

package com.example.examplemod.block;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
// Ember Block: gives off FLAME particles, drawn in the client of every player near it (animateTick).
public class EmberBlock extends Block {
public EmberBlock(BlockBehaviour.Properties properties) {
super(properties);
}
@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
if (random.nextInt(2) == 0) {
level.addParticle(ParticleTypes.FLAME, pos.getX() + random.nextDouble(), pos.getY() + 1.0D, pos.getZ() + random.nextDouble(),
0.0D, 0.02D, 0.0D);
}
}
}

It’s registered like any other block, as EmberBlock: see a new block.

Forge 1.17.1 to 1.18.2, Fabric 1.16.5 to 1.18.2

Section titled “Forge 1.17.1 to 1.18.2, Fabric 1.16.5 to 1.18.2”

Uses:

  • Block.animateTick
  • Level.addParticle
  • ParticleTypes
  • RandomSource

src/main/java/com/example/examplemod/block/EmberBlock.java

package com.example.examplemod.block;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import java.util.Random;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
// Ember Block: gives off FLAME particles, drawn in the client of every player near it (animateTick).
public class EmberBlock extends Block {
public EmberBlock(BlockBehaviour.Properties properties) {
super(properties);
}
@Override
public void animateTick(BlockState state, Level level, BlockPos pos, Random random) {
if (random.nextInt(2) == 0) {
level.addParticle(ParticleTypes.FLAME, pos.getX() + random.nextDouble(), pos.getY() + 1.0D, pos.getZ() + random.nextDouble(),
0.0D, 0.02D, 0.0D);
}
}
}

It’s registered like any other block, as EmberBlock: see a new block.

Uses:

  • Block.animateTick
  • World.addParticle
  • ParticleTypes
  • java.util.Random

In 1.16.5 the level is a World, the random source is a java.util.Random, and the method takes (state, world, pos, rand).

src/main/java/com/example/examplemod/block/EmberBlock.java

package com.example.examplemod.block;
import net.minecraft.util.math.BlockPos;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.world.World;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
// Ember Block: gives off FLAME particles, drawn in the client of every player near it (animateTick).
public class EmberBlock extends Block {
public EmberBlock(AbstractBlock.Properties properties) {
super(properties);
}
@Override
public void animateTick(BlockState state, World world, BlockPos pos, Random random) {
if (random.nextInt(2) == 0) {
world.addParticle(ParticleTypes.FLAME, pos.getX() + random.nextDouble(), pos.getY() + 1.0D, pos.getZ() + random.nextDouble(),
0.0D, 0.02D, 0.0D);
}
}
}

It’s registered like any other block, as EmberBlock: see a new block.

Uses:

  • Block.animateTick
  • Level.addParticle
  • ParticleTypes
  • RandomSource

src/main/java/com/example/examplemod/block/EmberBlock.java

package com.example.examplemod.block;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
// Ember Block: gives off FLAME particles, drawn in the client of every player near it (animateTick).
public class EmberBlock extends Block {
public EmberBlock(BlockBehaviour.Properties properties) {
super(properties);
}
@Override
public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) {
if (random.nextInt(2) == 0) {
level.addParticle(ParticleTypes.FLAME, pos.getX() + random.nextDouble(), pos.getY() + 1.0D, pos.getZ() + random.nextDouble(),
0.0D, 0.02D, 0.0D);
}
}
}

It’s registered like any other block, as EmberBlock: see a new block.

Uses:

  • Block.randomDisplayTick
  • World.spawnParticle
  • EnumParticleTypes

In 1.12.2 the method is randomDisplayTick(state, world, pos, rand), and a particle is added with world.spawnParticle(EnumParticleTypes.X, x, y, z, dx, dy, dz).

src/main/java/com/example/examplemod/block/EmberBlock.java

package com.example.examplemod.block;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
// Ember Block: gives off FLAME particles, drawn in the client of every player near it (randomDisplayTick).
public class EmberBlock extends Block {
public EmberBlock() {
super(Material.ROCK);
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random random) {
if (random.nextInt(2) == 0) {
world.spawnParticle(particle("FLAME"), pos.getX() + random.nextDouble(), pos.getY() + 1.0D, pos.getZ() + random.nextDouble(),
0.0D, 0.02D, 0.0D);
}
}
// 1.12.2 has FLAME and SMOKE_NORMAL; SOUL_FIRE_FLAME does not exist yet.
private static EnumParticleTypes particle(String name) {
switch (name) {
case "SMOKE":
return EnumParticleTypes.SMOKE_NORMAL;
default:
return EnumParticleTypes.FLAME;
}
}
}

It’s registered like any other block, as EmberBlock: see a new block.

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.