User Tools

Site Tools


zh_cn:tutorial:ores

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
zh_cn:tutorial:ores [2021/09/23 00:12] – [在世界中添加矿石] solidblockzh_cn:tutorial:ores [2022/08/18 03:25] solidblock
Line 1: Line 1:
-====== 在世界中添加矿石 ======+====== 生成自定义的矿石(1.18.2) ======
 许多模组会添加自己的矿石,您需要找到一种方法以将其放置在现有生物群系中让玩家寻找。在本教程中,我们将研究将矿石添加到现有生物群系以及其他模组添加的生物群系。将矿石添加到生物群系需要2个步骤。 许多模组会添加自己的矿石,您需要找到一种方法以将其放置在现有生物群系中让玩家寻找。在本教程中,我们将研究将矿石添加到现有生物群系以及其他模组添加的生物群系。将矿石添加到生物群系需要2个步骤。
-  * 制作一个 ConfiguredFeature,定义你的矿石方块如何生成。+  * 制作一个 ConfiguredFeature(已配置的地物),定义你的矿石方块如何生成。
   * 使用 [[https://github.com/FabricMC/fabric/pull/1097|Fabric API 中的 Biome Modification API]]以将地物添加到生物群系。   * 使用 [[https://github.com/FabricMC/fabric/pull/1097|Fabric API 中的 Biome Modification API]]以将地物添加到生物群系。
  
Line 7: Line 7:
  
 我们假设您此时已经创建了自己的矿石。本教程中,我们使用羊毛方块进行替换。你可以适时将羊毛改成你自己的矿石。 我们假设您此时已经创建了自己的矿石。本教程中,我们使用羊毛方块进行替换。你可以适时将羊毛改成你自己的矿石。
-==== 在群系中添加矿石 ====+==== 添加到主世界生物群系 ==== 
 +本段落将会在主世界生成矿石。
  
-首先,我们需要创建一种方法来处理生群系检查其是否为有效群系然后添加矿石。 +我们需要创建一个已配置的地物,确保在 ''onInitialize'' 中注册你已配置的地物,你可以自由地改变一些值以适应你的模组 
-<code java [enable_line_numbers="true"]+ 
-private void handleBiome(Biome biome) +<code java> 
- if(biome.getCategory() != Biome.Category.NETHER && biome.getCategory() != Biome.Category.THEEND{ +public class ExampleMod implements ModInitializer 
- biome.addFeature+  private static ConfiguredFeature<?, ?> OVERWORLD_WOOL_ORE_CONFIGURED_FEATURE = new ConfiguredFeature 
-             GenerationStep.Feature.UNDERGROUND_ORES+      (Feature.ORE, new OreFeatureConfig( 
-             Biome.configureFeature+          OreConfiguredFeatures.STONE_ORE_REPLACEABLES, 
-                 Feature.ORE+          Blocks.WHITE_WOOL.getDefaultState()
-         new OreFeatureConfig( +          9)); // 矿脉大小 
-        OreFeatureConfig.Target.NATURAL_STONE+ 
-         Blocks.NETHER_QUARTZ_ORE.getDefaultState(), +  public static PlacedFeature OVERWORLD_WOOL_ORE_PLACED_FEATURE = new PlacedFeature
-                 8 //Ore vein size +      RegistryEntry.of(OVERWORLD_WOOL_ORE_CONFIGURED_FEATURE)
-         ), +      Arrays.asList
-                 Decorator.COUNT_RANGE+          CountPlacementModifier.of(20)// 每个区块的矿脉数量 
-         new RangeDecoratorConfig+          SquarePlacementModifier.of()// 水平传播 
-         8//Number of veins per chunk +          HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.fixed(64)) 
-         0//Bottom Offset +      )); // 高度 
-         0//Min y level + 
-         64 //Max y level +  @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"))); 
 +  }
 } }
 </code> </code>
  
-此方法通过提供的生成设置将您的矿石添加到整个世界。 随意更改值适合您mod+=== 结果 === 
 +检查你世界生成结果时,记得要创建新世界。你应该看见羊毛在主世界生成了。你可使用下面命令移除周围的石头方块 
 +<code> 
 +/fill ~-8 0 ~-8 ~8 ~ ~8 minecraft:air replace minecraft:stone 
 +</code>
  
-==== 迭代生物群系注册表 ====+{{tutorial:ores.png?800}}
  
-来,我们需要处理已注册的所有生物群系以及将来要注册所有生物群(由其他模块添加)。 我们首先遍历当前注册表,然后注册一个侦听器,以供将来添加。+==== 添加到生物群系 ==== 
 +本段落会基于前面落添加矿石到下界生物群系
  
-<code java [enable_line_numbers="true"]> +在下界,需要替换的方块和主世界地不同,所以需要把 ''OreConfiguredFeatures.STONE_ORE_REPLACEABLES'' 替换成 ''OreConfiguredFeatures.NETHERRACK''
-@Override +
-public void onInitialize() { +
- //Loop over existing biomes +
- Registry.BIOME.forEach(this::handleBiome);+
  
- //Listen for other biomes being registered +<code java> 
- RegistryEntryAddedCallback.event(Registry.BIOME).register((iidentifierbiome-> handleBiome(biome));+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"))); 
 +  }
 } }
 </code> </code>
  
-==== 结论 ==== +==== 添加到末地生物群系 ==== 
-您应该在整个世界中看到石英矿石生成:+本段落将基于主世界的代码添加矿石到末地物群系。 
 + 
 +在末地,基础方块是末地石,所以需要把 ''OreConfiguredFeatures.STONE_ORE_REPLACEABLES'' 替换成 ''new BlockMatchRuleTest(Blocks.END_STONE)''。 
 + 
 +<code java> 
 +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"))); 
 +  } 
 +
 +</code>
  
-{{https://i.imgur.com/UemsMaI.png|Quartz Ores}} 
  
  
zh_cn/tutorial/ores.txt · Last modified: 2023/12/18 01:03 by solidblock