diff --git a/src/main/java/mods/tesseract/underworld/biomes/UnderworldDecorator.java b/src/main/java/mods/tesseract/underworld/biomes/UnderworldDecorator.java index 70e1606..7372562 100644 --- a/src/main/java/mods/tesseract/underworld/biomes/UnderworldDecorator.java +++ b/src/main/java/mods/tesseract/underworld/biomes/UnderworldDecorator.java @@ -1,20 +1,20 @@ package mods.tesseract.underworld.biomes; +import mods.tesseract.underworld.config.IConfigCSV; import mods.tesseract.underworld.world.WorldGenMinableUnderworld; -import net.minecraft.init.Blocks; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeDecorator; import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.gen.feature.WorldGenBigMushroom; -import net.minecraft.world.gen.feature.WorldGenerator; import java.util.Random; public class UnderworldDecorator extends BiomeDecorator { - private final WorldGenerator silverfishGen; + private final WorldGenMinableUnderworld[] oreGens; public UnderworldDecorator() { super(); + this.oreGens = (WorldGenMinableUnderworld[]) IConfigCSV.parseCSV("aa", WorldGenMinableUnderworld.class); + /* this.bigMushroomGen = new WorldGenBigMushroom(0); this.dirtGen = new WorldGenMinableUnderworld(Blocks.dirt, 32); this.gravelGen = new WorldGenMinableUnderworld(Blocks.gravel, 32); @@ -26,6 +26,8 @@ public UnderworldDecorator() { this.diamondGen = new WorldGenMinableUnderworld(Blocks.diamond_ore, 3); this.lapisGen = new WorldGenMinableUnderworld(Blocks.lapis_ore, 3); this.silverfishGen = new WorldGenMinableUnderworld(Blocks.monster_egg, 3); + + */ } public void genMinable(int frequency, WorldGenMinableUnderworld world_gen_minable) { @@ -61,16 +63,18 @@ public void genDecorations(BiomeGenBase biome) { } public void generateOres() { + /* this.genMinable(300, (WorldGenMinableUnderworld) this.gravelGen); - //this.genMinable(40, this.copperGen, true); - //this.genMinable(10, this.silverGen, true); + this.genMinable(40, this.copperGen, true); + this.genMinable(10, this.silverGen, true); this.genMinable(160, (WorldGenMinableUnderworld) this.goldGen); this.genMinable(480, (WorldGenMinableUnderworld) this.ironGen); - //this.genMinable(10, this.mithrilGen, true); - //this.genMinable(5, this.adamantiteGen, true); + this.genMinable(10, this.mithrilGen, true); + this.genMinable(5, this.adamantiteGen, true); this.genMinable(80, (WorldGenMinableUnderworld) this.redstoneGen); this.genMinable(40, (WorldGenMinableUnderworld) this.diamondGen); this.genMinable(40, (WorldGenMinableUnderworld) this.lapisGen); this.genMinable(400, (WorldGenMinableUnderworld) this.silverfishGen); + */ } } diff --git a/src/main/java/mods/tesseract/underworld/config/IConfigCSV.java b/src/main/java/mods/tesseract/underworld/config/IConfigCSV.java new file mode 100644 index 0000000..46d0414 --- /dev/null +++ b/src/main/java/mods/tesseract/underworld/config/IConfigCSV.java @@ -0,0 +1,82 @@ +package mods.tesseract.underworld.config; + +import java.util.ArrayList; +import java.util.Arrays; + +public interface IConfigCSV { + String[] getTypes(); + + String toCSV(); + + IConfigCSV parseCSV(String[] csv); + + static IConfigCSV[] parseCSV(String csv, Class cls) { + ArrayList list = new ArrayList<>(); + String[] l = split2(csv, '\n'); + if (l.length < 2) + return new IConfigCSV[0]; + try { + String[] n = cls.newInstance().getTypes(); + StringBuilder b = new StringBuilder(); + for (String s : n) + b.append(",").append(s); + b.delete(0, 1); + if (!l[0].contentEquals(b)) + throw new RuntimeException("不匹配的类型!应为:" + b + " 实为:" + l[0]); + for (int i = 1; i < l.length; i++) { + String t = l[i]; + String[] s = split(t, ','); + if (s.length != n.length) + throw new RuntimeException("不匹配的值数!应为:" + n.length + " 实为:" + s.length + " " + Arrays.toString(s)); + IConfigCSV c = cls.newInstance(); + c.parseCSV(s); + list.add(c); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return list.toArray(new IConfigCSV[0]); + } + + static String toCSV(IConfigCSV[] csv, Class cls) { + if (csv.length == 0) + return ""; + StringBuilder str = new StringBuilder(); + String[] n = csv[0].getTypes(); + StringBuilder b = new StringBuilder(); + for (String s : n) + b.append(",").append(s); + b.delete(0, 1); + str.append(b); + for (IConfigCSV c : csv) + str.append("\n").append(c.toCSV()); + return str.toString(); + } + + static String[] split(String str, char c) { + ArrayList strs = new ArrayList<>(); + int l = str.length(); + int j = 0; + for (int i = 0; i <= l; i++) + if (i == l || str.charAt(i) == c) { + strs.add(str.substring(j, i)); + j = i + 1; + } + return strs.toArray(new String[0]); + } + + static String[] split2(String str, char c) { + ArrayList strs = new ArrayList<>(); + int l = str.length(); + int j = 0; + for (int i = 0; i <= l; i++) + if (i == l || str.charAt(i) == c) { + String t = str.substring(j, i).trim(); + j = i + 1; + if (t.isEmpty() || t.charAt(0) == '#') + continue; + strs.add(t); + } + return strs.toArray(new String[0]); + } +} diff --git a/src/main/java/mods/tesseract/underworld/world/WorldGenMinableUnderworld.java b/src/main/java/mods/tesseract/underworld/world/WorldGenMinableUnderworld.java index c5187de..24dc662 100644 --- a/src/main/java/mods/tesseract/underworld/world/WorldGenMinableUnderworld.java +++ b/src/main/java/mods/tesseract/underworld/world/WorldGenMinableUnderworld.java @@ -1,22 +1,51 @@ package mods.tesseract.underworld.world; +import cpw.mods.fml.common.registry.GameRegistry; +import mods.tesseract.underworld.config.IConfigCSV; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.gen.feature.WorldGenerator; import java.util.Random; -public class WorldGenMinableUnderworld extends WorldGenerator { +public class WorldGenMinableUnderworld extends WorldGenerator implements IConfigCSV { + public static final String[] types = {"oreDict", "block", "blockMeta", "veinSize", "minY", "maxY", "blockToReplace", "sizeIncreasesWithDepth"}; + public String oreDict; public Block minableBlock; public int blockMetadata; - public int numberOfBlocks; - public int maxY; + public int veinSize; public int minY; + public int maxY; public Block blockToReplace; public boolean sizeIncreasesWithDepth; + @Override + public String[] getTypes() { + return types; + } + + @Override + public String toCSV() { + return null; + } + + @Override + public IConfigCSV parseCSV(String[] csv) { + this.oreDict = csv[0]; + String[] b = IConfigCSV.split(csv[1], ':'); + this.minableBlock = GameRegistry.findBlock(b[0], b[1]); + this.blockMetadata = Integer.parseInt(csv[2]); + this.veinSize = Integer.parseInt(csv[3]); + this.minY = Integer.parseInt(csv[4]); + this.maxY = Integer.parseInt(csv[5]); + b = IConfigCSV.split(csv[6], ':'); + this.blockToReplace = GameRegistry.findBlock(b[0], b[1]); + this.sizeIncreasesWithDepth = Boolean.parseBoolean(csv[7]); + return this; + } + + /* public WorldGenMinableUnderworld(Block block, int size, boolean increase) { this(block, 0, size, Blocks.stone, 255, 0, increase); } @@ -28,25 +57,20 @@ public WorldGenMinableUnderworld(Block block, int size) { public WorldGenMinableUnderworld(Block block, int meta, int size, Block base, int max, int min, boolean increase) { this.minableBlock = block; this.blockMetadata = meta; - this.numberOfBlocks = size; + this.veinSize = size; this.blockToReplace = base; this.maxY = max; this.minY = min; this.sizeIncreasesWithDepth = increase; } +*/ - public int growVein(World world, Random rand, int blocks_to_grow, int x, int y, int z, boolean must_be_supported, boolean is_dirt) { + public int growVein(World world, Random rand, int blocks_to_grow, int x, int y, int z, boolean must_be_supported) { if (blocks_to_grow >= 1 && world.blockExists(x, y, z) && world.getBlock(x, y, z) == this.blockToReplace) { if (must_be_supported && (y < 1 || world.getBlock(x, y - 1, z).getMaterial().isReplaceable())) { return 0; } else { - if (is_dirt && world.canBlockSeeTheSky(x, y + 1, z)) { - BiomeGenBase biome = world.getBiomeGenForCoords(x, z); - world.setBlock(x, y, z, biome != BiomeGenBase.desert && biome != BiomeGenBase.desertHills ? Blocks.grass : Blocks.sand, 0, 2); - } else { world.setBlock(x, y, z, this.minableBlock, this.blockMetadata, 2); - } - int ore_blocks_grown = 1; for (int attempts = 0; attempts < 16; ++attempts) { @@ -62,7 +86,7 @@ public int growVein(World world, Random rand, int blocks_to_grow, int x, int y, dz = rand.nextInt(2) == 0 ? -1 : 1; } - ore_blocks_grown += this.growVein(world, rand, blocks_to_grow - ore_blocks_grown, x + dx, y + dy, z + dz, must_be_supported, is_dirt); + ore_blocks_grown += this.growVein(world, rand, blocks_to_grow - ore_blocks_grown, x + dx, y + dy, z + dz, must_be_supported); if (ore_blocks_grown == blocks_to_grow) { break; } @@ -78,7 +102,7 @@ public int growVein(World world, Random rand, int blocks_to_grow, int x, int y, @Override public boolean generate(World world, Random rand, int x, int y, int z) { if (world.blockExists(x, y, z) && world.getBlock(x, y, z) == this.blockToReplace) { - int vein_size = this.numberOfBlocks; + int vein_size = this.veinSize; float scale = 1.0F; while (rand.nextInt(2) == 0) { @@ -120,8 +144,7 @@ public boolean generate(World world, Random rand, int x, int y, int z) { } boolean must_be_supported = this.minableBlock == Blocks.gravel; - boolean is_dirt = this.minableBlock == Blocks.dirt; - this.growVein(world, rand, vein_size, x, y, z, must_be_supported, is_dirt); + this.growVein(world, rand, vein_size, x, y, z, must_be_supported); return true; } } else { @@ -131,7 +154,7 @@ public boolean generate(World world, Random rand, int x, int y, int z) { public int getRandomVeinHeight(World world, Random rand) { - int y = minY + rand.nextInt(maxY); - return rand.nextFloat() < 0.75f ? y / 2 : y; + int y = rand.nextInt(maxY - minY); + return minY + rand.nextFloat() < 0.75f ? y / 2 : y; } }