# Tutorial Custom Particle Effects (creating a single particle in the world)

Discussion in 'Resources' started by doyoumath, Apr 27, 2015.

Not open for further replies.
1. Offline

### doyoumath

This tutorial will show how to create custom particle effects (arrangements of particles) using packets.

Make sure that you have added CraftBukkit to your build path. Press Ctrl-O often to auto-import classes.

Code:
`PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.DRIP_WATER, false, x, y, z, 0, 0, 0, 0, 1, null);`
Let's analyze the important parameters. (Or, check out http://wiki.vg/Protocol#Particle for a table that describes every paramater).

Code:
`EnumParticle.DRIP_WATER`
This is the type of particle that will be used - assuming you use Eclipse, type "EnumParticle." and press Ctrl-SPACE to show a list of all the possible particle types.

Code:
`x, y, z`
You guessed it - these are the x, y, and z coordinates of the particle. They are floats, so you can use a few decimal places. You can use the coordinates off the F3 screen, or use the location of an entity.

Code:
`0, 0, 0`
This is the x, y, and z Offsets of how far you want particles to be from the particle group's center. These parameters don't apply to create 1 single particle, so leave these at 0. (Check the wiki above if you're curious).

Code:
`0, 1, null`
ParticleData, ParticleCount, and Data. ParticleData is a number that is used in some particle types. For example, when creating Splash Potion particles, use this to set what type of potion particles to create. ParticleCount is the number of particles to create - following this tutorial, you probably want 1. If you set this to a number greater than 1, make sure to put a positive value in for the Offsets, or all the particles will be in the same place. Data is an array that is relevant for setting the texture used in block-interact particles (jump, break, etc.) Unless you are using one of the mentioned block-interact particle types, you can leave this as null.

You now have created a packet! Now you can send it off to players. This can be done as follows:

Code:
`((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);`
To send it to EVERY player, just put the above line into a for loop:

Code:
```for (Player player : Bukkit.getServer().getOnlinePlayers()) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
```
Remember, only the players who you send the packet too will see the particle effects.

Here's an example where only players who are OP see the particles:

Code:
```for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (player.isOp()) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
```
Once you can create 1 particle, try sending multiple packets, and packets of different types. Make large patterns of particles, and mass send them to players.

Happy coding!

Above, I have used a couple of for loops modifying the X- and Z- coordinates to create a grid of water particles around the player.

EDIT by Timtower: merged posts

Last edited by a moderator: Apr 27, 2015
#1
2. Offline

### ChipDev

This is going to help people alot, Some tutorials are not updated!

#2
gal0511Dev and GrandmaJam like this.
3. Offline

### doyoumath

SAMPLE: Add trig functions to create cool patterns!

#3
4. Offline

### Yannici

How long the particles will stay?

#4
5. Offline

@Yannici All particles are different and will not always be the same.

#5
6. Offline

### seanliam2000

This is awesome! I was searching for a way to do this and I didn't know how since I am still pretty nooby with this stuff Thanks!

#6
7. Offline

### doyoumath

Correct, every particle acts differently. Here are some examples:

FLAME: Slowly shrinks in size
DRIP_WATER: Hovers momentarily, then drops down until impact with a solid block, causing a WATER_SPLASH
ENCHANTMENT_TABLE: Hovers momentarily, then sinks down and fades out