diff --git a/common/MysticRuins/Config.java b/common/MysticRuins/Config.java index 5d98579..8e30b1a 100644 --- a/common/MysticRuins/Config.java +++ b/common/MysticRuins/Config.java @@ -4,15 +4,18 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Random; import java.util.Set; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; 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; +import net.minecraftforge.common.DungeonHooks.DungeonMob; public class Config { public static Configuration config; @@ -21,7 +24,11 @@ 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 List dungeonMobs = new ArrayList(); + public static final String commonItems = Item.pickaxeIron.itemID + "," + Item.axeIron.itemID + "," + Item.swordIron.itemID + "," + Item.shovelIron.itemID + "," + Item.ingotGold.itemID + "," + + Item.ingotIron.itemID; + public static final String rareItems = Item.enderPearl.itemID + ":4," + Item.diamond.itemID + "," + Item.emerald.itemID + "," + Item.appleGold.itemID + "," + Item.ingotGold.itemID + "," + + Item.ingotIron.itemID; public static void addDungeonMob(String name, int rarity) { for (DungeonMob mob : dungeonMobs) { @@ -44,7 +51,7 @@ public class Config { 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[] mobs = config.get("DungeonMobs", "Spawner Type & Relative Chance", "Skeleton-50,Spider-50,Zombie-20,Cavepider-10,Blaze-1", "MobName-RelativeWeight").getString().split(","); String[] mob; for (String txt : mobs) { mob = txt.split("-"); @@ -55,6 +62,8 @@ public class Config { } } } + setChest("Common Items", commonItems, ChestFiller.valuables); + setChest("Rare Items", rareItems, ChestFiller.rares); StringBuilder build = new StringBuilder("Available biome tags are: "); for (Type t : Type.values()) { build.append(t); @@ -115,4 +124,31 @@ public class Config { } config.save(); } + + private static void setChest(String type, String list, List valuables) { + String[] items = config.get("Chests", type, list, "itemid:stacksize:damage").getString().split(","); + String[] item; + for (String txt : items) { + item = txt.split(":"); + int id = -1, amount = 1, data = 0; + try { + switch (item.length) { + case 3: + data = Integer.parseInt(item[2]); + case 2: + amount = Integer.parseInt(item[1]); + case 1: + id = Integer.parseInt(item[0]); + break; + default: + continue; + } + } catch (NumberFormatException n) { + continue; + } + if (id > 0 && amount > 0 && data >= 0) { + valuables.add(new ItemStack(id, amount, data)); + } + } + } } \ No newline at end of file diff --git a/common/mysticruins/ChestFiller.java b/common/mysticruins/ChestFiller.java index 372a79a..3849e6e 100644 --- a/common/mysticruins/ChestFiller.java +++ b/common/mysticruins/ChestFiller.java @@ -1,66 +1,34 @@ package mysticruins; +import java.util.ArrayList; +import java.util.List; import java.util.Random; import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; public class ChestFiller { + public static List rares = new ArrayList(); + public static List valuables = new ArrayList(); + public static void fillWithRares(TileEntity tile) { - if (tile instanceof IInventory) { - IInventory chest = (IInventory) tile; - Random rand = new Random(); - int num; - for (int slot = 0; slot < chest.getSizeInventory(); slot++) { - num = rand.nextInt(16); - if (num == 1) { - chest.setInventorySlotContents(slot, new ItemStack(Item.enderPearl, 4, 0)); - } - if (num == 2) { - chest.setInventorySlotContents(slot, new ItemStack(Item.diamond, 1, 0)); - } - if (num == 3) { - chest.setInventorySlotContents(slot, new ItemStack(Item.emerald, 1, 0)); - } - if (num == 4) { - chest.setInventorySlotContents(slot, new ItemStack(Item.appleGold, 1, 0)); - } - if (num == 5) { - chest.setInventorySlotContents(slot, new ItemStack(Item.ingotGold, 1, 0)); - } - if (num == 6) { - chest.setInventorySlotContents(slot, new ItemStack(Item.ingotIron, 1, 0)); - } - } - } + fill(tile, rares, 2.5D); } public static void fillWithValuables(TileEntity tile) { + fill(tile, valuables, 5D); + } + + private static void fill(TileEntity tile, List stacks, double factor) { if (tile instanceof IInventory) { IInventory chest = (IInventory) tile; Random rand = new Random(); int num; for (int slot = 0; slot < chest.getSizeInventory(); slot++) { - num = rand.nextInt(32); - if (num == 1) { - chest.setInventorySlotContents(slot, new ItemStack(Item.pickaxeIron, 1, 0)); - } - if (num == 2) { - chest.setInventorySlotContents(slot, new ItemStack(Item.axeIron, 1, 0)); - } - if (num == 3) { - chest.setInventorySlotContents(slot, new ItemStack(Item.swordIron, 1, 0)); - } - if (num == 4) { - chest.setInventorySlotContents(slot, new ItemStack(Item.shovelIron, 1, 0)); - } - if (num == 5) { - chest.setInventorySlotContents(slot, new ItemStack(Item.ingotGold, 1, 0)); - } - if (num == 6) { - chest.setInventorySlotContents(slot, new ItemStack(Item.ingotIron, 1, 0)); + num = rand.nextInt((int) (stacks.size() * factor)); + if (num < stacks.size()) { + chest.setInventorySlotContents(slot, stacks.get(num)); } } }