Skip to content

Commit feebfb3

Browse files
committed
ores in other dimensions can now be generated but i broke base MI deepslate ores along the way somewhere
1 parent c71017e commit feebfb3

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/main/java/aztech/modern_industrialization/compat/kubejs/material/PartJsonCreator.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,20 @@
3232
import aztech.modern_industrialization.materials.set.MaterialOreSet;
3333
import aztech.modern_industrialization.materials.set.MaterialRawSet;
3434
import aztech.modern_industrialization.nuclear.NuclearConstant;
35+
import aztech.modern_industrialization.util.TagHelper;
3536
import com.google.gson.JsonObject;
3637
import net.minecraft.core.registries.BuiltInRegistries;
38+
import net.minecraft.core.registries.Registries;
39+
import net.minecraft.resources.ResourceLocation;
40+
import net.minecraft.tags.BiomeTags;
41+
import net.minecraft.tags.TagKey;
42+
import net.minecraft.tags.TagManager;
3743
import net.minecraft.util.valueproviders.UniformInt;
44+
import net.minecraft.world.level.biome.Biome;
45+
import net.minecraft.world.level.biome.BiomeResolver;
3846
import net.minecraft.world.level.block.Block;
47+
import net.neoforged.neoforge.common.Tags;
48+
import net.neoforged.neoforge.registries.NeoForgeRegistries;
3949

4050
public class PartJsonCreator {
4151

@@ -133,10 +143,14 @@ public PartTemplate orePart(JsonObject json, Block stoneType) {
133143
}
134144

135145
if (generate) {
146+
TagKey<Biome> biomeTag = BiomeTags.IS_OVERWORLD;
147+
if(json.has("biome_tag")) {
148+
biomeTag = TagKey.create(Registries.BIOME, ResourceLocation.parse(json.get("biome_tag").getAsString()));
149+
}
136150
int veinSize = json.get("vein_size").getAsInt();
137151
int veinPerChunk = json.get("veins_per_chunk").getAsInt();
138152
int maxY = json.get("max_y").getAsInt();
139-
return act.of(UniformInt.of(minXp, maxXp), veinSize, veinPerChunk, maxY, oreSet);
153+
return act.of(UniformInt.of(minXp, maxXp), veinSize, veinPerChunk, maxY, oreSet, biomeTag);
140154
} else {
141155
return act.of(UniformInt.of(minXp, maxXp), oreSet);
142156
}

src/main/java/aztech/modern_industrialization/materials/part/OrePart.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@
4545
import net.minecraft.resources.ResourceLocation;
4646
import net.minecraft.tags.BiomeTags;
4747
import net.minecraft.tags.BlockTags;
48+
import net.minecraft.tags.TagKey;
4849
import net.minecraft.util.valueproviders.UniformInt;
50+
import net.minecraft.world.level.biome.Biome;
4951
import net.minecraft.world.level.block.Block;
52+
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
5053
import net.minecraft.world.level.levelgen.GenerationStep;
5154
import net.minecraft.world.level.levelgen.VerticalAnchor;
5255
import net.minecraft.world.level.levelgen.feature.Feature;
5356
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration;
5457
import 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;
5560
import net.minecraft.world.level.levelgen.structure.templatesystem.TagMatchTest;
5661
import net.neoforged.neoforge.common.Tags;
5762
import 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

Comments
 (0)