summaryrefslogtreecommitdiff
path: root/TF2 Crates/src/main/java/tf2crates/crate
diff options
context:
space:
mode:
Diffstat (limited to 'TF2 Crates/src/main/java/tf2crates/crate')
-rwxr-xr-xTF2 Crates/src/main/java/tf2crates/crate/Crates.java313
-rwxr-xr-xTF2 Crates/src/main/java/tf2crates/crate/RandomLoot.java1065
-rwxr-xr-xTF2 Crates/src/main/java/tf2crates/crate/RandomRandomLoot.java158
-rwxr-xr-xTF2 Crates/src/main/java/tf2crates/crate/RandomTinkersTool.java143
4 files changed, 1679 insertions, 0 deletions
diff --git a/TF2 Crates/src/main/java/tf2crates/crate/Crates.java b/TF2 Crates/src/main/java/tf2crates/crate/Crates.java
new file mode 100755
index 0000000..542b88a
--- /dev/null
+++ b/TF2 Crates/src/main/java/tf2crates/crate/Crates.java
@@ -0,0 +1,313 @@
+package tf2crates.crate;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
+import net.minecraft.item.Item;
+import net.minecraft.item.Item.ToolMaterial;
+import net.minecraft.item.ItemArmor.ArmorMaterial;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.StatCollector;
+import tf2crates.ServerProxyTC;
+import tlhpoeCore.ReferenceT;
+import tlhpoeCore.util.MathUtil;
+
+public class Crates {
+ public static final Map<Integer,
+ Object[]> CRATE_LOOT = new HashMap<
+ Integer, Object[]>();
+ public static final Map<String,
+ Integer> SPECIAL_CRATES = new HashMap<
+ String, Integer>();
+ public static final Map<Integer,
+ String> SCRATES_REVERSE = new HashMap<
+ Integer, String>();
+
+ public static void init() {
+ addNormalCrates();
+
+ addSpecialCrates();
+
+ List<Integer> IDs = new ArrayList<Integer>();
+ List<String> names = new ArrayList<String>();
+
+ IDs.addAll(SPECIAL_CRATES.values());
+ names.addAll(SPECIAL_CRATES.keySet());
+
+ for (int i = 0; i < SPECIAL_CRATES.size(); i++) {
+ SCRATES_REVERSE.put(IDs.get(i), names.get(i));
+ }
+
+ if (ReferenceT.DEOBFUSCATED) {
+ for (int i = 1; i < getNumberOfSeries() + 1; i++) {
+ Object[] lootItems = getLootForCrate(i);
+
+ if (SPECIAL_CRATES.containsValue(i)) {
+ System.out.println("* '''"
+ + StatCollector.translateToLocal("crate."
+ + SCRATES_REVERSE.get(i) + ".name")
+ + "''' <br />");
+ } else {
+ System.out.println(
+ "* '''Crate Series #" + i + "''' <br />");
+ }
+
+ for (int j = 0; j < lootItems.length; j++) {
+ Object loot = lootItems[j];
+ String name = null;
+
+ if (loot instanceof ItemStack) {
+ name = ((ItemStack) loot).getDisplayName();
+ } else if (loot instanceof RandomLoot) {
+ name = ((RandomLoot) loot).getDisplayName();
+ }
+
+ System.out.println("** " + name + " <br />");
+ }
+
+ System.out
+ .println("** or an Exceedingly Rare Special Item!"
+ + " <br /> <br />");
+ System.out.println(" ");
+ }
+ }
+ }
+
+ private static void addSpecialCrates() {
+ addSpecialCrateLoot("spookyCrate",
+ new ItemStack(ServerProxyTC.noiseMakerSpooky, 1),
+ new RandomLoot.SpecificItem(Items.emerald, 8, 16),
+ new RandomLoot.SpecificItem(Items.diamond, 8, 16),
+ new RandomLoot.SpecificItem(Items.gold_ingot, 16, 32),
+ new RandomLoot.SpecificItem(Items.iron_ingot, 32, 64),
+ new RandomLoot.SpecificItem(Items.cookie, 48, 64));
+
+ addSpecialCrateLoot("festiveCrate",
+ new ItemStack(ServerProxyTC.noiseMakerFestive, 1),
+ new RandomLoot.SpecificItem(Items.emerald, 8, 16),
+ new RandomLoot.SpecificItem(Items.diamond, 8, 16),
+ new RandomLoot.SpecificItem(Items.gold_ingot, 16, 32),
+ new RandomLoot.SpecificItem(Items.iron_ingot, 32, 64),
+ new RandomLoot.SpecificItem(Items.experience_bottle, 48,
+ 64));
+
+ addSpecialCrateLoot("birthdayCrate",
+ new ItemStack(ServerProxyTC.noiseMakerBirthday, 1),
+ new RandomLoot.SpecificItem(Items.emerald, 8, 16),
+ new RandomLoot.SpecificItem(Items.diamond, 8, 16),
+ new RandomLoot.SpecificItem(Items.gold_ingot, 16, 32),
+ new RandomLoot.SpecificItem(Items.iron_ingot, 32, 64),
+ new RandomLoot.SpecificItem(Items.cake, 16, 64));
+ }
+
+ private static void addNormalCrates() {
+ addCrateLoot(new ItemStack(Items.name_tag, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 0),
+ new ItemStack(ServerProxyTC.paint, 1, 15),
+ new RandomLoot.Pickaxe(true));
+
+ addCrateLoot(new RandomLoot.Pickaxe(true),
+ new RandomLoot.Sword(true), new RandomLoot.EnchantedBook(),
+ new RandomLoot.Food());
+
+ addCrateLoot(new RandomLoot.Food(), new RandomLoot.Potion(),
+ new RandomLoot.Chestplate(false),
+ new RandomLoot.Boot(false));
+
+ addCrateLoot(new ItemStack(Items.nether_wart, 32),
+ new RandomLoot.SpecificItem(Items.blaze_rod, 16, 32),
+ new RandomLoot.SpecificItem(Items.ghast_tear, 8, 16),
+ new RandomLoot.SpecificItem(
+ Item.getItemFromBlock(Blocks.enchanting_table), 2,
+ 4),
+ new RandomLoot.SpecificItem(
+ Item.getItemFromBlock(Blocks.beacon), 2, 4));
+
+ addCrateLoot(new ItemStack(Items.name_tag, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 7),
+ new ItemStack(ServerProxyTC.paint, 1, 8),
+ new RandomLoot.Hoe(true));
+
+ addCrateLoot(new RandomLoot.Food(), new RandomLoot.Potion(),
+ new RandomLoot.Axe(false), new RandomLoot.Sword(false));
+
+ addCrateLoot(new ItemStack(Items.name_tag, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 14),
+ new RandomLoot.Shovel(true));
+
+ addCrateLoot(new RandomLoot.Shovel(true), new RandomLoot.Axe(true),
+ new RandomLoot.EnchantedBook(), new RandomLoot.Food());
+
+ addCrateLoot(new RandomLoot.Pickaxe(false),
+ new RandomLoot.Shovel(false), new RandomLoot.Axe(false),
+ new RandomLoot.Sword(false), new RandomLoot.Hoe(false));
+
+ addCrateLoot(new ItemStack(Items.name_tag, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 5),
+ new ItemStack(ServerProxyTC.paint, 1, 10),
+ new RandomLoot.Shovel(true));
+
+ addCrateLoot(new ItemStack(ServerProxyTC.paint, 1, 12),
+ new RandomLoot.CertainMaterialArmor(ArmorMaterial.DIAMOND,
+ true),
+ new RandomLoot.CertainMaterialTool(ToolMaterial.EMERALD,
+ true));
+
+ addCrateLoot(new RandomLoot.Helmet(true),
+ new RandomLoot.Legging(true),
+ new RandomLoot.EnchantedBook(), new RandomLoot.Food());
+
+ addCrateLoot(
+ new RandomLoot.SpecificItem(Items.carrot_on_a_stick, 1, 4),
+ new RandomLoot.SpecificItem(Items.bone, 32, 64),
+ new RandomLoot.Food(),
+ new RandomLoot.SpecificItem(Items.nether_star, 1, 4),
+ new RandomLoot.Pickaxe(true));
+
+ addCrateLoot(new ItemStack(Items.name_tag, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 2),
+ new ItemStack(ServerProxyTC.paint, 1, 13),
+ new RandomLoot.Sword(true));
+
+ addCrateLoot(new RandomLoot.Food(), new RandomLoot.SplashPotion(),
+ new RandomLoot.Shovel(false),
+ new RandomLoot.Pickaxe(false));
+
+ addCrateLoot(new ItemStack(Items.name_tag, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 3),
+ new ItemStack(ServerProxyTC.paint, 1, 12),
+ new RandomLoot.Axe(true));
+
+ addCrateLoot(new RandomLoot.Helmet(false),
+ new RandomLoot.Legging(false), new RandomLoot.Boot(false),
+ new RandomLoot.Axe(false), new RandomLoot.Hoe(false));
+
+ addCrateLoot(new ItemStack(ServerProxyTC.paint, 1, 11),
+ new RandomLoot.CertainMaterialArmor(ArmorMaterial.GOLD,
+ true),
+ new RandomLoot.CertainMaterialTool(ToolMaterial.GOLD,
+ true));
+
+ addCrateLoot(new RandomLoot.Chestplate(true),
+ new RandomLoot.Boot(true), new RandomLoot.Shovel(true),
+ new RandomLoot.Axe(true));
+
+ addCrateLoot(new RandomLoot.Hoe(true), new RandomLoot.Axe(true),
+ new RandomLoot.EnchantedBook(), new RandomLoot.Food());
+
+ addCrateLoot(new ItemStack(Items.name_tag, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 6),
+ new ItemStack(ServerProxyTC.paint, 1, 9),
+ new RandomLoot.Pickaxe(true));
+
+ addCrateLoot(new RandomLoot.Chestplate(false),
+ new RandomLoot.Pickaxe(false), new RandomLoot.Sword(true),
+ new RandomLoot.Food(), new RandomLoot.Boot(true));
+
+ addCrateLoot(new RandomLoot.Food(), new RandomLoot.SplashPotion(),
+ new RandomLoot.Helmet(true), new RandomLoot.Legging(true),
+ new RandomLoot.Chestplate(false));
+
+ addCrateLoot(new RandomLoot.Chestplate(true),
+ new RandomLoot.Boot(true), new RandomLoot.EnchantedBook(),
+ new RandomLoot.Food());
+
+ addCrateLoot(new ItemStack(Items.name_tag, 1),
+ new ItemStack(ServerProxyTC.paint, 1, 4),
+ new ItemStack(ServerProxyTC.paint, 1, 11),
+ new RandomLoot.Sword(true));
+
+ addCrateLoot(new RandomLoot.Helmet(false),
+ new RandomLoot.Chestplate(false),
+ new RandomLoot.Legging(false), new RandomLoot.Boot(false));
+
+ addCrateLoot(new RandomLoot.Paint(), new RandomLoot.Potion(),
+ new RandomLoot.SplashPotion(), new RandomLoot.Food());
+
+ addCrateLoot(new ItemStack(ServerProxyTC.paint, 1, 7),
+ new RandomLoot.CertainMaterialArmor(ArmorMaterial.IRON,
+ true),
+ new RandomLoot.CertainMaterialTool(ToolMaterial.IRON,
+ true));
+
+ addCrateLoot(new RandomLoot.Helmet(true),
+ new RandomLoot.Legging(true), new RandomLoot.Pickaxe(true),
+ new RandomLoot.Sword(true));
+
+ addCrateLoot(new RandomLoot.EnchantedBook(), new RandomLoot.Food(),
+ new RandomLoot.Paint(), new RandomLoot.FishingRod());
+
+ addCrateLoot(new RandomLoot.Bow(true), new RandomLoot.Arrow(),
+ new RandomLoot.FishingRod(),
+ new RandomLoot.SplashPotion());
+
+ addCrateLoot(new RandomLoot.SpecificItem(Items.dye, 16, 32, 15),
+ new RandomLoot.Hoe(true), new RandomLoot.Seed(),
+ new RandomLoot.Saplings());
+
+ addCrateLoot(new RandomLoot.Amulet(), new RandomLoot.Belt(),
+ new RandomLoot.Ring());
+
+ // Add in random random crates - per MC load
+ for (int i = 0; i < ServerProxyTC.numRandomCrates; i++) {
+ int numInCrate = MathUtil.getRandomIntegerBetween(0, 2) + 3;
+
+ List<RandomLoot> crateContents = new ArrayList<RandomLoot>(numInCrate);
+
+ for (int j = 0; j < numInCrate; j++) {
+ RandomLoot possibleLoot = RandomRandomLoot.getRandomLoot();
+
+ while (crateContents.contains(possibleLoot)) {
+ possibleLoot = RandomRandomLoot.getRandomLoot();
+ }
+
+ crateContents.add(possibleLoot);
+ }
+
+ CRATE_LOOT.put(CRATE_LOOT.size() + 1, crateContents.toArray());
+ }
+ }
+
+ private static void addCrateLoot(Object... lootItems) {
+ CRATE_LOOT.put(CRATE_LOOT.size() + 1, lootItems);
+ }
+
+ public static Object[] getLootForCrate(int series) {
+ return CRATE_LOOT.get(series);
+ }
+
+ public static int getNumberOfSeries() {
+ return CRATE_LOOT.size();
+ }
+
+ private static void addSpecialCrateLoot(String name,
+ Object... lootItems) {
+ addCrateLoot(lootItems);
+ SPECIAL_CRATES.put(name, CRATE_LOOT.size());
+ }
+
+ public static Object[] getLootForSpecialCreate(String crateName) {
+ return CRATE_LOOT.get(SPECIAL_CRATES.get(crateName));
+ }
+
+ public static String getNameFromSeries(int series) {
+ return SCRATES_REVERSE.get(series);
+ }
+
+ public static boolean isSeriesSpecial(int series) {
+ return SPECIAL_CRATES.containsValue(series);
+ }
+
+ public static int getNumberOfSpecialCrates() {
+ return SPECIAL_CRATES.size();
+ }
+
+ public static int getSeriesFromName(String name) {
+ return SPECIAL_CRATES.get(name);
+ }
+} \ No newline at end of file
diff --git a/TF2 Crates/src/main/java/tf2crates/crate/RandomLoot.java b/TF2 Crates/src/main/java/tf2crates/crate/RandomLoot.java
new file mode 100755
index 0000000..ee7ef5a
--- /dev/null
+++ b/TF2 Crates/src/main/java/tf2crates/crate/RandomLoot.java
@@ -0,0 +1,1065 @@
+package tf2crates.crate;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.enchantment.EnchantmentData;
+import net.minecraft.enchantment.EnchantmentHelper;
+import net.minecraft.init.Items;
+import net.minecraft.item.Item;
+import net.minecraft.item.Item.ToolMaterial;
+import net.minecraft.item.ItemArmor.ArmorMaterial;
+import net.minecraft.item.ItemStack;
+import tf2crates.ServerProxyTC;
+import tf2crates.item.ItemPaint;
+import tlhpoeCore.util.MathUtil;
+
+public abstract class RandomLoot {
+ private static int nextID = 0;
+ private int ID;
+
+ private List<Item> possibleLoot;
+ protected boolean enchanted;
+ public int min = 1, max = 1;
+
+ protected RandomLoot(List<Item> possibleLoot, boolean enchanted) {
+ this.possibleLoot = possibleLoot;
+ this.enchanted = enchanted;
+
+ ID = nextID++;
+ }
+
+ public ItemStack getLoot() {
+ ItemStack loot = new ItemStack(
+ possibleLoot.get(MathUtil.nextInt(possibleLoot.size())),
+ MathUtil.getRandomIntegerBetween(min, max));
+
+ if (enchanted) {
+ EnchantmentHelper.addRandomEnchantment(MathUtil.getRandom(),
+ loot, MathUtil.getRandomIntegerBetween(25, 30));
+ }
+
+ return loot;
+ }
+
+ public abstract String getDisplayName();
+
+ public int getID() {
+ return ID;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ID;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ RandomLoot other = (RandomLoot) obj;
+
+ if (ID != other.ID) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public static class SpecificItem extends RandomLoot {
+ private ItemStack itemStack;
+ private Item item;
+ private int meta = -1;
+
+ public SpecificItem(Item item, int min, int max) {
+ super(null, false);
+
+ this.itemStack = new ItemStack(item, 1);
+ this.item = item;
+ this.min = min;
+ this.max = max;
+ }
+
+ public SpecificItem(Item item, int min, int max, int meta) {
+ this(item, min, max);
+
+ this.meta = meta;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return min != max ? (min + " to " + max + " "
+ + itemStack.getDisplayName() + (min > 1 ? "s" : ""))
+ : ((min > 1 ? (min + " ") : "A ")
+ + itemStack.getDisplayName()
+ + (min > 1 ? "s" : ""));
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ return new ItemStack(item,
+ MathUtil.getRandomIntegerBetween(min, max), meta);
+ }
+ }
+
+ public static class Pickaxe extends RandomLoot {
+ public Pickaxe(boolean enchanted) {
+ super(PICKAXES, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "An Enchanted Random Pickaxe"
+ : "A Random Pickaxe";
+ }
+ }
+
+ public static class Shovel extends RandomLoot {
+ public Shovel(boolean enchanted) {
+ super(SHOVELS, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "An Enchanted Random Shovel"
+ : "A Random Shovel";
+ }
+ }
+
+ public static class Axe extends RandomLoot {
+ public Axe(boolean enchanted) {
+ super(AXES, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "An Enchanted Random Axe" : "A Random Axe";
+ }
+ }
+
+ public static class Hoe extends RandomLoot {
+ public Hoe(boolean enchanted) {
+ super(HOES, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "An Enchanted Random Hoe" : "A Random Hoe";
+ }
+ }
+
+ public static class ToolHead extends RandomLoot {
+ public ToolHead() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack head = TOOL_HEADS
+ .get(MathUtil.getRandomIntegerBetween(0,
+ RandomLoot.TOOL_HEADS.size()))
+ .copy();
+
+ return head;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "A Random Tool Head";
+ }
+
+ }
+
+ public static class Sword extends RandomLoot {
+ public Sword(boolean enchanted) {
+ super(SWORDS, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "An Enchanted Random Sword"
+ : "A Random Sword";
+ }
+ }
+
+ public static class Bow extends RandomLoot {
+ public Bow(boolean enchanted) {
+ super(BOWS, enchanted);
+
+ this.min = 1;
+ this.max = 1;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "An Enchanted Random Bow" : "A Random Bow";
+ }
+ }
+
+ public static class Seed extends RandomLoot {
+ public Seed() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack seedType = SEEDS
+ .get(MathUtil.getRandomIntegerBetween(0, SEEDS.size()))
+ .copy();
+
+ seedType.stackSize = MathUtil.getRandomIntegerBetween(16, 32);
+
+ return seedType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 32 Seeds of a Random Type";
+ }
+ }
+
+ public static class Saplings extends RandomLoot {
+ public Saplings() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack saplingType = SAPLINGS.get(
+ MathUtil.getRandomIntegerBetween(0, SAPLINGS.size()))
+ .copy();
+
+ saplingType.stackSize = MathUtil.getRandomIntegerBetween(16,
+ 32);
+
+ return saplingType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 32 Saplings of a Random Type";
+ }
+ }
+
+ public static class Arrow extends RandomLoot {
+ public Arrow() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack arrowType = ARROWS.get(
+ MathUtil.getRandomIntegerBetween(0, ARROWS.size()))
+ .copy();
+
+ arrowType.stackSize = MathUtil.getRandomIntegerBetween(16, 32);
+
+ return arrowType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 32 Arrows of a Random Type";
+ }
+ }
+
+ public static class Helmet extends RandomLoot {
+ public Helmet(boolean enchanted) {
+ super(HELMETS, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "An Enchanted Random Helmet"
+ : "A Random Helmet";
+ }
+ }
+
+ public static class Chestplate extends RandomLoot {
+ public Chestplate(boolean enchanted) {
+ super(CHESTPLATES, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "An Enchanted Random Chestplate"
+ : "A Random Chestplate";
+ }
+ }
+
+ public static class Legging extends RandomLoot {
+ public Legging(boolean enchanted) {
+ super(LEGGINGS, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "Enchanted Random Leggings"
+ : "Random Leggings";
+ }
+ }
+
+ public static class Boot extends RandomLoot {
+ public Boot(boolean enchanted) {
+ super(BOOTS, enchanted);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted ? "Enchanted Random Boots" : "Random Boots";
+ }
+ }
+
+ public static class Food extends RandomLoot {
+ public Food() {
+ super(FOOD, false);
+
+ this.min = 16;
+ this.max = 64;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 64 of a Random Food Item";
+ }
+ }
+
+ public static class Potion extends RandomLoot {
+ public Potion() {
+ super(null, false);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "4 to 16 of a Random Potion";
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack loot = POTIONS.get(MathUtil.nextInt(POTIONS.size()))
+ .copy();
+
+ loot.stackSize = MathUtil.getRandomIntegerBetween(4, 16);
+
+ return loot;
+ }
+ }
+
+ public static class SplashPotion extends RandomLoot {
+ public SplashPotion() {
+ super(null, false);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "4 to 16 of a Random Splash Potion";
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack loot = SPLASH_POTIONS
+ .get(MathUtil.nextInt(SPLASH_POTIONS.size())).copy();
+
+ loot.stackSize = MathUtil.getRandomIntegerBetween(4, 16);
+
+ return loot;
+ }
+ }
+
+ public static class CertainMaterialTool extends RandomLoot {
+ private ToolMaterial material;
+
+ public CertainMaterialTool(ToolMaterial material,
+ boolean enchanted) {
+ super(MATERIAL_TOOLS.get(material), enchanted);
+
+ this.material = material;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted
+ ? "Enchanted Random " + material.name() + " Tool"
+ : "Random " + material.name() + " Tool";
+ }
+ }
+
+ public static class CertainMaterialArmor extends RandomLoot {
+ private ArmorMaterial material;
+
+ public CertainMaterialArmor(ArmorMaterial material,
+ boolean enchanted) {
+ super(MATERIAL_ARMOR.get(material), enchanted);
+
+ this.material = material;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return enchanted
+ ? "Enchanted Random " + material.name() + " Armor"
+ : "Random " + material.name() + " Armor";
+ }
+ }
+
+ public static class Paint extends RandomLoot {
+ public Paint() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ int dmg = MathUtil.nextInt(ItemPaint.TYPES.length);
+
+ if (MathUtil.getChance(1, 50)) {
+ dmg = 11;
+ }
+
+ return new ItemStack(ServerProxyTC.paint, 1, dmg);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "A Random Paint";
+ }
+ }
+
+ public static class EnchantedBook extends RandomLoot {
+ public EnchantedBook() {
+ super(null, true);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack loot = new ItemStack(Items.enchanted_book,
+ MathUtil.getRandomIntegerBetween(2, 8));
+ Enchantment enchantment = Enchantment.enchantmentsBookList[MathUtil
+ .nextInt(Enchantment.enchantmentsBookList.length)];
+
+ Items.enchanted_book.addEnchantment(loot,
+ new EnchantmentData(enchantment,
+ MathUtil.getRandomIntegerBetween(
+ enchantment.getMinLevel(),
+ enchantment.getMaxLevel())));
+
+ return loot;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "2 to 8 Random Enchanted Books";
+ }
+ }
+
+ public static class FishingRod extends RandomLoot {
+ public FishingRod() {
+ super(null, true);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack loot = new ItemStack(Items.fishing_rod, 1);
+
+ EnchantmentHelper.addRandomEnchantment(MathUtil.getRandom(),
+ loot, 30);
+
+ return loot;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "A Randomly Enchanted Fishing Rod";
+ }
+ }
+
+ public static class Slab extends RandomLoot {
+ public Slab() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack slabType = SLABS
+ .get(MathUtil.getRandomIntegerBetween(0, SLABS.size()))
+ .copy();
+
+ slabType.stackSize = MathUtil.getRandomIntegerBetween(16, 64);
+
+ return slabType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 64 Slabs of a Random Type";
+ }
+ }
+
+ public static class Stair extends RandomLoot {
+ public Stair() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack stairType = STAIRS.get(
+ MathUtil.getRandomIntegerBetween(0, STAIRS.size()))
+ .copy();
+
+ stairType.stackSize = MathUtil.getRandomIntegerBetween(16, 64);
+
+ return stairType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 64 Stairs of a Random Type";
+ }
+ }
+
+ public static class Fence extends RandomLoot {
+ public Fence() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack fenceType = FENCES.get(
+ MathUtil.getRandomIntegerBetween(0, FENCES.size()))
+ .copy();
+
+ fenceType.stackSize = MathUtil.getRandomIntegerBetween(16, 64);
+
+ return fenceType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 64 Fences of a Random Type";
+ }
+ }
+
+ public static class Planks extends RandomLoot {
+ public Planks() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack plankType = PLANKS.get(
+ MathUtil.getRandomIntegerBetween(0, PLANKS.size()))
+ .copy();
+
+ plankType.stackSize = MathUtil.getRandomIntegerBetween(16, 64);
+
+ return plankType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 64 Planks of a Random Type";
+ }
+ }
+
+ public static class Logs extends RandomLoot {
+ public Logs() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack logType = LOGS
+ .get(MathUtil.getRandomIntegerBetween(0, LOGS.size()))
+ .copy();
+
+ logType.stackSize = MathUtil.getRandomIntegerBetween(16, 32);
+
+ return logType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 32 Logs of a Random Type";
+ }
+ }
+
+ public static class Crop extends RandomLoot {
+ public Crop() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack cropType = CROPS
+ .get(MathUtil.getRandomIntegerBetween(0, CROPS.size()))
+ .copy();
+
+ cropType.stackSize = MathUtil.getRandomIntegerBetween(16, 32);
+
+ return cropType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "8 to 16 Crops of a Random Type";
+ }
+ }
+
+ public static class Dye extends RandomLoot {
+ public Dye() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack dyeType = DYES
+ .get(MathUtil.getRandomIntegerBetween(0, DYES.size()))
+ .copy();
+
+ dyeType.stackSize = MathUtil.getRandomIntegerBetween(16, 32);
+
+ return dyeType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 32 Logs of a Random Type";
+ }
+ }
+
+ public static class Record extends RandomLoot {
+ public Record() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack dyeType = RECORDS.get(
+ MathUtil.getRandomIntegerBetween(0, RECORDS.size()))
+ .copy();
+
+ dyeType.stackSize = 1;
+
+ return dyeType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "A Random Record";
+ }
+ }
+
+ public static class Glass extends RandomLoot {
+ public Glass() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack glassType = GLASS.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.GLASS.size()))
+ .copy();
+
+ glassType.stackSize = MathUtil.getRandomIntegerBetween(32, 64);
+
+ return glassType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "32 to 64 Glass of a Random Type";
+ }
+ }
+
+ public static class Wool extends RandomLoot {
+ public Wool() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack woolType = WOOL.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.WOOL.size()))
+ .copy();
+
+ woolType.stackSize = MathUtil.getRandomIntegerBetween(8, 32);
+
+ return woolType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "8 to 32 Wool of a Random Type";
+ }
+ }
+
+ public static class Stone extends RandomLoot {
+ public Stone() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack stoneType = STONES.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.STONES.size()))
+ .copy();
+
+ stoneType.stackSize = MathUtil.getRandomIntegerBetween(16, 48);
+
+ return stoneType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 48 Stone of a Random Type";
+ }
+ }
+
+ public static class Dust extends RandomLoot {
+ public Dust() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack dustType = RandomLoot.DUSTS.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.DUSTS.size()))
+ .copy();
+
+ dustType.stackSize = MathUtil.getRandomIntegerBetween(8, 16);
+
+ return dustType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "8 to 16 Dust of a Random Type";
+ }
+ }
+
+ public static class Block extends RandomLoot {
+ public Block() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack blockType = RandomLoot.DUSTS.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.DUSTS.size()))
+ .copy();
+
+ blockType.stackSize = MathUtil.getRandomIntegerBetween(4, 8);
+
+ return blockType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "4 to 8 Random Blocks";
+ }
+ }
+
+ public static class Crate extends RandomLoot {
+ public Crate() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack crateType = RandomLoot.CRATES.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.CRATES.size()))
+ .copy();
+
+ crateType.stackSize = MathUtil.getRandomIntegerBetween(4, 8);
+
+ return crateType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "4 to 8 Storage Crates of a Random Type";
+ }
+ }
+
+ public static class Gem extends RandomLoot {
+ public Gem() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack gemType = RandomLoot.GEMS.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.GEMS.size()))
+ .copy();
+
+ gemType.stackSize = MathUtil.getRandomIntegerBetween(8, 16);
+
+ return gemType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "8 to 16 Gems of a Random Type";
+ }
+ }
+
+ public static class Ingot extends RandomLoot {
+ public Ingot() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack ingotType = RandomLoot.INGOTS.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.INGOTS.size()))
+ .copy();
+
+ ingotType.stackSize = MathUtil.getRandomIntegerBetween(16, 32);
+
+ return ingotType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 32 Ingots of a Random Type";
+ }
+ }
+
+ public static class Ore extends RandomLoot {
+ public Ore() {
+ super(null, false);
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ ItemStack oreType = RandomLoot.ORES.get(MathUtil
+ .getRandomIntegerBetween(0, RandomLoot.ORES.size()))
+ .copy();
+
+ oreType.stackSize = MathUtil.getRandomIntegerBetween(16, 32);
+
+ return oreType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "16 to 32 Ores of a Random Type";
+ }
+ }
+
+ public static class Belt extends RandomLoot {
+ public Belt() {
+ super(RandomLoot.BELTS, false);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "A Random Belt";
+ }
+
+ }
+
+ public static class Amulet extends RandomLoot {
+ public Amulet() {
+ super(RandomLoot.AMULETS, false);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "A Random Amulet";
+ }
+
+ }
+
+ public static class Ring extends RandomLoot {
+ public Ring() {
+ super(RandomLoot.RINGS, false);
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "A Random Ring";
+ }
+ }
+
+ /*
+ * Tool Loot
+ */
+ public static final List<
+ Item> PICKAXES = new ArrayList<
+ Item>();
+ public static final List<
+ Item> SHOVELS = new ArrayList<
+ Item>();
+ public static final List<
+ Item> AXES = new ArrayList<
+ Item>();
+ public static final List<
+ Item> HOES = new ArrayList<
+ Item>();
+ public static final List<
+ ItemStack> TOOL_HEADS = new ArrayList<
+ ItemStack>();
+
+ /*
+ * Weapon Loot
+ */
+ public static final List<
+ Item> SWORDS = new ArrayList<
+ Item>();
+ public static final List<
+ Item> BOWS = new ArrayList<
+ Item>();
+ public static final List<
+ ItemStack> ARROWS = new ArrayList<
+ ItemStack>();
+
+ /*
+ * Tool Material Loot
+ */
+ public static final Map<ToolMaterial,
+ ArrayList<
+ Item>> MATERIAL_TOOLS = new HashMap<
+ ToolMaterial, ArrayList<Item>>();
+
+ /*
+ * Armor Loot
+ */
+ public static final List<
+ Item> HELMETS = new ArrayList<
+ Item>();
+ public static final List<
+ Item> CHESTPLATES = new ArrayList<
+ Item>();
+ public static final List<
+ Item> LEGGINGS = new ArrayList<
+ Item>();
+ public static final List<
+ Item> BOOTS = new ArrayList<
+ Item>();
+
+ /*
+ * Armor Material Loot
+ */
+ public static final Map<ArmorMaterial,
+ ArrayList<
+ Item>> MATERIAL_ARMOR = new HashMap<
+ ArmorMaterial, ArrayList<Item>>();
+
+ /*
+ * Food Loot
+ */
+ public static final List<
+ Item> FOOD = new ArrayList<
+ Item>();
+ public static final List<
+ ItemStack> CROPS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> SEEDS = new ArrayList<
+ ItemStack>();
+
+ /*
+ * Potion Loot
+ */
+ public static final List<
+ ItemStack> POTIONS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> SPLASH_POTIONS = new ArrayList<
+ ItemStack>();
+
+ /*
+ * Resource Loot
+ */
+ public static final List<
+ ItemStack> DUSTS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> BLOCKS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> CRATES = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> GEMS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> INGOTS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> ORES = new ArrayList<
+ ItemStack>();
+
+ /*
+ * Decorative Loot
+ */
+ public static final List<
+ ItemStack> GLASS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> WOOL = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> DYES = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> FENCES = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> LOGS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> PLANKS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> RECORDS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> SLABS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> STAIRS = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> STONES = new ArrayList<
+ ItemStack>();
+ public static final List<
+ ItemStack> SAPLINGS = new ArrayList<
+ ItemStack>();
+
+ /*
+ * List of weapons
+ */
+ public static final List<
+ Item> WEAPONS = new ArrayList<
+ Item>();
+
+ /*
+ * List of baubles
+ */
+ public static final List<
+ Item> BELTS = new ArrayList<
+ Item>();
+ public static final List<
+ Item> AMULETS = new ArrayList<
+ Item>();
+ public static final List<
+ Item> RINGS = new ArrayList<
+ Item>();
+} \ No newline at end of file
diff --git a/TF2 Crates/src/main/java/tf2crates/crate/RandomRandomLoot.java b/TF2 Crates/src/main/java/tf2crates/crate/RandomRandomLoot.java
new file mode 100755
index 0000000..f8f184d
--- /dev/null
+++ b/TF2 Crates/src/main/java/tf2crates/crate/RandomRandomLoot.java
@@ -0,0 +1,158 @@
+package tf2crates.crate;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import tconstruct.library.crafting.ToolBuilder;
+import tconstruct.library.crafting.ToolRecipe;
+import tlhpoeCore.util.MathUtil;
+
+/**
+ * Get random instances of random loot :)
+ *
+ * @author ben
+ *
+ */
+public class RandomRandomLoot {
+ private static List<RandomLoot> loot;
+
+ public static void init() {
+ loot = new ArrayList<RandomLoot>();
+
+ // Tool loot
+ addToolLoot();
+
+ // Weapon loot
+ addWeaponLoot();
+
+ // Armor loot
+ addArmorLoot();
+
+ // Potion loot
+ addPotionLoot();
+
+ // Plant loot
+ addPlantLoot();
+ addPlantLoot();
+
+ // Dye loot
+ addDyeLoot();
+ addDyeLoot();
+
+ // Decorative loot
+ addDecorativeLoot();
+ addDecorativeLoot();
+
+ // Valuble loot
+ addValubleLoot();
+
+ // Bauble loot
+ addBaubleLoot();
+
+ // Misc Loot
+ addMiscLoot();
+ addMiscLoot();
+
+ addTinkersLoot();
+ }
+
+ private static void addTinkersLoot() {
+ List<ToolRecipe> combos = ToolBuilder.instance.combos;
+ for (ToolRecipe toolRecipe : combos) {
+ boolean isLegendary;
+
+ if (MathUtil.nextDouble() > .8) {
+ isLegendary = true;
+ } else {
+ isLegendary = false;
+ }
+
+ loot.add(new RandomTinkersTool(isLegendary, toolRecipe));
+ }
+ }
+
+ private static void addToolLoot() {
+ loot.add(new RandomLoot.Pickaxe(false));
+ loot.add(new RandomLoot.Pickaxe(true));
+ loot.add(new RandomLoot.Shovel(false));
+ loot.add(new RandomLoot.Shovel(true));
+ loot.add(new RandomLoot.Axe(false));
+ loot.add(new RandomLoot.Axe(true));
+ loot.add(new RandomLoot.Hoe(false));
+ loot.add(new RandomLoot.Hoe(true));
+
+ loot.add(new RandomLoot.ToolHead());
+ }
+
+ private static void addWeaponLoot() {
+ loot.add(new RandomLoot.Sword(false));
+ loot.add(new RandomLoot.Sword(true));
+ loot.add(new RandomLoot.Bow(false));
+ loot.add(new RandomLoot.Bow(true));
+ loot.add(new RandomLoot.Arrow());
+ }
+
+ private static void addArmorLoot() {
+ loot.add(new RandomLoot.Helmet(false));
+ loot.add(new RandomLoot.Helmet(true));
+ loot.add(new RandomLoot.Chestplate(false));
+ loot.add(new RandomLoot.Chestplate(true));
+ loot.add(new RandomLoot.Legging(false));
+ loot.add(new RandomLoot.Legging(true));
+ loot.add(new RandomLoot.Boot(false));
+ loot.add(new RandomLoot.Boot(true));
+ }
+
+ private static void addPotionLoot() {
+ loot.add(new RandomLoot.Potion());
+ loot.add(new RandomLoot.SplashPotion());
+ }
+
+ private static void addPlantLoot() {
+ loot.add(new RandomLoot.Food());
+ loot.add(new RandomLoot.Seed());
+ loot.add(new RandomLoot.Crop());
+ loot.add(new RandomLoot.Saplings());
+ loot.add(new RandomLoot.Logs());
+ loot.add(new RandomLoot.Planks());
+ }
+
+ private static void addDyeLoot() {
+ loot.add(new RandomLoot.Paint());
+ loot.add(new RandomLoot.Dye());
+ }
+
+ private static void addDecorativeLoot() {
+ loot.add(new RandomLoot.Slab());
+ loot.add(new RandomLoot.Stair());
+ loot.add(new RandomLoot.Fence());
+ loot.add(new RandomLoot.Glass());
+ loot.add(new RandomLoot.Stone());
+ }
+
+ private static void addValubleLoot() {
+ loot.add(new RandomLoot.Dust());
+ loot.add(new RandomLoot.Block());
+ loot.add(new RandomLoot.Crate());
+ loot.add(new RandomLoot.Gem());
+ loot.add(new RandomLoot.Ingot());
+ loot.add(new RandomLoot.Ore());
+ }
+
+ private static void addBaubleLoot() {
+ loot.add(new RandomLoot.Amulet());
+ loot.add(new RandomLoot.Belt());
+ loot.add(new RandomLoot.Ring());
+ }
+
+ private static void addMiscLoot() {
+ loot.add(new RandomLoot.EnchantedBook());
+ loot.add(new RandomLoot.FishingRod());
+ loot.add(new RandomLoot.Record());
+ }
+
+ public static RandomLoot getRandomLoot() {
+ return loot
+ .get(MathUtil.getRandomIntegerBetween(0, loot.size() - 1));
+ }
+}
diff --git a/TF2 Crates/src/main/java/tf2crates/crate/RandomTinkersTool.java b/TF2 Crates/src/main/java/tf2crates/crate/RandomTinkersTool.java
new file mode 100755
index 0000000..c79ea86
--- /dev/null
+++ b/TF2 Crates/src/main/java/tf2crates/crate/RandomTinkersTool.java
@@ -0,0 +1,143 @@
+package tf2crates.crate;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import net.minecraft.enchantment.EnchantmentHelper;
+import net.minecraft.init.Items;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import tconstruct.library.TConstructRegistry;
+import tconstruct.library.crafting.ModifyBuilder;
+import tconstruct.library.crafting.ToolBuilder;
+import tconstruct.library.crafting.ToolRecipe;
+import tconstruct.library.modifier.ItemModifier;
+import tconstruct.library.tools.ToolCore;
+import tconstruct.library.tools.ToolMaterial;
+import tconstruct.library.util.IToolPart;
+import tlhpoeCore.util.MathUtil;
+
+public class RandomTinkersTool extends RandomLoot {
+ private boolean isLegendary;
+
+ private ToolRecipe toolType;
+
+ private ArrayList<Integer> materialIDs;
+
+ public RandomTinkersTool(boolean isLegendary, ToolRecipe toolType) {
+ super(null, isLegendary);
+
+ this.isLegendary = isLegendary;
+ this.toolType = toolType;
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "A Random " + (isLegendary ? " Legendary" : "")
+ + " Tinker's " + toolType.getType().getLocalizedToolName();
+ }
+
+ @Override
+ public ItemStack getLoot() {
+ if (materialIDs == null) {
+ prepareMaterials();
+ }
+
+ // determine type
+ ToolRecipe recipe = toolType;
+ ToolCore type = recipe.getType();
+
+ ItemStack tool = null;
+ int tries = 0;
+ // try to build the tool
+ do {
+ tries++;
+ // get components
+ ItemStack[] parts = new ItemStack[] { null, null, null, null };
+
+ Item[] items = new Item[4];
+ items[0] = type.getHeadItem();
+ items[1] = type.getHandleItem();
+ items[2] = type.getAccessoryItem();
+ items[3] = type.getExtraItem();
+
+ for (int i = 0; i < 4; i++) {
+ if (items[i] == null) {
+ continue;
+ }
+
+ do {
+ // get a material
+ Integer matId = materialIDs
+ .get(MathUtil.nextInt(materialIDs.size()));
+
+ parts[i] = new ItemStack(items[i], 1, matId);
+ } while (((IToolPart) items[i])
+ .getMaterialID(parts[i]) == -1);
+ }
+ // build the tool
+ tool = ToolBuilder.instance.buildTool(parts[0], parts[1],
+ parts[2], parts[3], "");
+ } while (tool == null && tries < 200);
+
+ if (tool == null) {
+ ItemStack oops = new ItemStack(Items.stick);
+
+ oops.setStackDisplayName("Crate Malfunction");
+
+ return oops;
+ }
+
+ int modCount = MathUtil.nextInt(3);
+
+ for (int i = modCount; i > 0; i--) {
+ doModifyWeapon(tool);
+ }
+
+ if (isLegendary) {
+ EnchantmentHelper.addRandomEnchantment(MathUtil.getRandom(),
+ tool, MathUtil.getRandomIntegerBetween(25, 30));
+ }
+
+ return tool;
+ }
+
+ private void doModifyWeapon(ItemStack tool) {
+ List<ItemModifier> modifiers = ModifyBuilder.instance.itemModifiers;
+
+ ItemModifier mod = modifiers
+ .get(MathUtil.nextInt(modifiers.size()));
+
+ ItemStack[] stacks = stackFromModifier(mod);
+
+ if (!mod.matches(stacks, tool)) {
+ return;
+ }
+
+ mod.addMatchingEffect(tool);
+
+ mod.modify(stacks, tool);
+ }
+
+ private static ItemStack[] stackFromModifier(ItemModifier modifier) {
+ ItemStack[] stack = new ItemStack[modifier.stacks.size()];
+ int i = 0;
+ for (Object s : modifier.stacks)
+ stack[i++] = (ItemStack) s;
+
+ return stack;
+ }
+
+ private void prepareMaterials() {
+ materialIDs = new ArrayList<Integer>(); // converted to list for
+ // indexed access for
+ // random
+
+ for (Map.Entry<Integer,
+ ToolMaterial> entry : TConstructRegistry.toolMaterials
+ .entrySet()) {
+ materialIDs.add(entry.getKey());
+ }
+ }
+}