Add isFabric and isForge to Platform

This commit is contained in:
shedaniel
2020-11-22 00:03:51 +08:00
parent 1d0773c790
commit 6cbd3967ff

View File

@@ -23,6 +23,7 @@ import me.shedaniel.architectury.Architectury;
import me.shedaniel.architectury.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.minecraft.SharedConstants;
import net.minecraft.util.LazyLoadedValue;
import org.jetbrains.annotations.NotNull;
import java.nio.file.Path;
@@ -31,6 +32,7 @@ import java.util.Optional;
public final class Platform {
private Platform() {}
private static int simpleLoaderCache = -1;
/**
* @return the current mod loader, either "fabric" or "forge"
@@ -40,6 +42,27 @@ public final class Platform {
return Architectury.getModLoader();
}
public static boolean isFabric() {
updateLoaderCache();
return simpleLoaderCache == 0;
}
public static boolean isForge() {
updateLoaderCache();
return simpleLoaderCache == 1;
}
private static void updateLoaderCache() {
switch (getModLoader()) {
case "fabric":
simpleLoaderCache = 0;
return;
case "forge":
simpleLoaderCache = 1;
return;
}
}
@NotNull
public static String getMinecraftVersion() {
return SharedConstants.getCurrentVersion().getId();