|
1 | 1 | package fr.alasdiablo.janoeo.world; |
2 | 2 |
|
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.*; |
6 | 5 | 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; |
7 | 9 | import net.minecraft.world.biome.Biome; |
| 10 | +import net.minecraft.world.biome.BiomeGenerationSettings; |
8 | 11 | 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; |
12 | 14 | 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; |
13 | 18 |
|
| 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 | + */ |
14 | 27 | public class OreGenUtils { |
15 | 28 |
|
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 | + } |
36 | 51 | } |
37 | 52 |
|
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"); |
57 | 67 | } |
58 | 68 | } |
0 commit comments