當前位置: 首頁>>代碼示例>>Java>>正文


Java FontRenderer.getStringWidth方法代碼示例

本文整理匯總了Java中net.minecraft.client.gui.FontRenderer.getStringWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java FontRenderer.getStringWidth方法的具體用法?Java FontRenderer.getStringWidth怎麽用?Java FontRenderer.getStringWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.client.gui.FontRenderer的用法示例。


在下文中一共展示了FontRenderer.getStringWidth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getButtonText

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
private String getButtonText(ShaderOption so, int btnWidth)
{
    String s = so.getNameText();

    if (so instanceof ShaderOptionScreen)
    {
        ShaderOptionScreen shaderoptionscreen = (ShaderOptionScreen)so;
        return s + "...";
    }
    else
    {
        FontRenderer fontrenderer = Config.getMinecraft().fontRendererObj;

        for (int i = fontrenderer.getStringWidth(": " + Lang.getOff()) + 5; fontrenderer.getStringWidth(s) + i >= btnWidth && s.length() > 0; s = s.substring(0, s.length() - 1))
        {
            ;
        }

        String s1 = so.isChanged() ? so.getValueColor(so.getValue()) : "";
        String s2 = so.getValueText(so.getValue());
        return s + ": " + s1 + s2;
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:24,代碼來源:GuiShaderOptions.java

示例2: renderExtraInfo

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
@Override
public void renderExtraInfo() {
    if (getExtraStringInfo() != null) {
        GL11.glPushMatrix();
        GL11.glScaled(0.5, 0.5, 0.5);
        FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
        String[] splittedInfo = WordUtils.wrap(getExtraStringInfo(), 40).split(System.getProperty("line.separator"));
        for (int i = 0; i < splittedInfo.length; i++) {
            int stringLength = fr.getStringWidth(splittedInfo[i]);
            int startX = getWidth() / 2 - stringLength / 4;
            int startY = getHeight() / 2 - (fr.FONT_HEIGHT + 1) * (splittedInfo.length - 1) / 4 + (fr.FONT_HEIGHT + 1) * i / 2 - fr.FONT_HEIGHT / 4;
            Gui.drawRect(startX * 2 - 1, startY * 2 - 1, startX * 2 + stringLength + 1, startY * 2 + fr.FONT_HEIGHT + 1, 0xFFFFFFFF);
            fr.drawString(splittedInfo[i], startX * 2, startY * 2, 0xFF000000);
        }
        GL11.glPopMatrix();
        GL11.glColor4d(1, 1, 1, 1);
    }
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:19,代碼來源:ProgWidget.java

示例3: getDefaultWidth

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
@Override
public int getDefaultWidth()
{
	FontRenderer fr = Fonts.segoe18;
	return fr.getStringWidth(setting.getName())
		+ fr.getStringWidth(setting.getValueString()) + 6;
}
 
開發者ID:Wurst-Imperium,項目名稱:Wurst-MC-1.12,代碼行數:8,代碼來源:Slider.java

示例4: mainMenuMouseClick

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
public static void mainMenuMouseClick(int mouseX, int mouseY, int mouseButton, FontRenderer font, int width)
{
    if (!Loader.instance().java8)
    {
        if (mouseY >= (4 + (8 * 10)) && mouseY < (4 + (10 * 10)))
        {
            int w = font.getStringWidth(I18n.format("fml.messages.java8warning.1", TextFormatting.RED, TextFormatting.RESET));
            w = Math.max(w, font.getStringWidth(I18n.format("fml.messages.java8warning.2")));
            if (mouseX >= ((width - w) / 2) && mouseX <= ((width + w) / 2))
            {
                FMLClientHandler.instance().showGuiScreen(new GuiJava8Error(new Java8VersionException(Collections.<ModContainer>emptyList())));
            }
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:16,代碼來源:ForgeHooksClient.java

示例5: renderZoomedStack

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
private static void renderZoomedStack(ItemStack itemStack, GuiContainer guiContainer, Minecraft minecraft) {
	ScaledResolution scaledResolution = new ScaledResolution(minecraft);
	final float scale = Config.getZoomAmount() / 100f * guiContainer.getGuiLeft() / 17f; // item is 16 wide, give it some extra space on each side
	final float xPosition = (guiContainer.getGuiLeft() / scale - 16f) / 2f;
	final float yPosition = (scaledResolution.getScaledHeight() / scale - 16f) / 2f;
	FontRenderer font = getFontRenderer(minecraft, itemStack);

	GlStateManager.pushMatrix();
	GlStateManager.scale(scale, scale, 1);
	GlStateManager.translate(xPosition, yPosition, 0);
	ZoomRenderHelper.enableGUIStandardItemLighting(scale);

	minecraft.getRenderItem().zLevel += 100;
	minecraft.getRenderItem().renderItemAndEffectIntoGUI(minecraft.player, itemStack, 0, 0);
	renderItemOverlayIntoGUI(font, itemStack);
	minecraft.getRenderItem().zLevel -= 100;
	GlStateManager.disableBlend();
	RenderHelper.disableStandardItemLighting();

	GlStateManager.popMatrix();

	if (Config.showHelpText()) {
		String modName = ItemZoom.MOD_NAME;
		int stringWidth = font.getStringWidth(modName);
		int x = (guiContainer.getGuiLeft() - stringWidth) / 2;
		int y = (scaledResolution.getScaledHeight() + Math.round(17 * scale)) / 2;
		font.drawString(modName, x, y, 4210752);

		if (Config.isToggledEnabled()) {
			String toggleText = KeyBindings.TOGGLE.getDisplayName();
			stringWidth = font.getStringWidth(toggleText);
			x = (guiContainer.getGuiLeft() - stringWidth) / 2;
			y += font.FONT_HEIGHT;
			font.drawString(toggleText, x, y, 4210752);
		}
	}
}
 
開發者ID:mezz,項目名稱:ItemZoom,代碼行數:38,代碼來源:EventHandler.java

示例6: drawNameplate

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
public static void drawNameplate(FontRenderer fontRendererIn, String str, float x, float y, float z, int verticalShift, float viewerYaw, float viewerPitch, boolean isThirdPersonFrontal)
{
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    GlStateManager.glNormal3f(0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-viewerYaw, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate((float)(isThirdPersonFrontal ? -1 : 1) * viewerPitch, 1.0F, 0.0F, 0.0F);
    GlStateManager.scale(-0.025F, -0.025F, 0.025F);
    GlStateManager.disableLighting();
    GlStateManager.depthMask(false);

    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    int i = fontRendererIn.getStringWidth(str) / 2;
    GlStateManager.disableTexture2D();
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexbuffer = tessellator.getBuffer();
    vertexbuffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
    vertexbuffer.pos((double)(-i - 1), (double)(-1 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos((double)(-i - 1), (double)(8 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos((double)(i + 1), (double)(8 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos((double)(i + 1), (double)(-1 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    tessellator.draw();
    GlStateManager.enableTexture2D();

    GlStateManager.depthMask(true);
    fontRendererIn.drawString(str, -fontRendererIn.getStringWidth(str) / 2, verticalShift, -1);
    GlStateManager.enableLighting();
    GlStateManager.disableBlend();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.popMatrix();
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:33,代碼來源:RenderUtils.java

示例7: drawNameplate

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
public static void drawNameplate(FontRenderer fontRendererIn, String str, float x, float y, float z, int verticalShift, float viewerYaw, float viewerPitch, boolean isThirdPersonFrontal, boolean isSneaking)
{
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    GlStateManager.glNormal3f(0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-viewerYaw, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate((float)(isThirdPersonFrontal ? -1 : 1) * viewerPitch, 1.0F, 0.0F, 0.0F);
    GlStateManager.scale(-0.025F, -0.025F, 0.025F);
    GlStateManager.disableLighting();
    GlStateManager.depthMask(false);

    if (!isSneaking)
    {
        GlStateManager.disableDepth();
    }

    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    int i = fontRendererIn.getStringWidth(str) / 2;
    GlStateManager.disableTexture2D();
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexbuffer = tessellator.getBuffer();
    vertexbuffer.begin(7, DefaultVertexFormats.POSITION_COLOR);
    vertexbuffer.pos((double)(-i - 1), (double)(-1 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos((double)(-i - 1), (double)(8 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos((double)(i + 1), (double)(8 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    vertexbuffer.pos((double)(i + 1), (double)(-1 + verticalShift), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    tessellator.draw();
    GlStateManager.enableTexture2D();

    if (!isSneaking)
    {
        fontRendererIn.drawString(str, -fontRendererIn.getStringWidth(str) / 2, verticalShift, 553648127);
        GlStateManager.enableDepth();
    }

    GlStateManager.depthMask(true);
    fontRendererIn.drawString(str, -fontRendererIn.getStringWidth(str) / 2, verticalShift, isSneaking ? 553648127 : -1);
    GlStateManager.enableLighting();
    GlStateManager.disableBlend();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.popMatrix();
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:44,代碼來源:EntityRenderer.java

示例8: drawScreen

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
public void drawScreen()
{
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_FOG);
    Tessellator tessellator = Tessellator.instance;


    this.mc.getTextureManager().bindTexture(Gui.optionsBackground);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    float f1 = 32.0F;
    tessellator.startDrawingQuads();
    tessellator.setColorOpaque_I(2105376);
    tessellator.addVertexWithUV((double) this.left, (double) this.bottom, 0.0D, (double) ((float) this.left / f1), (double) ((float) this.bottom / f1));
    tessellator.addVertexWithUV((double) this.right, (double) this.bottom, 0.0D, (double) ((float) this.right / f1), (double) ((float) this.bottom / f1));
    tessellator.addVertexWithUV((double) this.right, (double) this.top, 0.0D, (double) ((float) this.right / f1), (double) ((float) this.top / f1));
    tessellator.addVertexWithUV((double) this.left, (double) this.top, 0.0D, (double) ((float) this.left / f1), (double) ((float) this.top / f1));
    tessellator.draw();


    GL11.glDisable(GL11.GL_DEPTH_TEST);
    byte b0 = 4;
    GL11.glEnable(GL11.GL_BLEND);
    OpenGlHelper.glBlendFunc(770, 771, 0, 1);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    tessellator.startDrawingQuads();
    tessellator.setColorRGBA_I(0, 0);
    tessellator.addVertexWithUV((double) this.left, (double) (this.top + b0), 0.0D, 0.0D, 1.0D);
    tessellator.addVertexWithUV((double) this.right, (double) (this.top + b0), 0.0D, 1.0D, 1.0D);
    tessellator.setColorRGBA_I(0, 255);
    tessellator.addVertexWithUV((double) this.right, (double) this.top, 0.0D, 1.0D, 0.0D);
    tessellator.addVertexWithUV((double) this.left, (double) this.top, 0.0D, 0.0D, 0.0D);
    tessellator.draw();
    tessellator.startDrawingQuads();
    tessellator.setColorRGBA_I(0, 255);
    tessellator.addVertexWithUV((double) this.left, (double) this.bottom, 0.0D, 0.0D, 1.0D);
    tessellator.addVertexWithUV((double) this.right, (double) this.bottom, 0.0D, 1.0D, 1.0D);
    tessellator.setColorRGBA_I(0, 0);
    tessellator.addVertexWithUV((double) this.right, (double) (this.bottom - b0), 0.0D, 1.0D, 0.0D);
    tessellator.addVertexWithUV((double) this.left, (double) (this.bottom - b0), 0.0D, 0.0D, 0.0D);
    tessellator.draw();

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glDisable(GL11.GL_BLEND);

    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;

    int titleWidth = fontRenderer.getStringWidth(title);
    fontRenderer.drawStringWithShadow(title, this.left + ((this.right - this.left) / 2) - (titleWidth / 2), this.top + 2, 0xFFFFFF);

    int topStart = this.top + 15;

    for (String line : lines)
    {
        if (centeredF)
        {
            int stringWidth = fontRenderer.getStringWidth(line);
            fontRenderer.drawStringWithShadow(line, this.left + ((this.right - this.left) / 2) - (stringWidth / 2), topStart, 0xFFFFFF);
        }
        else
        {
            fontRenderer.drawStringWithShadow(line, this.left, topStart, 0xFFFFFF);
        }
        topStart += 10;
    }

}
 
開發者ID:CreeperHost,項目名稱:CreeperHostGui,代碼行數:71,代碼來源:GuiWell.java

示例9: renderTooltip

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
public static void renderTooltip(int x, int y, List<String> tooltipData, Color color, Color colorFade, Color strColor, FontRenderer fontRenderer) {
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    boolean lighting = GL11.glGetBoolean(GL11.GL_LIGHTING);
    if (lighting)
        RenderHelper.disableStandardItemLighting();

    if (!tooltipData.isEmpty()) {
        int esWidth = 0;
        for (String toolTip : tooltipData) {
            int width = fontRenderer.getStringWidth(toolTip);
            if (width > esWidth)
                esWidth = width;
        }
        ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
        if(x + 15 + esWidth > sr.getScaledWidth()) {
            x -= esWidth + 24;
        }

        int sumLineHeight = 8;
        if (tooltipData.size() > 1)
            sumLineHeight += 2 + (tooltipData.size() - 1) * 10;


        if(y + sumLineHeight > sr.getScaledHeight()) {
            y = (sr.getScaledHeight() - sumLineHeight);
            y = Math.max(25, y);
        }

        int pX = x + 12;
        int pY = y - 12;

        float z = 300F;

        drawGradientRect(pX - 3,           pY - 4,                 z, pX + esWidth + 3, pY - 3,                 color, colorFade);
        drawGradientRect(pX - 3,           pY + sumLineHeight + 3, z, pX + esWidth + 3, pY + sumLineHeight + 4, color, colorFade);
        drawGradientRect(pX - 3,           pY - 3,                 z, pX + esWidth + 3, pY + sumLineHeight + 3, color, colorFade);
        drawGradientRect(pX - 4,           pY - 3,                 z, pX - 3,           pY + sumLineHeight + 3, color, colorFade);
        drawGradientRect(pX + esWidth + 3, pY - 3,                 z, pX + esWidth + 4, pY + sumLineHeight + 3, color, colorFade);

        int rgb = color.getRGB();
        int col = (rgb & 0x00FFFFFF) | rgb & 0xFF000000;
        Color colOp = new Color(col);
        drawGradientRect(pX - 3,           pY - 3 + 1,             z, pX - 3 + 1,       pY + sumLineHeight + 3 - 1, color, colOp);
        drawGradientRect(pX + esWidth + 2, pY - 3 + 1,             z, pX + esWidth + 3, pY + sumLineHeight + 3 - 1, color, colOp);
        drawGradientRect(pX - 3,           pY - 3,                 z, pX + esWidth + 3, pY - 3 + 1,                 colOp, colOp);
        drawGradientRect(pX - 3,           pY + sumLineHeight + 2, z, pX + esWidth + 3, pY + sumLineHeight + 3,     color, color);

        GlStateManager.disableDepth();
        for (int i = 0; i < tooltipData.size(); ++i) {
            String str = tooltipData.get(i);
            fontRenderer.drawString(str, pX, pY, strColor.getRGB());
            if (i == 0)
                pY += 2;
            pY += 10;
        }
        GlStateManager.color(1F, 1F, 1F, 1F);
        GlStateManager.enableDepth();
    }

    if (lighting)
        RenderHelper.enableStandardItemLighting();
    GlStateManager.color(1F, 1F, 1F, 1F);
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
}
 
開發者ID:HellFirePvP,項目名稱:ModularMachinery,代碼行數:65,代碼來源:RenderingUtils.java

示例10: renderItemOverlayIntoGUI

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
@Override
public void renderItemOverlayIntoGUI(FontRenderer fontRenderer, @Nonnull ItemStack is, int par4, int par5, String par6Str) {
	if (!is.isEmpty() && !dankNull.isEmpty()) {
		float scaleFactor = useLg ? 1.0F : 0.5F;
		float inverseScaleFactor = 1.0F / scaleFactor;
		int offset = useLg ? 0 : -1;
		String stackSize = "";

		boolean unicodeFlag = fontRenderer.getUnicodeFlag();
		fontRenderer.setUnicodeFlag(false);
		if (is.getItem().showDurabilityBar(is)) {
			double health = is.getItem().getDurabilityForDisplay(is);
			int j = (int) Math.round(13.0D - health * 13.0D);
			int i = (int) Math.round(255.0D - health * 255.0D);

			GlStateManager.disableDepth();
			GlStateManager.disableTexture2D();

			Tessellator tessellator = Tessellator.getInstance();
			VertexBuffer vertexbuffer = tessellator.getBuffer();
			draw(vertexbuffer, par4 + 2, par5 + 13, 13, 2, 0, 0, 0, 255);
			draw(vertexbuffer, par4 + 2, par5 + 13, 12, 1, (255 - i) / 4, 64, 0, 255);
			draw(vertexbuffer, par4 + 2, par5 + 13, j, 1, 255 - i, i, 0, 255);

			GlStateManager.enableTexture2D();

			GlStateManager.enableDepth();
		}
		int amount = 0;
		amount = is.getCount();
		if (container != null) {
			//amount = container.getDankNullInventory().getSizeForSlot(DankNullUtils.getIndexForStack(container.getDankNullInventory(), is));
		}
		if (amount < 0 || amount > 127) {
			//amount = (byte) amount & (0xff);
		}
		if (amount != 0) {
			scaleFactor = 0.5F;
			inverseScaleFactor = 1.0F / scaleFactor;
			offset = -1;
			stackSize = getToBeRenderedStackSize(amount);
		}
		GlStateManager.disableLighting();
		GlStateManager.disableAlpha();
		GlStateManager.disableBlend();
		GlStateManager.disableDepth();
		GlStateManager.pushMatrix();
		GlStateManager.scale(scaleFactor, scaleFactor, scaleFactor);
		int X = (int) ((par4 + offset + 16.0F - fontRenderer.getStringWidth(stackSize) * scaleFactor) * inverseScaleFactor);
		int Y = (int) ((par5 + offset + 16.0F - 7.0F * scaleFactor) * inverseScaleFactor);
		if (amount > 1L) {
			fontRenderer.drawStringWithShadow(stackSize, X, Y, 16777215);
		}
		GlStateManager.popMatrix();
		GlStateManager.enableDepth();
		GlStateManager.enableBlend();
		GlStateManager.enableAlpha();
		GlStateManager.enableLighting();

		fontRenderer.setUnicodeFlag(unicodeFlag);
	}
}
 
開發者ID:p455w0rd,項目名稱:DankNull,代碼行數:63,代碼來源:DankNullRenderItem.java

示例11: renderName

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
public void renderName(T entity, double x, double y, double z)
{
    if (this.canRenderName(entity))
    {
        double d0 = entity.getDistanceSqToEntity(this.renderManager.livingPlayer);
        float f = entity.isSneaking() ? 32.0F : 64.0F;

        if (d0 < (double)(f * f))
        {
            String s = entity.getDisplayName().getFormattedText();
            float f1 = 0.02666667F;
            GlStateManager.alphaFunc(516, 0.1F);

            if (entity.isSneaking())
            {
                FontRenderer fontrenderer = this.getFontRendererFromRenderManager();
                GlStateManager.pushMatrix();
                GlStateManager.translate((float)x, (float)y + entity.height + 0.5F - (entity.isChild() ? entity.height / 2.0F : 0.0F), (float)z);
                GL11.glNormal3f(0.0F, 1.0F, 0.0F);
                GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
                GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
                GlStateManager.scale(-0.02666667F, -0.02666667F, 0.02666667F);
                GlStateManager.translate(0.0F, 9.374999F, 0.0F);
                GlStateManager.disableLighting();
                GlStateManager.depthMask(false);
                GlStateManager.enableBlend();
                GlStateManager.disableTexture2D();
                GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
                int i = fontrenderer.getStringWidth(s) / 2;
                Tessellator tessellator = Tessellator.getInstance();
                WorldRenderer worldrenderer = tessellator.getWorldRenderer();
                worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
                worldrenderer.pos((double)(-i - 1), -1.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                worldrenderer.pos((double)(-i - 1), 8.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                worldrenderer.pos((double)(i + 1), 8.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                worldrenderer.pos((double)(i + 1), -1.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                tessellator.draw();
                GlStateManager.enableTexture2D();
                GlStateManager.depthMask(true);
                fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, 0, 553648127);
                GlStateManager.enableLighting();
                GlStateManager.disableBlend();
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                GlStateManager.popMatrix();
            }
            else
            {
                this.renderOffsetLivingLabel(entity, x, y - (entity.isChild() ? (double)(entity.height / 2.0F) : 0.0D), z, s, 0.02666667F, d0);
            }
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:53,代碼來源:RendererLivingEntity.java

示例12: renderName

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
protected void renderName(EntityItemFrame entity, double x, double y, double z)
{
    if (Minecraft.isGuiEnabled() && entity.getDisplayedItem() != null && entity.getDisplayedItem().hasDisplayName() && this.renderManager.pointedEntity == entity)
    {
        float f = 1.6F;
        float f1 = 0.016666668F * f;
        double d0 = entity.getDistanceSqToEntity(this.renderManager.livingPlayer);
        float f2 = entity.isSneaking() ? 32.0F : 64.0F;

        if (d0 < (double)(f2 * f2))
        {
            String s = entity.getDisplayedItem().getDisplayName();

            if (entity.isSneaking())
            {
                FontRenderer fontrenderer = this.getFontRendererFromRenderManager();
                GlStateManager.pushMatrix();
                GlStateManager.translate((float)x + 0.0F, (float)y + entity.height + 0.5F, (float)z);
                GL11.glNormal3f(0.0F, 1.0F, 0.0F);
                GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
                GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
                GlStateManager.scale(-f1, -f1, f1);
                GlStateManager.disableLighting();
                GlStateManager.translate(0.0F, 0.25F / f1, 0.0F);
                GlStateManager.depthMask(false);
                GlStateManager.enableBlend();
                GlStateManager.blendFunc(770, 771);
                Tessellator tessellator = Tessellator.getInstance();
                WorldRenderer worldrenderer = tessellator.getWorldRenderer();
                int i = fontrenderer.getStringWidth(s) / 2;
                GlStateManager.disableTexture2D();
                worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
                worldrenderer.pos((double)(-i - 1), -1.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                worldrenderer.pos((double)(-i - 1), 8.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                worldrenderer.pos((double)(i + 1), 8.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                worldrenderer.pos((double)(i + 1), -1.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                tessellator.draw();
                GlStateManager.enableTexture2D();
                GlStateManager.depthMask(true);
                fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, 0, 553648127);
                GlStateManager.enableLighting();
                GlStateManager.disableBlend();
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                GlStateManager.popMatrix();
            }
            else
            {
                this.renderLivingLabel(entity, s, x, y, z, 64);
            }
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:53,代碼來源:RenderItemFrame.java

示例13: renderName

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
public void renderName(T entity, double x, double y, double z)
{
    if (!Reflector.RenderLivingEvent_Specials_Pre_Constructor.exists() || !Reflector.postForgeBusEvent(Reflector.RenderLivingEvent_Specials_Pre_Constructor, new Object[] {entity, this, Double.valueOf(x), Double.valueOf(y), Double.valueOf(z)}))
    {
        if (this.canRenderName(entity))
        {
            double d0 = entity.getDistanceSqToEntity(this.renderManager.livingPlayer);
            float f = entity.isSneaking() ? NAME_TAG_RANGE_SNEAK : NAME_TAG_RANGE;

            if (d0 < (double)(f * f) || (ModuleManager.getModule(Tags.class).enabled))
            {
                String s = entity.getDisplayName().getFormattedText();
                float f1 = 0.02666667F;
                GlStateManager.alphaFunc(516, 0.1F);

                if (entity.isSneaking())
                {
                    FontRenderer fontrenderer = this.getFontRendererFromRenderManager();
                    GlStateManager.pushMatrix();
                    GlStateManager.translate((float)x, (float)y + entity.height + 0.5F - (entity.isChild() ? entity.height / 2.0F : 0.0F), (float)z);
                    GL11.glNormal3f(0.0F, 1.0F, 0.0F);
                    GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
                    GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
                    GlStateManager.scale(-0.02666667F, -0.02666667F, 0.02666667F);
                    GlStateManager.translate(0.0F, 9.374999F, 0.0F);
                    GlStateManager.disableLighting();
                    GlStateManager.depthMask(false);
                    GlStateManager.enableBlend();
                    GlStateManager.disableTexture2D();
                    GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
                    int i = fontrenderer.getStringWidth(s) / 2;
                    Tessellator tessellator = Tessellator.getInstance();
                    WorldRenderer worldrenderer = tessellator.getWorldRenderer();
                    worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
                    worldrenderer.pos((double)(-i - 1), -1.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                    worldrenderer.pos((double)(-i - 1), 8.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                    worldrenderer.pos((double)(i + 1), 8.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                    worldrenderer.pos((double)(i + 1), -1.0D, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
                    tessellator.draw();
                    GlStateManager.enableTexture2D();
                    GlStateManager.depthMask(true);
                    fontrenderer.drawString(s, -fontrenderer.getStringWidth(s) / 2, 0, 553648127);
                    GlStateManager.enableLighting();
                    GlStateManager.disableBlend();
                    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
                    GlStateManager.popMatrix();
                }
                else
                {
                    this.renderOffsetLivingLabel(entity, x, y - (entity.isChild() ? (double)(entity.height / 2.0F) : 0.0D), z, s, 0.02666667F, d0);
                }
            }
        }

        if (!Reflector.RenderLivingEvent_Specials_Post_Constructor.exists() || !Reflector.postForgeBusEvent(Reflector.RenderLivingEvent_Specials_Post_Constructor, new Object[] {entity, this, Double.valueOf(x), Double.valueOf(y), Double.valueOf(z)}))
        {
            ;
        }
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:61,代碼來源:RendererLivingEntity.java

示例14: renderLivingLabel

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
/**
 * Renders an entity's name above its head
 */
protected void renderLivingLabel(Entity entityIn, String str, double x, double y, double z, int maxDistance)
{
	if (entityIn instanceof EntityPlayer)
	{
	    NametagRenderEvent event = new NametagRenderEvent(entityIn, str, x, y, z);
	    event.call();

	    if (event.isCancelled()) return;
	}

    double d0 = entityIn.getDistanceSqToEntity(this.renderManager.livingPlayer);

    if (d0 <= (double)(maxDistance * maxDistance))
    {
        FontRenderer fontrenderer = this.getFontRendererFromRenderManager();
        float f = 1.6F;
        float f1 = 0.016666668F * f;
        GlStateManager.pushMatrix();
        GlStateManager.translate((float)x + 0.0F, (float)y + entityIn.height + 0.5F, (float)z);
        GL11.glNormal3f(0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
        GlStateManager.scale(-f1, -f1, f1);
        GlStateManager.disableLighting();
        GlStateManager.depthMask(false);
        GlStateManager.disableDepth();
        GlStateManager.enableBlend();
        GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
        Tessellator tessellator = Tessellator.getInstance();
        WorldRenderer worldrenderer = tessellator.getWorldRenderer();
        byte b0 = 0;

        if (str.equals("deadmau5"))
        {
            b0 = -10;
        }

        int i = fontrenderer.getStringWidth(str) / 2;
        GlStateManager.disableTexture2D();
        worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
        worldrenderer.pos((double)(-i - 1), (double)(-1 + b0), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
        worldrenderer.pos((double)(-i - 1), (double)(8 + b0), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
        worldrenderer.pos((double)(i + 1), (double)(8 + b0), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
        worldrenderer.pos((double)(i + 1), (double)(-1 + b0), 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
        tessellator.draw();
        GlStateManager.enableTexture2D();
        fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, b0, 553648127);
        GlStateManager.enableDepth();
        GlStateManager.depthMask(true);
        fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, b0, -1);
        GlStateManager.enableLighting();
        GlStateManager.disableBlend();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.popMatrix();
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:60,代碼來源:Render.java

示例15: renderStackTooltip

import net.minecraft.client.gui.FontRenderer; //導入方法依賴的package包/類
public static void renderStackTooltip(int x, int y, List<Tuple<ItemStack, String>> tooltipData, Color color, Color colorFade, Color strColor, FontRenderer fr, RenderItem ri) {
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    if (!tooltipData.isEmpty()) {
        int esWidth = 0;
        for (Tuple<ItemStack, String> toolTip : tooltipData) {
            int width = fr.getStringWidth(toolTip.getSecond()) + 17;
            if (width > esWidth)
                esWidth = width;
        }
        ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
        if(x + 15 + esWidth > sr.getScaledWidth()) {
            x -= esWidth + 24;
        }
        int sumLineHeight = 8;
        int lastAdded = 0;
        if (tooltipData.size() > 1) {
            sumLineHeight += 2;
            for (Tuple<ItemStack, String> tooltipEntry : tooltipData) {
                int height = tooltipEntry.getFirst().isEmpty() ? 10 : 17;
                sumLineHeight += height;
                lastAdded = height;
            }
            sumLineHeight -= lastAdded;
        }

        if(y + sumLineHeight > sr.getScaledHeight()) {
            y = (sr.getScaledHeight() - sumLineHeight);
            y = Math.max(25, y);
        }

        int pX = x + 12;
        int pY = y - 12;

        float z = 300F;

        GlStateManager.disableDepth();
        drawGradientRect(pX - 3,           pY - 4,                 z, pX + esWidth + 3, pY - 3,                 color, colorFade);
        drawGradientRect(pX - 3,           pY + sumLineHeight + 3, z, pX + esWidth + 3, pY + sumLineHeight + 4, color, colorFade);
        drawGradientRect(pX - 3,           pY - 3,                 z, pX + esWidth + 3, pY + sumLineHeight + 3, color, colorFade);
        drawGradientRect(pX - 4,           pY - 3,                 z, pX - 3,           pY + sumLineHeight + 3, color, colorFade);
        drawGradientRect(pX + esWidth + 3, pY - 3,                 z, pX + esWidth + 4, pY + sumLineHeight + 3, color, colorFade);

        int rgb = color.getRGB();
        int col = (rgb & 0x00FFFFFF) | rgb & 0xFF000000;
        Color colOp = new Color(col);
        drawGradientRect(pX - 3,           pY - 3 + 1,             z, pX - 3 + 1,       pY + sumLineHeight + 3 - 1, color, colOp);
        drawGradientRect(pX + esWidth + 2, pY - 3 + 1,             z, pX + esWidth + 3, pY + sumLineHeight + 3 - 1, color, colOp);
        drawGradientRect(pX - 3,           pY - 3,                 z, pX + esWidth + 3, pY - 3 + 1,                 colOp, colOp);
        drawGradientRect(pX - 3,           pY + sumLineHeight + 2, z, pX + esWidth + 3, pY + sumLineHeight + 3,     color, color);

        for (Tuple<ItemStack, String> stackDesc : tooltipData) {
            if(!stackDesc.getFirst().isEmpty()) {
                fr.drawString(stackDesc.getSecond(), pX + 17, pY, strColor.getRGB());
                GlStateManager.color(1F, 1F, 1F, 1F);
                GlStateManager.pushMatrix();
                RenderHelper.enableGUIStandardItemLighting();
                ri.renderItemAndEffectIntoGUI(stackDesc.getFirst(), pX - 1, pY - 5);
                GlStateManager.popMatrix();
                pY += 17;
            } else {
                fr.drawString(stackDesc.getSecond(), pX, pY, strColor.getRGB());
                GlStateManager.color(1F, 1F, 1F, 1F);
                pY += 10;
            }
            GlStateManager.enableBlend();
            GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        }
        GlStateManager.color(1F, 1F, 1F, 1F);
        GlStateManager.enableDepth();
    }

    GlStateManager.enableAlpha();
    GlStateManager.color(1F, 1F, 1F, 1F);
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
}
 
開發者ID:HellFirePvP,項目名稱:ModularMachinery,代碼行數:76,代碼來源:RenderingUtils.java


注:本文中的net.minecraft.client.gui.FontRenderer.getStringWidth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。