diff --git a/common/MysticRuins/Config.java b/common/MysticRuins/Config.java index 8a4353f..5d98579 100644 --- a/common/MysticRuins/Config.java +++ b/common/MysticRuins/Config.java @@ -1,13 +1,17 @@ package mysticruins; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.Random; import java.util.Set; +import net.minecraft.util.WeightedRandom; import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.BiomeDictionary.Type; +import net.minecraftforge.common.DungeonHooks.DungeonMob; import net.minecraftforge.common.Configuration; public class Config { @@ -17,10 +21,40 @@ public class Config { public static Set[] allowId = new HashSet[4]; public static final String[] allows = { "Ruin allowed dimension id", "Dungeon allowed dimension id", "Ruin allowed biome id", "Dungeon allowed biome id" }; public static Set[] allowType = new HashSet[2]; + public static ArrayList dungeonMobs = new ArrayList(); + + public static void addDungeonMob(String name, int rarity) { + for (DungeonMob mob : dungeonMobs) { + if (name.equals(mob.type)) { + mob.itemWeight += rarity; + return; + } + } + dungeonMobs.add(new DungeonMob(rarity, name)); + } + + public static String getRandomDungeonMob(Random rand) { + DungeonMob mob = (DungeonMob) WeightedRandom.getRandomItem(rand, dungeonMobs); + if (mob == null) { + return ""; + } + return mob.type; + } public static void initialize(File file) { config = new Configuration(file); config.load(); + String[] mobs = config.get("DungeonMobs", "Spawner Type & Relative Chance", "Skeleton-50,Spider-50,Zombie-20,Cavepider-10,Blaze-1").getString().split(","); + String[] mob; + for (String txt : mobs) { + mob = txt.split("-"); + if (mob.length == 2) { + try { + addDungeonMob(mob[0].trim(), Integer.parseInt(mob[1].trim())); + } catch (NumberFormatException e) { + } + } + } StringBuilder build = new StringBuilder("Available biome tags are: "); for (Type t : Type.values()) { build.append(t); diff --git a/common/MysticRuins/StructureMysticDungeon.java b/common/MysticRuins/StructureMysticDungeon.java index 8400adb..dd83609 100644 --- a/common/MysticRuins/StructureMysticDungeon.java +++ b/common/MysticRuins/StructureMysticDungeon.java @@ -393,14 +393,14 @@ public class StructureMysticDungeon extends WorldGenerator { world.setBlock(j1, k1 + 1, l1 + 1, Block.mobSpawner.blockID); TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getBlockTileEntity(j1, k1 + 1, l1 + 1); if (spawner != null) { - spawner.getSpawnerLogic().setMobID("Zombie"); + spawner.getSpawnerLogic().setMobID(Config.getRandomDungeonMob(random)); } world.setBlock(j1, k1 + 2, l1 + 1, Block.chest.blockID); ChestFiller.fillWithRares(world.getBlockTileEntity(j1, k1 + 2, l1 + 1)); world.setBlock(j1, k1 + 3, l1 + 1, Block.mobSpawner.blockID); - TileEntityMobSpawner spawnerII = (TileEntityMobSpawner) world.getBlockTileEntity(j1, k1 + 3, l1 + 1); - if (spawnerII != null) { - spawnerII.getSpawnerLogic().setMobID("CaveSpider"); + spawner = (TileEntityMobSpawner) world.getBlockTileEntity(j1, k1 + 3, l1 + 1); + if (spawner != null) { + spawner.getSpawnerLogic().setMobID(Config.getRandomDungeonMob(random)); } world.setBlock(j1, k1 + 1, l1 + 2, 0); world.setBlock(j1, k1 + 2, l1 + 2, 0); @@ -444,7 +444,7 @@ public class StructureMysticDungeon extends WorldGenerator { world.setBlock(j1, k1 + 1, l1 + 3, Block.mobSpawner.blockID); TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getBlockTileEntity(j1, k1 + 1, l1 + 3); if (spawner != null) { - spawner.getSpawnerLogic().setMobID("Creeper"); + spawner.getSpawnerLogic().setMobID(Config.getRandomDungeonMob(random)); } } } @@ -477,7 +477,7 @@ public class StructureMysticDungeon extends WorldGenerator { world.setBlock(j1, k1 + 2, l1 + 2, Block.mobSpawner.blockID); TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getBlockTileEntity(j1, k1 + 2, l1 + 2); if (spawner != null) { - spawner.getSpawnerLogic().setMobID("Skeleton"); + spawner.getSpawnerLogic().setMobID(Config.getRandomDungeonMob(random)); } world.setBlock(j1, k1 + 3, l1 + 2, Block.bookShelf.blockID); world.setBlock(j1, k1 + 1, l1 + 3, Block.bookShelf.blockID); @@ -523,7 +523,7 @@ public class StructureMysticDungeon extends WorldGenerator { world.setBlock(j1, k1 + 1, l1 + 2, Block.mobSpawner.blockID); TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getBlockTileEntity(j1, k1 + 1, l1 + 2); if (spawner != null) { - spawner.getSpawnerLogic().setMobID("Blaze"); + spawner.getSpawnerLogic().setMobID(Config.getRandomDungeonMob(random)); } world.setBlock(j1, k1 + 1, l1 + 3, Block.blockGold.blockID); } @@ -573,7 +573,7 @@ public class StructureMysticDungeon extends WorldGenerator { world.setBlock(j1, k1 + 2, l1 - 1, Block.mobSpawner.blockID); TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getBlockTileEntity(j1, k1 + 2, l1 - 1); if (spawner != null) { - spawner.getSpawnerLogic().setMobID("Zombie"); + spawner.getSpawnerLogic().setMobID(Config.getRandomDungeonMob(random)); } world.setBlock(j1, k1 + 1, l1 - 2, 0); world.setBlock(j1, k1 + 2, l1 - 2, 0); @@ -1808,7 +1808,7 @@ public class StructureMysticDungeon extends WorldGenerator { world.setBlock(j1 - 4, k1 - 10, l1, Block.mobSpawner.blockID); TileEntityMobSpawner spawner = (TileEntityMobSpawner) world.getBlockTileEntity(j1 - 4, k1 - 10, l1); if (spawner != null) { - spawner.getSpawnerLogic().setMobID("Zombie"); + spawner.getSpawnerLogic().setMobID(Config.getRandomDungeonMob(random)); } world.setBlock(j1 - 8, k1 - 10, l1, Block.stoneSingleSlab.blockID); world.setBlock(j1 - 8, k1 - 10, l1 + 1, Block.stoneSingleSlab.blockID);