跳到主要内容

38矿石生成

代码

ModConfiguredFeatures配置:

public class ModConfiguredFeatures {
public static final RegistryKey<ConfiguredFeature<?, ?>> RUBY_ORE_KEY = registerKey("ruby_ore");
public static final RegistryKey<ConfiguredFeature<?, ?>> NETHER_RUBY_ORE_KEY = registerKey("nether_ruby_ore");
public static final RegistryKey<ConfiguredFeature<?, ?>> END_RUBY_ORE_KEY = registerKey("end_ruby_ore");

public static void boostrap(Registerable<ConfiguredFeature<?, ?>> context) {
RuleTest stoneReplacables = new TagMatchRuleTest(BlockTags.STONE_ORE_REPLACEABLES);
RuleTest deepslateReplacables = new TagMatchRuleTest(BlockTags.DEEPSLATE_ORE_REPLACEABLES);
RuleTest netherReplacables = new TagMatchRuleTest(BlockTags.BASE_STONE_NETHER);
RuleTest endReplacables = new BlockMatchRuleTest(Blocks.END_STONE);

List<OreFeatureConfig.Target> overworldRubyOres =
List.of(OreFeatureConfig.createTarget(stoneReplacables, ModBlocks.RUBY_ORE.getDefaultState()),
OreFeatureConfig.createTarget(deepslateReplacables, ModBlocks.DEEPSLATE_RUBY_ORE.getDefaultState()));

List<OreFeatureConfig.Target> netherRubyOres =
List.of(OreFeatureConfig.createTarget(netherReplacables, ModBlocks.NETHER_RUBY_ORE.getDefaultState()));

List<OreFeatureConfig.Target> endRubyOres =
List.of(OreFeatureConfig.createTarget(endReplacables, ModBlocks.END_STONE_RUBY_ORE.getDefaultState()));

register(context, RUBY_ORE_KEY, Feature.ORE, new OreFeatureConfig(overworldRubyOres, 12));
register(context, NETHER_RUBY_ORE_KEY, Feature.ORE, new OreFeatureConfig(netherRubyOres, 12));
register(context, END_RUBY_ORE_KEY, Feature.ORE, new OreFeatureConfig(endRubyOres, 12));
}

public static RegistryKey<ConfiguredFeature<?, ?>> registerKey(String name) {
return RegistryKey.of(RegistryKeys.CONFIGURED_FEATURE, new Identifier(TutorialMod.MOD_ID, name));
}

private static <FC extends FeatureConfig, F extends Feature<FC>> void register(Registerable<ConfiguredFeature<?, ?>> context,
RegistryKey<ConfiguredFeature<?, ?>> key, F feature, FC configuration) {
context.register(key, new ConfiguredFeature<>(feature, configuration));
}
}

ModOrePlacement配置:

public class ModOrePlacement {
public static List<PlacementModifier> modifiers(PlacementModifier countModifier, PlacementModifier heightModifier) {
return List.of(countModifier, SquarePlacementModifier.of(), heightModifier, BiomePlacementModifier.of());
}

public static List<PlacementModifier> modifiersWithCount(int count, PlacementModifier heightModifier) {
return modifiers(CountPlacementModifier.of(count), heightModifier);
}

public static List<PlacementModifier> modifiersWithRarity(int chance, PlacementModifier heightModifier) {
return modifiers(RarityFilterPlacementModifier.of(chance), heightModifier);
}
}

ModPlacedFeatures配置:

public class ModPlacedFeatures {
public static final RegistryKey<PlacedFeature> RUBY_ORE_PLACED_KEY = registerKey("ruby_ore_placed");
public static final RegistryKey<PlacedFeature> NETHER_RUBY_ORE_PLACED_KEY = registerKey("nether_ruby_ore_placed");
public static final RegistryKey<PlacedFeature> END_RUBY_ORE_PLACED_KEY = registerKey("end_ruby_ore_placed");

public static void boostrap(Registerable<PlacedFeature> context) {
var configuredFeatureRegistryEntryLookup = context.getRegistryLookup(RegistryKeys.CONFIGURED_FEATURE);

register(context, RUBY_ORE_PLACED_KEY, configuredFeatureRegistryEntryLookup.getOrThrow(ModConfiguredFeatures.RUBY_ORE_KEY),
ModOrePlacement.modifiersWithCount(12, // Veins per Chunk
HeightRangePlacementModifier.uniform(YOffset.fixed(-80), YOffset.fixed(80))));
register(context, NETHER_RUBY_ORE_PLACED_KEY, configuredFeatureRegistryEntryLookup.getOrThrow(ModConfiguredFeatures.NETHER_RUBY_ORE_KEY),
ModOrePlacement.modifiersWithCount(12, // Veins per Chunk
HeightRangePlacementModifier.uniform(YOffset.fixed(-80), YOffset.fixed(80))));
register(context, END_RUBY_ORE_PLACED_KEY, configuredFeatureRegistryEntryLookup.getOrThrow(ModConfiguredFeatures.END_RUBY_ORE_KEY),
ModOrePlacement.modifiersWithCount(12, // Veins per Chunk
HeightRangePlacementModifier.uniform(YOffset.fixed(-80), YOffset.fixed(80))));
}

public static RegistryKey<PlacedFeature> registerKey(String name) {
return RegistryKey.of(RegistryKeys.PLACED_FEATURE, new Identifier(TutorialMod.MOD_ID, name));
}

private static void register(Registerable<PlacedFeature> context, RegistryKey<PlacedFeature> key, RegistryEntry<ConfiguredFeature<?, ?>> configuration,
List<PlacementModifier> modifiers) {
context.register(key, new PlacedFeature(configuration, List.copyOf(modifiers)));
}
}

ModOreGeneration:

public class ModOreGeneration {
public static void generateOres() {
BiomeModifications.addFeature(BiomeSelectors.foundInOverworld(),
GenerationStep.Feature.UNDERGROUND_ORES, ModPlacedFeatures.RUBY_ORE_PLACED_KEY);

BiomeModifications.addFeature(BiomeSelectors.foundInTheNether(),
GenerationStep.Feature.UNDERGROUND_ORES, ModPlacedFeatures.NETHER_RUBY_ORE_PLACED_KEY);

BiomeModifications.addFeature(BiomeSelectors.foundInTheEnd(),
GenerationStep.Feature.UNDERGROUND_ORES, ModPlacedFeatures.END_RUBY_ORE_PLACED_KEY);
}
}

ModWorldGeneration:

public class ModWorldGeneration {
public static void generateModWorldGen() {
ModOreGeneration.generateOres();
}
}

在启动类中加载上面的信息:

TutorialMod

ModWorldGeneration.generateModWorldGen();

TutorialModDataGenerator:

public class TutorialModDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
pack.addProvider(ModWorldGenerator::new);
}

@Override
public void buildRegistry(RegistryBuilder registryBuilder) {
registryBuilder.addRegistry(RegistryKeys.CONFIGURED_FEATURE, ModConfiguredFeatures::boostrap);
registryBuilder.addRegistry(RegistryKeys.PLACED_FEATURE, ModPlacedFeatures::boostrap);
}
}

效果

image-20240825203736618

地狱:

image-20240825203937202

末地:

image-20240825204107394