4545import net .minecraft .resources .ResourceLocation ;
4646import net .minecraft .tags .BiomeTags ;
4747import net .minecraft .tags .BlockTags ;
48+ import net .minecraft .tags .TagKey ;
4849import net .minecraft .util .valueproviders .UniformInt ;
50+ import net .minecraft .world .level .biome .Biome ;
4951import net .minecraft .world .level .block .Block ;
52+ import net .minecraft .world .level .dimension .BuiltinDimensionTypes ;
5053import net .minecraft .world .level .levelgen .GenerationStep ;
5154import net .minecraft .world .level .levelgen .VerticalAnchor ;
5255import net .minecraft .world .level .levelgen .feature .Feature ;
5356import net .minecraft .world .level .levelgen .feature .configurations .OreConfiguration ;
5457import net .minecraft .world .level .levelgen .placement .HeightRangePlacement ;
58+ import net .minecraft .world .level .levelgen .structure .templatesystem .BlockMatchTest ;
59+ import net .minecraft .world .level .levelgen .structure .templatesystem .RuleTest ;
5560import net .minecraft .world .level .levelgen .structure .templatesystem .TagMatchTest ;
5661import net .neoforged .neoforge .common .Tags ;
5762import net .neoforged .neoforge .common .world .BiomeModifiers ;
@@ -68,6 +73,10 @@ public PartKey key() {
6873 return key ;
6974 }
7075
76+ public PartTemplate of (UniformInt xpProvider , int veinsPerChunk , int veinSize , int maxYLevel , MaterialOreSet set , TagKey <Biome > biomeTag ) {
77+ return of (new OrePartParams (xpProvider , set , veinsPerChunk , veinSize , maxYLevel , biomeTag ));
78+ }
79+
7180 public PartTemplate of (int veinsPerChunk , int veinSize , int maxYLevel , MaterialOreSet set ) {
7281 return of (new OrePartParams (UniformInt .of (0 , 2 ), set , veinsPerChunk , veinSize , maxYLevel ));
7382 }
@@ -123,9 +132,9 @@ public PartTemplate of(OrePartParams oreParams) {
123132 // like netherrack, it should still take at least as long to mine as a stone block.
124133 .destroyTime (Math .max (stoneType .defaultDestroyTime (), 2.25f )));
125134
126- // Sanity check: Ensure that ores don't drop xp, iff the main part is an ingot
135+ // Sanity check: Ensure that ores don't drop xp, if the main part is an ingot
127136 // (i.e. the drop is raw ore).
128- if (mainPartKey .equals (MIParts .INGOT .key ()) != (oreParams .xpDropped .getMaxValue () = = 0 )) {
137+ if (mainPartKey .equals (MIParts .INGOT .key ()) && (oreParams .xpDropped .getMaxValue () ! = 0 )) {
129138 throw new IllegalArgumentException ("Mismatch between raw ore and xp drops for material: " + partContext .getMaterialName ());
130139 }
131140
@@ -152,13 +161,13 @@ public PartTemplate of(OrePartParams oreParams) {
152161 var modifierKey = ResourceKey .create (NeoForgeRegistries .Keys .BIOME_MODIFIERS , oreGenId );
153162
154163 DynamicRegistryDatagen .addAction (() -> {
155- TagMatchTest ruleTest ;
164+ RuleTest ruleTest ;
156165 if (stoneId .equals ("stone" )) {
157166 ruleTest = new TagMatchTest (BlockTags .STONE_ORE_REPLACEABLES );
158167 } else if (stoneId .equals ("deepslate" )) {
159168 ruleTest = new TagMatchTest (BlockTags .DEEPSLATE_ORE_REPLACEABLES );
160169 } else {
161- return ;
170+ ruleTest = new BlockMatchTest ( stoneType ) ;
162171 }
163172 var target = List .of (
164173 OreConfiguration .target (ruleTest , oreBlockBlockDefinition .asBlock ().defaultBlockState ()));
@@ -176,8 +185,9 @@ public PartTemplate of(OrePartParams oreParams) {
176185 });
177186
178187 DynamicRegistryDatagen .add (NeoForgeRegistries .Keys .BIOME_MODIFIERS , context -> {
188+
179189 var modifier = new BiomeModifiers .AddFeaturesBiomeModifier (
180- context .lookup (Registries .BIOME ).getOrThrow (BiomeTags . IS_OVERWORLD ),
190+ context .lookup (Registries .BIOME ).getOrThrow (oreParams . biomeTag ),
181191 HolderSet .direct (context .lookup (Registries .PLACED_FEATURE ).getOrThrow (placedFeatureKey )),
182192 GenerationStep .Decoration .UNDERGROUND_ORES );
183193 context .register (modifierKey , modifier );
@@ -208,27 +218,33 @@ public static class OrePartParams {
208218 public final MaterialOreSet set ;
209219 public final boolean generate ;
210220
221+ public final TagKey <Biome > biomeTag ;
211222 public final int veinsPerChunk ;
212223 public final int veinSize ;
213224 public final int maxYLevel ;
214225
215- private OrePartParams (UniformInt xpDropped , MaterialOreSet set , boolean generate , int veinsPerChunk , int veinSize , int maxYLevel ) {
226+ private OrePartParams (UniformInt xpDropped , MaterialOreSet set , boolean generate , int veinsPerChunk , int veinSize , int maxYLevel , TagKey < Biome > biomeTag ) {
216227 this .xpDropped = xpDropped ;
217228 this .set = set ;
218229 this .generate = generate ;
219230
231+ this .biomeTag = biomeTag ;
220232 this .veinsPerChunk = veinsPerChunk ;
221233 this .veinSize = veinSize ;
222234 this .maxYLevel = maxYLevel ;
223235 }
224236
225237 public OrePartParams (UniformInt xpDropped , MaterialOreSet set ) {
226- this (xpDropped , set , false , 0 , 0 , 0 );
238+ this (xpDropped , set , false , 0 , 0 , 0 , BiomeTags . IS_OVERWORLD );
227239 }
228240
229241 public OrePartParams (UniformInt xpDropped , MaterialOreSet set , int veinsPerChunk , int veinSize , int maxYLevel ) {
230- this (xpDropped , set , true , veinsPerChunk , veinSize , maxYLevel );
242+ this (xpDropped , set , true , veinsPerChunk , veinSize , maxYLevel , BiomeTags . IS_OVERWORLD );
231243 }
244+ public OrePartParams (UniformInt xpDropped , MaterialOreSet set , int veinsPerChunk , int veinSize , int maxYLevel , TagKey <Biome > biomeTag ) {
245+ this (xpDropped , set , true , veinsPerChunk , veinSize , maxYLevel , biomeTag );
246+ }
247+
232248 }
233249
234250}
0 commit comments