Allow items to provide there own FontRenderer for there tooltips. Added for #463

This commit is contained in:
LexManos 2013-04-04 18:37:10 -07:00 committed by Christian
parent 9b58fb9384
commit 829a60722c
3 changed files with 113 additions and 5 deletions

View File

@ -18,3 +18,21 @@
i3 = -1;
if (this.mc.thePlayer.isPotionActive(Potion.regeneration))
@@ -431,7 +433,16 @@
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- fontrenderer.drawStringWithShadow(s1, i1, j1, 16777215 + (j5 << 24));
+ FontRenderer font = field_92016_l.getItem().getFontRenderer(field_92016_l);
+ if (font != null)
+ {
+ i1 = (k - font.getStringWidth(s1)) / 2;
+ font.drawStringWithShadow(s1, i1, j1, 16777215 + (j5 << 24));
+ }
+ else
+ {
+ fontrenderer.drawStringWithShadow(s1, i1, j1, 16777215 + (j5 << 24));
+ }
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
}

View File

@ -0,0 +1,69 @@
--- ../src_base/minecraft/net/minecraft/client/gui/inventory/GuiContainer.java
+++ ../src_work/minecraft/net/minecraft/client/gui/inventory/GuiContainer.java
@@ -8,6 +8,7 @@
import java.util.List;
import java.util.Set;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
@@ -203,8 +204,10 @@
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
this.zLevel = 200.0F;
itemRenderer.zLevel = 200.0F;
- itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, par1ItemStack, par2, par3);
- itemRenderer.renderItemStack(this.fontRenderer, this.mc.renderEngine, par1ItemStack, par2, par3 - (this.draggedStack == null ? 0 : 8), par4Str);
+ FontRenderer font = par1ItemStack.getItem().getFontRenderer(par1ItemStack);
+ if (font == null) font = fontRenderer;
+ itemRenderer.renderItemAndEffectIntoGUI(font, this.mc.renderEngine, par1ItemStack, par2, par3);
+ itemRenderer.renderItemStack(font, this.mc.renderEngine, par1ItemStack, par2, par3 - (this.draggedStack == null ? 0 : 8), par4Str);
this.zLevel = 0.0F;
itemRenderer.zLevel = 0.0F;
}
@@ -225,7 +228,8 @@
}
}
- this.func_102021_a(list, par2, par3);
+ FontRenderer font = par1ItemStack.getItem().getFontRenderer(par1ItemStack);
+ drawHoveringText(list, par2, par3, (font == null ? fontRenderer : font));
}
/**
@@ -238,6 +242,11 @@
}
protected void func_102021_a(List par1List, int par2, int par3)
+ {
+ drawHoveringText(par1List, par2, par3, fontRenderer);
+ }
+
+ protected void drawHoveringText(List par1List, int par2, int par3, FontRenderer font)
{
if (!par1List.isEmpty())
{
@@ -246,12 +255,12 @@
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
int k = 0;
- Iterator iterator = par1List.iterator();
+ Iterator iterator = par1List.iterator();
while (iterator.hasNext())
{
String s = (String)iterator.next();
- int l = this.fontRenderer.getStringWidth(s);
+ int l = font.getStringWidth(s);
if (l > k)
{
@@ -296,7 +305,7 @@
for (int k2 = 0; k2 < par1List.size(); ++k2)
{
String s1 = (String)par1List.get(k2);
- this.fontRenderer.drawStringWithShadow(s1, i1, j1, -1);
+ font.drawStringWithShadow(s1, i1, j1, -1);
if (k2 == 0)
{

View File

@ -1,6 +1,14 @@
--- ../src_base/minecraft/net/minecraft/item/Item.java
+++ ../src_work/minecraft/net/minecraft/item/Item.java
@@ -14,6 +14,7 @@
@@ -7,6 +7,7 @@
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
+import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
@@ -14,6 +15,7 @@
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.player.EntityPlayer;
@ -8,7 +16,7 @@
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionHelper;
import net.minecraft.stats.StatList;
@@ -23,7 +24,10 @@
@@ -23,7 +25,10 @@
import net.minecraft.util.StatCollector;
import net.minecraft.util.StringTranslate;
import net.minecraft.util.Vec3;
@ -19,7 +27,7 @@
public class Item
{
@@ -238,13 +242,16 @@
@@ -238,13 +243,16 @@
/** Icon index in the icons table. */
protected Icon iconIndex;
@ -37,7 +45,7 @@
}
itemsList[256 + par1] = this;
@@ -640,6 +647,10 @@
@@ -640,6 +648,10 @@
float f7 = f4 * f5;
float f8 = f3 * f5;
double d3 = 5.0D;
@ -48,7 +56,7 @@
Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
return par1World.rayTraceBlocks_do_do(vec3, vec31, par3, !par3);
}
@@ -720,4 +731,367 @@
@@ -720,4 +732,380 @@
{
StatList.initStats();
}
@ -414,5 +422,18 @@
+ public String getArmorTexture(ItemStack stack, Entity entity, int slot, int layer)
+ {
+ return isArmorProvider ? ((IArmorTextureProvider)this).getArmorTextureFile(stack) : null;
+ }
+
+ /**
+ * Returns the font renderer used to render tooltips and overlays for this item.
+ * Returning null will use the standard font renderer.
+ *
+ * @param stack The current item stack
+ * @return A instance of FontRenderer or null to use default
+ */
+ @SideOnly(Side.CLIENT)
+ public FontRenderer getFontRenderer(ItemStack stack)
+ {
+ return null;
+ }
}