Skip to content

Commit bf282cd

Browse files
committed
Make a new working version of the code
1 parent 0e76516 commit bf282cd

File tree

8 files changed

+406
-592
lines changed

8 files changed

+406
-592
lines changed

src/main/java/fr/alasdiablo/janoeo/JANOEO.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,18 @@ public JANOEO() {
3434
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, FrequencyConfig.CONFIG_SPEC, "janoeo-frequency.toml");
3535
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, FrequencyConfig.CONFIG_SPEC, "janoeo-basalt.toml");
3636
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
37-
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::bleble);
37+
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::initFeatures);
3838
}
3939

40-
private void bleble(RegistryEvent.NewRegistry e) {
40+
private void initFeatures(RegistryEvent.NewRegistry e) {
4141
OresFeatures.init();
4242
}
4343

4444
/**
4545
* setup function
46-
* @param event
46+
* @param e
4747
*/
48-
private void setup(final FMLCommonSetupEvent event) {
49-
//OresFeatures.init();
48+
private void setup(final FMLCommonSetupEvent e) {
5049
setup.init();
5150
}
5251
}
Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,68 @@
11
package fr.alasdiablo.janoeo.world;
22

3-
import fr.alasdiablo.janoeo.world.gen.feature.CustomFillerBlockType;
4-
import fr.alasdiablo.janoeo.world.gen.feature.CustomOreFeature;
5-
import fr.alasdiablo.janoeo.world.gen.feature.CustomOreFeatureConfig;
3+
import com.google.common.collect.Lists;
4+
import fr.alasdiablo.janoeo.world.gen.*;
65
import net.minecraft.block.BlockState;
6+
import net.minecraft.util.RegistryKey;
7+
import net.minecraft.util.registry.Registry;
8+
import net.minecraft.util.registry.WorldGenRegistries;
79
import net.minecraft.world.biome.Biome;
10+
import net.minecraft.world.biome.BiomeGenerationSettings;
811
import net.minecraft.world.gen.GenerationStage;
9-
import net.minecraft.world.gen.feature.Feature;
10-
import net.minecraft.world.gen.feature.ReplaceBlockConfig;
11-
import net.minecraft.world.gen.placement.CountRangeConfig;
12+
import net.minecraft.world.gen.feature.*;
13+
import net.minecraft.world.gen.feature.template.RuleTest;
1214
import net.minecraft.world.gen.placement.Placement;
15+
import net.minecraft.world.gen.placement.TopSolidRangeConfig;
16+
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
17+
import net.minecraftforge.registries.ForgeRegistries;
1318

19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Map;
22+
import java.util.function.Supplier;
23+
24+
/**
25+
* Some part of this code is inspire by Applied Energistics 2
26+
*/
1427
public class OreGenUtils {
1528

16-
public static void addOreGenOnBiome(Biome biome, CustomFillerBlockType blockType, BlockState oreBlock, int size, int count, int bottom, int top) {
17-
biome.addFeature(
18-
GenerationStage.Decoration.UNDERGROUND_ORES,
19-
CustomOreFeature.INSTANCE.withConfiguration(
20-
new CustomOreFeatureConfig(
21-
blockType,
22-
oreBlock,
23-
size
24-
)
25-
).withPlacement(
26-
Placement.COUNT_RANGE.configure(
27-
new CountRangeConfig(
28-
count,
29-
bottom,
30-
0,
31-
top
32-
)
33-
)
34-
)
35-
);
29+
private static final IWorldGenerator OVERWORLD_GENERATOR = new OverworldOreGenerator();
30+
private static final IWorldGenerator NETHER_GENERATOR = new NetherOreGenerator();
31+
private static final IWorldGenerator END_GENERATOR = new EndOreGenerator();
32+
private static final IWorldGenerator GRAVEL_GENERATOR = new GravelOreGenerator();
33+
private static final IWorldGenerator BASALT_GENERATOR = new BasaltOreGenerator();
34+
35+
public static void setupOres() {
36+
37+
for (Biome biome : ForgeRegistries.BIOMES) {
38+
if (!biome.getCategory().equals(Biome.Category.NETHER) && !biome.getCategory().equals(Biome.Category.THEEND)) {
39+
OVERWORLD_GENERATOR.startWorldGeneration(biome);
40+
GRAVEL_GENERATOR.startWorldGeneration(biome);
41+
}
42+
if (biome.getCategory().equals(Biome.Category.NETHER)) {
43+
GRAVEL_GENERATOR.startWorldGeneration(biome);
44+
NETHER_GENERATOR.startWorldGeneration(biome);
45+
BASALT_GENERATOR.startWorldGeneration(biome);
46+
}
47+
if (biome.getCategory().equals(Biome.Category.THEEND)) {
48+
END_GENERATOR.startWorldGeneration(biome);
49+
}
50+
}
3651
}
3752

38-
public static void addBlockGenOnBiome(Biome biome, BlockState replamentBlock, BlockState oreBlock, int count, int bottom, int top) {
39-
biome.addFeature(
40-
GenerationStage.Decoration.UNDERGROUND_ORES,
41-
Feature.EMERALD_ORE.withConfiguration(
42-
new ReplaceBlockConfig(
43-
replamentBlock,
44-
oreBlock
45-
)
46-
).withPlacement(
47-
Placement.COUNT_RANGE.configure(
48-
new CountRangeConfig(
49-
count,
50-
bottom,
51-
0,
52-
top
53-
)
54-
)
55-
)
56-
);
53+
public static void addFeatureToBiome(Biome biome, ConfiguredFeature<?, ?> configuredFeature) {
54+
System.out.println("Feature added ! " + configuredFeature.feature.getRegistryName().toString());
55+
56+
GenerationStage.Decoration decoration = GenerationStage.Decoration.UNDERGROUND_ORES;
57+
58+
List<List<Supplier<ConfiguredFeature<?, ?>>>> biomeFeatures = new ArrayList<>(biome.func_242440_e().func_242498_c());
59+
while (biomeFeatures.size() <= decoration.ordinal()) {
60+
biomeFeatures.add(Lists.newArrayList());
61+
}
62+
List<Supplier<ConfiguredFeature<?, ?>>> features = new ArrayList<>(biomeFeatures.get(decoration.ordinal()));
63+
features.add(() -> configuredFeature);
64+
biomeFeatures.set(decoration.ordinal(), features);
65+
66+
ObfuscationReflectionHelper.setPrivateValue(BiomeGenerationSettings.class, biome.func_242440_e(), biomeFeatures, "field_242484_f");
5767
}
5868
}

src/main/java/fr/alasdiablo/janoeo/world/gen/BasaltOreGenerator.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package fr.alasdiablo.janoeo.world.gen;
22

3-
import fr.alasdiablo.janoeo.block.BasaltOresBlocks;
43
import fr.alasdiablo.janoeo.config.BasaltConfig;
54
import fr.alasdiablo.janoeo.config.FrequencyConfig;
65
import fr.alasdiablo.janoeo.config.GlobalConfig;
7-
import fr.alasdiablo.janoeo.world.OreGenUtils;
8-
import net.minecraft.block.Blocks;
9-
import net.minecraft.util.RegistryKey;
106
import net.minecraft.world.biome.Biome;
11-
import net.minecraftforge.registries.ForgeRegistries;
12-
13-
import java.util.Map;
147

158
public class BasaltOreGenerator implements IWorldGenerator {
169
@Override
17-
public void startWorldGeneration(Map.Entry<RegistryKey<Biome>, Biome> biome) {
10+
public void startWorldGeneration(Biome biome) {
1811
GlobalConfig.Config globalConfig = GlobalConfig.CONFIG;
1912
BasaltConfig.Config basaltConfig = BasaltConfig.CONFIG;
2013
FrequencyConfig.Config frequencyConfig = FrequencyConfig.CONFIG;

src/main/java/fr/alasdiablo/janoeo/world/gen/EndOreGenerator.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@
22

33
import fr.alasdiablo.janoeo.config.EndConfig;
44
import fr.alasdiablo.janoeo.config.GlobalConfig;
5-
import fr.alasdiablo.janoeo.block.EndOresBlocks;
6-
import fr.alasdiablo.janoeo.world.OreGenUtils;
7-
import net.minecraft.block.Blocks;
8-
import net.minecraft.util.RegistryKey;
95
import net.minecraft.world.biome.Biome;
10-
import net.minecraftforge.registries.ForgeRegistries;
11-
12-
import java.util.Map;
136

147
public class EndOreGenerator implements IWorldGenerator {
158
@Override
16-
public void startWorldGeneration(Map.Entry<RegistryKey<Biome>, Biome> biome) {
9+
public void startWorldGeneration(Biome biome) {
1710
GlobalConfig.Config globalConfig = GlobalConfig.CONFIG;
1811
EndConfig.Config endConfig = EndConfig.CONFIG;
1912

src/main/java/fr/alasdiablo/janoeo/world/gen/GravelOreGenerator.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,12 @@
22

33
import fr.alasdiablo.janoeo.config.GlobalConfig;
44
import fr.alasdiablo.janoeo.config.GravelConfig;
5-
import fr.alasdiablo.janoeo.block.GravelsOresBlocks;
6-
import fr.alasdiablo.janoeo.world.OreGenUtils;
7-
import net.minecraft.util.RegistryKey;
85
import net.minecraft.world.biome.Biome;
9-
import net.minecraft.world.biome.Biomes;
10-
import net.minecraftforge.registries.ForgeRegistries;
11-
12-
import java.util.Arrays;
13-
import java.util.List;
14-
import java.util.Map;
156

167
public class GravelOreGenerator implements IWorldGenerator {
178

189
@Override
19-
public void startWorldGeneration(Map.Entry<RegistryKey<Biome>, Biome> biome) {
10+
public void startWorldGeneration(Biome biome) {
2011
GlobalConfig.Config globalConfig = GlobalConfig.CONFIG;
2112
GravelConfig.Config gravelConfig = GravelConfig.CONFIG;
2213

src/main/java/fr/alasdiablo/janoeo/world/gen/IWorldGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
import java.util.Map;
77

88
public interface IWorldGenerator {
9-
void startWorldGeneration(Map.Entry<RegistryKey<Biome>, Biome> biome);
9+
void startWorldGeneration(Biome biome);
1010
}

0 commit comments

Comments
 (0)