Skip to content

Instantly share code, notes, and snippets.

@TelepathicGrunt
Last active December 4, 2021 00:20
Show Gist options
  • Save TelepathicGrunt/6955dba1aca2636b8816595fa4868b86 to your computer and use it in GitHub Desktop.
Save TelepathicGrunt/6955dba1aca2636b8816595fa4868b86 to your computer and use it in GitHub Desktop.
// FORGE
@Mod(Test.MODID)
public class Test {
public static final String MODID = "test";
// A Feature + Config to say how the feature should generate.
public static ConfiguredFeature<?, ?> CUSTOM_ORE_CF;
// A ConfiguredFeature + 0 or more Placement Modifiers that tells the
// ConfiguredFeature where and how often it should generate in chunks.
public static PlacedFeature CUSTOM_ORE_PF;
public Test() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
MinecraftForge.EVENT_BUS.addListener(this::biomeModification);
}
public void setup(final FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
CUSTOM_ORE_CF = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(Test.MODID, "test_ore_cf"),
Feature.ORE.configured(new OreConfiguration(
new TagMatchTest(BlockTags.BASE_STONE_OVERWORLD), // The blocks this ore can replace.
Blocks.DIAMOND_BLOCK.defaultBlockState(), // The ore block to place.
10, // The size of the vein. Do not do less than 3 or else it places nothing.
0.2f // % of exposed ore block will not generate if touching air.
)));
CUSTOM_ORE_PF = Registry.register(BuiltinRegistries.PLACED_FEATURE, new ResourceLocation(Test.MODID, "test_ore_pf"),
CUSTOM_ORE_CF.placed(
CountPlacement.of(25), // How many attempts per chunk to spawn this feature.
InSquarePlacement.spread(), // Randomizes the x/z so it is in a random 0-15 spot in the chunk.
HeightRangePlacement.uniform( // Equal chance for any height in the following range:
VerticalAnchor.aboveBottom(20), // Bottom of spawn range starts 20 blocks above world bottom.
VerticalAnchor.belowTop(50)), // Top of the spawn range starts 50 blocks below world max height.
BiomeFilter.biome()) // Needed to allow the feature to spawn in biomes properly.
);
}
}
public void biomeModification(final BiomeLoadingEvent event) {
Biome.BiomeCategory category = event.getCategory();
if(category != Biome.BiomeCategory.NETHER && category != Biome.BiomeCategory.THEEND && category != Biome.BiomeCategory.NONE) {
event.getGeneration().addFeature(GenerationStep.Decoration.UNDERGROUND_ORES, CUSTOM_ORE_PF);
}
}
}
// FABRIC (Mojmap)
public class Test implements ModInitializer {
public static final String MODID = "test";
// A Feature + Config to say how the feature should generate.
public static ConfiguredFeature<?, ?> CUSTOM_ORE_CF;
// A ConfiguredFeature + 0 or more Placement Modifiers that tells the
// ConfiguredFeature where and how often it should generate in chunks.
public static PlacedFeature CUSTOM_ORE_PF;
@Override
public void onInitialize() {
CUSTOM_ORE_CF = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(Test.MODID, "test_ore_cf"),
Feature.ORE.configured(new OreConfiguration(
new TagMatchTest(BlockTags.BASE_STONE_OVERWORLD), // The blocks this ore can replace.
Blocks.DIAMOND_BLOCK.defaultBlockState(), // The ore block to place.
10, // The size of the vein. Do not do less than 3 or else it places nothing.
0.2f // % of exposed ore block will not generate if touching air.
)));
CUSTOM_ORE_PF = Registry.register(BuiltinRegistries.PLACED_FEATURE, new ResourceLocation(Test.MODID, "test_ore_pf"),
CUSTOM_ORE_CF.placed(
CountPlacement.of(25), // How many attempts per chunk to spawn this feature.
InSquarePlacement.spread(), // Randomizes the x/z so it is in a random 0-15 spot in the chunk.
HeightRangePlacement.uniform( // Equal chance for any height in the following range:
VerticalAnchor.aboveBottom(20), // Bottom of spawn range starts 20 blocks above world bottom.
VerticalAnchor.belowTop(50)), // Top of the spawn range starts 50 blocks below world max height.
BiomeFilter.biome()) // Needed to allow the feature to spawn in biomes properly.
);
BiomeModifications.create(new ResourceLocation(Test.MODID, "add_custom_ore_1")).add(
// We are adding so we specify the additions stage
ModificationPhase.ADDITIONS,
// What check to use to determine if a biome should receive our feature.
// Use this instead of `BiomeSelectors.foundInOverworld()` because that helper method is currently
// broken and will not work for json/modded biomes injected into the Overworld.
(context) -> {
Biome.BiomeCategory category = context.getBiome().getBiomeCategory();
return category != Biome.BiomeCategory.NETHER && category != Biome.BiomeCategory.THEEND && category != Biome.BiomeCategory.NONE;
},
// What to do witht he biome that passed the above check. here we add out feature to the biome.
context -> context.getGenerationSettings().addBuiltInFeature(GenerationStep.Decoration.UNDERGROUND_ORES, CUSTOM_ORE_PF));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment