Skip to content

Commit 313d958

Browse files
committed
Made keybind fix only a client dependency
1 parent 7b62fe2 commit 313d958

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx4G
88
loader_version=0.14.24
99

1010
# Mod Properties
11-
mod_version=1.17.3-beta
11+
mod_version=dev
1212
maven_group = org.minefortress
1313
archives_base_name = minefortress
1414

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.minefortress.earlyriser
2+
3+
import net.fabricmc.api.EnvType
4+
import net.fabricmc.loader.api.FabricLoader
5+
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint
6+
import net.fabricmc.loader.impl.discovery.ModResolutionException
7+
8+
class MineFortressPreLaunch : PreLaunchEntrypoint {
9+
10+
// Define constants for better readability and maintenance
11+
private val THIS_MOD_ID = "minefortress"
12+
private val REQUIRED_MOD_ID = "keybind_fix"
13+
private val REQUIRED_MOD_VERSION = ">=1.0.0" // From your mod.json
14+
15+
override fun onPreLaunch() {
16+
// This check ensures the code only runs on the client
17+
if (FabricLoader.getInstance().environmentType == EnvType.CLIENT) {
18+
19+
// Check if the required client-side mod is loaded
20+
if (!FabricLoader.getInstance().isModLoaded(REQUIRED_MOD_ID)) {
21+
22+
// Get our own mod's metadata to make the error message more specific
23+
val modContainer = FabricLoader.getInstance()
24+
.getModContainer(THIS_MOD_ID)
25+
.orElseThrow { IllegalStateException("Could not find the '$THIS_MOD_ID' mod container, which is required for a dependency check.") }
26+
27+
val metadata = modContainer.metadata
28+
val modName = metadata.name
29+
val modVersion = metadata.version.friendlyString
30+
31+
// Build a clear, multi-line error message
32+
val errorMessage = """
33+
|
34+
|The mod '$modName' ($THIS_MOD_ID) version $modVersion has a missing dependency.
35+
|
36+
|It requires the mod 'Keybind Fix' ($REQUIRED_MOD_ID) version $REQUIRED_MOD_VERSION to be installed on the client.
37+
|
38+
|Please download and install the required mod to continue.
39+
""".trimMargin() // trimMargin() cleans up the indentation in multi-line strings
40+
41+
// Throw the special exception to show Fabric's error screen
42+
throw ModResolutionException(errorMessage)
43+
}
44+
}
45+
}
46+
}

src/main/resources/fabric.mod.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"org.minefortress.MineFortressClient"
2525
],
2626
"server": [],
27+
"preLaunch": [
28+
"org.minefortress.earlyriser.MineFortressPreLaunch"
29+
],
2730
"mm:early_risers": [
2831
"org.minefortress.earlyriser.GameModeEarlyRiser"
2932
],
@@ -43,8 +46,10 @@
4346
"minecraft": "1.20.2",
4447
"java": ">=17",
4548
"mm": ">=2.3",
46-
"keybind_fix": ">=1.0.0",
4749
"fabric-language-kotlin": ">=1.10.20+kotlin.1.9.24"
4850
},
51+
"recommends": {
52+
"keybind_fix": ">=1.0.0"
53+
},
4954
"suggests": {}
5055
}

0 commit comments

Comments
 (0)