Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terrain API 1.3.1 #14

Merged
merged 17 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Config overhaul (#8)
* Allow for custom Config classes

* Configuration Maps

* new ManagedOreMethod

* Replaced Parameters Enum with Parameters Class
  • Loading branch information
UselessBullets authored Nov 8, 2023
commit 79eb2da2460d9b87c758ebd486ba5e07e969e993
151 changes: 68 additions & 83 deletions src/main/java/useless/terrainapi/TerrainInitialization.java
Original file line number Diff line number Diff line change
@@ -5,21 +5,22 @@
import net.minecraft.core.world.biome.Biomes;
import net.minecraft.core.world.generate.feature.*;
import useless.terrainapi.api.TerrainAPI;
import useless.terrainapi.config.NetherConfig;
import useless.terrainapi.config.OverworldConfig;
import useless.terrainapi.generation.Parameters;
import useless.terrainapi.generation.nether.ChunkDecoratorNetherAPI;
import useless.terrainapi.generation.overworld.ChunkDecoratorOverworldAPI;
import useless.terrainapi.generation.VanillaFunctions;
import useless.terrainapi.generation.overworld.OverworldBiomeFeatures;

import java.util.HashMap;
import useless.terrainapi.generation.nether.NetherFunctions;
import useless.terrainapi.generation.nether.api.ChunkDecoratorNetherAPI;
import useless.terrainapi.generation.overworld.OverworldFunctions;
import useless.terrainapi.generation.overworld.api.ChunkDecoratorOverworldAPI;

public class TerrainInitialization implements TerrainAPI {
private static boolean hasInitialized = false;
private static final OverworldConfig overworldConfig = ChunkDecoratorOverworldAPI.overworldConfig;
private static final NetherConfig netherConfig = ChunkDecoratorNetherAPI.netherConfig;
@Override
public String getModID() {
return TerrainMain.MOD_ID;
}

@Override
public void onInitialize() {
if (hasInitialized) {return;}
@@ -33,83 +34,67 @@ public void onInitialize() {

initializeNether();
}
public static void initializeOverworldStructures() {
ChunkDecoratorOverworldAPI.structureFeatures.addStructure(VanillaFunctions::generateDungeons, null);
ChunkDecoratorOverworldAPI.structureFeatures.addStructure(VanillaFunctions::generateLabyrinths, null);

}
public static void initializeDefaultValues(){
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID, Block.blockClay, 32, 20, 1f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.dirt, 32, 20, 1f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.gravel, 32, 10, 1f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.oreCoalStone, 16, 20, 1f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.oreIronStone, 8, 20, 1/2f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.oreGoldStone, 8, 2, 1/4f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.oreRedstoneStone, 7, 8, 1/8f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.oreDiamondStone, 7, 1, 1/8f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.mossStone, 32, 1, 1/2f);
ChunkDecoratorOverworldAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID,Block.oreLapisStone, 6, 1, 1/8f);

OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_FOREST, 2);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_MEADOW, 2);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_RAINFOREST, 10);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_DESERT, 5);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_SEASONAL_FOREST, 2);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_TAIGA, 1);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_BOREAL_FOREST, 5);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_PLAINS, 10);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_SWAMPLAND, 4);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_SHRUBLAND, 2);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_OUTBACK_GRASSY, 25);
OverworldBiomeFeatures.grassDensityMap.put(Biomes.OVERWORLD_BIRCH_FOREST, 10);
overworldConfig.setOreValues(TerrainMain.MOD_ID, Block.blockClay, 32, 20, 1f);

OverworldBiomeFeatures.flowerDensityMap.put(Biomes.OVERWORLD_SEASONAL_FOREST, 1);
OverworldBiomeFeatures.flowerDensityMap.put(Biomes.OVERWORLD_MEADOW, 2);
OverworldBiomeFeatures.flowerDensityMap.put(Biomes.OVERWORLD_BOREAL_FOREST, 2);
OverworldBiomeFeatures.flowerDensityMap.put(Biomes.OVERWORLD_SHRUBLAND, 1);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_FOREST, 2);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_MEADOW, 2);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_RAINFOREST, 10);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_DESERT, 5);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_SEASONAL_FOREST, 2);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_TAIGA, 1);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_BOREAL_FOREST, 5);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_PLAINS, 10);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_SWAMPLAND, 4);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_SHRUBLAND, 2);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_OUTBACK_GRASSY, 25);
overworldConfig.addGrassDensity(Biomes.OVERWORLD_BIRCH_FOREST, 10);

OverworldBiomeFeatures.yellowFlowerDensityMap.put(Biomes.OVERWORLD_FOREST, 2);
OverworldBiomeFeatures.yellowFlowerDensityMap.put(Biomes.OVERWORLD_SWAMPLAND, 2);
OverworldBiomeFeatures.yellowFlowerDensityMap.put(Biomes.OVERWORLD_TAIGA, 2);
OverworldBiomeFeatures.yellowFlowerDensityMap.put(Biomes.OVERWORLD_PLAINS, 3);
OverworldBiomeFeatures.yellowFlowerDensityMap.put(Biomes.OVERWORLD_OUTBACK_GRASSY, 2);
OverworldBiomeFeatures.yellowFlowerDensityMap.put(Biomes.OVERWORLD_OUTBACK, 2);
overworldConfig.addFlowerDensity(Biomes.OVERWORLD_SEASONAL_FOREST, 1);
overworldConfig.addFlowerDensity(Biomes.OVERWORLD_MEADOW, 2);
overworldConfig.addFlowerDensity(Biomes.OVERWORLD_BOREAL_FOREST, 2);
overworldConfig.addFlowerDensity(Biomes.OVERWORLD_SHRUBLAND, 1);

OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_FOREST, 5);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_BIRCH_FOREST, 4);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_RAINFOREST, 10);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_SEASONAL_FOREST, 2);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_TAIGA, 5);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_BOREAL_FOREST, 3);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_DESERT, -1000);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_TUNDRA, -1000);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_PLAINS, -1000);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_SWAMPLAND, 4);
OverworldBiomeFeatures.treeDensityMap.put(Biomes.OVERWORLD_OUTBACK_GRASSY, 0);
overworldConfig.addYellowFlowerDensity(Biomes.OVERWORLD_FOREST, 2);
overworldConfig.addYellowFlowerDensity(Biomes.OVERWORLD_SWAMPLAND, 2);
overworldConfig.addYellowFlowerDensity(Biomes.OVERWORLD_TAIGA, 2);
overworldConfig.addYellowFlowerDensity(Biomes.OVERWORLD_PLAINS, 3);
overworldConfig.addYellowFlowerDensity(Biomes.OVERWORLD_OUTBACK_GRASSY, 2);
overworldConfig.addYellowFlowerDensity(Biomes.OVERWORLD_OUTBACK, 2);

VanillaFunctions.biomeRandomGrassType.put(Biomes.OVERWORLD_RAINFOREST, Block.tallgrassFern.id);
VanillaFunctions.biomeRandomGrassType.put(Biomes.OVERWORLD_SWAMPLAND, Block.tallgrassFern.id);
VanillaFunctions.biomeRandomGrassType.put(Biomes.OVERWORLD_BOREAL_FOREST, Block.tallgrassFern.id);
VanillaFunctions.biomeRandomGrassType.put(Biomes.OVERWORLD_TAIGA, Block.tallgrassFern.id);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_FOREST, 5);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_BIRCH_FOREST, 4);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_RAINFOREST, 10);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_SEASONAL_FOREST, 2);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_TAIGA, 5);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_BOREAL_FOREST, 3);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_DESERT, -1000);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_TUNDRA, -1000);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_PLAINS, -1000);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_SWAMPLAND, 4);
overworldConfig.addTreeDensity(Biomes.OVERWORLD_OUTBACK_GRASSY, 0);

ChunkDecoratorNetherAPI.oreFeatures.setOreValues(TerrainMain.MOD_ID, Block.oreNethercoalNetherrack, 12, 10, 120/128f);
overworldConfig.addRandomGrassBlock(Biomes.OVERWORLD_RAINFOREST, Block.tallgrassFern);
overworldConfig.addRandomGrassBlock(Biomes.OVERWORLD_SWAMPLAND, Block.tallgrassFern);
overworldConfig.addRandomGrassBlock(Biomes.OVERWORLD_BOREAL_FOREST, Block.tallgrassFern);
overworldConfig.addRandomGrassBlock(Biomes.OVERWORLD_TAIGA, Block.tallgrassFern);
}
public static void initializeOverworldStructures() {
ChunkDecoratorOverworldAPI.structureFeatures.addStructure(OverworldFunctions::generateDungeons, null);
ChunkDecoratorOverworldAPI.structureFeatures.addStructure(OverworldFunctions::generateLabyrinths, null);
}
public static void initializeOverworldOre(){
HashMap<String, Integer> blockNumberMap = ChunkDecoratorOverworldAPI.overworldConfig.clusterSize;
HashMap<String, Integer> chancesMap = ChunkDecoratorOverworldAPI.overworldConfig.chancesPerChunk;
HashMap<String, Float> rangeMap = ChunkDecoratorOverworldAPI.overworldConfig.verticalRange;
String currentBlock;
currentBlock = Block.blockClay.getKey();
ChunkDecoratorOverworldAPI.oreFeatures.addFeature(new WorldFeatureClay(blockNumberMap.get(currentBlock)), chancesMap.get(currentBlock), rangeMap.get(currentBlock));
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.dirt, false);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.gravel, false);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.oreCoalStone, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.oreIronStone, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.oreGoldStone, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.oreRedstoneStone, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.oreDiamondStone, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.mossStone, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(Block.oreLapisStone, true);
String currentBlock = Block.blockClay.getKey();
ChunkDecoratorOverworldAPI.oreFeatures.addFeature(new WorldFeatureClay(overworldConfig.clusterSize.get(currentBlock)), overworldConfig.chancesPerChunk.get(currentBlock), overworldConfig.verticalRange.get(currentBlock));
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.dirt, 32, 20, 1f, false);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.gravel, 32, 10, 1f, false);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.oreCoalStone, 16, 20, 1f, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.oreIronStone, 8, 20, 1/2f, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.oreGoldStone, 8, 2, 1/4f, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.oreRedstoneStone, 7, 8, 1/8f, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.oreDiamondStone, 7, 1, 1/8f, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.mossStone, 32, 1, 1/2f, true);
ChunkDecoratorOverworldAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID,Block.oreLapisStone, 6, 1, 1/8f, true);
}
public static void initializeOverworldRandom(){
ChunkDecoratorOverworldAPI.randomFeatures.addFeature(new WorldFeatureFlowers(Block.flowerRed.id), 2, 1);
@@ -121,20 +106,20 @@ public static void initializeOverworldRandom(){
}
public static void initializeOverworldBiome(){
ChunkDecoratorOverworldAPI.biomeFeatures.addFeatureSurface(new WorldFeatureRichScorchedDirt(10), 1, new Biome[]{Biomes.OVERWORLD_OUTBACK, Biomes.OVERWORLD_OUTBACK_GRASSY});
ChunkDecoratorOverworldAPI.biomeFeatures.addComplexFeature(VanillaFunctions::getTreeFeature, null, VanillaFunctions::getTreeDensity, null, -1f);
ChunkDecoratorOverworldAPI.biomeFeatures.addComplexFeature(OverworldFunctions::getTreeFeature, null, OverworldFunctions::getTreeDensity, null, -1f);
ChunkDecoratorOverworldAPI.biomeFeatures.addFeatureSurface(new WorldFeatureSugarCaneTall(), 1, new Biome[]{Biomes.OVERWORLD_RAINFOREST});
ChunkDecoratorOverworldAPI.biomeFeatures.addComplexFeature(VanillaFunctions::flowerTypeCondition, null, (Object[] x) -> OverworldBiomeFeatures.flowerDensityMap.getOrDefault(Parameters.getBiome(x), 0), null, 1f);
ChunkDecoratorOverworldAPI.biomeFeatures.addComplexFeature((Object[] x) -> new WorldFeatureFlowers(Block.flowerYellow.id), null, (Object[] x) -> OverworldBiomeFeatures.yellowFlowerDensityMap.getOrDefault(Parameters.getBiome(x), 0), null, 1);
ChunkDecoratorOverworldAPI.biomeFeatures.addComplexFeature(VanillaFunctions::grassTypeCondition, null, (Object[] x) -> OverworldBiomeFeatures.grassDensityMap.getOrDefault(Parameters.getBiome(x), 0), null, 1);
ChunkDecoratorOverworldAPI.biomeFeatures.addComplexFeature(OverworldFunctions::flowerTypeCondition, null, (Parameters x) -> ChunkDecoratorOverworldAPI.overworldConfig.getFlowerDensity(x.biome, 0), null, 1f);
ChunkDecoratorOverworldAPI.biomeFeatures.addComplexFeature((Parameters x) -> new WorldFeatureFlowers(Block.flowerYellow.id), null, (Parameters x) -> ChunkDecoratorOverworldAPI.overworldConfig.getYellowFlowerDensity(x.biome, 0), null, 1);
ChunkDecoratorOverworldAPI.biomeFeatures.addComplexFeature(OverworldFunctions::grassTypeCondition, null, (Parameters x) -> ChunkDecoratorOverworldAPI.overworldConfig.getGrassDensity(x.biome, 0), null, 1);
ChunkDecoratorOverworldAPI.biomeFeatures.addFeature(new WorldFeatureSpinifexPatch(), 1, 4, new Biome[]{Biomes.OVERWORLD_OUTBACK});
ChunkDecoratorOverworldAPI.biomeFeatures.addFeature(new WorldFeatureDeadBush(Block.deadbush.id), 1, 2, new Biome[]{Biomes.OVERWORLD_DESERT});
ChunkDecoratorOverworldAPI.biomeFeatures.addFeature(new WorldFeatureCactus(), 1, 10, new Biome[]{Biomes.OVERWORLD_DESERT});
}
public static void initializeNether(){
ChunkDecoratorNetherAPI.oreFeatures.addFeature(new WorldFeatureNetherLava(Block.fluidLavaFlowing.id), 8,120/128f);
ChunkDecoratorNetherAPI.oreFeatures.addManagedOreFeature(Block.oreNethercoalNetherrack, false);
ChunkDecoratorNetherAPI.oreFeatures.addComplexFeature((Object[] x) -> new WorldFeatureFire(), null, VanillaFunctions::netherFireDensity, null, 120/128f);
ChunkDecoratorNetherAPI.oreFeatures.addComplexFeature((Object[] x) -> new WorldFeatureGlowstoneA(), null, VanillaFunctions::netherFireDensity, null, 120/128f);
ChunkDecoratorNetherAPI.oreFeatures.addManagedOreFeature(TerrainMain.MOD_ID, Block.oreNethercoalNetherrack, 12, 10, 120/128f, false);
ChunkDecoratorNetherAPI.oreFeatures.addComplexFeature((Parameters x) -> new WorldFeatureFire(), null, NetherFunctions::netherFireDensity, null, 120/128f);
ChunkDecoratorNetherAPI.oreFeatures.addComplexFeature((Parameters x) -> new WorldFeatureGlowstoneA(), null, NetherFunctions::netherFireDensity, null, 120/128f);
ChunkDecoratorNetherAPI.oreFeatures.addFeature(new WorldFeatureGlowstoneB(), 10, 120/128f);
ChunkDecoratorNetherAPI.randomFeatures.addFeature(new WorldFeatureLake(Block.fluidLavaStill.id), 8, 120/128f);
}
6 changes: 3 additions & 3 deletions src/main/java/useless/terrainapi/TerrainMain.java
Original file line number Diff line number Diff line change
@@ -8,11 +8,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import useless.terrainapi.api.TerrainAPI;
import useless.terrainapi.config.TerrainAPIConfigManager;
import useless.terrainapi.config.ConfigManager;


public class TerrainMain implements ModInitializer {
public static final Gson GSON = (new GsonBuilder()).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setPrettyPrinting().create();
public static final Gson GSON = (new GsonBuilder()).setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();
public static final String MOD_ID = "terrain-api";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
@@ -28,6 +28,6 @@ public static void loadModules(){
} catch (NoSuchMethodException ignored) {
}
});
TerrainAPIConfigManager.saveAll();
ConfigManager.saveAll();
}
}
11 changes: 11 additions & 0 deletions src/main/java/useless/terrainapi/config/APIConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package useless.terrainapi.config;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class APIConfig {
@SerializedName(value = "Override Default Values") @Expose
private boolean configOverride = false;
public boolean getConfigOverride(){
return configOverride;
}
}
Original file line number Diff line number Diff line change
@@ -5,14 +5,15 @@
import useless.terrainapi.TerrainMain;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;

public class TerrainAPIConfigManager {
public class ConfigManager {
private static final HashMap<String, File> fileHashMap = new HashMap<>();
private static final HashMap<String, TerrainAPIConfig> configHashMap = new HashMap<>();
private static final HashMap<String, APIConfig> configHashMap = new HashMap<>();

private static void prepareBiomeConfigFile(String id) {
if (fileHashMap.get(id) != null) {
@@ -26,7 +27,7 @@ private static void prepareBiomeConfigFile(String id) {
}
fileHashMap.put(id, new File(filePath.toFile(), id + ".json"));
}
private static void load(String id) {
private static void load(String id, Class<? extends APIConfig> clazz) {
prepareBiomeConfigFile(id);

try {
@@ -35,8 +36,7 @@ private static void load(String id) {
}
if (fileHashMap.get(id).exists()) {
BufferedReader br = new BufferedReader(new FileReader(fileHashMap.get(id)));

configHashMap.put(id, TerrainMain.GSON.fromJson(br, TerrainAPIConfig.class));
configHashMap.put(id, TerrainMain.GSON.fromJson(br, clazz));
save(id);
}
} catch (FileNotFoundException e) {
@@ -48,7 +48,6 @@ public static void save(String id) {
prepareBiomeConfigFile(id);

String jsonString = TerrainMain.GSON.toJson(configHashMap.get(id));
TerrainMain.LOGGER.info(jsonString);

try (FileWriter fileWriter = new FileWriter(fileHashMap.get(id))) {
fileWriter.write(jsonString);
@@ -62,18 +61,22 @@ public static void saveAll(){
save(id);
}
}
public static TerrainAPIConfig getConfig(String id) {
public static <T extends APIConfig> T getConfig(String id, Class<T> classOfT) {
if (configHashMap.get(id) == null){
configHashMap.put(id, new TerrainAPIConfig());
}
load(id);
TerrainAPIConfig config = configHashMap.get(id);
if (config.getConfigOverride()){
return configHashMap.getOrDefault(id, new TerrainAPIConfig());
} else {
configHashMap.put(id, new TerrainAPIConfig());
return configHashMap.get(id);
try {
configHashMap.put(id, classOfT.getDeclaredConstructor().newInstance());
load(id, classOfT);
APIConfig config = configHashMap.get(id);
if (config.getConfigOverride()){
return classOfT.cast(configHashMap.getOrDefault(id, classOfT.getDeclaredConstructor().newInstance()));
} else {
configHashMap.put(id, classOfT.getDeclaredConstructor().newInstance());
return classOfT.cast(configHashMap.get(id));
}
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

return null;
}
}
4 changes: 4 additions & 0 deletions src/main/java/useless/terrainapi/config/NetherConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package useless.terrainapi.config;

public class NetherConfig extends OreConfig{
}
Loading
Loading