WorldGenPamGarden(花园方块生成)
事实基准:
harvestcraft-1.3.14-GTNH.jar(MC 1.7.10 / Forge 10.13.4.1614)CFR 0.152 反编译源码。
基本信息
| 属性 | 值 | 来源 |
|---|---|---|
| 类 | com.pam.harvestcraft.WorldGenPamGarden |
WorldGenPamGarden.java:11 |
| 父类 | WorldGenerator |
WorldGenPamGarden.java:12 |
| 构造器 | WorldGenPamGarden(Block plantBlockId, int flowerType) |
:16-19 |
| 实例化方 | PamGardenGenerator.generateSurface(12 类花园中的 11 类) |
PamGardenGenerator.java:51,60,69,78,87,96,105,123,132,141,150 |
| 直接注册 | 否 | — |
构造器参数
| 形参 | 字段 | 说明 |
|---|---|---|
p_i45452_1_ |
plantBlockId |
要放置的花园方块(Block,非 IBlockAccess) |
i |
flowerType |
放置时用的 meta |
两个字段都是 private 非 final。形参名 p_i45452_1_ 是 CFR 对无法还原的形参名的占位(p_i45452_ 是 MCP 混淆名残留),不代表原版字段名。
生成逻辑(func_76484_a,:21-30)
for (int l = 0; l < 8; ++l) {
int i1 = i + random.nextInt(8) - random.nextInt(8);
if (!world.func_147437_c(i1, j1 = j + random.nextInt(4) - random.nextInt(4),
k1 = k + random.nextInt(8) - random.nextInt(8))
|| !this.plantBlockId.func_149742_c(world, i1, j1, k1)) continue;
world.func_147465_d(i1, j1, k1, this.plantBlockId, this.flowerType, 2);
}
return true;
| 项 | 值 | 说明 |
|---|---|---|
| 每次生成尝试次数 | 8(硬编码 :22) |
每次调用 generate 最多放 8 块 |
| X 偏移 | rand.nextInt(8) - rand.nextInt(8) → −7 … +7 |
注意是两个独立随机数相减,不是 nextInt(15)-7 |
| Y 偏移 | rand.nextInt(4) - rand.nextInt(4) → −3 … +3 |
— |
| Z 偏移 | rand.nextInt(8) - rand.nextInt(8) → −7 … +7 |
— |
| 放置的 meta | this.flowerType |
实参由 PamGardenGenerator 传入 rand.nextInt(1),恒为 0 |
| 放置的更新标志 | 字面量 2 |
对应原版 Block 的更新标志常量,具体语义未解析 |
双重前置条件
每个候选位置必须同时通过:
world.func_147437_c(x, y, z)—— SRG → 未解析;语义佐证:在WorldGenPamFruitPalmTree.java:44中它与k1.isLeaves(...)、k1.isWood(...)用||并列出现在"这里可以放东西"的判定里,因此是**"该位置可被替换/是空气"类判断**。this.plantBlockId.func_149742_c(world, x, y, z)—— SRG → 未解析;语义佐证:入参是(World, int, int, int)且返回boolean,被用作"这个方块能不能放在这里",在 Forge 体系中对应方块的canPlaceBlockAt族方法。不凭记忆断定具体方法名。
两项都由 || 连接,任一为假则 continue(跳过该次尝试)。
SRG 名(全部未解析)
| SRG 名 | 行 | 语义佐证 |
|---|---|---|
world.func_147437_c |
:26 |
"该位置可放置"类判定(见上) |
plantBlockId.func_149742_c |
:26 |
方块自身的放置可行性判定 |
world.func_147465_d |
:27 |
六参 (x, y, z, Block, int meta, int flags) 放置方块 |
func_76484_a |
:21 |
5 参生成入口 |
源码缺陷 / 观察
| 位置 | 问题 | 有无运行时影响 |
|---|---|---|
:27 |
meta 恒为 0(因为上游传 rand.nextInt(1)) |
有 —— 12 类花园的随机多样性完全失效,见 PamGardenGenerator |
:25,27 |
rand.nextInt(8) - rand.nextInt(8) 的写法是两个独立随机数相减,分布不是均匀的连续区间(中间值概率约为两端的 2 倍) |
有 —— 影响花园斑块的形状分布,但不改变"能否生成" |
:22 |
8 次尝试硬编码,与配置项 gardenRarity(每区块调用次数)是两个独立维度 |
无 —— 语义不同(前者是单次调用内的落点尝试,后者是每区块调用次数) |
:30 |
无论 8 次尝试是否成功,一律 return true |
有 —— 虚报成功;但 PamGardenGenerator 不消费该返回值 |
相关条目
- PamGardenGenerator —— 生态筛选、稀有度、以及调用本类的 11 处
- WorldGenPamMushroomGarden —— 第 12 类,单独实现(会铺地面)
- 兄弟维度:网络包 · 配置 · 兼容层