From 910034ff39dc6fa4efe716bb9f84a2c0117ea1d3 Mon Sep 17 00:00:00 2001 From: naqaden Date: Thu, 29 Nov 2018 15:09:25 -0700 Subject: [PATCH] Use ItemStackRenderer for EnchantDataRenderer and minor clean up with 'enchant' abbreviation consistency and ItemEnchantedBook's existing enchanted book function. --- .../ingredients/EnchantDataRenderer.java | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/main/java/mezz/jei/plugins/vanilla/ingredients/EnchantDataRenderer.java b/src/main/java/mezz/jei/plugins/vanilla/ingredients/EnchantDataRenderer.java index abb773248..4cd29e32a 100644 --- a/src/main/java/mezz/jei/plugins/vanilla/ingredients/EnchantDataRenderer.java +++ b/src/main/java/mezz/jei/plugins/vanilla/ingredients/EnchantDataRenderer.java @@ -9,13 +9,9 @@ import mezz.jei.util.Log; import mezz.jei.util.Translator; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.enchantment.EnchantmentData; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemEnchantedBook; import net.minecraft.item.ItemStack; @@ -23,31 +19,33 @@ public class EnchantDataRenderer implements IIngredientRenderer { + private IIngredientRenderer itemRenderer; + + public EnchantDataRenderer() { + this(new ItemStackRenderer()); + } + + public EnchantDataRenderer(IIngredientRenderer itemRenderer) { + this.itemRenderer = itemRenderer; + } + @Override public void render(Minecraft minecraft, int xPosition, int yPosition, @Nullable EnchantmentData ingredient) { if (ingredient != null) { - GlStateManager.enableDepth(); - RenderHelper.enableGUIStandardItemLighting(); - FontRenderer font = getFontRenderer(minecraft, ingredient); - ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK); - ItemEnchantedBook.addEnchantment(enchantedBook, ingredient); - minecraft.getRenderItem().renderItemAndEffectIntoGUI(null, enchantedBook, xPosition, yPosition); - minecraft.getRenderItem().renderItemOverlayIntoGUI(font, enchantedBook, xPosition, yPosition, null); - GlStateManager.disableBlend(); - RenderHelper.disableStandardItemLighting(); + ItemStack enchantBook = ItemEnchantedBook.getEnchantedItemStack(ingredient); + itemRenderer.render(minecraft, xPosition, yPosition, enchantBook); } } @Override public List getTooltip(Minecraft minecraft, EnchantmentData ingredient, ITooltipFlag tooltipFlag) { EntityPlayer player = minecraft.player; - ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK); - ItemEnchantedBook.addEnchantment(enchantedBook, ingredient); + ItemStack enchantBook = ItemEnchantedBook.getEnchantedItemStack(ingredient); List list; try { - list = enchantedBook.getTooltip(player, tooltipFlag); + list = enchantBook.getTooltip(player, tooltipFlag); } catch (RuntimeException | LinkageError e) { - String itemStackInfo = ErrorUtil.getItemStackInfo(enchantedBook); + String itemStackInfo = ErrorUtil.getItemStackInfo(enchantBook); Log.get().error("Failed to get tooltip: {}", itemStackInfo, e); list = new ArrayList<>(); list.add(TextFormatting.RED + Translator.translateToLocal("jei.tooltip.error.crash")); @@ -71,13 +69,4 @@ public List getTooltip(Minecraft minecraft, EnchantmentData ingredient, return list; } - - @Override - public FontRenderer getFontRenderer(Minecraft minecraft, EnchantmentData ingredient) { - FontRenderer fontRenderer = Items.ENCHANTED_BOOK.getFontRenderer(new ItemStack(Items.ENCHANTED_BOOK)); - if (fontRenderer == null) { - fontRenderer = minecraft.fontRenderer; - } - return minecraft.fontRenderer; - } -} \ No newline at end of file +}