EnvironmentDetector API
一个轻量级且防崩溃的 Fabric、Quilt 及现代整合包启动器环境检测 API。
EnvironmentDetector 自动识别:
- 启动器
- 整合包实例
- 加载器
- Minecraft 版本
- 特殊客户端环境
该 API 专为以下用途设计:
- 模组
- HUD(抬头显示)
- 占位符系统
- 数据分析
- 兼容层
- 感知启动器的集成
✨ 特性
自动启动器检测
EnvironmentDetector 可以自动检测以下启动器:
- Modrinth App
- CurseForge
- GDLauncher
- Prism Launcher
- MultiMC
- ATLauncher
- Feather Client
- NoRisk Client
- Lunar Client
- Badlion Client
- 官方 Minecraft 启动器
无需手动配置。
? 兼容性
支持的 Minecraft 版本
主要支持
- Minecraft
1.21.x(1.21、1.21.1、1.21.2 等)
- 针对现代 Minecraft 环境进行了优化和测试。
该项目目前面向:
Java 21
- 现代 Fabric Loader 版本
- 当前启动器生态系统
向后兼容
EnvironmentDetector 主要依赖:
- Fabric Loader API
- 文件系统检查
- 运行时分析
该 API 不会深度修改 Minecraft 内部结构,并且避免在检测逻辑中使用复杂的 mixins。
因此,该项目也可以移植到较旧的版本,如:
只需进行最小程度的调整:
- 将 Java 目标版本从
21 降低至 17
- 调整
fabric.mod.json
- 重新构建项目
支持的模组加载器
Fabric
✅ 完全原生支持
(主要目标平台)
Quilt
✅ 完全原生支持
Quilt 原生支持 Fabric 模组,且 EnvironmentDetector 包含专门的 Quilt 检测逻辑。
这意味着在 Quilt 上运行时,日志会正确显示为:
Loader=Quilt
而不是 Fabric。
NeoForge / Forge
⚡ 非原生支持
EnvironmentDetector 主要是 Fabric 模组。
但是,通过兼容层(如 Sinytra Connector 或 Fabric Connector 实现),该模组也能正常工作。
通过这些层使用时,API 甚至可以检测到环境运行在:
技术要求
Java 版本
- Minecraft
1.20.5+ 需要 Java 21
Fabric Loader
兼容性概览
| 特性 |
状态 |
| Minecraft 1.21.x |
✅ 已优化 & 已测试 |
| Fabric |
✅ 原生支持 |
| Quilt |
✅ 原生支持 |
| NeoForge / Forge |
⚡ 仅通过连接器 |
| 专用服务器 |
✅ 完全兼容 |
| Java 21 |
?️ 必需 |
? 高精度检测系统
与许多其他模组不同,EnvironmentDetector 不仅仅依赖进程名称。
相反,它使用:
- 基于文件的验证
- 递归目录扫描
- 启动器元数据验证
- 类路径分析
- 运行时环境分析
这避免了误报和重复检测。
示例:
其他模组可能只是简单地扫描系统中运行的 "Modrinth"。
而 EnvironmentDetector 则使用更先进的基于运行时的检测系统。
1. JVM 参数扫描
API 会扫描 Minecraft 启动参数(即通常在日志和运行时启动参数中可见的信息)。
如果以下单词:
modrinth
出现在 JVM 参数、启动路径或运行时参数中,启动器将被自动检测为:
Modrinth App
这非常可靠,因为 Modrinth 启动器通常会将与 Modrinth 相关的路径或标识符注入到 Minecraft 运行时环境中。
2. 手动配置回退
在首次启动时,EnvironmentDetector 会自动创建:
config/environmentdetector.properties
在此文件中,可以手动配置自定义值:
manual_pack_name=你的整合包名称
manual_launcher_name=你的自定义启动器
如果设置了这些值,它们将始终具有最高优先级并覆盖自动检测结果。
这使得以下内容能够与 API 可靠配合工作:
- 自定义启动器
- 私有整合包
- 不受支持的启动器
- 开发环境
- 便携版实例
? 检测逻辑
API 会扫描多个目录级别以识别启动器结构。
支持的标记
Modrinth App
- 运行时 JVM 分析
- 启动参数分析
- 可选元数据验证
CurseForge
CURSEFORGE_INSTANCE_NAME
minecraftinstance.json
.curseclient
Feather Client
feather
feather-core
.feather
NoRisk Client
norisk.config
- 模组 ID:
norisk
GDLauncher
gd-launcher.json
gdlauncher.json
Prism Launcher / MultiMC
prism.config
prism.json
multimc.cfg
ATLauncher
instance.json
atlauncher.json
Lunar / Badlion
类路径关键字分析:
官方启动器
? 标准化日志
初始化后,EnvironmentDetector 输出统一的日志条目。
示例:
[EnvironmentDetector] Launcher=Modrinth App, Instance=Ultra Survival, NoRisk=false, Loader=Fabric, Version=1.21.1
其他示例:
[EnvironmentDetector] Launcher=CurseForge, Instance=BetterMC, NoRisk=false, Loader=Fabric, Version=1.21.1
[EnvironmentDetector] Launcher=NoRisk Client, Instance=Unknown Pack, NoRisk=true, Loader=Fabric, Version=1.21.1
回退情况:
[EnvironmentDetector] Unknown Environment
⚡ 性能
- 单次启动扫描
- 缓存结果
- 线程安全的内部结构
- 极小的开销
- 无后台扫描
EnvironmentDetector 仅在启动期间运行一次,之后仅提供缓存数据。
? 开发者集成
Gradle 设置
repositories {
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
}
依赖项
dependencies {
modImplementation "maven.modrinth:environmentdetector-api:VERSION"
}
将 VERSION 替换为最新版本号。
? 使用示例
public String getLauncherName() {
if (FabricLoader.getInstance().isModLoaded("environmentdetector")) {
return de.felixfgf.environmentdetector.EnvironmentDetectorAPI
.getEnvironment()
.launcher();
}
return "Vanilla";
}
⚠ 最佳实践
始终使用可选集成
不要硬依赖 EnvironmentDetector。
在使用 API 之前,请务必检查:
FabricLoader.getInstance().isModLoaded("environmentdetector")
? 常见错误
错误的包名
正确的包名:
de.felixfgf.environmentdetector
不是:
de.felixfgf.environmentdetector.api
缺少对 isModLoaded 的检查
在未检查模组是否存在的情况下直接访问 API 可能导致其他模组崩溃。
每帧解析占位符
不要在每个渲染帧中解析占位符。
在打开菜单或 HUD 时缓存数值。
? Bug 报告与支持
发现了 Bug 或检测问题?
请报告以下内容:
- 使用的启动器
- Minecraft 版本
- 加载器
- latest.log
- 检测到的环境输出
加入 Discord 服务器以获取支持、Bug 报告和 API 讨论:
? 目标
- 最大程度地实现环境透明化
- 可靠的启动器识别
- 高兼容性
- 零配置设置
- 防崩溃集成
- 轻量级架构
EnvironmentDetector 旨在成为现代 Minecraft 启动器生态系统的标准环境 API ?
EnvironmentDetector API
A lightweight and crash-safe Minecraft environment detection API for Fabric, Quilt and modern modpack launchers.
EnvironmentDetector automatically identifies:
- Launcher
- Modpack instance
- Loader
- Minecraft version
- Special client environments
The API is designed for:
- Mods
- HUDs
- Placeholder systems
- Analytics
- Compatibility layers
- Launcher-aware integrations
✨ Features
Automatic Launcher Detection
EnvironmentDetector can automatically detect:
- Modrinth App
- CurseForge
- GDLauncher
- Prism Launcher
- MultiMC
- ATLauncher
- Feather Client
- NoRisk Client
- Lunar Client
- Badlion Client
- Official Minecraft Launcher
No manual configuration required.
? Compatibility
Supported Minecraft Versions
Primary Support
- Minecraft
1.21.x (1.21, 1.21.1, 1.21.2, etc.)
- Optimized and tested for modern Minecraft environments.
The project currently targets:
Java 21
- modern Fabric Loader versions
- current launcher ecosystems
Backwards Compatibility
EnvironmentDetector mainly relies on:
- Fabric Loader APIs
- filesystem checks
- runtime analysis
The API does NOT deeply modify Minecraft internals and avoids complex mixins for detection logic.
Because of this, the project can also be ported to older versions like:
with only minimal adjustments:
- lowering the Java target from
21 → 17
- adjusting
fabric.mod.json
- rebuilding the project
Supported Mod Loaders
Fabric
✅ Full native support
(Main target platform)
Quilt
✅ Full native support
Quilt supports Fabric mods natively and EnvironmentDetector includes dedicated Quilt detection logic.
This means logs will correctly show:
Loader=Quilt
instead of Fabric when running on Quilt.
NeoForge / Forge
⚡ Not natively supported
EnvironmentDetector is primarily a Fabric mod.
However, the mod works correctly through compatibility layers such as:
- Sinytra Connector
- Fabric Connector implementations
When used through these layers, the API can even detect that the environment is running on:
Technical Requirements
Java Version
- Java
21 required for Minecraft 1.20.5+
Fabric Loader
Compatibility Overview
| Feature |
Status |
| Minecraft 1.21.x |
✅ Optimized & Tested |
| Fabric |
✅ Native Support |
| Quilt |
✅ Native Support |
| NeoForge / Forge |
⚡ Via Connector Only |
| Dedicated Server |
✅ Fully Compatible |
| Java 21 |
?️ Required |
? High Precision Detection System
Unlike many other mods, EnvironmentDetector does NOT rely on process names only.
Instead, it uses:
- file-based validation
- recursive directory scanning
- launcher metadata verification
- classpath analysis
- runtime environment analysis
This avoids false positives and duplicate detections.
Example:
Other mods may simply scan for "Modrinth" running on the system.
EnvironmentDetector instead uses a more advanced runtime-based detection system.
1. JVM Argument Scan
The API scans Minecraft startup arguments (the same information normally visible in logs and runtime launch parameters).
If the word:
modrinth
appears inside JVM arguments, launch paths or runtime parameters, the launcher is automatically detected as:
Modrinth App
This works reliably because the Modrinth launcher usually injects Modrinth-related paths or identifiers into the Minecraft runtime environment.
2. Manual Configuration Fallback
On first startup, EnvironmentDetector automatically creates:
config/environmentdetector.properties
Inside this file, custom values can be manually configured:
manual_pack_name=Your Modpack Name
manual_launcher_name=Your Custom Launcher
If these values are set, they always take highest priority and override automatic detection.
This allows:
- custom launchers
- private modpacks
- unsupported launchers
- development environments
- portable instances
to work reliably with the API.
? Detection Logic
The API scans multiple directory levels to identify launcher structures.
Supported Markers
Modrinth App
- Runtime JVM analysis
- launch argument analysis
- optional metadata validation
CurseForge
CURSEFORGE_INSTANCE_NAME
minecraftinstance.json
.curseclient
Feather Client
feather
feather-core
.feather
NoRisk Client
norisk.config
- Mod ID:
norisk
GDLauncher
gd-launcher.json
gdlauncher.json
Prism Launcher / MultiMC
prism.config
prism.json
multimc.cfg
ATLauncher
instance.json
atlauncher.json
Lunar / Badlion
Classpath keyword analysis:
Official Launcher
? Standardized Logging
After initialization, EnvironmentDetector outputs a unified log entry.
Example:
[EnvironmentDetector] Launcher=Modrinth App, Instance=Ultra Survival, NoRisk=false, Loader=Fabric, Version=1.21.1
Other examples:
[EnvironmentDetector] Launcher=CurseForge, Instance=BetterMC, NoRisk=false, Loader=Fabric, Version=1.21.1
[EnvironmentDetector] Launcher=NoRisk Client, Instance=Unknown Pack, NoRisk=true, Loader=Fabric, Version=1.21.1
Fallback:
[EnvironmentDetector] Unknown Environment
⚡ Performance
- Single startup scan
- Cached results
- Thread-safe internals
- Minimal overhead
- No background scanning
EnvironmentDetector runs once during startup and afterwards only serves cached data.
? Developer Integration
Gradle Setup
repositories {
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
}
Dependency
dependencies {
modImplementation "maven.modrinth:environmentdetector-api:VERSION"
}
Replace VERSION with the latest release.
? Usage Example
public String getLauncherName() {
if (FabricLoader.getInstance().isModLoaded("environmentdetector")) {
return de.felixfgf.environmentdetector.EnvironmentDetectorAPI
.getEnvironment()
.launcher();
}
return "Vanilla";
}
⚠ Best Practices
Always use optional integration
Do NOT hard depend on EnvironmentDetector.
Always check:
FabricLoader.getInstance().isModLoaded("environmentdetector")
before using the API.
? Common Mistakes
Wrong package
Correct package:
de.felixfgf.environmentdetector
NOT:
de.felixfgf.environmentdetector.api
Missing modLoaded check
Direct API access without checking if the mod exists can crash other mods.
Using placeholders every frame
Do not resolve placeholders every render frame.
Cache values when opening menus or HUDs.
? Bug Reports & Support
Found a bug or detection issue?
Please report:
- launcher used
- Minecraft version
- loader
- latest.log
- detected environment output
Join the Discord server for support, bug reports and API discussions:
? Goals
- Maximum environment transparency
- Reliable launcher identification
- High compatibility
- Zero-config setup
- Crash-safe integration
- Lightweight architecture
EnvironmentDetector is built to become the standard environment API for modern Minecraft launcher ecosystems ?
评论 0
登录后参与评分
还没有评论,来抢沙发吧