diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-02-03 21:09:09 +0000 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-02-03 21:09:09 +0000 |
| commit | 3f4c717de5ebc9b942d65ae45ac87c43bdf8a31b (patch) | |
| tree | 15c68c8b61dbd0b7f44937a5c790c4b844e50f58 /java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java | |
| parent | 73ca377dc01f859dabd7b07738cb7aeb762272b1 (diff) | |
Made a few modifications to some classes, added earrings and bracelets. Improved coloring algorithm and balanced the Thieving Glove
Diffstat (limited to 'java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java')
| -rw-r--r-- | java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java b/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java index c4c0a2f..5c61398 100644 --- a/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java +++ b/java/darkknight/jewelrycraft/item/ItemMoltenMetalBucket.java @@ -2,6 +2,12 @@ package darkknight.jewelrycraft.item; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import javax.imageio.ImageIO; @@ -41,8 +47,7 @@ public class ItemMoltenMetalBucket extends Item } /** - * Called whenever this item is equipped and the right mouse button is - * pressed. Args: itemStack, world, entityPlayer + * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer) { @@ -180,9 +185,9 @@ public class ItemMoltenMetalBucket extends Item else if (stack != null && JewelryNBT.ingot(stack) != null) { if (!world.isRemote && flag && !material.isLiquid()) world.func_147480_a(x, y, z, true); - - JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage()); - JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage())); + int color = color(stack, 1); + JewelrycraftMod.saveData.setString(x + " " + y + " " + z + " " + world.provider.dimensionId, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()) + ":" + JewelryNBT.ingot(stack).getItemDamage() + ":" + color); + JewelrycraftMod.netWrapper.sendToAll(new PacketSendLiquidData(world.provider.dimensionId, x, y, z, Item.getIdFromItem(JewelryNBT.ingot(stack).getItem()), JewelryNBT.ingot(stack).getItemDamage(), color)); world.setBlock(x, y, z, BlockList.moltenMetal, 0, 3); return true; @@ -229,7 +234,6 @@ public class ItemMoltenMetalBucket extends Item String domain = "", texture; IResourceManager rm = Minecraft.getMinecraft().getResourceManager(); BufferedImage icon; - int x = 0, y = 0, ok = 0, red, green, blue; if (pass == 1 && 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); @@ -246,33 +250,54 @@ public class ItemMoltenMetalBucket extends Item else ingot = new ResourceLocation(domain.toLowerCase(), "textures/blocks/" + texture); icon = ImageIO.read(rm.getResource(ingot).getInputStream()); - while (ok == 0) - { - red = (icon.getRGB(x, y) >> 16) & 0xFF; - green = (icon.getRGB(x, y) >> 8) & 0xFF; - blue = icon.getRGB(x, y) & 0xFF; - if (!isColorPretty(red, green, blue)) + 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++) { - if (x < icon.getTileWidth() - 1) x++; - if (x >= icon.getTileWidth() - 1 && y < icon.getTileWidth() - 1) - { - x = 0; - y++; - } - if (x == icon.getTileWidth() - 1 && y == icon.getTileWidth() - 1) ok = 1; + int rgb = icon.getRGB(i, j); + 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); } - else ok = 1; - } - JewelryNBT.addIngotColor(stack, icon.getRGB(x, y)); + 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); } if (JewelryNBT.ingot(stack) != null && pass == 1) return JewelryNBT.ingotColor(stack); return 16777215; } - public static boolean isColorPretty(int r, int g, int b) + public static int getMostCommonColour(Map map) { - if ((r >= 100 && g >= 100 && b >= 100 && r < 230 && b < 230 && g < 230) || ((r >= 100 && (g < 100 || b < 100)) || (g >= 100 && (r < 100 || b < 100)) || (b >= 100 && (g < 100 || r < 100)))) return true; - else return false; + 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; + } + + public static boolean isGray(int[] rgbArr) + { + int rgbSum = rgbArr[0] + rgbArr[1] + rgbArr[2]; + if (rgbSum > 0 && rgbSum < 256 * 3) { return false; } + return true; } public ItemStack getModifiedItemStack(ItemStack ingot) @@ -284,14 +309,10 @@ public class ItemMoltenMetalBucket extends Item public String getItemStackDisplayName(ItemStack stack) { - if (JewelryNBT.ingot(stack) != null){ + if (JewelryNBT.ingot(stack) != null) + { ItemStack ingot = JewelryNBT.ingot(stack); - if(Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) - || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass_pane) - || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) - || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.wool) - || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.carpet)) - ingot.setItemDamage(15 - ingot.getItemDamage()); + if (Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(ingot.getItem()) == Block.getIdFromBlock(Blocks.carpet)) ingot.setItemDamage(15 - ingot.getItemDamage()); return (StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim() + " " + ingot.getDisplayName().replace("Ingot", " ").trim(); } return ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim() + " Metal"; |
