跳到主要内容
版本:1.21 - 1.21.1

生物群系修饰符

生物群落修改器是一个数据驱动的系统,可以改变生物群落的许多方面,包括注入或删除 PlacedFeatures、添加或删除生物生成、改变气候以及调整树叶和水的颜色的能力。 NeoForge 提供了几种默认的生物群系修改器,涵盖了玩家和 Mod 开发者的大多数用例。

应用生物群系修改器

要让 NeoForge 将生物群落修改器 JSON 文件加载到游戏中,该文件需要位于 mod 资源中的 data/<modid>/neoforge/biome_modifier/<path>.json 文件夹下,或位于 Datapack 中。然后,一旦 NeoForge 加载生物群落修改器,它将读取其指令,并在加载世界时将所描述的修改应用于所有目标生物群落。 Mod 中预先存在的生物群落修饰符可以被具有完全相同位置和名称的新 JSON 文件的数据包覆盖。

JSON 文件可以按照“内置 NeoForge 生物群落修改器”部分中的示例手动创建,也可以按照“数据生成生物群落修改器”部分中所示的方式进行数据生成。

内置生物群系修改器

这些生物群系修改器由 NeoForge 注册,供任何人使用。

该生物群落修改器没有任何操作,也不会进行任何修改。包制作者和玩家可以在数据包中使用此功能,通过使用下面的 JSON 覆盖其生物群系修改器 JSON 来禁用 Mod 的生物群系修改器。

{
"type": "neoforge:none"
}

添加功能

此生物群落修改器类型将 PlacedFeature(例如树木或矿石)添加到生物群落中,以便它们可以在世界生成期间生成。修改器接受要添加到的生物群落的生物群落 ID 或标签、要添加到所选生物群落的 PlacedFeatureID 或标签,以及将在其中生成的特征的 GenerationStep.Decoration

{
"type": "neoforge:add_features",
// Can either be a biome id, such as "minecraft:plains",
// or a list of biome ids, such as ["minecraft:plains", "minecraft:badlands", ...],
// or a biome tag, such as "#c:is_overworld".
"biomes": "#namespace:your_biome_tag",
// Can either be a placed feature id, such as "examplemod:add_features_example",
// or a list of placed feature ids, such as ["examplemod:add_features_example", minecraft:ice_spike", ...],
// or a placed feature tag, such as "#examplemod:placed_feature_tag".
"features": "namespace:your_feature",
// See the GenerationStep.Decoration enum in code for a list of valid enum names.
// The decoration step section further down also has the list of values for reference.
"step": "underground_ores"
}
注意

将普通 PlacedFeature 添加到生物群落时应小心,因为这样做可能会导致所谓的功能循环违规(两个生物群落在其功能列表中具有相同的两个功能,但在同一 GenerationStep 中顺序不同),从而导致崩溃。出于类似的原因,你不应在多个生物群系修改器中使用相同的 PlacedFeature

原版PlacedFeature 可以在生物群落 JSON 中引用或通过生物群落修饰符添加,但不应在两者中使用。如果你仍然需要以这种方式添加它们,那么在你自己的命名空间下制作普通 PlacedFeature 的副本是避免这些问题的最简单的解决方案。

删除功能

这种生物群落修改器类型会从生物群落中删除特征(例如树木或矿石),以便它们在世界生成期间不再生成。修改器接受要从中删除要素的生物群落的生物群落 ID 或标签、要从所选生物群落中删除的 PlacedFeatureID 或标签,以及要从中删除要素的 GenerationStep.Decoration

{
"type": "neoforge:remove_features",
// Can either be a biome id, such as "minecraft:plains",
// or a list of biome ids, such as ["minecraft:plains", "minecraft:badlands", ...],
// or a biome tag, such as "#c:is_overworld".
"biomes": "#namespace:your_biome_tag",
// Can either be a placed feature id, such as "examplemod:add_features_example",
// or a list of placed feature ids, such as ["examplemod:add_features_example", "minecraft:ice_spike", ...],
// or a placed feature tag, such as "#examplemod:placed_feature_tag".
"features": "namespace:problematic_feature",
// Optional field specifying a GenerationStep, or a list of GenerationSteps, to remove features from.
// If omitted, defaults to all GenerationSteps.
// See the GenerationStep.Decoration enum in code for a list of valid enum names.
// The decoration step section further down also has the list of values for reference.
"steps": ["underground_ores", "underground_decoration"]
}

添加生成点

此生物群落修改器类型将实体生成添加到生物群落。修改器接受实体生成的生物群落的生物群落 ID 或标签,以及要添加的实体的 SpawnerData。每个 SpawnerData 包含实体 ID、生成重量以及给定时间生成的实体的最小/最大数量。

备注

如果你是添加新实体的 Mod 开发者,请确保该实体已注册到 RegisterSpawnPlacementsEvent 的生成限制。生成限制用于使实体在表面或水中安全地生成。如果你没有注册生成限制,你的实体可能会在半空中生成、坠落并死亡。

{
"type": "neoforge:add_spawns",
// Can either be a biome id, such as "minecraft:plains",
// or a list of biome ids, such as ["minecraft:plains", "minecraft:badlands", ...],
// or a biome tag, such as "#c:is_overworld".
"biomes": "#namespace:biome_tag",
// Can be either a single object or a list of objects.
"spawners": [
{
"type": "namespace:entity_type", // The id of the entity type to spawn
"weight": 100, // int, spawn weight
"minCount": 1, // int, minimum group size
"maxCount": 4 // int, maximum group size
},
{
"type": "minecraft:ghast",
"weight": 1,
"minCount": 5,
"maxCount": 10
}
]
}

删除生成点

此生物群落修改器类型会从生物群落中移除实体生成。修改器接受从中删除实体生成的生物群落的生物群落 ID 或标签,以及要删除的实体的 EntityTypeID 或标签。

{
"type": "neoforge:remove_spawns",
// Can either be a biome id, such as "minecraft:plains",
// or a list of biome ids, such as ["minecraft:plains", "minecraft:badlands", ...],
// or a biome tag, such as "#c:is_overworld".
"biomes": "#namespace:biome_tag",
// Can either be an entity type id, such as "minecraft:ghast",
// or a list of entity type ids, such as ["minecraft:ghast", "minecraft:skeleton", ...],
// or an entity type tag, such as "#minecraft:skeletons".
"entity_types": "#namespace:entitytype_tag"
}

添加生成成本

允许为生物群系添加新的生成成本。生成成本是一种使生物在生物群系中分散生成以减少集群的新方法。它的工作原理是让实体发出围绕它们的 charge 并与其他实体的 charge 相加。当生成新实体时,生成算法会查找该位置处的总 charge 字段乘以生成实体的 charge 值小于生成实体的 energy_budget 的点。这是一种生成小怪的高级方法,因此最好参考灵魂沙谷生物群系(这是该系统最著名的用户)来借用现有值。

该修改器接受添加生成成本的生物群落的生物群落 ID 或标签、要为其添加生成成本的实体类型的 EntityTypeID 或标签,以及实体的 MobSpawnSettings.MobSpawnCostMobSpawnCost 包含能量预算,它指示根据为生成的每个实体提供的费用,可以在某个位置生成的实体的最大数量。

备注

如果你是添加新实体的 Mod 开发者,请确保该实体已注册到 RegisterSpawnPlacementsEvent 的生成限制。

{
"type": "neoforge:add_spawn_costs",
// Can either be a biome id, such as "minecraft:plains",
// or a list of biome ids, such as ["minecraft:plains", "minecraft:badlands", ...],
// or a biome tag, such as "#c:is_overworld".
"biomes": "#namespace:biome_tag",
// Can either be an entity type id, such as "minecraft:ghast",
// or a list of entity type ids, such as ["minecraft:ghast", "minecraft:skeleton", ...],
// or an entity type tag, such as "#minecraft:skeletons".
"entity_types": "#minecraft:skeletons",
"spawn_cost": {
// The energy budget
"energy_budget": 1.0,
// The amount of charge each entity takes up from the budget
"charge": 0.1
}
}

删除生成成本

允许从生物群落中消除生成成本。生成成本是一种使生物在生物群系中分散生成以减少集群的新方法。修改器接受从中删除生成成本的生物群落的生物群系 ID 或标签,以及要删除其生成成本的实体的 EntityTypeID 或标签。

{
"type": "neoforge:remove_spawn_costs",
// Can either be a biome id, such as "minecraft:plains",
// or a list of biome ids, such as ["minecraft:plains", "minecraft:badlands", ...],
// or a biome tag, such as "#c:is_overworld".
"biomes": "#namespace:biome_tag",
// Can either be an entity type id, such as "minecraft:ghast",
// or a list of entity type ids, such as ["minecraft:ghast", "minecraft:skeleton", ...],
// or an entity type tag, such as "#minecraft:skeletons".
"entity_types": "#minecraft:skeletons"
}

添加旧雕刻师

这种生物群系修改器类型允许向生物群系添加雕刻洞穴和峡谷。这些是在洞穴和悬崖更新之前用于洞穴生成的内容。它不能将噪声洞穴添加到生物群落中,因为噪声洞穴是某些基于噪声的块生成器系统的一部分,并且实际上与生物群落无关。

{
"type": "neoforge:add_carvers",
// Can either be a biome id, such as "minecraft:plains",
// or a list of biome ids, such as ["minecraft:plains", "minecraft:badlands", ...],
// or a biome tag, such as "#c:is_overworld".
"biomes": "minecraft:plains",
// Can either be a carver id, such as "examplemod:add_carvers_example",
// or a list of carver ids, such as ["examplemod:add_carvers_example", "minecraft:canyon", ...],
// or a carver tag, such as "#examplemod:configured_carver_tag".
"carvers": "examplemod:add_carvers_example",
// See GenerationStep.Carving in code for a list of valid enum names.
// Only "air" and "liquid" are available.
"step": "air"
}

删除旧版雕刻机

这种生物群落修改器类型允许从生物群落中移除雕刻洞穴和峡谷。这些是在洞穴和悬崖更新之前用于洞穴生成的内容。它无法从生物群落中移除噪音洞穴,因为噪音洞穴被烘焙到维度的噪音设置系统中,并且实际上并不与生物群系相关联。

{
"type": "neoforge:remove_carvers",
// Can either be a biome id, such as "minecraft:plains",
// or a list of biome ids, such as ["minecraft:plains", "minecraft:badlands", ...],
// or a biome tag, such as "#c:is_overworld".
"biomes": "minecraft:plains",
// Can either be a carver id, such as "examplemod:add_carvers_example",
// or a list of carver ids, such as ["examplemod:add_carvers_example", "minecraft:canyon", ...],
// or a carver tag, such as "#examplemod:configured_carver_tag".
"carvers": "examplemod:add_carvers_example",
// Can either be a single generation step, such as "air",
// or a list of generation steps, such as ["air", "liquid"].
// See GenerationStep.Carving for a list of valid enum names.
// Only "air" and "liquid" are available.
"steps": [
"air",
"liquid"
]
}

装饰步骤的可用值

上述许多 JSON 中的 stepsteps 字段均引用 GenerationStep.Decoration 枚举。该枚举具有按以下顺序列出的步骤,该顺序与游戏在世界生成期间生成的顺序相同。尝试将功能放入对他们最有意义的步骤中。

步骤描述
raw_generation第一个跑。这用于特殊的地形特征,例如小恩德群岛。
lakes专用于熔岩湖等类似产卵池的特征。
local_modifications用于修改地形,例如晶洞、冰山、巨石或滴水石。
underground_structures用于类似地下结构的小型特征,例如地下城或化石。
surface_structures对于小表面,仅类似结构的特征,例如沙漠井。
strongholds专用于要塞结构。未修改的 Minecraft 中未添加任何功能。
underground_ores添加所有矿石和矿脉的步骤。这包括黄金、泥土、花岗岩等。
underground_decoration通常用于装饰洞穴。滴石簇和斯库克矿脉就在这里。
fluid_springs小熔岩瀑布和瀑布就来自这个阶段的特征。
vegetal_decoration几乎所有植物(花卉、树木、藤蔓等)都会添加到此阶段。
top_layer_modification最后跑。用于将雪和冰放置在寒冷生物群系的表面。

创建自定义生物群系修改器

BiomeModifier 实施

在底层,生物群落修改器由三部分组成:

  • 数据包已注册BiomeModifier 用于修改生物群系构建器。
  • 静态注册MapCodec 对修饰符进行编码和解码。
  • 构造 BiomeModifier 的 JSON,使用 MapCodec 的注册 id 作为可索引类型。

BiomeModifier 包含两个方法:#modify#codecmodify 接收当前 Biome、当前 BiomeModifier.PhaseHolder 以及要修改的生物群系构建器。每个 BiomeModifier 都会被调用一次,以组织何时对生物群落进行某些修改:

描述
BEFORE_EVERYTHING涵盖了标准阶段之前需要运行的所有内容。
ADD添加功能、生物生成等。
REMOVE删除功能、生物生成等。
MODIFY修改单个值(例如气候、颜色)。
AFTER_EVERYTHING标准阶段之后需要运行的所有内容的包罗万象。

所有 BiomeModifier 都包含一个 type 密钥,该密钥引用用于 BiomeModifierMapCodec 的 id。 codec 接收对修饰符进行编码和解码的 MapCodec。这个 MapCodec静态注册的,它的 id 就是 BiomeModifiertype

public record ExampleBiomeModifier(HolderSet<Biome> biomes, int value) implements BiomeModifier {

@Override
public void modify(Holder<Biome> biome, Phase phase, ModifiableBiomeInfo.BiomeInfo.Builder builder) {
if (phase == /* Pick the phase that best matches what your want to modify */) {
// Modify the 'builder', checking any information about the biome itself
}
}

@Override
public MapCodec<? extends BiomeModifier> codec() {
return EXAMPLE_BIOME_MODIFIER.get();
}
}

// In some registration class
private static final DeferredRegister<MapCodec<? extends BiomeModifier>> BIOME_MODIFIERS =
DeferredRegister.create(NeoForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, MOD_ID);

public static final Supplier<MapCodec<ExampleBiomeModifier>> EXAMPLE_BIOME_MODIFIER =
BIOME_MODIFIERS.register("example_biome_modifier", () -> RecordCodecBuilder.mapCodec(instance ->
instance.group(
Biome.LIST_CODEC.fieldOf("biomes").forGetter(ExampleBiomeModifier::biomes),
Codec.INT.fieldOf("value").forGetter(ExampleBiomeModifier::value)
).apply(instance, ExampleBiomeModifier::new)
));

数据生成生物群系修改器

通过将 RegistrySetBuilder 传递给 DatapackBuiltinEntriesProvider,可以通过数据生成 创建 BiomeModifierJSON。 JSON 将放置在 data/<modid>/neoforge/biome_modifier/<path>.json 处。

有关 RegistrySetBuilderDatapackBuiltinEntriesProvider 工作原理的更多信息,请参阅有关 Datapack Registries 的数据生成 的文章。

// Define the ResourceKey for our BiomeModifier.
public static final ResourceKey<BiomeModifier> EXAMPLE_MODIFIER = ResourceKey.create(
NeoForgeRegistries.Keys.BIOME_MODIFIERS, // The registry this key is for
ResourceLocation.fromNamespaceAndPath(MOD_ID, "example_modifier") // The registry name
);

// BUILDER is a RegistrySetBuilder passed to DatapackBuiltinEntriesProvider
// in a listener for GatherDataEvent.
BUILDER.add(NeoForgeRegistries.Keys.BIOME_MODIFIERS, bootstrap -> {
// Lookup any necessary registries.
// Static registries only need to be looked up if you need to grab the tag data.
HolderGetter<Biome> biomes = bootstrap.lookup(Registries.BIOME);

// Register the biome modifiers.
bootstrap.register(EXAMPLE_MODIFIER,
new ExampleBiomeModifier(
biomes.getOrThrow(Tags.Biomes.IS_OVERWORLD),
20
)
);
});

这将导致创建以下 JSON:

// In data/examplemod/neoforge/biome_modifier/example_modifier.json
{
// The registy key of the MapCodec for the modifier
"type": "examplemod:example_biome_modifier",
// All additional settings are applied to the root object
"biomes": "#c:is_overworld",
"value": 20
}