Skip to content

Commit

Permalink
Use ItemStackRenderer for EnchantDataRenderer
Browse files Browse the repository at this point in the history
and minor clean up with 'enchant' abbreviation consistency and ItemEnchantedBook's existing enchanted book function.
  • Loading branch information
naqaden authored Nov 29, 2018
1 parent eb4a002 commit 910034f
Showing 1 changed file with 16 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,43 @@
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;
import net.minecraft.util.text.TextFormatting;

public class EnchantDataRenderer implements IIngredientRenderer<EnchantmentData> {

private IIngredientRenderer<ItemStack> itemRenderer;

public EnchantDataRenderer() {
this(new ItemStackRenderer());
}

public EnchantDataRenderer(IIngredientRenderer<ItemStack> 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<String> 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<String> 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"));
Expand All @@ -71,13 +69,4 @@ public List<String> 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;
}
}
}

0 comments on commit 910034f

Please sign in to comment.