库工具类
[!INFO] Git Commit:
d3dbd5f| Updated: 2026-10-01
除矿辞典注册与 IC2 mixin 外,本 mod 还有 5 个小型工具类,全部是 public static 方法的容器,
供下游作物 mod(BerriesPP)调用。本仓库 20 个源文件中没有任何一处调用它们
(除 OreDict.register() 与 ModsLoaded.check_init()),它们的存在完全是为了对外提供 API。
MyRandom(MyRandom.java)
两个静态随机方法,每次调用都新建一个 SplittableRandom,种子为 System.nanoTime()
(:14、:25)——即不持有实例、不可复现、不可设种子。
| 方法 | 返回 | 实现 |
|---|---|---|
intrandom(int max, int min) |
[min, max] 闭区间整数 |
random.nextInt((max - min) + 1) + min |
floatrandom(float max, float min) |
[min, max) 浮点 |
(float)(min + random.nextDouble() * (max - min)) |
两个方法开头都用 4 行代码交换 max/min 处理参数倒置(:8-13、:19-24)。
注意整数版是闭区间(+1 后 nextInt 上界含端点),浮点版是半开区间
(nextDouble() 返回 [0,1)),两者边界语义不一致。
Operators.csig(Operators.java)
public static float csig(float input, float modifier, boolean rising) {
return (float) ((float) 1 + Math.tanh((rising ? 1.0 : (-1.0)) * (double) input / (double) modifier));
}
Operators.java:8-10。Javadoc 写 Calculates a percentage in a custom way。
这是一个 tanh 饱和函数,把 input / modifier 压到 (-1, 1) 区间后映射为 (0, 2)——
用作百分比系数时天然被限制在 0–200%,无论 input 多大都不会溢出。
rising = false 时取负号,得到单调递减的曲线。
modifier 没有零值保护:modifier == 0 时整型提升后为 0.0,x / 0.0 得 NaN,
tanh(NaN) = NaN,最终返回 NaN。调用方需自行保证非零。
类只有这一个方法——Operators 是个通用命名,但目前仅服务于作物成长曲线。
BlockGetterTC(BlockGetterTC.java)
两个方法,都是把 Thaumcraft 的物品/方块查询结果转成 net.minecraft.block.Block:
| 方法 | 实现 | 用途 |
|---|---|---|
getBlock_asBlock(String itemString, int meta) |
Block.getBlockFromItem(ItemApi.getBlock(itemString, meta).getItem()) |
方块名 → Block |
getItem_asBlock(String itemString, int meta) |
Block.getBlockFromItem(ItemApi.getItem(itemString, meta).getItem()) |
物品名 → Block |
两者都走 thaumcraft.api.ItemApi,区别仅在调 getBlock 还是 getItem。
方法名带 _asBlock 后缀说明其存在意义就是跨类型取 Block——
ItemApi.getItem 返回的可能是纯物品(无方块),此时 getBlockFromItem 返回 null,
调用方必须判空。
本 mod 自身只在 RegisterThaumcraft 中用了 ItemApi.getBlock(静态导入,:3),
并未使用这个类。
config(config.java)
类名全小写,且全仓无任何 new config(...) 调用(已 grep 确认)——是一个未被本仓库使用的
配置包装器:
public class config {
public Configuration tConfig;
public config(FMLPreInitializationEvent preinit, String cfgname) {
File tFile = new File(preinit.getModConfigurationDirectory(), cfgname);
tConfig = new Configuration(tFile);
tConfig.load();
}
public void save() { tConfig.save(); }
}
config.java:9-23。它只是把 Forge Configuration 的「构造 + load」两步包起来,并暴露一个
save()。没有 get() 之类的取值辅助方法、没有默认值、没有分类、没有范围校验——
真正取值仍需调用方自己用 tConfig.get(...)。
与 StructureCompat 的 Config 相比(后者是 ExampleMod 模板遗留的 greeting 死代码),
本类虽然同样在本仓库内无人使用,但它是有实际语义的公共 API:下游 mod 可以直接
new config(preinit, "mycrop.cfg") 拿到一个已 load 的 Configuration。
gradle.properties 的 replaceGradleTokenInFile = CropLoadCore.java 也确认 token 只作用于主类。
ModsLoaded(ModsLoaded.java)
9 个 public static boolean 标志位 + 一个 check_init(String name) 静态方法,
纯粹用于打印日志——OreDict 不读这些字段,而是各自再查一次 Loader.isModLoaded。
| 字段 | 探测的 modid | 对应 @Mod 依赖? |
|---|---|---|
IC2 |
IC2 |
❌ 未声明(仅在 ASM 容器中) |
Natura |
Natura |
✅ after:Natura |
TConstruct |
TConstruct |
✅ after:TConstruct |
BoP |
BiomesOPlenty |
✅ after:BiomesOPlenty |
TC |
Thaumcraft |
✅ after:Thaumcraft |
witchery |
witchery |
✅ after:witchery |
GT5uNH |
gregtech_nh |
❌ 列表里是 gregtech |
dreamcraft |
dreamcraft |
✅ after:dreamcraft |
PHC |
harvestcraft |
❌ 未声明 |
GTpp |
miscutils |
❌ 未声明 |
日志分两段(ModsLoaded.java:30-55):若 GTpp(GT++,miscutils)为真,只输出
GT++ installed, the logs will show you the installed Mods. 一行,跳过全部 7 条逐项日志;
否则对 IC2 / Natura / TConstruct / BoP / TC / GT5uNH / dreamcraft / PHC 逐条输出
found 或 NOT found。witchery 的日志在 if/else 之外(:56-57),总是输出。
日志等级不统一:IC2 缺失用 error(:32),其余缺失用 warn,存在一律用 info。
IC2 那条的存在/缺失文案也与其余不同——IC2 found! <name> will now load! 与
IC2 NOT INSTALLED! WTF? YOU NEED IT FOR CROPS! POWAOFCAPLSLOCK!(原文如此,含拼写错误)。
传入的 name 参数("bartimaeusnek's mods")被拼接进每条消息,使同一个核心库在不同下游 mod
中的日志可区分。