Skip to content

How to make an item that makes a burst of particles (Minecraft mod)

Particles are drawn by the client, so a server asks for them: ServerLevel.sendParticles(type, x, y, z, count, spreadX, spreadY, spreadZ, speed) sends them to nearby players. Call it from the item’s use method on the server. The types are fields of ParticleTypes, such as HEART, FLAME, END_ROD and HAPPY_VILLAGER. In client-only code, level.addParticle does the same for one particle.

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. Override use in an Item subclass.
  2. On the server, cast the level to ServerLevel.
  3. Call sendParticles at the player’s position with a count and spread.
  4. Right-click and look at the player.

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

Setting In the example What it does
particle HAPPY_VILLAGER Which particle.
count 20 How many.

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

Fabric and NeoForge 1.20.4 to 1.21.1, NeoForge 1.20.1 to 1.20.2, Forge 1.17.1 to 1.20.1

Section titled “Fabric and NeoForge 1.20.4 to 1.21.1, NeoForge 1.20.1 to 1.20.2, Forge 1.17.1 to 1.20.1”

Uses:

  • ServerLevel.sendParticles
  • ParticleTypes
  • Item.use

src/main/java/com/example/examplemod/item/SparkWandItem.java

package com.example.examplemod.item;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
// Spark Wand: right-click for 20 HAPPY_VILLAGER particles around you. The server sends them; every nearby player sees them.
public class SparkWandItem extends Item {
public SparkWandItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
if (level instanceof ServerLevel serverLevel) {
serverLevel.sendParticles(ParticleTypes.HAPPY_VILLAGER, player.getX(), player.getY() + 1.0, player.getZ(), 20, 0.5, 0.5, 0.5, 0.05);
}
return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), level.isClientSide());
}
}

It’s registered like any other item, as SparkWandItem: see a new item.

Uses:

  • ServerLevel.sendParticles
  • ParticleTypes
  • Item.use

src/main/java/com/example/examplemod/item/SparkWandItem.java

package com.example.examplemod.item;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
// Spark Wand: right-click for 20 HAPPY_VILLAGER particles around you. The server sends them; every nearby player sees them.
public class SparkWandItem extends Item {
public SparkWandItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
if (level instanceof ServerLevel serverLevel) {
serverLevel.sendParticles(ParticleTypes.HAPPY_VILLAGER, player.getX(), player.getY() + 1.0, player.getZ(), 20, 0.5, 0.5, 0.5, 0.05);
}
return InteractionResult.SUCCESS;
}
}

It’s registered like any other item, as SparkWandItem: see a new item.

Uses:

  • ServerWorld.sendParticles
  • ParticleTypes
  • Item.use

src/main/java/com/example/examplemod/item/SparkWandItem.java

package com.example.examplemod.item;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.util.Hand;
import net.minecraft.util.ActionResult;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
// Spark Wand: right-click for 20 HAPPY_VILLAGER particles around you. The server sends them; every nearby player sees them.
public class SparkWandItem extends Item {
public SparkWandItem(Item.Properties properties) {
super(properties);
}
@Override
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
if (world instanceof ServerWorld) {
ServerWorld serverWorld = (ServerWorld) world;
serverWorld.sendParticles(ParticleTypes.HAPPY_VILLAGER, player.getX(), player.getY() + 1.0, player.getZ(), 20, 0.5, 0.5, 0.5, 0.05);
}
return ActionResult.sidedSuccess(player.getItemInHand(hand), world.isClientSide());
}
}

It’s registered like any other item, as SparkWandItem: see a new item.

Uses:

  • ServerLevel.sendParticles
  • ParticleTypes
  • Item.use

src/main/java/com/example/examplemod/item/SparkWandItem.java

package com.example.examplemod.item;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
// Spark Wand: right-click for 20 HAPPY_VILLAGER particles around you. The server sends them; every nearby player sees them.
public class SparkWandItem extends Item {
public SparkWandItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
if (level instanceof ServerLevel) {
ServerLevel serverLevel = (ServerLevel) level;
serverLevel.sendParticles(ParticleTypes.HAPPY_VILLAGER, player.getX(), player.getY() + 1.0, player.getZ(), 20, 0.5, 0.5, 0.5, 0.05);
}
return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), level.isClientSide());
}
}

It’s registered like any other item, as SparkWandItem: see a new item.

Uses:

  • WorldServer.sendParticles
  • EnumParticleTypes
  • Item.use

In 1.12.2 the call is WorldServer#spawnParticle(particle, x, y, z, count, spreadX, spreadY, spreadZ, speed) and the types are EnumParticleTypes.

src/main/java/com/example/examplemod/item/SparkWandItem.java

package com.example.examplemod.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
// Spark Wand: right-click for 20 HAPPY_VILLAGER particles around you. The server sends them; every nearby player sees them.
public class SparkWandItem extends Item {
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (world instanceof WorldServer) {
((WorldServer) world).spawnParticle(particle("HAPPY_VILLAGER"), player.posX, player.posY + 1.0, player.posZ, 20, 0.5, 0.5, 0.5, 0.05);
}
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
// 1.12.2 names its particles differently from newer versions: HAPPY_VILLAGER is VILLAGER_HAPPY, ENCHANT is ENCHANTMENT_TABLE; SOUL_FIRE_FLAME does not exist yet.
private static EnumParticleTypes particle(String name) {
switch (name) {
case "HEART":
return EnumParticleTypes.HEART;
case "FLAME":
return EnumParticleTypes.FLAME;
case "END_ROD":
return EnumParticleTypes.END_ROD;
case "NOTE":
return EnumParticleTypes.NOTE;
case "CLOUD":
return EnumParticleTypes.CLOUD;
case "ENCHANT":
return EnumParticleTypes.ENCHANTMENT_TABLE;
default:
return EnumParticleTypes.VILLAGER_HAPPY;
}
}
}

It’s registered like any other item, as SparkWandItem: see a new item.

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.