More work on the new ore config, please leave feedback
This commit is contained in:
parent
82043cadc4
commit
8ab9ecd28e
2 changed files with 65 additions and 26 deletions
|
@ -9,14 +9,8 @@ public class OreConfig {
|
|||
|
||||
public String blockName;
|
||||
|
||||
public String unloclisedName;
|
||||
|
||||
public String blockSate;
|
||||
|
||||
public int meta;
|
||||
|
||||
public String c = "↓↓↓↓CHANGE ME↓↓↓↓";
|
||||
|
||||
public int veinSize;
|
||||
|
||||
public int veinsPerChunk;
|
||||
|
@ -27,10 +21,8 @@ public class OreConfig {
|
|||
|
||||
|
||||
public OreConfig(IBlockState blockSate, int veinSize, int veinsPerChunk, int minYHeight, int maxYHeight) {
|
||||
this.blockName = blockSate.getBlock().getLocalizedName();
|
||||
this.meta = blockSate.getBlock().getMetaFromState(blockSate);
|
||||
this.unloclisedName = blockSate.getBlock().getUnlocalizedName();
|
||||
this.blockSate = blockSate.toString();
|
||||
this.blockName = blockSate.getBlock().getLocalizedName();
|
||||
this.veinSize = veinSize;
|
||||
this.veinsPerChunk = veinsPerChunk;
|
||||
this.minYHeight = minYHeight;
|
||||
|
|
|
@ -2,34 +2,89 @@ package techreborn.world;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import mcmultipart.raytrace.PartMOP;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.fml.common.IWorldGenerator;
|
||||
import techreborn.Core;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 11/03/2016.
|
||||
*/
|
||||
public class TechRebornWorldGen implements IWorldGenerator {
|
||||
|
||||
private void init(){
|
||||
defaultConfig = new WorldGenConfig();
|
||||
defaultConfig.overworldOres = new ArrayList<>();
|
||||
defaultConfig.endOres = new ArrayList<>();
|
||||
defaultConfig.neatherOres = new ArrayList<>();
|
||||
|
||||
defaultConfig.overworldOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Galena"), 8, 16, 10, 60));
|
||||
defaultConfig.overworldOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Iridium"), 1, 1, 10, 60));
|
||||
defaultConfig.overworldOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Ruby"), 6, 3, 10, 60));
|
||||
//TODO add the rest of the overworld ones
|
||||
|
||||
defaultConfig.neatherOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Pyrite"), 6, 3, 10, 250));
|
||||
defaultConfig.neatherOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Cinnabar"), 6, 3, 10, 250));
|
||||
defaultConfig.neatherOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Sphalerite"), 6, 3, 10, 250));
|
||||
|
||||
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Tungston"), 6, 3, 10, 250));
|
||||
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Sheldonite"), 6, 3, 10, 250));
|
||||
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Peridot"), 6, 3, 10, 250));
|
||||
defaultConfig.endOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Sodalite"), 6, 3, 10, 250));
|
||||
}
|
||||
|
||||
WorldGenConfig config;
|
||||
WorldGenConfig defaultConfig;
|
||||
public File configFile;
|
||||
|
||||
public void load(){
|
||||
if(config == null){
|
||||
if(configFile.exists()){
|
||||
init();
|
||||
if(configFile.exists()){
|
||||
loadFromJson();
|
||||
} else {
|
||||
config = defaultConfig;
|
||||
}
|
||||
config.overworldOres.addAll(getMissingOres(config.overworldOres, defaultConfig.overworldOres));
|
||||
config.neatherOres.addAll(getMissingOres(config.neatherOres, defaultConfig.neatherOres));
|
||||
config.endOres.addAll(getMissingOres(config.endOres, defaultConfig.endOres));
|
||||
save();
|
||||
}
|
||||
|
||||
} else {
|
||||
addOres();
|
||||
save();
|
||||
private List<OreConfig> getMissingOres(List<OreConfig> config, List<OreConfig> defaultOres){
|
||||
List<OreConfig> missingOres = new ArrayList<>();
|
||||
for (OreConfig defaultOre : defaultOres){
|
||||
boolean hasFoundOre = false;
|
||||
for (OreConfig ore : config){
|
||||
if(ore.blockName.equals(defaultOre.blockName) && ore.meta == defaultOre.meta){
|
||||
hasFoundOre = true;
|
||||
}
|
||||
}
|
||||
if(!hasFoundOre){
|
||||
missingOres.add(defaultOre);
|
||||
}
|
||||
}
|
||||
return missingOres;
|
||||
}
|
||||
|
||||
private void loadFromJson(){
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
BufferedReader reader = new BufferedReader(new FileReader(configFile));
|
||||
Type typeOfHashMap = new TypeToken<WorldGenConfig>(){}.getType();
|
||||
config = gson.fromJson(reader, typeOfHashMap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,19 +96,11 @@ public class TechRebornWorldGen implements IWorldGenerator {
|
|||
writer.write(json);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
Core.logHelper.error("The ores.json file was invalid, bad things are about to happen");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addOres(){
|
||||
config = new WorldGenConfig();
|
||||
config.overworldOres = new ArrayList<>();
|
||||
config.endOres = new ArrayList<>();
|
||||
config.neatherOres = new ArrayList<>();
|
||||
|
||||
config.overworldOres.add(new OreConfig(ModBlocks.ore.getBlockStateFromName("Galena"), 8, 16, 10, 60));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue