You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Minecraft 1.16.5模组自定义树木生成异常问题求助

问题解决:Minecraft 1.16.5 自定义树木仅在区块角落生成且参数无效

问题根源

你代码里重复叠加了装饰器逻辑:Features.Placements.HEIGHTMAP本身已经包含Placement.HEIGHTMAP装饰器,这个装饰器的核心逻辑是仅在区块的四个角落坐标处尝试生成特征。后续叠加的COUNT_EXTRA/CHANCE/COUNT_NOISE等装饰器,只会在这四个固定点重复执行生成判断,所以不管怎么调参数,结果要么是四个角落全生成,要么全不生成(只有参数全0时才会完全关闭)。

修复方案

移除多余的Features.Placements.HEIGHTMAP装饰器,改为将数量控制装饰器和位置高度装饰器按正确顺序链式调用:先指定生成数量/概率,再指定生成的高度位置。

修正后的核心代码示例

public class ModTreeGeneration {
    public static void generateTrees(final BiomeLoadingEvent event){

        RegistryKey<Biome> key = RegistryKey.create(Registry.BIOME_REGISTRY, event.getName());
        Set<BiomeDictionary.Type> types = BiomeDictionary.getTypes(key);

        if(types.contains(BiomeDictionary.Type.PLAINS)){
            List<Supplier<ConfiguredFeature<?, ?>>> base =
                    event.getGeneration().getFeatures(GenerationStage.Decoration.VEGETAL_DECORATION);

            // 正确链式顺序:先控制生成数量,再指定生成高度(适配地表)
            base.add(() -> ModConfiguredFeatures.MAGICWOOD
                    .decorated(Placement.COUNT_EXTRA.configured(new AtSurfaceWithExtraConfig(1, 0.25F, 1)))
                    .decorated(Placement.HEIGHTMAP.configured(new HeightmapConfig(Heightmap.Type.MOTION_BLOCKING))));
        }
    }
}

参数说明

  • AtSurfaceWithExtraConfig(int baseCount, float extraChance, int extraMax):
    • baseCount:每个区块的基础生成数量
    • extraChance:每区块额外生成的概率(0.25F代表25%概率多生成1棵)
    • extraMax:额外生成的最大数量上限
  • Heightmap.Type.MOTION_BLOCKING:基于游戏内的碰撞高度图判断,确保树木生成在合法的固体方块地表上

其他可选配置示例

如果想用概率控制生成:

// 每区块50%概率生成1棵树
base.add(() -> ModConfiguredFeatures.MAGICWOOD
        .decorated(Placement.CHANCE.configured(new ChanceConfig(2))) // 参数为n时,概率是1/n
        .decorated(Placement.HEIGHTMAP.configured(new HeightmapConfig(Heightmap.Type.MOTION_BLOCKING))));

如果想用世界噪声控制生成密度:

// 基于世界噪声,阈值0.5以上时生成1-3棵树
base.add(() -> ModConfiguredFeatures.MAGICWOOD
        .decorated(Placement.COUNT_NOISE.configured(new NoiseDependant(0.5D, 1, 3)))
        .decorated(Placement.HEIGHTMAP.configured(new HeightmapConfig(Heightmap.Type.MOTION_BLOCKING))));

内容的提问来源于stack exchange,提问作者Lune

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 03:33:30