Skip to content

Commit

Permalink
Fixed Ore Configs not working. Closes #359
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Oct 19, 2021
1 parent c7a4e28 commit 11e3d26
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.teammetallurgy.atum.api.IFogReductionItem;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.*;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.IDyeableArmorItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;

import javax.annotation.Nonnull;
Expand Down
88 changes: 64 additions & 24 deletions src/main/java/com/teammetallurgy/atum/misc/AtumConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.File;
import java.util.HashMap;
import java.util.List;

public class AtumConfig {
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
Expand All @@ -20,13 +21,12 @@ public class AtumConfig {
public static final Biome BIOME = new Biome(BUILDER);
public static final Mobs MOBS = new Mobs(BUILDER);

public static class General {
public static final String GENERAL = "general";
public static class General implements BaseConfig {
public final ForgeConfigSpec.BooleanValue allowCreation;
public final ForgeConfigSpec.BooleanValue fogEnabled;

public General(ForgeConfigSpec.Builder builder) {
builder.push(GENERAL);
builder.push(getBaseCategory());
this.allowCreation = builder.comment("Can a non-creative user create a portal using the scarab?")
.translation("atum.config.portal_creation")
.define("Atum Portal", true);
Expand All @@ -36,16 +36,20 @@ public General(ForgeConfigSpec.Builder builder) {
.define("Atum Fog", true);
builder.pop();
}

@Override
public String getBaseCategory() {
return "general";
}
}

public static class AtumStart {
public static final String ATUM_START = "atum start";
public static class AtumStart implements BaseConfig {
public ForgeConfigSpec.BooleanValue startInAtum;
public ForgeConfigSpec.ConfigValue<String> atumStartStructure;
public ForgeConfigSpec.BooleanValue startInAtumPortal;

AtumStart(ForgeConfigSpec.Builder builder) {
builder.push(ATUM_START);
builder.push(getBaseCategory());
this.startInAtum = builder.comment("New players should start in Atum?")
.translation("atum.config.atum_start")
.define("Start in Atum", false);
Expand All @@ -57,10 +61,14 @@ public static class AtumStart {
.define("Create Atum Portal", false);
builder.pop();
}

@Override
public String getBaseCategory() {
return "atum start";
}
}

public static class Sandstorm {
public static final String SANDSTORM = "sandstorm";
public static class Sandstorm implements BaseConfig {
public final ForgeConfigSpec.BooleanValue sandstormEnabled;
public final ForgeConfigSpec.IntValue sandstormSandLayerChance;
public final ForgeConfigSpec.IntValue sandstormFog;
Expand All @@ -70,7 +78,7 @@ public static class Sandstorm {
public final ForgeConfigSpec.IntValue sandstormTransitionTime;

Sandstorm(ForgeConfigSpec.Builder builder) {
builder.push(SANDSTORM);
builder.push(getBaseCategory());
this.sandstormEnabled = builder.comment("Enable/disables all functionality of sandstorms")
.translation("atum.configGui.sandstormenabled")
.define("Sandstorm Enabled", true);
Expand All @@ -94,10 +102,14 @@ public static class Sandstorm {
.defineInRange("Sandstorm Transition Time", 25, 0, 100);
builder.pop();
}

@Override
public String getBaseCategory() {
return "sandstorm";
}
}

public static class WorldGen {
public static final String WORLDGEN = "world gen";
public static class WorldGen implements BaseConfig {
public static final String OREGEN = "ore gen";
public final ForgeConfigSpec.DoubleValue mineshaftProbability;
public final ForgeConfigSpec.IntValue ruinsAmount;
Expand Down Expand Up @@ -155,7 +167,7 @@ public static class WorldGen {
public final ForgeConfigSpec.IntValue marlMaxHeight;

WorldGen(ForgeConfigSpec.Builder builder) {
builder.push(WORLDGEN);
builder.push(getBaseCategory());
this.mineshaftProbability = builder.comment("Probability of mineshafts generating. Set to 0 to disable. Default value same as vanilla overworld")
.translation("atum.config.mineshaft_probability")
.defineInRange("Minecraft probability", 0.007D, 0.0D, 1.0D);
Expand All @@ -168,7 +180,6 @@ public static class WorldGen {
this.sandLayerEdge = builder.comment("Should Sand Layers generate along all edges?")
.translation("atum.config.sand_layer_enabled")
.define("Enable Sand Layer along edges", true);
builder.pop();
builder.push(OREGEN).comment("All vanilla based ores, uses the vanilla values by default.");
this.coalVeinSize = builder.defineInRange("Coal vein size", 17, 1, 64);
this.coalCount = builder.defineInRange("Coal count, set to 0 to disable", 20, 0, 64);
Expand Down Expand Up @@ -218,18 +229,22 @@ public static class WorldGen {
this.marlVeinSize = builder.defineInRange("Marl vein size", 14, 1, 64);
this.marlCount = builder.defineInRange("Marl count, set to 0 to disable", 8, 0, 64);
this.marlMaxHeight = builder.defineInRange("Marl max height", 50, 1, 255);
builder.pop();
builder.pop(2);
}

@Override
public String getBaseCategory() {
return "worldgen";
}
}

public static class Biome {
public static final String BIOME = "biome";
public static class Biome implements BaseConfig {
public ForgeConfigSpec.IntValue subBiomeChance;
public ForgeConfigSpec.IntValue oasisChance;
public ForgeConfigSpec.IntValue weight;

Biome(ForgeConfigSpec.Builder builder) {
builder.push(BIOME);
builder.push(getBaseCategory());
this.subBiomeChance = builder.comment("By default 1 in 30 Sand Plains biomes can contain either an Oasis or Dead Oasis. Set to 0 to disable both oases biomes.")
.translation("atum.config.oaseschances")
.defineInRange("Oases chance", 30, 0, 10000);
Expand All @@ -240,15 +255,19 @@ public static class Biome {
}

public Biome(ForgeConfigSpec.Builder builder, String biomeName, int weight) {
builder.push(BIOME);
builder.push(getBaseCategory());
builder.push(biomeName);
this.weight = builder.defineInRange("weight", weight, -1, 1000);
builder.pop(2);
}

@Override
public String getBaseCategory() {
return "biome";
}
}

public static class Mobs {
public static final String MOBS = "mobs";
public static class Mobs implements BaseConfig {
public static HashMap<EntityType<?>, EntityClassification> ENTITY_CLASSIFICATION = new HashMap<>();
public static HashMultimap<ResourceLocation, EntityType<?>> ENTITY_TYPE = HashMultimap.create();
public ForgeConfigSpec.IntValue min;
Expand All @@ -259,7 +278,7 @@ public static class Mobs {
public ForgeConfigSpec.IntValue markedForDeathTimeBaseValue;

public Mobs(ForgeConfigSpec.Builder builder) {
builder.push(MOBS);
builder.push(getBaseCategory());
this.banditPatrolFrequency = builder.comment("How frequent Bandit patrols are. The higher the number, the less patrols will spawn")
.defineInRange("banditPatrolFrequency", 1000, -1, 10000);
this.markedForDeathTimeBaseValue = builder.comment("How long time is required for an Assassin to spawn. The higher the number, the less frequent Assassin will spawn")
Expand All @@ -270,30 +289,51 @@ public Mobs(ForgeConfigSpec.Builder builder) {
public Mobs(ForgeConfigSpec.Builder builder, String mobName, int min, int max, int weight, EntityType<?> entityType, EntityClassification classification, ResourceLocation biomeName) {
ENTITY_CLASSIFICATION.put(entityType, classification);
ENTITY_TYPE.put(biomeName, entityType);
builder.push(MOBS);
builder.push(getBaseCategory());
builder.push(mobName);
this.min = builder.defineInRange("min", min, -1, 63);
this.max = builder.defineInRange("max", max, 1, 64);
this.weight = builder.defineInRange("weight", weight, -1, 1000);
builder.pop(2);
}

@Override
public String getBaseCategory() {
return "mobs";
}
}

public static class ModIntegration {
public static class ModIntegration implements BaseConfig {
public static final String MOD_INTEGRATION = "mod integration";

public ModIntegration(ForgeConfigSpec.Builder builder, String modName, boolean defaultValue) {
builder.push(MOD_INTEGRATION);
builder.push(getBaseCategory());
builder.define(modName, defaultValue);
builder.pop();
}

@Override
public String getBaseCategory() {
return MOD_INTEGRATION;
}
}

public static interface BaseConfig {
String getBaseCategory();
}

public static ForgeConfigSpec spec = BUILDER.build();

public static class Helper {
private static final FileConfig CONFIG_FILE = FileConfig.of(new File(FMLPaths.CONFIGDIR.get().toFile(), "atum-common.toml"));

public static <T> T get(ForgeConfigSpec.ConfigValue<?> configValue) {
List<String> path = configValue.getPath();
String category = path.get(0);
String subOrValue = path.get(1);
return get(category + "." + subOrValue + (path.size() > 2 ? "." + path.get(2) : ""));
}

public static <T> T get(String category, String subCategory, String value) {
return get(category + "." + subCategory, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,64 +37,80 @@ public static void addSprings(BiomeGenerationSettings.Builder builder) {
}

public static void addMaterialPockets(BiomeGenerationSettings.Builder builder) {
if (AtumConfig.WORLD_GEN.sandCount.get() > 0) {
int sandCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.sandCount);
if (sandCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.SAND);
}
if (AtumConfig.WORLD_GEN.limestoneGravelCount.get() > 0) {
int limestoneGravelCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.limestoneGravelCount);
if (limestoneGravelCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.LIMESTONE_GRAVEL);
}
if (AtumConfig.WORLD_GEN.marlCount.get() > 0) {
int marlCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.marlCount);
if (marlCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.MARL);
}
}

public static void addStoneVariants(BiomeGenerationSettings.Builder builder) {
if (AtumConfig.WORLD_GEN.alabasterCount.get() > 0) {
int alabasterCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.alabasterCount);
if (alabasterCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.ALABASTER);
}
if (AtumConfig.WORLD_GEN.porphyryCount.get() > 0) {
int porphyryCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.porphyryCount);
if (porphyryCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.PORPHYRY);
}
}

public static void addOres(BiomeGenerationSettings.Builder builder) {
//Vanilla based ores
if (AtumConfig.WORLD_GEN.coalCount.get() > 0) {
int coalCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.coalCount);
if (coalCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.COAL_ORE);
}
if (AtumConfig.WORLD_GEN.ironCount.get() > 0) {
int ironCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.ironCount);
if (ironCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.IRON_ORE);
}
if (AtumConfig.WORLD_GEN.goldCount.get() > 0) {
int goldCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.goldCount);
if (goldCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.GOLD_ORE);
}
if (AtumConfig.WORLD_GEN.redstoneCount.get() > 0) {
int redstoneCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.redstoneCount);
if (redstoneCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.REDSTONE_ORE);
}
if (AtumConfig.WORLD_GEN.diamondCount.get() > 0) {
int diamondCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.diamondCount);
if (diamondCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.DIAMOND_ORE);
}
if (AtumConfig.WORLD_GEN.lapisBaseline.get() > 0) {
int lapisBaseline = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.lapisBaseline);
if (lapisBaseline > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.LAPIS_ORE);
}

//Atum ores
if (AtumConfig.WORLD_GEN.khnumiteCount.get() > 0) {
int khnumiteCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.khnumiteCount);
if (khnumiteCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.KHNUMITE_RAW);
}
if (AtumConfig.WORLD_GEN.boneOreCount.get() > 0) {
int boneOreCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.boneOreCount);
if (boneOreCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.BONE_ORE);
}
if (AtumConfig.WORLD_GEN.relicOreCount.get() > 0) {
int relicOreCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.relicOreCount);
if (relicOreCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.RELIC_ORE);
}
if (AtumConfig.WORLD_GEN.nebuCount.get() > 0) {
int nebuCount = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.nebuCount);
if (nebuCount > 0) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.NEBU_ORE);
}
}

public static void addEmeraldOre(BiomeGenerationSettings.Builder builder) {
if (AtumConfig.WORLD_GEN.emeraldEnabled.get()) {
boolean emeraldEnabled = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.emeraldEnabled);
if (emeraldEnabled) {
builder.withFeature(UNDERGROUND_ORES, AtumFeatures.EMERALD_ORE);
}
}
Expand All @@ -104,20 +120,23 @@ public static void addInfestedLimestone(BiomeGenerationSettings.Builder builder)
}

public static void addShrubs(BiomeGenerationSettings.Builder builder) {
if (AtumConfig.WORLD_GEN.shrubFrequency.get() > 0) {
int shrubFrequency = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.shrubFrequency);
if (shrubFrequency > 0) {
builder.withFeature(VEGETAL_DECORATION, AtumFeatures.SHRUB);
builder.withFeature(VEGETAL_DECORATION, AtumFeatures.WEED);
}
}

public static void addFossils(BiomeGenerationSettings.Builder builder) {
if (AtumConfig.WORLD_GEN.fossilsChance.get() > 0) {
int fossilsChance = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.fossilsChance);
if (fossilsChance > 0) {
builder.withFeature(UNDERGROUND_DECORATION, AtumFeatures.DIRTY_BONE_FOSSILS_CONFIGURED);
}
}

public static void addDungeon(BiomeGenerationSettings.Builder builder) {
if (AtumConfig.WORLD_GEN.dungeonChance.get() > 0) {
int dungeonChance = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.dungeonChance);
if (dungeonChance > 0) {
builder.withFeature(UNDERGROUND_STRUCTURES, AtumFeatures.LIMESTONE_DUNGEONS_CONFIGURED);
}
}
Expand All @@ -143,7 +162,8 @@ public static void addGenericVillage(BiomeGenerationSettings.Builder builder) {
}

public static void addMineshaft(BiomeGenerationSettings.Builder builder, boolean isSurface) {
if (AtumConfig.WORLD_GEN.mineshaftProbability.get() > 0.0D) {
double mineshaftProbability = AtumConfig.Helper.get(AtumConfig.WORLD_GEN.mineshaftProbability);
if (mineshaftProbability > 0.0D) {
if (isSurface) {
builder.withStructure(AtumStructures.MINESHAFT_DEADWOOD_SURFACE_FEATURE);
builder.withStructure(AtumStructures.MINESHAFT_LIMESTONE_SURFACE_FEATURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public AtumBiomeLayer(Registry<Biome> biomeRegistry) {
for (RegistryKey<Biome> biomeKey : AtumRegistry.BIOME_KEYS) {
ResourceLocation location = biomeKey.getLocation();
if (location != null) {
String subConfig = AtumConfig.Helper.getSubConfig(AtumConfig.Biome.BIOME, location.getPath());
String subConfig = AtumConfig.Helper.getSubConfig(AtumConfig.BIOME.getBaseCategory(), location.getPath());
if (AtumConfig.Helper.get(subConfig) != null) { //Ensure config exists
int weight = AtumConfig.Helper.get(subConfig, "weight");
if (weight > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.blocks.base.ChestBaseBlock;
import com.teammetallurgy.atum.blocks.stone.limestone.chest.tileentity.SarcophagusTileEntity;
import com.teammetallurgy.atum.blocks.wood.tileentity.crate.CrateTileEntity;
import com.teammetallurgy.atum.init.AtumBlocks;
import com.teammetallurgy.atum.init.AtumLootTables;
import com.teammetallurgy.atum.init.AtumStructurePieces;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.LockableLootTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Mirror;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Rotation;
Expand Down

0 comments on commit 11e3d26

Please sign in to comment.