-
Notifications
You must be signed in to change notification settings - Fork 7
Explosive API
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.
If you experience any issues, or found a bug, please submit an issue!
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)
IMPORTANT NOTE: Explosive Enhancement is a client-side mod, meaning that any calls of the API must be done client-side! If you can't reliably call the API client-side, you could try sending a packet including the API call. This page does not cover that, however, see the EE As An Optional Dependency section for how to ensure that your mod doesn't accidentally hard depend on EE.
You will need to have Explosive Enhancement in your build.gradle
and gradle.properties
files. This is done through Modrinth's built-in Maven.
repositories {
[...]
maven {
url = "https://api.modrinth.com/maven"
}
}
dependencies {
[...]
modApi("maven.modrinth:explosive-enhancement:${project.ee_version}")
}
ee_version=[version]
Replace [version]
with the latest version of Explosive Enhancement for the correct Minecraft version.
Explosive Enhancement versions
ee_version=1.2.1-1.20.x
ee_version=1.2.1-1.19.4
ee_version=1.2.1-1.19.3
ee_version=1.2.1-1.19.2
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
)
This method exclusively spawns particles! The sound will not be included!
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]);
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!!!
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.
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.
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).
Ensuring that Explosive Enhancement doesn't accidentally become a required dependency is probably something you want to care about. The easiest way to do this is to have a compat class with a method which calls the ExplosiveApi method. This compat class will only be called if the if(FabricLoader.getInstance().isModLoaded("explosiveenhancement"))
statement is passed.
Example here.
public class MyClass {
...
public void myMethod() {
...
if(FabricLoader.getInstance().isModLoaded("explosiveenhancement")) {
boolean isUnderwater = [determine if underwater here];
boolean didDestroyBlocks = [determine if blocks were broken here];
ExplosiveCompat.spawnParticles(world, pos.x, pos.y, pos.z, power, isUnderwater, didDestroyBlocks);
}
...
}
...
}
Your ExplosiveCompat class, recommended to be placed in a compat
package(if you have one already, otherwise, consider making one).
public class ExplosiveCompat {
public static void spawnParticles(World world, double x, double y, double z, float power, boolean isUnderwater, boolean didDestroyBlocks) {
ExplosiveApi.spawnParticles(world, x, y, z, power, isUnderwater, didDestroyBlocks);
}
}