Skip to content

Commit

Permalink
Make a new working version of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlasDiablo committed Oct 13, 2020
1 parent 0e76516 commit bf282cd
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 592 deletions.
9 changes: 4 additions & 5 deletions src/main/java/fr/alasdiablo/janoeo/JANOEO.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@ public JANOEO() {
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, FrequencyConfig.CONFIG_SPEC, "janoeo-frequency.toml");
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, FrequencyConfig.CONFIG_SPEC, "janoeo-basalt.toml");
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::bleble);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::initFeatures);
}

private void bleble(RegistryEvent.NewRegistry e) {
private void initFeatures(RegistryEvent.NewRegistry e) {
OresFeatures.init();
}

/**
* setup function
* @param event
* @param e
*/
private void setup(final FMLCommonSetupEvent event) {
//OresFeatures.init();
private void setup(final FMLCommonSetupEvent e) {
setup.init();
}
}
100 changes: 55 additions & 45 deletions src/main/java/fr/alasdiablo/janoeo/world/OreGenUtils.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,68 @@
package fr.alasdiablo.janoeo.world;

import fr.alasdiablo.janoeo.world.gen.feature.CustomFillerBlockType;
import fr.alasdiablo.janoeo.world.gen.feature.CustomOreFeature;
import fr.alasdiablo.janoeo.world.gen.feature.CustomOreFeatureConfig;
import com.google.common.collect.Lists;
import fr.alasdiablo.janoeo.world.gen.*;
import net.minecraft.block.BlockState;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeGenerationSettings;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.ReplaceBlockConfig;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.feature.template.RuleTest;
import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.placement.TopSolidRangeConfig;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

/**
* Some part of this code is inspire by Applied Energistics 2
*/
public class OreGenUtils {

public static void addOreGenOnBiome(Biome biome, CustomFillerBlockType blockType, BlockState oreBlock, int size, int count, int bottom, int top) {
biome.addFeature(
GenerationStage.Decoration.UNDERGROUND_ORES,
CustomOreFeature.INSTANCE.withConfiguration(
new CustomOreFeatureConfig(
blockType,
oreBlock,
size
)
).withPlacement(
Placement.COUNT_RANGE.configure(
new CountRangeConfig(
count,
bottom,
0,
top
)
)
)
);
private static final IWorldGenerator OVERWORLD_GENERATOR = new OverworldOreGenerator();
private static final IWorldGenerator NETHER_GENERATOR = new NetherOreGenerator();
private static final IWorldGenerator END_GENERATOR = new EndOreGenerator();
private static final IWorldGenerator GRAVEL_GENERATOR = new GravelOreGenerator();
private static final IWorldGenerator BASALT_GENERATOR = new BasaltOreGenerator();

public static void setupOres() {

for (Biome biome : ForgeRegistries.BIOMES) {
if (!biome.getCategory().equals(Biome.Category.NETHER) && !biome.getCategory().equals(Biome.Category.THEEND)) {
OVERWORLD_GENERATOR.startWorldGeneration(biome);
GRAVEL_GENERATOR.startWorldGeneration(biome);
}
if (biome.getCategory().equals(Biome.Category.NETHER)) {
GRAVEL_GENERATOR.startWorldGeneration(biome);
NETHER_GENERATOR.startWorldGeneration(biome);
BASALT_GENERATOR.startWorldGeneration(biome);
}
if (biome.getCategory().equals(Biome.Category.THEEND)) {
END_GENERATOR.startWorldGeneration(biome);
}
}
}

public static void addBlockGenOnBiome(Biome biome, BlockState replamentBlock, BlockState oreBlock, int count, int bottom, int top) {
biome.addFeature(
GenerationStage.Decoration.UNDERGROUND_ORES,
Feature.EMERALD_ORE.withConfiguration(
new ReplaceBlockConfig(
replamentBlock,
oreBlock
)
).withPlacement(
Placement.COUNT_RANGE.configure(
new CountRangeConfig(
count,
bottom,
0,
top
)
)
)
);
public static void addFeatureToBiome(Biome biome, ConfiguredFeature<?, ?> configuredFeature) {
System.out.println("Feature added ! " + configuredFeature.feature.getRegistryName().toString());

GenerationStage.Decoration decoration = GenerationStage.Decoration.UNDERGROUND_ORES;

List<List<Supplier<ConfiguredFeature<?, ?>>>> biomeFeatures = new ArrayList<>(biome.func_242440_e().func_242498_c());
while (biomeFeatures.size() <= decoration.ordinal()) {
biomeFeatures.add(Lists.newArrayList());
}
List<Supplier<ConfiguredFeature<?, ?>>> features = new ArrayList<>(biomeFeatures.get(decoration.ordinal()));
features.add(() -> configuredFeature);
biomeFeatures.set(decoration.ordinal(), features);

ObfuscationReflectionHelper.setPrivateValue(BiomeGenerationSettings.class, biome.func_242440_e(), biomeFeatures, "field_242484_f");
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package fr.alasdiablo.janoeo.world.gen;

import fr.alasdiablo.janoeo.block.BasaltOresBlocks;
import fr.alasdiablo.janoeo.config.BasaltConfig;
import fr.alasdiablo.janoeo.config.FrequencyConfig;
import fr.alasdiablo.janoeo.config.GlobalConfig;
import fr.alasdiablo.janoeo.world.OreGenUtils;
import net.minecraft.block.Blocks;
import net.minecraft.util.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.Map;

public class BasaltOreGenerator implements IWorldGenerator {
@Override
public void startWorldGeneration(Map.Entry<RegistryKey<Biome>, Biome> biome) {
public void startWorldGeneration(Biome biome) {
GlobalConfig.Config globalConfig = GlobalConfig.CONFIG;
BasaltConfig.Config basaltConfig = BasaltConfig.CONFIG;
FrequencyConfig.Config frequencyConfig = FrequencyConfig.CONFIG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

import fr.alasdiablo.janoeo.config.EndConfig;
import fr.alasdiablo.janoeo.config.GlobalConfig;
import fr.alasdiablo.janoeo.block.EndOresBlocks;
import fr.alasdiablo.janoeo.world.OreGenUtils;
import net.minecraft.block.Blocks;
import net.minecraft.util.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.Map;

public class EndOreGenerator implements IWorldGenerator {
@Override
public void startWorldGeneration(Map.Entry<RegistryKey<Biome>, Biome> biome) {
public void startWorldGeneration(Biome biome) {
GlobalConfig.Config globalConfig = GlobalConfig.CONFIG;
EndConfig.Config endConfig = EndConfig.CONFIG;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@

import fr.alasdiablo.janoeo.config.GlobalConfig;
import fr.alasdiablo.janoeo.config.GravelConfig;
import fr.alasdiablo.janoeo.block.GravelsOresBlocks;
import fr.alasdiablo.janoeo.world.OreGenUtils;
import net.minecraft.util.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class GravelOreGenerator implements IWorldGenerator {

@Override
public void startWorldGeneration(Map.Entry<RegistryKey<Biome>, Biome> biome) {
public void startWorldGeneration(Biome biome) {
GlobalConfig.Config globalConfig = GlobalConfig.CONFIG;
GravelConfig.Config gravelConfig = GravelConfig.CONFIG;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import java.util.Map;

public interface IWorldGenerator {
void startWorldGeneration(Map.Entry<RegistryKey<Biome>, Biome> biome);
void startWorldGeneration(Biome biome);
}
Loading

0 comments on commit bf282cd

Please sign in to comment.