/
MechworksWorld.java
69 lines (57 loc) · 2.91 KB
/
MechworksWorld.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package slimeknights.tmechworks.common.worldgen;
import com.google.common.collect.ImmutableList;
import net.minecraft.block.BlockState;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.registries.ForgeRegistries;
import slimeknights.tmechworks.common.MechworksContent;
import slimeknights.tmechworks.common.config.MechworksConfig;
import java.util.List;
import java.util.stream.Collectors;
public class MechworksWorld {
private static final List<OreProperties> OVERWORLD_ORES = ImmutableList.of(
new OreProperties(MechworksContent.Blocks.copper_ore.getDefaultState(), new CountRangeConfig(8, 40, 0, 75), 8, MechworksConfig.WORLD_GENERATION.COPPER),
new OreProperties(MechworksContent.Blocks.aluminum_ore.getDefaultState(), new CountRangeConfig(8, 40, 0, 75), 8, MechworksConfig.WORLD_GENERATION.ALUMINUM)
);
public static void registerWorldGeneration() {
if (!MechworksConfig.WORLD_GENERATION.enabled.get()) {
return;
}
/*
* TODO: https://github.com/MinecraftForge/MinecraftForge/pull/6250
*/
for (Biome biome : ForgeRegistries.BIOMES.getValues().stream().filter(x -> x.getCategory() != Biome.Category.THEEND && x.getCategory() != Biome.Category.NETHER).collect(Collectors.toList())) {
addOresTo(biome);
}
}
private static void addOresTo(Biome biome) {
OVERWORLD_ORES.forEach(ore -> ore.add(biome));
}
private static class OreProperties {
private final BlockState state;
private final CountRangeConfig countRange;
private final int frequency;
private final MechworksConfig.WorldGeneration.Ore config;
OreProperties(BlockState state, CountRangeConfig countRange, int frequency, MechworksConfig.WorldGeneration.Ore config) {
this.state = state;
this.countRange = countRange;
this.frequency = frequency;
this.config = config;
}
private void add(Biome biome){
if(!config.enabled.get())
return;
boolean isWhitelist = config.isWhitelist.get();
List<? extends String> filter = config.filter.get();
boolean matches = filter.stream().anyMatch(val -> biome.getRegistryName().toString().equals(val));
if((isWhitelist && !matches) || (!isWhitelist && matches)) {
return;
}
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, state, frequency)).func_227228_a_(Placement.COUNT_RANGE.func_227446_a_(countRange)));
}
}
}