Skip to content

Commit

Permalink
Merge branch 'feature/ore-gen-config'
Browse files Browse the repository at this point in the history
Closes #72
  • Loading branch information
klikli-dev committed Dec 30, 2020
2 parents 235e89a + 6234ff0 commit d974728
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.common.world.multichunk.MultiChunkFeatureConfig;
import com.github.klikli_dev.occultism.common.world.tree.OtherworldNaturalTree;
import com.github.klikli_dev.occultism.config.OccultismConfig;
import com.github.klikli_dev.occultism.registry.OccultismBiomeFeatures;
import com.github.klikli_dev.occultism.registry.OccultismBlocks;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.feature.template.TagMatchRuleTest;
import net.minecraft.world.gen.foliageplacer.BlobFoliagePlacer;
import net.minecraft.world.gen.placement.NoPlacementConfig;
import net.minecraft.world.gen.placement.Placement;
Expand All @@ -47,9 +48,9 @@
public class WorldGenHandler {

//region Fields
public static ConfiguredFeature<?, ?> ORE_COPPER;
public static ConfiguredFeature<?, ?> ORE_SILVER;
public static ConfiguredFeature<?, ?> ORE_IESNIUM;
public static ConfiguredFeature<?, ?> COPPER_ORE;
public static ConfiguredFeature<?, ?> SILVER_ORE;
public static ConfiguredFeature<?, ?> IESNIUM_ORE;

public static ConfiguredFeature<?, ?> UNDERGROUND_GROVE;

Expand All @@ -60,43 +61,66 @@ public class WorldGenHandler {
//region Static Methods
@SubscribeEvent
public static void onBiomeLoading(BiomeLoadingEvent event) {
event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ORE_COPPER);
event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ORE_SILVER);
event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, ORE_IESNIUM);

event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_STRUCTURES, UNDERGROUND_GROVE);
if(Occultism.CONFIG.worldGen.oreGen.copperOre.generateOre.get())
event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, COPPER_ORE);
if(Occultism.CONFIG.worldGen.oreGen.silverOre.generateOre.get())
event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, SILVER_ORE);
if(Occultism.CONFIG.worldGen.oreGen.iesniumOre.generateOre.get())
event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, IESNIUM_ORE);
if(Occultism.CONFIG.worldGen.undergroundGroveGen.generateUndergroundGroves.get())
event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_STRUCTURES, UNDERGROUND_GROVE);
}

public static void registerConfiguredFeatures() {
//Register the features with default setting here.
ORE_COPPER = Feature.ORE
.withConfiguration(new OreFeatureConfig(
OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
OccultismBlocks.COPPER_ORE.get().getDefaultState(), 9))
.withPlacement(Placement.RANGE.configure(new TopSolidRangeConfig(10, 0, 64)))
.func_242731_b(20); //count decorator
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("ore_copper"), ORE_COPPER);

ORE_SILVER = Feature.ORE
.withConfiguration(new OreFeatureConfig(
OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
OccultismBlocks.SILVER_ORE.get().getDefaultState(), 7))
.withPlacement(Placement.RANGE.configure(new TopSolidRangeConfig(5, 0, 30)))
.func_242731_b(3); // func_242731_b = count decorator
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("ore_silver"), ORE_SILVER);

ORE_IESNIUM = Feature.ORE
.withConfiguration(new OreFeatureConfig(
OreFeatureConfig.FillerBlockType.BASE_STONE_NETHER,
OccultismBlocks.IESNIUM_ORE.get().getDefaultState(), 3))
.withPlacement(Features.Placements.NETHER_SPRING_ORE_PLACEMENT)
.func_242731_b(10); // func_242731_b = count decorator
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("ore_iesnium"), ORE_IESNIUM);
OccultismConfig.WorldGenSettings.OreGenSettings oreGen = Occultism.CONFIG.worldGen.oreGen;
OccultismConfig.WorldGenSettings.UndergroundGroveGenSettings groveGen = Occultism.CONFIG.worldGen.undergroundGroveGen;


COPPER_ORE = Feature.ORE.withConfiguration(
new OreFeatureConfig(
new TagMatchRuleTest(oreGen.copperOre.getFillerBlockTag()),
OccultismBlocks.COPPER_ORE.get().getDefaultState(), oreGen.copperOre.size.get()))
.withPlacement(Placement.RANGE.configure(
new TopSolidRangeConfig(
oreGen.copperOre.bottomOffset.get(),
oreGen.copperOre.topOffset.get(),
oreGen.copperOre.maximum.get())))
.func_242731_b(oreGen.copperOre.count.get()); // func_242731_b =count decorator
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("copper_ore"), COPPER_ORE);

SILVER_ORE = Feature.ORE.withConfiguration(
new OreFeatureConfig(
new TagMatchRuleTest(oreGen.silverOre.getFillerBlockTag()),
OccultismBlocks.SILVER_ORE.get().getDefaultState(), oreGen.silverOre.size.get()))
.withPlacement(Placement.RANGE.configure(
new TopSolidRangeConfig(
oreGen.silverOre.bottomOffset.get(),
oreGen.silverOre.topOffset.get(),
oreGen.silverOre.maximum.get())))
.func_242731_b(oreGen.silverOre.count.get()); // func_242731_b =count decorator
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("silver_ore"), SILVER_ORE);

IESNIUM_ORE = Feature.ORE.withConfiguration(
new OreFeatureConfig(
new TagMatchRuleTest(oreGen.iesniumOre.getFillerBlockTag()),
OccultismBlocks.IESNIUM_ORE.get().getDefaultState(), oreGen.iesniumOre.size.get()))
.withPlacement(Placement.RANGE.configure(
new TopSolidRangeConfig(
oreGen.iesniumOre.bottomOffset.get(),
oreGen.iesniumOre.topOffset.get(),
oreGen.iesniumOre.maximum.get())))
.func_242731_b(oreGen.iesniumOre.count.get()); // func_242731_b =count decorator
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("iesnium_ore"), IESNIUM_ORE);

UNDERGROUND_GROVE =
OccultismBiomeFeatures.UNDERGROUND_GROVE_FEATURE.get()
.withConfiguration(new MultiChunkFeatureConfig(
7, 400, 25, 60, 14653667))
OccultismBiomeFeatures.UNDERGROUND_GROVE_FEATURE.get().withConfiguration(
new MultiChunkFeatureConfig(
7,
groveGen.groveSpawnChance.get(),
groveGen.groveSpawnMin.get(),
groveGen.groveSpawnMax.get(),
14653667))
.withPlacement(Placement.NOPE.configure(new NoPlacementConfig()));
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("underground_grove"), UNDERGROUND_GROVE);

Expand All @@ -107,7 +131,8 @@ public static void registerConfiguredFeatures() {
new BlobFoliagePlacer(FeatureSpread.func_242252_a(2), FeatureSpread.func_242252_a(0), 3),
new StraightTrunkPlacer(4, 2, 0),
new TwoLayerFeature(1, 0, 1))).setIgnoreVines().build());
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("otherworld_tree_natural"), OTHERWORLD_TREE_NATURAL);
Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, modLoc("otherworld_tree_natural"),
OTHERWORLD_TREE_NATURAL);

OTHERWORLD_TREE = Feature.TREE.withConfiguration((
new BaseTreeFeatureConfig.Builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
import com.github.klikli_dev.occultism.config.value.CachedFloat;
import com.github.klikli_dev.occultism.config.value.CachedInt;
import com.github.klikli_dev.occultism.config.value.CachedObject;
import com.github.klikli_dev.occultism.registry.OccultismTags;
import net.minecraft.block.Block;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ITag;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.ForgeConfigSpec;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -176,30 +179,134 @@ public StorageSettings(IConfigCache parent, ForgeConfigSpec.Builder builder) {

public class WorldGenSettings extends ConfigCategoryBase {
//region Fields
public final OreGenSettings oreGen;
public final UndergroundGroveGenSettings undergroundGroveGen;
//endregion Fields

//region Initialization
public WorldGenSettings(IConfigCache parent, ForgeConfigSpec.Builder builder) {
super(parent, builder);
builder.comment("WorldGen Settings").push("worldgen");
this.oreGen = new OreGenSettings(this, builder);
this.undergroundGroveGen = new UndergroundGroveGenSettings(this, builder);
builder.pop();
}
//endregion Initialization

public class OreGenSettings extends ConfigCategoryBase {
//region Fields

public final OreSettings copperOre;
public final OreSettings silverOre;
public final OreSettings iesniumOre;

//endregion Fields

//region Initialization
public OreGenSettings(IConfigCache parent, ForgeConfigSpec.Builder builder) {
super(parent, builder);
builder.comment("Ore Gen Settings").push("oregen");

this.copperOre =
new OreSettings("copperOre", BlockTags.BASE_STONE_OVERWORLD, 9,
20, 20, 0, 64, this, builder);
this.silverOre =
new OreSettings("silverOre", BlockTags.BASE_STONE_OVERWORLD, 7,
3,5, 0, 30, this, builder);
this.iesniumOre =
new OreSettings("iesniumOre", OccultismTags.NETHERRACK, 3, 10,
10, 10, 128, this, builder);
builder.pop();
}
//endregion Initialization

public class OreSettings extends ConfigCategoryBase {
//region Fields
public final CachedBoolean generateOre;
public final CachedObject<String> fillerBlockTag;
public final CachedInt size;
public final CachedInt count;
public final CachedInt bottomOffset;
public final CachedInt topOffset;
public final CachedInt maximum;
//endregion Fields

//region Initialization
public OreSettings(String oreName, ITag<Block> fillerBlockTag,
int size, int count, int bottomOffset, int topOffset, int maximum,
IConfigCache parent, ForgeConfigSpec.Builder builder) {
super(parent, builder);
builder.comment("Ore Settings").push(oreName);

this.generateOre = CachedBoolean.cache(this,
builder.comment("True to generate this ore.")
.define("generateOre", true));
this.fillerBlockTag = CachedObject.cache(this,
builder.comment("The tag for the blocks this ore will spawn in.")
.define("fillerBlockTag",
BlockTags.getCollection()
.getDirectIdFromTag(fillerBlockTag).toString()));
this.size = CachedInt.cache(this,
builder.comment("The size of veins for this ore.")
.defineInRange("size", size, 0, Byte.MAX_VALUE));
this.count = CachedInt.cache(this,
builder.comment("The count value for the decorator for this ore.")
.defineInRange("count", count, 0, Byte.MAX_VALUE));
this.bottomOffset = CachedInt.cache(this,
builder.comment("Range configuration bottom offset.")
.define("bottomOffset", bottomOffset));
this.topOffset = CachedInt.cache(this,
builder.comment("Range configuration top offset.")
.define("topOffset", topOffset));
this.maximum = CachedInt.cache(this,
builder.comment("Range configuration maximum.")
.define("maximum", maximum));
builder.pop();
}
//endregion Initialization

//region Getter / Setter
public ITag<Block> getFillerBlockTag() {
return BlockTags.createOptional(new ResourceLocation(this.fillerBlockTag.get()));
}
//endregion Getter / Setter
}
}


public class UndergroundGroveGenSettings extends ConfigCategoryBase {
//region Fields
public CachedFloat grassChance;
public CachedFloat treeChance;
public CachedFloat vineChance;
public CachedFloat ceilingLightChance;
public final CachedBoolean generateUndergroundGroves;
public final CachedInt groveSpawnChance;
public final CachedInt groveSpawnMin;
public final CachedInt groveSpawnMax;
public final CachedFloat grassChance;
public final CachedFloat treeChance;
public final CachedFloat vineChance;
public final CachedFloat ceilingLightChance;
//endregion Fields

//region Initialization
public UndergroundGroveGenSettings(IConfigCache parent, ForgeConfigSpec.Builder builder) {
super(parent, builder);
builder.comment("Underground Grove Settings").push("underground_grove");
this.generateUndergroundGroves = CachedBoolean.cache(this,
builder.comment("True to generate underground groves. Should not be changed in most scenarios.")
.define("generateUndergroundGroves", true));

this.groveSpawnChance = CachedInt.cache(this,
builder.comment(
"The chance for a grove to spawn in a chunk (generates 1/groveSpawnChance chunks on average).")
.define("groveSpawnChance", 400));
this.groveSpawnMin = CachedInt.cache(this,
builder.comment(
"The min height for a grove to spawn (applied to the center of the grove, not the floor).")
.define("groveSpawnMin", 25));
this.groveSpawnMax = CachedInt.cache(this,
builder.comment(
"The max height for a grove to spawn (applied to the center of the grove, not the ceiling).")
.define("groveSpawnMax", 60));


this.grassChance = CachedFloat.cache(this,
builder.comment("The chance grass will spawn in the underground grove.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class OccultismTags {

// Block Tags
public static final ITag<Block> CAVE_WALL_BLOCKS = makeBlockTag(new ResourceLocation(Occultism.MODID,"cave_wall_blocks"));
public static final ITag<Block> NETHERRACK = makeBlockTag(new ResourceLocation(Occultism.MODID,"netherrack"));

//Item Tags

Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/data/occultism/tags/blocks/netherrack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"minecraft:netherrack"
]
}

0 comments on commit d974728

Please sign in to comment.