Plugin
集成插件抽象基类
基本信息
| 属性 | 值 |
|---|---|
| 路径 | com.github.lunatrius.ingameinfo.integration.Plugin |
| 行数 | 32 |
| 子类 | 5 个(BloodMagic / Gregtech / SimplyJetpacks / TerraFirmaCraft / Thaumcraft) |
三个抽象 / 可覆写成员
| 成员 | 行 | 性质 |
|---|---|---|
getDependency() |
:7 |
protected abstract |
getDependencyName() |
:9-11 |
可覆写,默认 return getDependency() |
getDependencyVersion() |
:13-15 |
可覆写,默认 return "" |
load() |
:21 |
public abstract |
两级方法设计
getDependency() 是 protected abstract(子类必须实现),
getDependencyName() 是 public 且默认委托给它。
所以只关心 modid 的集成只需覆写一个方法。 5 个子类中 3 个同时覆写了两个(为了给显示名):
| 子类 | getDependency() |
getDependencyName() |
getDependencyVersion() |
|---|---|---|---|
| BloodMagic | ✅ | ✅ | ❌(用默认 "") |
| Gregtech | ✅ | ✅ | ❌(用默认 "") |
| SimplyJetpacks | ✅ | ✅ | ❌(用默认 "") |
| TerraFirmaCraft | ✅ | ✅ | ✅ 覆写 |
| Thaumcraft | ✅ | ✅ | ✅ 覆写 |
⚠️ 只有 2 个覆写了 getDependencyVersion():
- Thaumcraft 返回
thaumcraft.common.Thaumcraft.VERSION - TerraFirmaCraft 返回
Reference.MOD_VERSION
⚠️ 在 TerraFirmaCraft 里,
Reference 是 com.bioxx.tfc.Reference(TFC 自己的类,
由 :3 的 import 决定),不是本 mod 的
Reference —— 同名不同类,易混。
canLoad(:17-19)
public boolean canLoad() { return Loader.isModLoaded(getDependency()); }
用 getDependency()(modid)判定,不是 getDependencyName()。
所以显示名不影响加载判断。
toString(:23-31)
final String dependencyVersion = getDependencyVersion();
if (dependencyVersion != null && !dependencyVersion.isEmpty()) {
return getDependencyName() + " " + dependencyVersion;
}
return getDependencyName();
有版本号时输出 名字 版本号,否则只输出名字。
被 PluginLoader 的 preInit(:56)
写进 event.getModMetadata().description:
event.getModMetadata().description += "\nCompiled against " + this.plugins;
所以模组列表里的描述会追加一行「Compiled against …」。
⚠️ 该 += 每次 preInit 都追加,
且 plugins 是 List.toString()(形如 [A 1.7.10-4.2.3.5, B])。
相关
- PluginLoader - 唯一调用方
- TagIntegration - 集成 tag 的基类