User Tools

Site Tools


Sidebar

← 返回首页

安装

基础

物品

方块和方块实体

数据生成

世界生成

命令

事件

实体

流体

Mixin 和 ASM

杂项

Yarn

贡献 Fabric

zh_cn:tutorial:ores

生成自定义的矿石(1.18.2)

许多模组会添加自己的矿石,您需要找到一种方法以将其放置在现有生物群系中让玩家寻找。在本教程中,我们将研究将矿石添加到现有生物群系以及其他模组添加的生物群系。将矿石添加到生物群系需要2个步骤。

注意 Biome Modification API 仍是实验性的。如果 API 不起作用,考虑 mixin 版本

我们假设您此时已经创建了自己的矿石。本教程中,我们使用羊毛方块进行替换。你可以适时将羊毛改成你自己的矿石。

添加到主世界生物群系

本段落将会在主世界生成矿石。

我们需要创建一个已配置的地物,确保在 onInitialize 中注册你的已配置的地物,你可以自由地改变一些值以适应你的模组。

public class ExampleMod implements ModInitializer {
  private static ConfiguredFeature<?, ?> OVERWORLD_WOOL_ORE_CONFIGURED_FEATURE = new ConfiguredFeature
      (Feature.ORE, new OreFeatureConfig(
          OreConfiguredFeatures.STONE_ORE_REPLACEABLES,
          Blocks.WHITE_WOOL.getDefaultState(),
          9)); // 矿脉大小
 
  public static PlacedFeature OVERWORLD_WOOL_ORE_PLACED_FEATURE = new PlacedFeature(
      RegistryEntry.of(OVERWORLD_WOOL_ORE_CONFIGURED_FEATURE),
      Arrays.asList(
          CountPlacementModifier.of(20), // 每个区块的矿脉数量
          SquarePlacementModifier.of(), // 水平传播
          HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.fixed(64))
      )); // 高度
 
  @Override
  public void onInitialize() {
    Registry.register(BuiltinRegistries.CONFIGURED_FEATURE,
        new Identifier("tutorial", "overworld_wool_ore"), OVERWORLD_WOOL_ORE_CONFIGURED_FEATURE);
    Registry.register(BuiltinRegistries.PLACED_FEATURE, new Identifier("tutorial", "overworld_wool_ore"),
        OVERWORLD_WOOL_ORE_PLACED_FEATURE);
    BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(), GenerationStep.Feature.UNDERGROUND_ORES,
        RegistryKey.of(Registry.PLACED_FEATURE_KEY,
            new Identifier("tutorial", "overworld_wool_ore")));
  }
}

结果

检查你的世界生成结果时,记得要创建新世界。你应该看见羊毛在主世界生成了。你可以使用下面的命令移除周围的石头方块。

/fill ~-8 0 ~-8 ~8 ~ ~8 minecraft:air replace minecraft:stone

添加到下界生物群系

本段落将会基于前面的段落添加矿石到下界生物群系。

在下界,需要替换的方块和主世界地不同,所以需要把 OreConfiguredFeatures.STONE_ORE_REPLACEABLES 替换成 OreConfiguredFeatures.NETHERRACK

public class ExampleMod implements ModInitializer {
  private static ConfiguredFeature<?, ?> NETHER_WOOL_ORE_CONFIGURED_FEATURE = new ConfiguredFeature
      (Feature.ORE, new OreFeatureConfig(
          OreConfiguredFeatures.NETHERRACK, // 我们这里使用 OreConfiguredFeatures.NETHERRACK
          Blocks.WHITE_WOOL.getDefaultState(),
          9));
 
  public static PlacedFeature NETHER_WOOL_ORE_PLACED_FEATURE = new PlacedFeature(
      RegistryEntry.of(NETHER_WOOL_ORE_CONFIGURED_FEATURE),
      Arrays.asList(
          CountPlacementModifier.of(20),
          SquarePlacementModifier.of(),
          HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.fixed(64))));
 
  @Override
  public void onInitialize() {
    Registry.register(BuiltinRegistries.CONFIGURED_FEATURE,
        new Identifier("tutorial", "nether_wool_ore"), NETHER_WOOL_ORE_CONFIGURED_FEATURE);
    Registry.register(BuiltinRegistries.PLACED_FEATURE, new Identifier("tutorial", "nether_wool_ore"),
        NETHER_WOOL_ORE_PLACED_FEATURE);
    BiomeModifications.addFeature(BiomeSelectors.foundInTheNether(), GenerationStep.Feature.UNDERGROUND_ORES,
        RegistryKey.of(Registry.PLACED_FEATURE_KEY,
            new Identifier("tutorial", "nether_wool_ore")));
  }
}

添加到末地生物群系

本段落将会基于主世界的代码添加矿石到末地生物群系。

在末地,基础方块是末地石,所以需要把 OreConfiguredFeatures.STONE_ORE_REPLACEABLES 替换成 new BlockMatchRuleTest(Blocks.END_STONE)

public class ExampleMod implements ModInitializer {
  private static ConfiguredFeature<?, ?> END_WOOL_ORE_CONFIGURED_FEATURE = new ConfiguredFeature
      (Feature.ORE, new OreFeatureConfig(
          new BlockMatchRuleTest(Blocks.END_STONE), // 我们这里使用 new BlockMatchRuleTest(Blocks.END_STONE)
          Blocks.WHITE_WOOL.getDefaultState(),
          9));
 
  public static PlacedFeature END_WOOL_ORE_PLACED_FEATURE = new PlacedFeature(
      RegistryEntry.of(END_WOOL_ORE_CONFIGURED_FEATURE),
      Arrays.asList(
          CountPlacementModifier.of(20),
          SquarePlacementModifier.of(),
          HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.fixed(64))));
 
  @Override
  public void onInitialize() {
    Registry.register(BuiltinRegistries.CONFIGURED_FEATURE,
        new Identifier("tutorial", "end_wool_ore"), END_WOOL_ORE_CONFIGURED_FEATURE);
    Registry.register(BuiltinRegistries.PLACED_FEATURE, new Identifier("tutorial", "end_wool_ore"),
        END_WOOL_ORE_PLACED_FEATURE);
    BiomeModifications.addFeature(BiomeSelectors.foundInTheEnd(), GenerationStep.Feature.UNDERGROUND_ORES,
        RegistryKey.of(Registry.PLACED_FEATURE_KEY,
            new Identifier("tutorial", "end_wool_ore")));
  }
}
zh_cn/tutorial/ores.txt · Last modified: 2022/08/18 03:25 by solidblock