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+ }
0 commit comments