User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:ores

Generating Custom Ores [1.18.2 / 1.19.2]

A lot of mods add their own ores, and you'll need a way to place them in existing biomes for players to find. In this tutorial, we'll look at adding ores to existing biomes. There are 2 steps that are required to add ores to biomes.

Note that the Biome Modification API is marked as experimental. If the API doesn't work, consider using the mixin version.

We'll assume you've already created your own ore block at this point. Wool block will serve as our replacement throughout this tutorial. Replace references to wool with your ore when appropriate.

Adding to the overworld biomes

In this section, our goal will be spawning the ore in the overworld.

We need to create a ConfiguredFeature. Make sure to register your ConfiguredFeature at onInitialize. Feel free to change the values to suit your mod.

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)); // vein size
 
  public static PlacedFeature OVERWORLD_WOOL_ORE_PLACED_FEATURE = new PlacedFeature(
      RegistryEntry.of(OVERWORLD_WOOL_ORE_CONFIGURED_FEATURE),
      Arrays.asList(
          CountPlacementModifier.of(20), // number of veins per chunk
          SquarePlacementModifier.of(), // spreading horizontally
          HeightRangePlacementModifier.uniform(YOffset.getBottom(), YOffset.fixed(64))
      )); // height
 
  @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")));
  }
}

Result

Always create a new world when you check the world generation result. You should see wool spawning in the overworld. You can use the command below to remove stone blocks surrounding you.

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

Adding to the nether biomes

In this section, based on the code in the previous section, we will add the ore to the nether biomes.

We need to replace OreConfiguredFeatures.STONE_ORE_REPLACEABLES with OreConfiguredFeatures.NETHERRACK because the ore has to replace different blocks in the nether than in the overworld.

public class ExampleMod implements ModInitializer {
  private static ConfiguredFeature<?, ?> NETHER_WOOL_ORE_CONFIGURED_FEATURE = new ConfiguredFeature
      (Feature.ORE, new OreFeatureConfig(
          OreConfiguredFeatures.NETHERRACK, // we use OreConfiguredFeatures.NETHERRACK here
          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")));
  }
}

Adding to the end biomes

In this section, based on the code in the overworld section, we will add the ore to the end biomes.

We replace OreConfiguredFeatures.STONE_ORE_REPLACEABLES with 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), // we use new BlockMatchRuleTest(Blocks.END_STONE) here
          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")));
  }
}
tutorial/ores.txt · Last modified: 2022/10/02 20:14 by nexus-dino