注册表 API
基本信息
| 属性 | 值 |
|---|---|
| 入口 | GendustryAPI.Registries(类型 registries.IRegistriesApi) |
| 实现 | apiimpl/RegistriesApiImpl |
| 绑定 | Gendustry.scala:74(preInit) |
| 引入版本 | 2.0.0(api-changelog.md) |
| 接口数 | 3(IRegistriesApi / IFluidSourceRegistry / IMutatronOverrides) |
IRegistriesApi(4 个方法)
RegistriesApiImpl 在 postInit 阶段调 mergeToMainRegistry()(Gendustry.scala:159)把先前由附属模组登记的内容合并进主表 —— 因此附属模组可以早在自己的 preInit 阶段登记,无需等待 Gendustry 完成加载。
| 方法 | 返回 |
|---|---|
getMutagenRegistry() |
IFluidSourceRegistry |
getLiquidDnaRegistry() |
IFluidSourceRegistry |
getProteinRegistry() |
IFluidSourceRegistry |
getMutatronOverrides() |
IMutatronOverrides |
3 个液体来源注册表分别对应 3 种流体(Mutagen / Liquid DNA / Protein),与 Mutagen、Liquid DNA、Protein 一一对应。
IFluidSourceRegistry(9 个方法)
| 方法 | 返回 | 说明 |
|---|---|---|
getFluid() |
Fluid |
本注册表对应的 Forge 流体 |
canAdd() |
boolean |
是否仍允许登记新来源 |
add(ItemStack, int) |
boolean |
按物品栈 + 数值登记 |
add(Item, int) |
boolean |
按物品类型 + 数值登记 |
add(Block, int) |
boolean |
按方块 + 数值登记 |
get(ItemStack) |
int |
查该物品的产出量(单位 mB) |
get(Item) |
int |
同上 |
get(Block) |
int |
同上 |
返回值单位是 mB(毫桶),与 recipes.cfg 里 mutagen: I:redstone => 100 mb 的数值同尺度。查不到返回 0(FluidSourceRegistry.getValue 的三个分支:无此物品 → 0;无精确 meta 但有 WILDCARD_VALUE → 用通配值;否则 0)。
canAdd() 的存在说明注册表可被关闭(canAdd 为假时拒绝新登记但仍可查询)—— 用途是允许附属模组在 Gendustry 完成加载后停止接受新的来源。
实现侧是 3 个 Scala object(MutagenSources / LiquidDNASources / ProteinSources),各自 extends FluidSourceRegistry,内部用 mutable.Map[Item, mutable.Map[Int, Int]] 二级索引(物品 → meta → 数值),支持 OreDictionary.WILDCARD_VALUE 通配。
IMutatronOverrides(2 个方法)
| 方法 | 说明 |
|---|---|
set(IAlleleSpecies, EnumMutationSetting) |
按物种对象设置 |
set(String speciesUid, EnumMutationSetting) |
按物种 UID 设置 |
EnumMutationSetting 三个枚举值(与 tuning.cfg 的 Genetics.MutatronOverrides 字符串一一对应):
| 枚举 | 含义 |
|---|---|
ENABLED |
无条件允许该变异(默认值) |
DISABLED |
禁止该变异在诱变机中出现 |
REQUIREMENTS |
按正常繁殖条件检查(仅对蜂种有效) |
MachineMutatron.mutatronOverrides 把 API 登记的值与 tuning.cfg 的值合并(MutatronOverridesImpl.overrides ++ 配置项),因此配置文件后加载的值会覆盖 API 登记的同名项。withDefaultValue(EnumMutationSetting.ENABLED) 保证未登记的物种一律 ENABLED。
配置里若出现非法字符串,会打 Ignoring mutatron override for species %s - invalid value (%s) 警告并跳过该条,不影响其他条目。
ApiaryModifiers
api/ApiaryModifiers.java 是升级件修正器的载体,IApiaryUpgrade.applyModifiers(ApiaryModifiers, ItemStack) 直接改写它的 public 字段:
| 字段 | 类型 | 默认值 |
|---|---|---|
territory / mutation / lifespan / production / flowering / geneticDecay |
float |
1 |
energy |
float |
1 |
temperature / humidity |
float |
0 |
isSealed / isSelfLighted / isSunlightSimulated / isAutomated / isCollectingPollen |
boolean |
false |
biomeOverride |
BiomeGenBase |
null |
temperature 与 humidity 的默认值是 0,其余 6 个 float 是 1 —— 这正是 环境调节升级 用 += 0.25 / -= 0.25 累加的基础(0 ± n×0.25),而产量类用 *= 1.2 相对放大(1 为基准)。
IConfigLoader
| 方法 | 说明 |
|---|---|
loadConfig(Reader) |
加载一段配置文本 |
loadConfig(File) |
加载一个配置文件 |
TuningLoader 实现它。日志固定输出 Loading config submitted by mod %s(loadConfig(File))或同文的另一个变体。失败时 logErrorException("Error loading config submitted by mod %s", e, modId) 并返回 false,不抛出。2.2.0 引入。
IApiaryUpgrade
| 方法 | 返回 |
|---|---|
getDisplayName(ItemStack) |
String |
getDisplayDetails(ItemStack) |
List<String> |
getStackingId(ItemStack) |
long |
getMaxNumber(ItemStack) |
int |
applyModifiers(ApiaryModifiers, ItemStack) |
void |
getStackingId 返回 long 而非 int —— 预留空间给数量很大的自定义升级件,第三方 mod 可实现自己的 Item + IApiaryUpgrade 来注册升级。
相关条目
- Gendustry API - 入口类与全部 17 个接口
- Industrial Apiary -
applyModifiers的唯一调用方