> For the complete documentation index, see [llms.txt](https://cjcrafter.gitbook.io/weaponmechanics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cjcrafter.gitbook.io/weaponmechanics/articles/optimizing-explosions.md).

# Optimizing Explosions

Article explaining causes of lag in explosions, and how to reduce it!

This article is for the [Explosion](/weaponmechanics/weapon-modules/explosion.md) feature of WeaponMechanics.

WeaponMechanics uses a custom explosion system; it is completely separate from the Minecraft code (*even though it looks very similar!*). WeaponMechanics, by default, uses a highly optimized Explosion algorithm. But what if you are still encountering lag?

## Falling Blocks

Falling blocks are visual effects added by [Explosion](/weaponmechanics/weapon-modules/explosion.md#block_damage). Although they are only visual, the math for calculating their collisions can cause a lot of lag. If you have a large explosion, you should either lower the chances for falling blocks, or completely disable them.

```yaml
<weapon>:
  Explosion:
    Block_Damage:
      Falling_Block_Chance: 5%  # Set this to 0% for best performance
```

## Reducing Rays

Explosions from WeaponMechanics are calculated the same way explosions from vanilla Minecraft are calculated; by casting $$16\cdot 16\cdot 6=1536$$ rays in all directions. *This is expensive on the CPU*, especially if you explosion yield is high ($$>10$$) or you have lots of explosions at the same time (Like an Airstrike).

```yaml
<weapon>:
  Explosion:
    Explosion_Type_Data:
      Rays: 16  # 16 is the default value. Change to something like 12 for better performance
```

{% hint style="warning" %}
This trick only works for `Explosion_Shape: DEFAULT`, other explosion shapes will not work.
{% endhint %}

## Changing Explosion Shape

Using `Explosion_Shape: DEFAULT` will *always* be taxing on the CPU. If you have a server that has 100s of explosions a minute, you should consider switching to a new shape, like `SPHERE`.

See [Explosion](/weaponmechanics/weapon-modules/explosion.md#explosion_shape) for more information.

## Changing Explosion Exposure

Using `Explosion_Exposure: DEFAULT` casts a lot of rays for each entity in the radius of the explosion. Switching to the optimized exposure can help reduce the number of rays.

```yaml
<weapon>:
  Explosion:
    Explosion_Exposure: OPTIMIZED
```

For a more draconian route, you can use `DISTANCE` to perform almost NO math per entity (At the cost of drastically reducing the features of an explosion).
