Setting Up

Below are the instructions to set up XunLib 1.21.1-3.0.0 or newer, make sure you are targeting the right version.

Build script

Xunlib does not have a repository that contains all its published artifacts, so you'll need to use either Curse Maven or Modrinth Maven.

Add the following code to your build.gradle:

repositories {
maven {
url "https://cursemaven.com"
}
}

If you are using Gradle 6.2+, you can use this instead, though it is not required.

repositories {
exclusiveContent {
forRepository {
maven {
url "https://cursemaven.com"
}
}
filter {
includeGroup "curse.maven"
}
}
}

Then, add XunLib to the dependencies section:

dependencies {
modImplementation "curse.maven:xunlib-1245630:${xunlib_version_artifact}" // Fabric
implementation "curse.maven:xunlib-1245630:${xunlib_version_artifact}" // NeoForge
}

Finally, define the XunLib version in gradle.properties:

xunlib_version=3.0.0

For Modrinth Maven, you can also shorten the dependency version from ${minecraft_version}-${xunlib_version} to just ${xunlib_version}. When doing this, include the Minecraft version directly in the property:

xunlib_version=1.21.1-3.0.0

This is completely optional; both formats work.

Initialize your mod ID

Whenever you use a ResourceUtil or TranslationUtil method that relies on the current mod ID, make sure to call ModSetup.setModId() during your mod's initialization.

These methods internally use ModIdManager.getModId() to determine the current mod ID. XunLib can automatically detect the mod ID in some situations, but the detection is intentionally strict. Because of this, explicitly setting the mod ID is recommended and can prevent errors caused by ambiguous or unsupported environments.

public final class ExampleMod {
public static final String MOD_ID = "examplemod";
public static void init() {
ModSetup.setModId(MOD_ID);
}
}