Skip to content

Explosive API

Superkat32 edited this page Aug 9, 2023 · 6 revisions

🚧 🛠️ This page is WIP! ⚙💾 It exists to save my current work on it!

Welcome to the Explosive API Wiki!

As of Explosive Enhancement version 1.2.1, there is an API available for developers to use.
You can find information about how to spawn Explosive Enhancement's effect with your own mod! The effect will respect the user's config, meaning if they have a particle turned off, the effect spawned from your mod using EE's API will not show that particle.

Quick Start

The API isn't too complex, having just one method to call the effect. There are also a couple of overflow methods to allow for easier code readability. This is what the main method looks like incase you are wondering. You can learn how to use it if you continue reading.

ExplosiveApi.spawnParticles(World world, double x, double y, double z, float power, boolean isUnderWater, boolean didDestroyBlocks, boolean isImportant)

You must remember that Explosive Enhancement is a client-side mod, meaning that trying to spawn the particles using a ServerWorld won't work. If you can't access a World in your method, then using MinecraftClient.getInstance().world will work.

Gradle

You will need to have Explosive Enhancement in your build.gradle and gradle.properties files.

build.gradle

repositories {
 [...]
 ADD ME!
}

dependencies {
 [...]
 ADD ME!
}

gradle.properties

ee_version=[version]

Replace [version] with the latest version of Explosive Enhancement for the correct Minecraft version.

Explosive Enhancement versions

1.20.0-1.20.1

ADD ME!

1.19.4

ADD ME!

1.19.3

ADD ME!

1.19.2

ADD ME!

The Spawn Particles Method

The ExplosiveApi.spawnParticles method is the main method to spawn Explosive Enhancement's effect. This method has multiple parameters, which are listed here.

ExplosiveApi.spawnParticles(
  World world, //The world to spawn the effect in
  double x, //The effect's x
  double y, //The effect's y
  double z, //The effect's z
  float power, //The effect's power, determines the size
  boolean isUnderWater, //If true, the underwater effect shows instead
  boolean didDestroyBlocks, //Used to help determine which vanilla particle to spawn(should one need to be spawned)
  boolean isImportant //If true, the particle will render from far distances despite the user's config option choice
)

World, x, y, and z

Typically, the world, x, y, and z is determined by methods that you call from your class. For example, methods to get the world, x, y, and z normally look something like this: this.getWorld(), this.getX(), this.getY(), this.getZ(). Most of the time, calling the spawn particles method will have these methods in place of the first few variables.

ExplosiveApi.spawnParticles(this.getWorld(), this.getX(), this.getY(), this.getZ(), [power]);

If using this.getWorld() doesn't return a World, you can also use MinecraftClient.getInstance().world instead.

ExplosiveApi.spawnParticles(MinecraftClient.getInstance().world, this.getX(), this.getY(), this.getZ(), [power]);

Power

The power determines how big the explosion is. The more power, the bigger the explosion.

ExplosiveApi.spawnParticles(this.getWorld(), this.getX(), this.getY(), this.getZ(), 30f); //HUGE EXPLOSION!!!

IsUnderWater

The isUnderWater boolean determines if the underwater effect should be shown or not. Typically, this would be determined by the API calling method. For explosions that Explosive Enhancement affects(tnt, end crystals, etc.), this is the code that is used to determine if the explosion is underwater or not(1.20 code).

BlockPos pos = BlockPos.ofFloored(this.x, this.y, this.z);
if (this.world.getFluidState(pos).isIn(FluidTags.WATER)) {
  isUnderWater = true;
}

This may or may not work for you when calling ExplosiveApi.

didDestroyBlocks

The didDestroyBlocks boolean is used to determine which vanilla Minecraft effect to show for smaller explosions. This is important for users who may want to combine Explosive Enhancement's particles with vanilla Minecraft's particles.

isImportant

The isImportant boolean is used to determine if the particles should be shown from farther away or not. If true, that specific effect will render from far away AND on lower particle settings. If false, the user's config option will be used instead(disabled by default). This should be used wisely! It is best to use it for bigger explosions typically viewed from very far away. Too many important explosion effects could cause lag depending on the user's hardware(though, a few won't really hurt).

Clone this wiki locally