forked from Cristelknight999/Cristel-Lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: splitting the utils for avoiding calling resource packs staffs t…
…oo early fix Cristelknight999#2
- Loading branch information
1 parent
a1a0795
commit b709a45
Showing
18 changed files
with
143 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.cristellib; | ||
|
||
import dev.architectury.injectables.annotations.ExpectPlatform; | ||
|
||
public class ModLoadingUtil { | ||
@ExpectPlatform | ||
public static boolean isModLoadedWithVersion(String modid, String minVersion){ | ||
throw new AssertionError(); | ||
} | ||
|
||
@ExpectPlatform | ||
public static boolean isModLoaded(String modid){ | ||
throw new AssertionError(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
fabric-like/src/main/java/net/cristellib/fabriclike/ModLoadingUtilFabricLike.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package net.cristellib.fabriclike; | ||
|
||
import net.cristellib.CristelLib; | ||
import net.cristellib.ModLoadingUtil; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.fabricmc.loader.api.Version; | ||
import net.fabricmc.loader.api.VersionParsingException; | ||
|
||
public class ModLoadingUtilFabricLike { | ||
public static boolean isModLoadedWithVersion(String modid, String minVersion) { | ||
if (ModLoadingUtil.isModLoaded(modid)) { | ||
Version version = FabricLoader.getInstance().getModContainer(modid).get().getMetadata().getVersion(); | ||
Version min; | ||
try { | ||
min = Version.parse(minVersion); | ||
} catch (VersionParsingException e) { | ||
CristelLib.LOGGER.error("Couldn't parse version: " + minVersion); | ||
return false; | ||
} | ||
return version.compareTo(min) >= 0; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
fabric/src/main/java/net/cristellib/fabric/ModLoadingUtilImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.cristellib.fabric; | ||
|
||
import net.cristellib.fabriclike.ModLoadingUtilFabricLike; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
public class ModLoadingUtilImpl { | ||
|
||
public static boolean isModLoaded(String modId) { | ||
return FabricLoader.getInstance().isModLoaded(modId); | ||
} | ||
|
||
public static boolean isModLoadedWithVersion(String modid, String minVersion) { | ||
return ModLoadingUtilFabricLike.isModLoadedWithVersion(modid, minVersion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
forge/src/main/java/net/cristellib/forge/ModLoadingUtilImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.cristellib.forge; | ||
|
||
import net.minecraftforge.fml.ModList; | ||
import net.minecraftforge.fml.loading.LoadingModList; | ||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo; | ||
import org.apache.maven.artifact.versioning.ArtifactVersion; | ||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class ModLoadingUtilImpl { | ||
|
||
public static boolean isModLoaded(String modid) { | ||
ModList modList = ModList.get(); | ||
if(modList != null){ | ||
return modList.isLoaded(modid); | ||
} | ||
return isModPreLoaded(modid); | ||
} | ||
|
||
public static boolean isModPreLoaded(String modid) { | ||
return getPreLoadedModInfo(modid) != null; | ||
} | ||
|
||
public static @Nullable ModInfo getPreLoadedModInfo(String modId){ | ||
for(ModInfo info : LoadingModList.get().getMods()){ | ||
if(info.getModId().equals(modId)) { | ||
return info; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static boolean isModLoadedWithVersion(String modid, String minVersion) { | ||
if(isModLoaded(modid)){ | ||
ModList modList = ModList.get(); | ||
ArtifactVersion version; | ||
if(modList != null) version = modList.getModContainerById(modid).get().getModInfo().getVersion(); | ||
else version = getPreLoadedModVersion(modid); | ||
|
||
ArtifactVersion min; | ||
min = new DefaultArtifactVersion(minVersion); | ||
return version.compareTo(min) >= 0; | ||
} | ||
return false; | ||
} | ||
|
||
public static ArtifactVersion getPreLoadedModVersion(String modid) { | ||
ModInfo info = getPreLoadedModInfo(modid); | ||
if(info == null) throw new RuntimeException("Couldn't find mod: " + modid); | ||
return info.getVersion(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
quilt/src/main/java/net/cristellib/fabric/ModLoadingUtilImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.cristellib.fabric; | ||
|
||
import net.cristellib.fabriclike.ModLoadingUtilFabricLike; | ||
import org.quiltmc.loader.api.QuiltLoader; | ||
|
||
public class ModLoadingUtilImpl { | ||
|
||
public static boolean isModLoaded(String modId) { | ||
return QuiltLoader.isModLoaded(modId); | ||
} | ||
|
||
public static boolean isModLoadedWithVersion(String modid, String minVersion) { | ||
return ModLoadingUtilFabricLike.isModLoadedWithVersion(modid, minVersion); | ||
} | ||
} |