/** * Retrieves a resource location from an <em>item</em> icon. * * @param icon the icon to get the resource location from. * @return the resource location for the icon, or null. */ public static ResourceLocation getItemResource(IIcon icon) { if (icon == null) { return null; } String path = icon.getIconName(); String domain = path.substring(0, path.indexOf(":") + 1); String file = path.substring(path.indexOf(':') + 1); return new ResourceLocation(domain + "textures/items/" + file + ".png"); }
@Nullable private static String getIconName(IIcon icon) { if (icon == null) return null; String iconName = icon.getIconName(); if (RendererHandler.items.getTextureExtry(iconName) != null || RendererHandler.blocks.getTextureExtry(iconName) != null) return iconName; else return null; }