|
| 1 | +# Particle data (1.20.5+) |
| 2 | + |
| 3 | +The particle argument requires additional data for a particle depending on what the particle is. The following particles have additional data required to display them: |
| 4 | + |
| 5 | +<!-- To whoever has to maintain this block, I am sorry! - Skepter --> |
| 6 | + |
| 7 | +<table class="table-wrapper"> |
| 8 | + <thead> |
| 9 | + <tr> |
| 10 | + <th>Bukkit Particle</th> |
| 11 | + <th>Argument syntax</th> |
| 12 | + </tr> |
| 13 | + </thead> |
| 14 | + <tr> |
| 15 | + <td><code>BLOCK</code></td> |
| 16 | + <td> |
| 17 | + <pre>block{block_state:{Name:<b>"block_name"</b>}}</pre> |
| 18 | + <ul style="padding-left: 1.5em;"> |
| 19 | + <li><b><code>block_name</code></b> - name of a block, such as <code>diamond_block</code></li> |
| 20 | + </ul> |
| 21 | + </td> |
| 22 | + </tr> |
| 23 | + <tr> |
| 24 | + <td><code>BLOCK_MARKER</code></td> |
| 25 | + <td> |
| 26 | + <pre>block_marker{block_state:{Name:<b>"block_name"</b>}}</pre> |
| 27 | + <ul style="padding-left: 1.5em;"> |
| 28 | + <li><b><code>block_name</code></b> - name of a block, such as <code>diamond_block</code></li> |
| 29 | + </ul> |
| 30 | + </td> |
| 31 | + </tr> |
| 32 | + <tr> |
| 33 | + <td><code>DUST</code></td> |
| 34 | + <td> |
| 35 | + <pre>dust{color:[<b>red</b>,<b>green</b>,<b>blue</b>],scale:<b>scale</b>}</pre> |
| 36 | + <ul style="padding-left: 1.5em;"> |
| 37 | + <li><b><code>red</code></b> - number for red, between 0.0 and 1.0</li> |
| 38 | + <li><b><code>green</code></b> - number for green, between 0.0 and 1.0</li> |
| 39 | + <li><b><code>blue</code></b> - number for blue, between 0.0 and 1.0</li> |
| 40 | + <li><b><code>scale</code></b> - number for the size of the particle</li> |
| 41 | + </ul> |
| 42 | + </td> |
| 43 | + </tr> |
| 44 | + <tr> |
| 45 | + <td><code>DUST_COLOR_TRANSITION</code></td> |
| 46 | + <td> |
| 47 | + <pre>dust_color_transition{from_color:[<b>red</b>,<b>green</b>,<b>blue</b>],<br>scale:<b>scale</b>,to_color:[<b>red</b>,<b>green</b>,<b>blue</b>]}</pre> |
| 48 | + <ul style="padding-left: 1.5em;"> |
| 49 | + <li><b><code>red</code></b> - number for red, between 0.0 and 1.0</li> |
| 50 | + <li><b><code>green</code></b> - number for green, between 0.0 and 1.0</li> |
| 51 | + <li><b><code>blue</code></b> - number for blue, between 0.0 and 1.0</li> |
| 52 | + <li><b><code>scale</code></b> - number for the size of the particle</li> |
| 53 | + </ul> |
| 54 | + </td> |
| 55 | + </tr> |
| 56 | + <tr> |
| 57 | + <td><code>DUST_PILLAR</code></td> |
| 58 | + <td> |
| 59 | + <pre>dust_pillar{block_state:{Name:<b>"block_name"</b>}}</pre> |
| 60 | + <ul style="padding-left: 1.5em;"> |
| 61 | + <li><b><code>block_name</code></b> - name of a block, such as <code>diamond_block</code></li> |
| 62 | + </ul> |
| 63 | + </td> |
| 64 | + </tr> |
| 65 | + <tr> |
| 66 | + <td><code>ENTITY_EFFECT</code></td> |
| 67 | + <td> |
| 68 | + <pre>entity_effect{color:[<b>red</b>,<b>green</b>,<b>blue</b>,<b>alpha</b>]}</pre> |
| 69 | + <ul style="padding-left: 1.5em;"> |
| 70 | + <li><b><code>red</code></b> - number for red, between 0.0 and 1.0</li> |
| 71 | + <li><b><code>green</code></b> - number for green, between 0.0 and 1.0</li> |
| 72 | + <li><b><code>blue</code></b> - number for blue, between 0.0 and 1.0</li> |
| 73 | + <li><b><code>alpha</code></b> - number for transparency, between 0.0 and 1.0</li> |
| 74 | + </ul> |
| 75 | + </td> |
| 76 | + </tr> |
| 77 | + <tr> |
| 78 | + <td><code>FALLING_DUST</code></td> |
| 79 | + <td> |
| 80 | + <pre>falling_dust{block_state:{Name:<b>"block_name"</b>}}</pre> |
| 81 | + <ul style="padding-left: 1.5em;"> |
| 82 | + <li><b><code>block_name</code></b> - name of a block, such as <code>diamond_block</code></li> |
| 83 | + </ul> |
| 84 | + </td> |
| 85 | + </tr> |
| 86 | + <tr> |
| 87 | + <td><code>ITEM</code></td> |
| 88 | + <td> |
| 89 | + <pre>item{item:"<b>item</b>"}</pre> |
| 90 | + <ul style="padding-left: 1.5em;"> |
| 91 | + <li><b><code>item</code></b> - name of an item, such as <code>apple</code></li> |
| 92 | + </ul> |
| 93 | + </td> |
| 94 | + </tr> |
| 95 | + <tr> |
| 96 | + <td><code>SCULK_CHARGE</code></td> |
| 97 | + <td> |
| 98 | + <pre>sculk_charge{roll:<b>angle</b>}</pre> |
| 99 | + <ul style="padding-left: 1.5em;"> |
| 100 | + <li><b><code>angle</code></b> - decimal angle the particle displays at in radians</li> |
| 101 | + </ul> |
| 102 | + </td> |
| 103 | + </tr> |
| 104 | + <tr> |
| 105 | + <td><code>SHRIEK</code></td> |
| 106 | + <td> |
| 107 | + <pre>shriek{delay:<b>delay</b>}</pre> |
| 108 | + <ul style="padding-left: 1.5em;"> |
| 109 | + <li><b><code>delay</code></b> - delay in ticks for when the shriek particle should appear</li> |
| 110 | + </ul> |
| 111 | + </td> |
| 112 | + </tr> |
| 113 | + <tr> |
| 114 | + <td><code>VIBRATION</code></td> |
| 115 | + <td> |
| 116 | + <pre>vibration{destination:{type:"block",pos:[<b>x</b>,<b>y</b>,<b>z</b>]},<br>arrival_in_ticks:<b>ticks</b>}</pre> |
| 117 | + <ul style="padding-left: 1.5em;"> |
| 118 | + <li><b><code>x</code></b> - decimal x-coordinate to move towards</li> |
| 119 | + <li><b><code>y</code></b> - decimal y-coordinate to move towards</li> |
| 120 | + <li><b><code>z</code></b> - decimal z-coordinate to move towards</li> |
| 121 | + <li><b><code>ticks</code></b> - time in ticks to take to move towards its destination</li> |
| 122 | + </ul> |
| 123 | + </td> |
| 124 | + </tr> |
| 125 | +</table> |
| 126 | + |
| 127 | +## ParticleArgument examples |
| 128 | + |
| 129 | +Because certain particles (in the table above) require additional data, it is not recommended to spawn a particle without its corresponding data. This can result in particles not showing due to missing requirements. |
| 130 | + |
| 131 | +<div class="warning"> |
| 132 | + |
| 133 | +### Example - Show particles at a player's location (without data) |
| 134 | + |
| 135 | +Say we wanted to have a command that displayed particles at a player's location. We will use the following command syntax: |
| 136 | + |
| 137 | +```mccmd |
| 138 | +/showparticle <particle> |
| 139 | +``` |
| 140 | + |
| 141 | +With this, we can simply spawn the particle using the `World.spawnParticle(Particle, Location, int)` method: |
| 142 | + |
| 143 | +<div class="multi-pre"> |
| 144 | + |
| 145 | +```java,Java |
| 146 | +{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentParticle1}} |
| 147 | +``` |
| 148 | + |
| 149 | +```kotlin,Kotlin |
| 150 | +{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentParticle1}} |
| 151 | +``` |
| 152 | + |
| 153 | +```kotlin,Kotlin_DSL |
| 154 | +{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentParticle1}} |
| 155 | +``` |
| 156 | + |
| 157 | +</div> |
| 158 | + |
| 159 | +Running this can result in errors due to missing requirements. If you provide a particle that has additional requirements, Bukkit will throw an error and the particle will not be displayed. Instead, the example below should be used. |
| 160 | + |
| 161 | +</div> |
| 162 | + |
| 163 | +<div class="example"> |
| 164 | + |
| 165 | +### Example - Show particles at a player's location (with data) |
| 166 | + |
| 167 | +We can fix the issues with the example above by providing the data of the argument using the `ParticleData` record: |
| 168 | + |
| 169 | +```mccmd |
| 170 | +/showparticle <particle> |
| 171 | +``` |
| 172 | + |
| 173 | +In this case, we'll use the `World.spawnParticle(Particle particle, Location location, int count, T data)` method which accepts some particle data: |
| 174 | + |
| 175 | +<div class="multi-pre"> |
| 176 | + |
| 177 | +```java,Java |
| 178 | +{{#include ../../commandapi-documentation-code/src/main/java/dev/jorel/commandapi/examples/java/Examples.java:argumentParticle2}} |
| 179 | +``` |
| 180 | + |
| 181 | +```kotlin,Kotlin |
| 182 | +{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/Examples.kt:argumentParticle2}} |
| 183 | +``` |
| 184 | + |
| 185 | +```kotlin,Kotlin_DSL |
| 186 | +{{#include ../../commandapi-documentation-code/src/main/kotlin/dev/jorel/commandapi/examples/kotlin/ExamplesKotlinDSL.kt:argumentParticle2}} |
| 187 | +``` |
| 188 | + |
| 189 | +</div> |
| 190 | + |
| 191 | +This can be used with commands such as: |
| 192 | + |
| 193 | +```mccmd |
| 194 | +/showparticle minecraft:dust_color_transition{from_color:[0.0,0.0,0.0],scale:20.0,to_color:[1.0,0.0,0.0]} |
| 195 | +/showparticle minecraft:block_marker{block_state:{Name:"diamond_block"}} |
| 196 | +``` |
| 197 | + |
| 198 | +</div> |
| 199 | + |
| 200 | +## Particle data implementation notes |
| 201 | + |
| 202 | +The `vibration` particle will return a particle data of the Bukkit `Vibration` class. In the `Vibration` class, you can access the destination location using the `Vibration.getDestination()` method, which returns a `Vibration.Destination` instance. The CommandAPI will **always** return a `Vibration.Destination.BlockDestination` instance, and will never return a `Vibration.Destination.EntityDestination` instance. An example of accessing the location can be found below: |
| 203 | + |
| 204 | +```java |
| 205 | +ParticleData<Vibration> particleData; // The particle data you get from your argument |
| 206 | +Location destination = ((BlockDestination) particleData.data().getDestination()).getLocation(); |
| 207 | +``` |
0 commit comments