diff options
Diffstat (limited to 'java/darkknight/jewelrycraft/item/ItemMoltenMetal.java')
| -rw-r--r-- | java/darkknight/jewelrycraft/item/ItemMoltenMetal.java | 97 |
1 files changed, 48 insertions, 49 deletions
diff --git a/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java b/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java index ef098f5..0638da7 100644 --- a/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java +++ b/java/darkknight/jewelrycraft/item/ItemMoltenMetal.java @@ -8,16 +8,12 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; - import javax.imageio.ImageIO; - import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.IResourceManager; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -25,79 +21,76 @@ import darkknight.jewelrycraft.util.JewelryNBT; public class ItemMoltenMetal extends Item { - private int amplifier, cooldown = 0; - int index = 0; + /** + * + */ public ItemMoltenMetal() { super(); - this.setMaxStackSize(1); + setMaxStackSize(1); } + /** + * @param iconRegister + */ + @Override public void registerIcons(IIconRegister iconRegister) { itemIcon = iconRegister.registerIcon("jewelrycraft:moltenMetalStill"); } - @SideOnly(Side.CLIENT) + /** + * @param stack + * @param pass + * @return + */ + @Override + @SideOnly (Side.CLIENT) public int getColorFromItemStack(ItemStack stack, int pass) { - try - { + try{ return color(stack, pass); } - catch (IOException e) - { + catch(IOException e){ e.printStackTrace(); } return 16777215; } + /** + * @param stack + * @param pass + * @return + * @throws IOException + */ public static int color(ItemStack stack, int pass) throws IOException { - String domain = "", texture; IResourceManager rm = Minecraft.getMinecraft().getResourceManager(); BufferedImage icon; - if (stack != null && JewelryNBT.ingot(stack) != null && Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) > 0 && JewelryNBT.ingot(stack).getIconIndex() != null && JewelryNBT.ingotColor(stack) == 16777215) - { - IIcon itemIcon = JewelryNBT.ingot(stack).getItem().getIcon(JewelryNBT.ingot(stack), 0); - String ingotIconName = itemIcon.getIconName(); - - if (ingotIconName.substring(0, ingotIconName.indexOf(":") + 1) != "") domain = ingotIconName.substring(0, ingotIconName.indexOf(":") + 1).replace(":", " ").trim(); - else domain = "minecraft"; - - texture = ingotIconName.substring(ingotIconName.lastIndexOf(":") + 1) + ".png"; - ResourceLocation ingot = null; - TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); - - if (texturemanager.getResourceLocation(JewelryNBT.ingot(stack).getItemSpriteNumber()).toString().contains("items")) ingot = new ResourceLocation(domain.toLowerCase(), "textures/items/" + texture); - else ingot = new ResourceLocation(domain.toLowerCase(), "textures/blocks/" + texture); - + if (stack != null && JewelryNBT.ingot(stack) != null && Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) > 0 && JewelryNBT.ingot(stack).getIconIndex() != null && JewelryNBT.ingotColor(stack) == 16777215){ + ResourceLocation ingot = ItemBaseJewelry.getLocation(JewelryNBT.ingot(stack), stack, false); icon = ImageIO.read(rm.getResource(ingot).getInputStream()); int height = icon.getHeight(); int width = icon.getWidth(); - Map m = new HashMap(); - for (int i = 0; i < width; i++) - for (int j = 0; j < height; j++) - { + for(int i = 0; i < width; i++) + for(int j = 0; j < height; j++){ int rgb = icon.getRGB(i, j); - int red = (rgb >> 16) & 0xff; - int green = (rgb >> 8) & 0xff; - int blue = (rgb) & 0xff; + int red = rgb >> 16 & 0xff; + int green = rgb >> 8 & 0xff; + int blue = rgb & 0xff; int[] rgbArr = {red, green, blue}; int Cmax = Math.max(red, Math.max(green, blue)); int Cmin = Math.min(red, Math.min(green, blue)); - if (!isGray(rgbArr)) m.put(rgb, (Cmax + Cmin)/2); + if (!isGray(rgbArr)) m.put(rgb, (Cmax + Cmin) / 2); } - try - { + try{ int color = getMostCommonColour(m); if (JewelryNBT.ingot(stack) != null && JewelryNBT.ingot(stack).getItem().getColorFromItemStack(JewelryNBT.ingot(stack), 1) != 16777215) JewelryNBT.addIngotColor(stack, JewelryNBT.ingot(stack).getItem().getColorFromItemStack(JewelryNBT.ingot(stack), 1)); else JewelryNBT.addIngotColor(stack, color); } - catch (Exception e) - { + catch(Exception e){ JewelryNBT.addIngotColor(stack, 16777215); } } @@ -105,30 +98,36 @@ public class ItemMoltenMetal extends Item return 0; } + /** + * @param map + * @return + */ public static int getMostCommonColour(Map map) { List list = new LinkedList(map.entrySet()); - Collections.sort(list, new Comparator() - { + Collections.sort(list, new Comparator(){ public int compare(Object o1, Object o2) { - return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue()); + 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++) - { + 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); + if (alpha < 180) me = (Map.Entry)list.get(i); } - int rgb = (Integer) me.getKey(); + int rgb = (Integer)me.getKey(); return rgb; } + /** + * @param rgbArr + * @return + */ public static boolean isGray(int[] rgbArr) { int rgbSum = rgbArr[0] + rgbArr[1] + rgbArr[2]; - if (rgbSum > 0 && rgbSum < 256 * 3) { return false; } + if (rgbSum > 0 && rgbSum < 256 * 3) return false; return true; } } |
