diff options
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java')
| -rwxr-xr-x | src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java | 222 |
1 files changed, 74 insertions, 148 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java index 6d207ff..80dfdf1 100755 --- a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -7,11 +7,8 @@ import java.util.Iterator; import java.util.Random;
import cpw.mods.fml.common.FMLCommonHandler;
-import cpw.mods.fml.common.Loader;
-import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
-import darkknight.jewelrycraft.JewelrycraftMod;
import darkknight.jewelrycraft.api.Curse;
import darkknight.jewelrycraft.block.BlockList;
import darkknight.jewelrycraft.item.ItemList;
@@ -29,13 +26,11 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
-import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.stats.Achievement;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
-import net.minecraftforge.oredict.OreDictionary;
public class JewelrycraftUtil {
public static ArrayList<ItemStack> objects = new ArrayList<>();
@@ -48,8 +43,8 @@ public class JewelrycraftUtil { public static ArrayList<ItemStack> ores = new ArrayList<>();
- public static HashMap<ItemStack, ItemStack> oreToIngot = new HashMap<>();
- public static HashMap<ItemStack, Integer> colors = new HashMap<>();
+ public static HashMap<ItemStack, ItemStack> oreToIngot = new HashMap<>();
+ public static HashMap<ItemStack, Integer> colors = new HashMap<>();
public static ArrayList<String> jamcraftPlayers = new ArrayList<>();
@@ -84,11 +79,11 @@ public class JewelrycraftUtil { jewelry.add(new ItemStack(ItemList.bracelet));
jewelry.add(new ItemStack(ItemList.earrings));
- for(ItemStack is : gem) {
+ for (ItemStack is : gem) {
objects.add(is.copy());
}
- for(ItemStack is : metal) {
+ for (ItemStack is : metal) {
objects.add(is.copy());
}
@@ -100,8 +95,7 @@ public class JewelrycraftUtil { // Structures
try {
- for (Field f : Generation.class
- .getDeclaredFields()) {
+ for (Field f : Generation.class.getDeclaredFields()) {
Object obj = f.get(null);
if (obj instanceof WorldGenStructure) {
structures.add((WorldGenStructure) obj);
@@ -113,24 +107,19 @@ public class JewelrycraftUtil { }
private static boolean itemHasSubtypes(Object item) {
- return ((Item) item).getHasSubtypes() && FMLCommonHandler
- .instance().getSide() == Side.CLIENT;
+ return ((Item) item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT;
}
@SideOnly(Side.CLIENT)
public static void generateColors() {
-
+
}
@SideOnly(Side.CLIENT)
public static int getColor(ItemStack item) {
for (ItemStack stack : colors.keySet()) {
- if (item != null && item.getItem() != null
- && stack.getItem() != null
- && item.getItem().equals(
- stack.getItem())
- && item.getItemDamage() == stack
- .getItemDamage()) {
+ if (item != null && item.getItem() != null && stack.getItem() != null
+ && item.getItem().equals(stack.getItem()) && item.getItemDamage() == stack.getItemDamage()) {
return colors.get(stack);
}
}
@@ -142,15 +131,11 @@ public class JewelrycraftUtil { public static int color(ItemStack stack, int pass) {
if (stack != null) {
if (Item.getIdFromItem(stack.getItem()) > 0
- && stack.getItem()
- .getColorFromItemStack(
- stack,
- pass) == 16777215) {
+ && stack.getItem().getColorFromItemStack(stack, pass) == 16777215) {
return (int) Math.random() * 16777215;
}
- return stack.getItem().getColorFromItemStack(stack,
- pass);
+ return stack.getItem().getColorFromItemStack(stack, pass);
}
return (int) Math.random() * 16777215;
@@ -164,67 +149,46 @@ public class JewelrycraftUtil { IIcon itemIcon = item.getItem().getIcon(item, 0);
if (isValidBlockFromItem(item)) {
- itemIcon = Block.getBlockFromItem(item.getItem())
- .getIcon(0, item.getItemDamage());
+ itemIcon = Block.getBlockFromItem(item.getItem()).getIcon(0, item.getItemDamage());
}
String iconName = itemIcon.getIconName();
- if (iconName.substring(0,
- iconName.indexOf(":") + 1) != "") {
- domain = iconName
- .substring(0, iconName.indexOf(":")
- + 1)
- .replace(":", " ").trim();
+ if (iconName.substring(0, iconName.indexOf(":") + 1) != "") {
+ domain = iconName.substring(0, iconName.indexOf(":") + 1).replace(":", " ").trim();
} else {
domain = "minecraft";
}
- texture = iconName.substring(iconName.lastIndexOf(":") + 1)
- + ".png";
+ texture = iconName.substring(iconName.lastIndexOf(":") + 1) + ".png";
ResourceLocation textureLocation = null;
- TextureManager texturemanager = Minecraft.getMinecraft()
- .getTextureManager();
+ TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
- if (texturemanager
- .getResourceLocation(
- item.getItemSpriteNumber())
- .toString().contains("items")) {
- textureLocation = new ResourceLocation(
- domain.toLowerCase(),
- "textures/items/" + texture);
+ if (texturemanager.getResourceLocation(item.getItemSpriteNumber()).toString().contains("items")) {
+ textureLocation = new ResourceLocation(domain.toLowerCase(), "textures/items/" + texture);
} else {
- textureLocation = new ResourceLocation(
- domain.toLowerCase(),
- "textures/blocks/" + texture);
+ textureLocation = new ResourceLocation(domain.toLowerCase(), "textures/blocks/" + texture);
}
return textureLocation;
}
private static boolean isValidBlockFromItem(ItemStack item) {
- return !(Block.getBlockFromItem(
- item.getItem()) instanceof BlockAir)
- && !Block.getBlockFromItem(item.getItem())
- .getIcon(0, item.getItemDamage())
- .getIconName()
- .equals("soul_sand");
+ return !(Block.getBlockFromItem(item.getItem()) instanceof BlockAir) && !Block.getBlockFromItem(item.getItem())
+ .getIcon(0, item.getItemDamage()).getIconName().equals("soul_sand");
}
/*
- * @SideOnly(Side.CLIENT) public static int getMostCommonColour(Map
- * map) { List list = new LinkedList(map.entrySet());
- * Collections.sort(list, new Comparator() { public int
- * compare(Object o1, Object o2) { return ((Comparable)
- * ((Map.Entry) o1).getValue()) .compareTo(((Map.Entry)
- * o2).getValue()); } }); Map.Entry me = (Map.Entry)
- * list.get(list.size() - 1); for (int i = 0; i < list.size(); i++)
- * { float alpha = Float
- * .valueOf(list.get(i).toString().split("=")[1]); if (alpha < 180)
- * me = (Map.Entry) list.get(i); } int rgb = (Integer) me.getKey();
- * return rgb; }
+ * @SideOnly(Side.CLIENT) public static int getMostCommonColour(Map map) { List
+ * list = new LinkedList(map.entrySet()); Collections.sort(list, new
+ * Comparator() { public int compare(Object o1, Object o2) { return
+ * ((Comparable) ((Map.Entry) o1).getValue()) .compareTo(((Map.Entry)
+ * o2).getValue()); } }); Map.Entry me = (Map.Entry) list.get(list.size() - 1);
+ * for (int i = 0; i < list.size(); i++) { float alpha = Float
+ * .valueOf(list.get(i).toString().split("=")[1]); if (alpha < 180) me =
+ * (Map.Entry) list.get(i); } int rgb = (Integer) me.getKey(); return rgb; }
*/
@SideOnly(Side.CLIENT)
@@ -238,17 +202,12 @@ public class JewelrycraftUtil { return true;
}
- public static WeightedRandomCurse[] getCurses(World world,
- EntityPlayer player, Random random) {
- WeightedRandomCurse[] curses = new WeightedRandomCurse[Curse.availableCurses
- .size()];
+ public static WeightedRandomCurse[] getCurses(World world, EntityPlayer player, Random random) {
+ WeightedRandomCurse[] curses = new WeightedRandomCurse[Curse.availableCurses.size()];
for (int c = 0; c < Curse.availableCurses.size(); c++) {
- curses[c] = new WeightedRandomCurse(
- Curse.availableCurses.get(c),
- Curse.availableCurses.get(c)
- .weight(world, player,
- random));
+ curses[c] = new WeightedRandomCurse(Curse.availableCurses.get(c),
+ Curse.availableCurses.get(c).weight(world, player, random));
}
return curses;
@@ -258,27 +217,21 @@ public class JewelrycraftUtil { * Adds curse points to a player
*
* @param player
- * the player to add the points to
+ * the player to add the points to
* @param points
- * amount of curse points
+ * amount of curse points
*/
- public static void addCursePoints(EntityPlayer player,
- int points) {
- NBTTagCompound playerInfo = PlayerUtils
- .getModPlayerPersistTag(player,
- Variables.MODID);
+ public static void addCursePoints(EntityPlayer player, int points) {
+ NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID);
playerInfo.setInteger("cursePoints",
- playerInfo.hasKey(
- "cursePoints") ? (playerInfo.getInteger("cursePoints") + points) : points);
+ playerInfo.hasKey("cursePoints") ? (playerInfo.getInteger("cursePoints") + points) : points);
playerInfo.setBoolean("playerCursePointsChanged", true);
}
public static int getCursePoints(EntityPlayer player) {
- NBTTagCompound playerInfo = PlayerUtils
- .getModPlayerPersistTag(player,
- Variables.MODID);
+ NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID);
return playerInfo.getInteger("cursePoints");
}
@@ -287,56 +240,37 @@ public class JewelrycraftUtil { * Adds the UUID's of the jamcrafters in a list (+ special people)
*/
public static void jamcrafters() {
- jamcraftPlayers.add(
- "d3214311-7550-4c9c-a372-d9292c10b8a6"); // allout58
- jamcraftPlayers.add(
- "a690119f-c4a2-4bd6-a99d-d63679abb328"); // ChewBaker
- jamcraftPlayers.add(
- "de7c9903-51fa-4a24-88cd-48faf122ca36"); // domi1819
- jamcraftPlayers.add(
- "70aeb298-3a7b-46da-a393-ab10df9359f2"); // founderio
- jamcraftPlayers.add(
- "6fbe603c-14bf-4085-afdd-abe592c26e7c"); // GerbShert
- jamcraftPlayers.add(
- "b0d21306-36bf-4d85-84df-a956d183c45a"); // isomgirls6
- jamcraftPlayers.add(
- "1733a31f-01f9-4f4d-82aa-7de30ca810d3"); // TH3N00B
- jamcraftPlayers.add(
- "4833eacf-1d94-49a7-9f89-4cf88d69dcf9"); // Joban
- jamcraftPlayers.add(
- "718cf671-9084-4e78-b91f-033e80aa11bf"); // KJ4IPS
- jamcraftPlayers.add(
- "bea5e0c4-85c4-454d-a081-e1eaae6895ee"); // Mitchellbrine
- jamcraftPlayers.add(
- "7ecf3e2f-fedf-4f7e-8d24-6731d078db4f"); // MrComputerGhost
- jamcraftPlayers.add(
- "1b11ad3a-f0ca-4695-a019-2d7e5d83a5fd"); // Resinresin
- jamcraftPlayers.add(
- "3ec9ac58-2f1b-4d3f-b4eb-3b875da877ae"); // sci4me
- jamcraftPlayers.add(
- "cf9fa23f-205e-4eed-aba3-9f2848cd6a4d"); // OnyxDarkKnight
- jamcraftPlayers.add(
- "91880caa-b032-48e3-bfe8-c2c7ed31824e"); // theminecoder
- jamcraftPlayers.add(
- "8d0b3804-f71c-4219-897b-8c315448ea7c"); // YSPilot
- jamcraftPlayers.add(
- "bbb87dbe-690f-4205-bdc5-72ffb8ebc29d"); // direwolf20
+ jamcraftPlayers.add("d3214311-7550-4c9c-a372-d9292c10b8a6"); // allout58
+ jamcraftPlayers.add("a690119f-c4a2-4bd6-a99d-d63679abb328"); // ChewBaker
+ jamcraftPlayers.add("de7c9903-51fa-4a24-88cd-48faf122ca36"); // domi1819
+ jamcraftPlayers.add("70aeb298-3a7b-46da-a393-ab10df9359f2"); // founderio
+ jamcraftPlayers.add("6fbe603c-14bf-4085-afdd-abe592c26e7c"); // GerbShert
+ jamcraftPlayers.add("b0d21306-36bf-4d85-84df-a956d183c45a"); // isomgirls6
+ jamcraftPlayers.add("1733a31f-01f9-4f4d-82aa-7de30ca810d3"); // TH3N00B
+ jamcraftPlayers.add("4833eacf-1d94-49a7-9f89-4cf88d69dcf9"); // Joban
+ jamcraftPlayers.add("718cf671-9084-4e78-b91f-033e80aa11bf"); // KJ4IPS
+ jamcraftPlayers.add("bea5e0c4-85c4-454d-a081-e1eaae6895ee"); // Mitchellbrine
+ jamcraftPlayers.add("7ecf3e2f-fedf-4f7e-8d24-6731d078db4f"); // MrComputerGhost
+ jamcraftPlayers.add("1b11ad3a-f0ca-4695-a019-2d7e5d83a5fd"); // Resinresin
+ jamcraftPlayers.add("3ec9ac58-2f1b-4d3f-b4eb-3b875da877ae"); // sci4me
+ jamcraftPlayers.add("cf9fa23f-205e-4eed-aba3-9f2848cd6a4d"); // OnyxDarkKnight
+ jamcraftPlayers.add("91880caa-b032-48e3-bfe8-c2c7ed31824e"); // theminecoder
+ jamcraftPlayers.add("8d0b3804-f71c-4219-897b-8c315448ea7c"); // YSPilot
+ jamcraftPlayers.add("bbb87dbe-690f-4205-bdc5-72ffb8ebc29d"); // direwolf20
}
/**
* Adds a random amount of modifiers to a list
*
* @param randValue
- * maximum number of modifiers
+ * maximum number of modifiers
* @return a list containing the random modifiers
*/
- public static ArrayList<ItemStack> addRandomModifiers(
- int randValue) {
+ public static ArrayList<ItemStack> addRandomModifiers(int randValue) {
ArrayList<ItemStack> list = new ArrayList<>();
for (int i = 0; i < 2 + randValue; i++) {
- ItemStack item = objects.get(new Random()
- .nextInt(objects.size()));
+ ItemStack item = objects.get(new Random().nextInt(objects.size()));
item.stackSize = 1 + new Random().nextInt(2);
@@ -357,7 +291,7 @@ public class JewelrycraftUtil { * Checks to see if the specified item is a gem
*
* @param item
- * ItemStack containing the item
+ * ItemStack containing the item
* @return is the item a gem
*/
public static boolean isGem(ItemStack item) {
@@ -368,7 +302,7 @@ public class JewelrycraftUtil { * Checks to see if the specified item is a metal
*
* @param item
- * ItemStack containing the item
+ * ItemStack containing the item
* @return is the item a metal
*/
public static boolean isMetal(ItemStack item) {
@@ -379,20 +313,17 @@ public class JewelrycraftUtil { * Checks to see if the specified item is a piece of jewelry
*
* @param item
- * ItemStack containing the item
+ * ItemStack containing the item
* @return is the item a piece of jewelry
*/
public static boolean isJewelry(ItemStack item) {
return isItemStackIn(item, jewelry.iterator());
}
- private static boolean isItemStackIn(ItemStack item,
- Iterator<ItemStack> i) {
+ private static boolean isItemStackIn(ItemStack item, Iterator<ItemStack> i) {
while (i.hasNext()) {
ItemStack temp = i.next();
- if (temp.getItem() == item.getItem()
- && temp.getItemDamage() == item
- .getItemDamage()) {
+ if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) {
return true;
}
}
@@ -404,7 +335,7 @@ public class JewelrycraftUtil { * Checks to see if the specified item is an ore
*
* @param item
- * ItemStack containing the item
+ * ItemStack containing the item
* @return is the item an ore
*/
public static boolean isOre(ItemStack item) {
@@ -415,14 +346,12 @@ public class JewelrycraftUtil { * Gets the ingot from the ore
*
* @param ore
- * the ore
+ * the ore
* @return the ingot
*/
public static ItemStack getIngotFromOre(ItemStack ore) {
for (ItemStack ors : JewelrycraftUtil.oreToIngot.keySet())
- if (ors.getItem().equals(ore.getItem())
- && ors.getItemDamage() == ore
- .getItemDamage()) {
+ if (ors.getItem().equals(ore.getItem()) && ors.getItemDamage() == ore.getItemDamage()) {
return oreToIngot.get(ors);
}
@@ -430,19 +359,16 @@ public class JewelrycraftUtil { }
/**
- * This determines whether the player unlocked an achievement or
- * not.
+ * This determines whether the player unlocked an achievement or not.
*
* @param player
- * The player to unlock the achievement
+ * The player to unlock the achievement
* @param achievement
- * The achievement to be unlocked
- * @return True or False depending if the player did unlock the
- * achievement or not
+ * The achievement to be unlocked
+ * @return True or False depending if the player did unlock the achievement or
+ * not
*/
- public static boolean isAchievementUnlocked(EntityPlayer player,
- Achievement achievement) {
- return ((EntityPlayerMP) player).func_147099_x()
- .hasAchievementUnlocked(achievement);
+ public static boolean isAchievementUnlocked(EntityPlayer player, Achievement achievement) {
+ return ((EntityPlayerMP) player).func_147099_x().hasAchievementUnlocked(achievement);
}
}
|
