Skip to content

Commit 38ddbb9

Browse files
committed
fetch version for initializer automatically.
Set minecraft dependency version to flat out the one compiled against. Supporting multiple minecraft versions need's way more work, since Mojang breaks round about everything every sub version. This change will ease the error-prone bumping of versions at multiple places.
1 parent 192503e commit 38ddbb9

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ targetCompatibility = JavaVersion.VERSION_21
99
archivesBaseName = project.archives_base_name
1010
version = project.mod_version
1111
group = project.maven_group
12+
String minecraftVersion = project.minecraft_version
1213

1314
repositories {
1415
// Add repositories to retrieve artifacts from in here.
@@ -36,10 +37,12 @@ dependencies {
3637
}
3738

3839
processResources {
39-
inputs.property "version", project.version
40+
inputs.properties "modVersion": project.version,
41+
"mcVersion": minecraftVersion
4042

4143
filesMatching("fabric.mod.json") {
42-
expand "version": project.version
44+
expand "modVersion": project.version,
45+
"mcVersion": minecraftVersion
4346
}
4447
}
4548

src/main/java/com/daniking/backtools/BackTools.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import net.fabricmc.api.EnvType;
44
import net.fabricmc.api.ModInitializer;
55
import net.fabricmc.loader.api.FabricLoader;
6+
import net.fabricmc.loader.api.Version;
7+
import org.jetbrains.annotations.NotNull;
68
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
810

@@ -11,12 +13,13 @@
1113
public class BackTools implements ModInitializer {
1214
public static final Logger LOGGER = LoggerFactory.getLogger(BackTools.class);
1315

14-
public static final String VERSION = "1.21.4-0";
15-
1616
@Override
1717
public void onInitialize() {
18-
BackTools.run(EnvType.SERVER, () -> () -> LOGGER.info("You are loading " + this.getClass().getName() + " on a server." + this.getClass().getName() + " is a client side-only mod!"));
19-
BackTools.run(EnvType.CLIENT, () -> () -> LOGGER.info("BackTools V{} Initialized", VERSION));
18+
final @NotNull String modName = this.getClass().getSimpleName();
19+
final @NotNull Version version = FabricLoader.getInstance().getModContainer(modName.toLowerCase()).orElseThrow().getMetadata().getVersion();
20+
21+
BackTools.run(EnvType.SERVER, () -> () -> LOGGER.info("You are loading " + modName + " on a server." + modName + " is a client side-only mod!"));
22+
BackTools.run(EnvType.CLIENT, () -> () -> LOGGER.info("{} V{} Initialized", modName, version.getFriendlyString()));
2023
}
2124

2225
public static void run(final EnvType type, final Supplier<Runnable> supplier) {

src/main/resources/fabric.mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"schemaVersion": 1,
33
"id": "backtools",
4-
"version": "${version}",
4+
"version": "${modVersion}",
55
"name": "BackTools",
66
"description": "Shows the last used tool on the player's back. Purely aesthetic.",
77
"authors": [
@@ -29,7 +29,7 @@
2929
"depends": {
3030
"fabricloader": "*",
3131
"fabric": "*",
32-
"minecraft": ">=1.21.4",
32+
"minecraft": "=${mcVersion}",
3333
"cloth-config2": "*"
3434
}
3535
}

0 commit comments

Comments
 (0)