|
| 1 | +# Particle Collided Event |
| 2 | + |
| 3 | +This event allows you to invoke logic when a particle collides in the |
| 4 | +[Particle Accelerator](../../recipe/machine/particle_accelerator.md). Colliding refers to controlled particle movement that results in a successful collision. For particles that exit the accelerator without colliding, refer to the |
| 5 | +[particle exited event](exited.md). |
| 6 | + |
| 7 | +> [!WARNING] NOTE |
| 8 | +> This event only exists since mod version 1.21.1-0.3.0, release date: 2026-02-06. |
| 9 | +
|
| 10 | +**It is a server event and reloadable!** |
| 11 | +Keep in mind that server events have to be located inside the `kubejs/server_scripts` folder. |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +This event is fired when a particle collision happens in the Particle Accelerator, but before checking if the collision matches a |
| 16 | +valid recipe. By cancelling the event, the collision will still happen, but not result in any item output, which is the samee thing |
| 17 | +that happens when no valid recipe is found. |
| 18 | + |
| 19 | +- access in a server script via: `OritechEvents.particleCollided` |
| 20 | +- properties |
| 21 | + - `level` |
| 22 | + - type: `ServerLevel` |
| 23 | + - description: the level where the particle collision is happening |
| 24 | + - `pos` |
| 25 | + - type: `BlockPos` |
| 26 | + - description: the position of the accelerator controller |
| 27 | + - `controller` |
| 28 | + - type: `AcceleratorControllerBlockEntity` |
| 29 | + - description: the `BlockEntity` of the accelerator controller block |
| 30 | + - `collisionPos` |
| 31 | + - type: `BlockPos` |
| 32 | + - description: the position in the world where the particle collision is happening |
| 33 | + - `itemA` |
| 34 | + - type: `ItemStack` |
| 35 | + - description: the first item that is being collided |
| 36 | + - `itemB` |
| 37 | + - type: `ItemStack` |
| 38 | + - description: the second item that is being collided |
| 39 | + - `speed` |
| 40 | + - type: `float` |
| 41 | + - description: the speed of the particle collision (added speeds of both particles) |
| 42 | + - `recipeId` |
| 43 | + - type: `ResourceLocation` (nullable) |
| 44 | + - description: the recipe id of the matched recipe; null if no valid recipe was found for this collision |
| 45 | + - `recipe` |
| 46 | + - type: `OritechRecipe` (nullable) |
| 47 | + - description: the matched recipe; null if no valid recipe was found for this collision |
| 48 | +- functions |
| 49 | + - `cancel()` |
| 50 | + - description: cancels the particle collision; collision still happens but no item output will be produced, even if a recipe matches |
| 51 | + |
| 52 | +## Event Listener |
| 53 | + |
| 54 | +To access the event, the first thing you need to do is to open an event listener for the `particleCollided` event in a server script. |
| 55 | + |
| 56 | +```js |
| 57 | +OritechEvents.particleCollided(event => { |
| 58 | + // ... |
| 59 | +}) |
| 60 | +``` |
| 61 | + |
| 62 | +After that, you can apply logic to modify the particle collision behavior. |
| 63 | + |
| 64 | +## Example |
| 65 | + |
| 66 | +```js |
| 67 | +OritechEvents.particleCollided(event => { |
| 68 | + // obtaining all properties of the event by destructuring |
| 69 | + let { level, pos, controller, collisionPos, itemA, itemB, speed, recipeId, recipe } = event |
| 70 | + |
| 71 | + // if the recipe id is null, there was no recipe meaning unmatched items have collided |
| 72 | + if (recipeId == null) return |
| 73 | + |
| 74 | + // disable particle collision for a specific recipe |
| 75 | + if (recipeId === "mymodpack:particle_accelerator/recipe1") { |
| 76 | + event.cancel() |
| 77 | + } |
| 78 | +}) |
| 79 | +``` |
0 commit comments