@SideOnly(Side.CLIENT) private static Pair<String, KnowledgeObject<?>> getObject(char type, String identifier) { KnowledgeObject<?> obj = null; String text = null; boolean isHEE = identifier.charAt(0) == '~' && identifier.length() > 1; if (isHEE) identifier = identifier.substring(1); switch (type) { case 'b': case 'i': int metaIndex = identifier.indexOf('/'), meta = 0; if (metaIndex != -1 && metaIndex + 1 < identifier.length()) { meta = DragonUtil.tryParse(identifier.substring(metaIndex + 1), 0); identifier = identifier.substring(0, metaIndex); } Item item = GameRegistry.findItem(isHEE ? "HardcoreEnderExpansion" : "minecraft", identifier); if (item != null) { text = StatCollector.translateToLocal( item.getUnlocalizedName(new ItemStack(item, 1, meta)) + ".name"); obj = KnowledgeObject.fromObject( type == 'b' ? (item instanceof ItemBlock ? new BlockInfo(((ItemBlock) item).field_150939_a, meta) : null) : item); } break; case 'e': if (isHEE) text = ItemSpawnEggs.getMobName( (Class<?>) EntityList.stringToClassMapping.get( identifier = ("HardcoreEnderExpansion." + identifier))); else text = StatCollector.translateToLocal("entity." + identifier + ".name"); Class<?> cls = (Class<?>) EntityList.stringToClassMapping.get(identifier); if (cls != null) obj = KnowledgeObject.fromObject(cls); break; case 'd': obj = KnowledgeObject.fromObject(identifier); if (obj != null) text = obj.getTranslatedTooltip(); break; } if (text == null || obj == null) { Log.warn("Invalid object type or identifier: $0:$1", type, identifier); return Pair.<String, KnowledgeObject<?>>of(text == null ? identifier : text, obj); } else return Pair.<String, KnowledgeObject<?>>of(text, obj); }
@Override @SideOnly(Side.CLIENT) public void onRender( GuiEnderCompendium gui, int x, int y, int mouseX, int mouseY, boolean isUnlocked) { String str = getString(isUnlocked); GuiHelper.renderUnicodeString(str, x + 1, y, CompendiumPageHandler.innerWidth, 255 << 24); if (isUnlocked) { KnowledgeObject<?> obj = getHoveredObject(gui.mc.fontRenderer, mouseX, mouseY, x, y); if (obj != null) GuiItemRenderHelper.setupTooltip( mouseX, mouseY, obj.getTranslatedTooltip() + "\n" + EnumChatFormatting.DARK_PURPLE + I18n.format("compendium.viewObject")); } }