net.minecraft.client.gui.FontRenderer Java Examples

The following examples show how to use net.minecraft.client.gui.FontRenderer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: GT-Classic   Author: e99999   File: GTRenderDisplayScreen.java    License: GNU Lesser General Public License v3.0 9 votes vote down vote up
@Override
public void render(GTTileDisplayScreen screen, double x, double y, double z, float partialTicks, int destroyStage,
		float alpha) {
	if (screen != null && screen.shouldDraw) {
		FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
		GlStateManager.pushMatrix();
		screen.applyRotation((float) x, (float) y, (float) z);
		screen.applySize(2.5F, 4D, 4D, -0.001D);
		int bright = 0xF0;
		int brightX = bright % 65536;
		int brightY = bright / 65536;
		OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightX, brightY);
		int i = 0;
		for (String text : screen.information.getWrapperList()) {
			i++;
			if (i > 8) {
				break;
			}
			renderer.drawString(text, (int) x + 10, (int) (y - 2) + (10 * i), Color.CYAN.getRGB());
		}
		GlStateManager.popMatrix();
	}
}
 
Example #2
Source Project: AgriCraft   Author: AgriCraft   File: GuiHelper.java    License: MIT License 6 votes vote down vote up
/**
 * Utility method: splits the string in different lines so it will fit on the page.
 *
 * @param fontRendererObj the font renderer to check against.
 * @param input the line to split up.
 * @param maxWidth the maximum allowable width of the line before being wrapped.
 * @param scale the scale of the text to the width.
 * @return the string split up into lines by the '\n' character.
 */
public static String splitInLines(FontRenderer fontRendererObj, String input, double maxWidth, double scale) {
    maxWidth = maxWidth / scale;
    String notProcessed = input;
    String output = "";
    while (fontRendererObj.getStringWidth(notProcessed) > maxWidth) {
        int index = 0;
        if (notProcessed != null && !notProcessed.equals("")) {
            //find the first index at which the string exceeds the size limit
            while (notProcessed.length() - 1 > index && fontRendererObj.getStringWidth(notProcessed.substring(0, index)) < maxWidth) {
                index = (index + 1) < notProcessed.length() ? index + 1 : index;
            }
            //go back to the first space to cut the string in two lines
            while (index > 0 && notProcessed.charAt(index) != ' ') {
                index--;
            }
            //update the data for the next iteration
            output = output.equals("") ? output : output + '\n';
            output = output + notProcessed.substring(0, index);
            notProcessed = notProcessed.length() > index + 1 ? notProcessed.substring(index + 1) : notProcessed;
        }
    }
    return output + '\n' + notProcessed;
}
 
Example #3
Source Project: MediaMod   Author: MediaModMC   File: CustomButton.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
    if (this.visible) {
        FontRenderer fontrenderer = mc.fontRendererObj;
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

        this.hovered =
                mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width
                        && mouseY < this.yPosition + this.height;

        Gui.drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, new Color(0, 0, 0, 175).getRGB());

        this.mouseDragged(mc, mouseX, mouseY);
        int j = 14737632;

        if (!this.enabled) {
            j = 10526880;
        } else if (this.hovered) {
            j = new Color(180, 180, 180).getRGB();
        }

        drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, j);
    }
}
 
Example #4
Source Project: LiquidBounce   Author: CCBlueX   File: Fonts.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static Object[] getFontDetails(final FontRenderer fontRenderer) {
    for(final Field field : Fonts.class.getDeclaredFields()) {
        try {
            field.setAccessible(true);

            final Object o = field.get(null);

            if(o.equals(fontRenderer)) {
                final FontDetails fontDetails = field.getAnnotation(FontDetails.class);

                return new Object[] {fontDetails.fontName(), fontDetails.fontSize()};
            }
        }catch(final IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    if (fontRenderer instanceof GameFontRenderer) {
        final Font font = ((GameFontRenderer) fontRenderer).getDefaultFont().getFont();

        return new Object[] {font.getName(), font.getSize()};
    }

    return null;
}
 
Example #5
Source Project: LiquidBounce   Author: CCBlueX   File: Fonts.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static List<FontRenderer> getFonts() {
    final List<FontRenderer> fonts = new ArrayList<>();

    for(final Field fontField : Fonts.class.getDeclaredFields()) {
        try {
            fontField.setAccessible(true);

            final Object fontObj = fontField.get(null);

            if(fontObj instanceof FontRenderer) fonts.add((FontRenderer) fontObj);
        }catch(final IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    fonts.addAll(Fonts.CUSTOM_FONT_RENDERERS);

    return fonts;
}
 
Example #6
Source Project: Valkyrien-Skies   Author: ValkyrienSkies   File: ControlEventsClient.java    License: Apache License 2.0 6 votes vote down vote up
@SubscribeEvent
public void render(RenderGameOverlayEvent.Post event) {
    Minecraft minecraft = Minecraft.getMinecraft();
    EntityPlayer player = Minecraft.getMinecraft().player;
    FontRenderer fontRenderer = minecraft.fontRenderer;
    if (fontRenderer != null && player != null && event.getType()
        == net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.TEXT) {
        IShipPilot playerPilot = (IShipPilot) player;
        if (playerPilot.isPiloting()) {
            BlockPos tilePilotedPos = playerPilot.getPosBeingControlled();
            TileEntity pilotedTile = player.getEntityWorld().getTileEntity(tilePilotedPos);
            if (pilotedTile instanceof TileEntityPilotableImpl) {
                TileEntityPilotableImpl pilotedControlEntity = (TileEntityPilotableImpl) pilotedTile;
                ScaledResolution scaledresolution = new ScaledResolution(
                    Minecraft.getMinecraft());
                pilotedControlEntity.renderPilotText(fontRenderer, scaledresolution);
            }
        }
    }
}
 
Example #7
Source Project: GregTech   Author: GregTechCE   File: ClickButtonWidget.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
    super.drawInBackground(mouseX, mouseY, context);
    Position position = getPosition();
    Size size = getSize();
    if (buttonTexture instanceof SizedTextureArea) {
        ((SizedTextureArea) buttonTexture).drawHorizontalCutSubArea(position.x, position.y, size.width, size.height, 0.0, 1.0);
    } else {
        buttonTexture.drawSubArea(position.x, position.y, size.width, size.height, 0.0, 0.0, 1.0, 1.0);
    }
    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
    String text = I18n.format(displayText);
    fontRenderer.drawString(text,
        position.x + size.width / 2 - fontRenderer.getStringWidth(text) / 2,
        position.y + size.height / 2 - fontRenderer.FONT_HEIGHT / 2, textColor);
    GlStateManager.color(1.0f, 1.0f, 1.0f);
}
 
Example #8
Source Project: GregTech   Author: GregTechCE   File: SliderWidget.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
    Position pos = getPosition();
    Size size = getSize();
    if (backgroundArea != null) {
        backgroundArea.draw(pos.x, pos.y, size.width, size.height);
    }
    if(displayString == null) {
        this.displayString = getDisplayString();
    }
    sliderIcon.draw(pos.x + (int) (this.sliderPosition * (float) (size.width - 8)), pos.y, sliderWidth, size.height);
    FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
    fontRenderer.drawString(displayString,
        pos.x + size.width / 2 - fontRenderer.getStringWidth(displayString) / 2,
        pos.y + size.height / 2 - fontRenderer.FONT_HEIGHT / 2, textColor);
    GlStateManager.color(1.0f, 1.0f, 1.0f);
}
 
Example #9
Source Project: WearableBackpacks   Author: copygirl   File: GuiButton.java    License: MIT License 6 votes vote down vote up
/** Draws the content on the button, such as text. */
protected void drawButtonForeground(boolean isHighlighted, float partialTicks) {
	String text = getText();
	if (text.isEmpty()) return;
	FontRenderer fontRenderer = getFontRenderer();
	
	int textWidth = fontRenderer.getStringWidth(text);
	int maxTextWidth = getWidth() - MIN_TEXT_PADDING;
	if ((textWidth > maxTextWidth) && (textWidth > ELLIPSIS_WIDTH)) {
		text = fontRenderer.trimStringToWidth(text, maxTextWidth - ELLIPSIS_WIDTH).trim() + ELLIPSIS;
		textWidth = fontRenderer.getStringWidth(text);
	}
	
	fontRenderer.drawStringWithShadow(text, getWidth() / 2 - textWidth / 2,
	                                        (getHeight() - 8) / 2, getTextColor(isHighlighted));
}
 
Example #10
Source Project: Hyperium   Author: HyperiumClient   File: DisplayTable.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void draw(int x, int y) {
    boolean first = true;
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, 0);

    for (String[] row : rows) {
        FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj;
        GlStateManager.pushMatrix();

        for (int i = 0; i < row.length; i++) {
            String tmp = row[i];
            fontRendererObj.drawString((first ? EnumChatFormatting.BOLD : "") + tmp, 0, 0, Color.WHITE.getRGB());
            GlStateManager.translate(rowSpacing[i], 0, 0);
        }

        GlStateManager.popMatrix();
        GlStateManager.translate(0, 11, 0);
        first = false;
    }

    GlStateManager.popMatrix();
}
 
Example #11
Source Project: Signals   Author: MineMaarten   File: WidgetTextFieldNumber.java    License: GNU General Public License v3.0 6 votes vote down vote up
public WidgetTextFieldNumber(FontRenderer fontRenderer, int x, int y, int width, int height){
    super(fontRenderer, x, y, width, height);
    setValue(0);

    setValidator(input -> {
        if(input == null || input.isEmpty() || input.equals("-")) {
            return true; // treat as numeric zero
        }
        try {
            double d = Double.parseDouble(input);
            return d >= this.minValue && d <= this.maxValue;
        } catch(NumberFormatException e) {
            return false;
        }
    });
}
 
Example #12
Source Project: GT-Classic   Author: e99999   File: GTJeiMultiRecipeWrapper.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
	int extraHeight = 0;
	FontRenderer font = minecraft.fontRenderer;
	font.drawString("Ticks: " + getEntryTicks(multiRecipe.getOutputs()), 0, 40, Color.black.getRGB());
	font.drawString("Seconds: " + getEntryTicks(multiRecipe.getOutputs()) / 20.0F, 0, 50, Color.black.getRGB());
	font.drawString("Tier: "
			+ GTValues.getTierString(EnergyNet.instance.getTierFromPower(multiRecipe.getMachineEu())), 0, 60, Color.black.getRGB());
	font.drawString("Usage: " + multiRecipe.getMachineEu() + " EU/t", 0, 70, Color.black.getRGB());
	font.drawString("Cost: "
			+ NumberFormat.getNumberInstance(Locale.US).format(getEntryTicks(multiRecipe.getOutputs())
					* multiRecipe.getMachineEu())
			+ " EU", 0, 80, Color.black.getRGB());
	if (multiRecipe.getMachineEu() == 8192 && getEntryTicks(multiRecipe.getOutputs()) > 3000) {
		extraHeight = 10;
		font.drawString("Output: "
				+ NumberFormat.getNumberInstance(Locale.US).format(getEntryTicks(multiRecipe.getOutputs()) * 32000)
				+ " EU Out", 0, 90, Color.black.getRGB());
	}
	if (GTConfig.general.debugMode) {
		font.drawString("Recipe Id: " + multiRecipe.getRecipeID(), 0, 90 + extraHeight, Color.black.getRGB());
	}
}
 
Example #13
Source Project: ehacks-pro   Author: radioegor146   File: XRayAddGui.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void drawItem(ItemStack itemstack, int x, int y, String name) {
    GL11.glColor3ub((byte) -1, (byte) -1, (byte) -1);
    GL11.glDisable(2896);
    this.zLevel = 200.0f;
    GuiScreen.itemRender.zLevel = 200.0f;
    FontRenderer font = null;
    if (itemstack != null) {
        font = itemstack.getItem().getFontRenderer(itemstack);
    }
    if (font == null) {
        font = this.fontRendererObj;
    }
    GuiScreen.itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), itemstack, x, y);
    GuiScreen.itemRender.renderItemOverlayIntoGUI(font, this.mc.getTextureManager(), itemstack, x, y, name);
    this.zLevel = 0.0f;
    GuiScreen.itemRender.zLevel = 0.0f;
    GL11.glEnable(2896);
}
 
Example #14
Source Project: NotEnoughItems   Author: TheCBProject   File: GuiNEIButton.java    License: MIT License 5 votes vote down vote up
@Override
public void drawButton(Minecraft minecraft, int mouseX, int mouseY, float partialTicks) {

    if (!visible) {
        return;
    }

    FontRenderer fontrenderer = minecraft.fontRenderer;
    TextureUtils.changeTexture(GUI_TEX);
    GlStateManager.color(1, 1, 1, 1);

    boolean flag = mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
    int k = getHoverState(flag);

    drawTexturedModalRect(x, y, 0, 46 + k * 20, width / 2, height / 2);//top left
    drawTexturedModalRect(x + width / 2, y, 200 - width / 2, 46 + k * 20, width / 2, height / 2);//top right
    drawTexturedModalRect(x, y + height / 2, 0, 46 + k * 20 + 20 - height / 2, width / 2, height / 2);//bottom left
    drawTexturedModalRect(x + width / 2, y + height / 2, 200 - width / 2, 46 + k * 20 + 20 - height / 2, width / 2, height / 2);//bottom right

    mouseDragged(minecraft, mouseX, mouseY);

    if (!enabled) {
        drawCenteredString(fontrenderer, displayString, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0);
    } else if (flag) {
        drawCenteredString(fontrenderer, displayString, x + width / 2, y + (height - 8) / 2, 0xffffa0);
    } else {
        drawCenteredString(fontrenderer, displayString, x + width / 2, y + (height - 8) / 2, 0xe0e0e0);
    }
}
 
Example #15
Source Project: BigReactors   Author: erogenousbeef-zz   File: BeefGuiLabel.java    License: MIT License 5 votes vote down vote up
private void recalculateSize() {
	FontRenderer fontRenderer = guiContainer.getFontRenderer();
	if(xMax > 0) {
		this.width = fontRenderer.splitStringWidth(labelText, xMax);
		int totalWidth = fontRenderer.getStringWidth(labelText);
		this.height = fontRenderer.FONT_HEIGHT * Math.max(1, (totalWidth / width));		
	}
	else {
		this.width = fontRenderer.getStringWidth(labelText);
		this.height = fontRenderer.FONT_HEIGHT;
	}
}
 
Example #16
Source Project: LiquidBounce   Author: CCBlueX   File: Fonts.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static FontRenderer getFontRenderer(final String name, final int size) {
    for(final Field field : Fonts.class.getDeclaredFields()) {
        try {
            field.setAccessible(true);

            final Object o = field.get(null);

            if(o instanceof FontRenderer) {
                final FontDetails fontDetails = field.getAnnotation(FontDetails.class);

                if(fontDetails.fontName().equals(name) && fontDetails.fontSize() == size)
                    return (FontRenderer) o;
            }
        }catch(final IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    for (final GameFontRenderer liquidFontRenderer : CUSTOM_FONT_RENDERERS) {
        final Font font = liquidFontRenderer.getDefaultFont().getFont();

        if(font.getName().equals(name) && font.getSize() == size)
            return liquidFontRenderer;
    }

    return minecraftFont;
}
 
Example #17
Source Project: GregTech   Author: GregTechCE   File: MultiblockInfoRecipeWrapper.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void drawText(Minecraft minecraft, int recipeWidth) {
    String localizedName = I18n.format(infoPage.getController().getMetaFullName());
    GTUtility.drawCenteredSizedText(recipeWidth / 2, 0, localizedName, 0x333333, 1.3);
    FontRenderer fontRenderer = minecraft.fontRenderer;
    List<String> lines = Arrays.stream(infoPage.getDescription())
        .flatMap(s -> fontRenderer.listFormattedStringToWidth(s, recipeWidth).stream())
        .collect(Collectors.toList());
    for (int i = 0; i < lines.size(); i++) {
        String lineText = lines.get(i);
        int x = (recipeWidth - fontRenderer.getStringWidth(lineText)) / 2;
        int y = 8 + i * fontRenderer.FONT_HEIGHT;
        fontRenderer.drawString(lineText, x, y, 0x333333);
    }
    GlStateManager.color(1.0f, 1.0f, 1.0f);
}
 
Example #18
Source Project: GregTech   Author: GregTechCE   File: LabelWidget.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void recomputeSize() {
    if (isClientSide()) {
        FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
        String resultText = getResultText();
        setSize(new Size(fontRenderer.getStringWidth(resultText), fontRenderer.FONT_HEIGHT));
        if (uiAccess != null) {
            uiAccess.notifySizeChange();
        }
    }
}
 
Example #19
Source Project: BetterChests   Author: Aroma1997   File: GuiUpgrades.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public GuiUpgrades(ContainerBase<? extends IUpgradableBlockInternal> container) {
	super(container, 194);
	
	FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
	
	String energyInfoText = LocalizationHelper.localize("betterchests:gui.upgrades.info.power");
	String disableInfoText = LocalizationHelper.localize("betterchests:gui.upgrades.info.disable");
	String filterInfoText = LocalizationHelper.localize("betterchests:gui.upgrades.info.filter");

	GuiElementProgressBar progBar = new GuiElementProgressBar(this, 155, 25, DynamicTexture.ENERGY, container.inventory.getEnergyStorage().getMaxEnergyStored(), container.inventory.getEnergyStorage()::getEnergyStored);
	progBar.addHoverTooltip(() -> LocalizationHelper.localize("betterchests:gui.upgrades.energy.desc"));
	progBar.addProgressTooltip("betterchests:gui.upgrades.energy.tooltip");
	addGuiElement(progBar);

	GuiElementExpandableColor energyInfo = addGuiElement(new GuiElementExpandableColor(this, right(22, 22), 160, fontRenderer.getWordWrappedHeight(energyInfoText, 80)));
	energyInfo.setColor(0xFF00FF00);
	energyInfo.setTexture(IRenderable.getRenderable(PowerUpgradeType.CAPACITOR.getStack()));
	energyInfo.setActualContent(IRenderable.getRenderable(() -> energyInfoText, energyInfo.getLocation()));

	GuiElementExpandableColor disableInfo = addGuiElement(new GuiElementExpandableColor(this, energyInfo.getLocation().below(22, 22), 160, fontRenderer.getWordWrappedHeight(disableInfoText, 60)));
	disableInfo.setColor(0xFFFF0000);
	disableInfo.setTexture(StaticTexture.INFO_BLUE.offset(3, 0).scaled(0.75F));
	disableInfo.setActualContent(IRenderable.getRenderable(() -> LocalizationHelper.localize("betterchests:gui.upgrades.info.disable"), disableInfo.getLocation()));

	GuiElementExpandableColor filterInfo = addGuiElement(new GuiElementExpandableColor(this, disableInfo.getLocation().below(22, 22), 160, fontRenderer.getWordWrappedHeight(filterInfoText, 70)));
	filterInfo.setColor(0xFFFFFF00);
	filterInfo.setTexture(IRenderable.getRenderable(new ItemStack(BlocksItemsBetterChests.filter)));
	filterInfo.setActualContent(IRenderable.getRenderable(() -> LocalizationHelper.localize("betterchests:gui.upgrades.info.filter"), filterInfo.getLocation()));
}
 
Example #20
Source Project: OpenModsLib   Author: OpenMods   File: GuiComponentLabel.java    License: MIT License 5 votes vote down vote up
private int calculateWidth() {
	final FontRenderer fr = parent.getFontRenderer();
	int maxWidth = 0;
	for (String s : getFormattedText(fr)) {
		if (s == null) break;
		int width = fr.getStringWidth(s);
		if (width > maxWidth) maxWidth = width;
	}
	return (int)(maxWidth * scale);
}
 
Example #21
Source Project: TFC2   Author: Deadrik   File: ClientRenderHandler.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent event)
{

	if(event.phase == Phase.START)
	{
		if(ClientRenderHandler.IsGeneratingFirstIsland)
		{
			Minecraft.getMinecraft().skipRenderWorld = true;
			skipRender = true;
		}
		else
		{
			skipRender = false;
		}
	}
	if(event.phase == Phase.END)
	{
		if(skipRender && ClientRenderHandler.IsGeneratingFirstIsland)
		{
			String gen = Core.translate("gui.generatingmapmessage");
			FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
			ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
			int sizeX = Minecraft.getMinecraft().displayWidth/2;
			int sizeY = Minecraft.getMinecraft().displayHeight/2;

			renderer.drawString(gen, sizeX/2 - (renderer.getStringWidth(gen) / 2)+1, sizeY/2+1, Color.black.getRGB());
			renderer.drawString(gen, sizeX/2 - (renderer.getStringWidth(gen) / 2), sizeY/2, Color.white.getRGB());
			Minecraft.getMinecraft().skipRenderWorld = false;
			skipRender = false;
		}
	}
}
 
Example #22
Source Project: PneumaticCraft   Author: MineMaarten   File: ArmorMessage.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void renderMessage(FontRenderer fontRenderer, float partialTicks){
    if(lifeSpan > 10) {
        stat.openWindow();
    } else {
        stat.closeWindow();
    }
    stat.render(-1, -1, partialTicks);
    // PneumaticCraftUtils.getPartOfString(
}
 
Example #23
Source Project: NotEnoughItems   Author: Chicken-Bones   File: GuiContainerManager.java    License: MIT License 5 votes vote down vote up
public static void drawItem(int i, int j, ItemStack itemstack, FontRenderer fontRenderer) {
    enable3DRender();
    float zLevel = drawItems.zLevel += 100F;
    try {
        drawItems.renderItemAndEffectIntoGUI(itemstack, i, j);
        drawItems.renderItemOverlays(fontRenderer, itemstack, i, j);

        if (!checkMatrixStack())
            throw new IllegalStateException("Modelview matrix stack too deep");
        if (Tessellator.getInstance().getWorldRenderer().isDrawing)
            throw new IllegalStateException("Still drawing");
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String stackTrace = itemstack + sw.toString();
        if (!stackTraces.contains(stackTrace)) {
            System.err.println("Error while rendering: " + itemstack);
            e.printStackTrace();
            stackTraces.add(stackTrace);
        }

        restoreMatrixStack();
        if (Tessellator.getInstance().getWorldRenderer().isDrawing)
            Tessellator.getInstance().draw();

        drawItems.zLevel = zLevel;
        drawItems.renderItemIntoGUI(new ItemStack(Blocks.fire), i, j);
    }

    enable2DRender();
    drawItems.zLevel = zLevel - 100;
}
 
Example #24
Source Project: OpenPeripheral-Addons   Author: OpenMods   File: Text.java    License: MIT License 5 votes vote down vote up
private void updateBoundingBox() {
	final int height = Math.round(8 * scale);

	final int width;
	if (Strings.isNullOrEmpty(text)) {
		width = 0;
	} else {
		FontRenderer fontRenderer = FMLClientHandler.instance().getClient().fontRenderer;
		width = Math.round(fontRenderer.getStringWidth(text) * scale);
	}

	setBoundingBox(Box2d.fromOriginAndSize(x, y, width, height));
}
 
Example #25
Source Project: YUNoMakeGoodMap   Author: LexManos   File: GuiCustomizeWorld.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void drawSlot(int slotIdx, int entryRight, int slotTop, int slotBuffer, Tessellator tess)
{
    ResourceLocation item = list.get(slotIdx);
    StructInfo info = getInfo(item);
    FontRenderer font = GuiCustomizeWorld.this.fontRenderer;

    font.drawString(font.trimStringToWidth(info.name, listWidth - 10), this.left + 3 , slotTop +  2, 0xFF2222);
}
 
Example #26
Source Project: Hyperium   Author: HyperiumClient   File: HyperiumRender.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void drawChromaWaveString(String text, int xIn, int y) {
    FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
    int x = xIn;
    for (char c : text.toCharArray()) {
        long dif = (x * 10) - (y * 10);
        long l = System.currentTimeMillis() - dif;
        float ff = 2000.0F;
        int i = Color.HSBtoRGB((float) (l % (int) ff) / ff, 0.8F, 0.8F);
        String tmp = String.valueOf(c);
        renderer.drawString(tmp, (float) ((double) x), (float) ((double) y), i, false);
        x += (double) renderer.getCharWidth(c);
    }
}
 
Example #27
Source Project: Hyperium   Author: HyperiumClient   File: AboveHeadRenderer.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void renderName(RenderPlayerEvent event, LevelheadTag tag, EntityPlayer player, double x, double y, double z) {
    FontRenderer fontrenderer = event.getRenderManager().getFontRenderer();
    float f = (float) (1.6F * Levelhead.getInstance().getDisplayManager().getMasterConfig().getFontSize());
    float f1 = 0.016666668F * f;
    GlStateManager.pushMatrix();
    GlStateManager.translate((float) x + 0.0F, (float) y + player.height + 0.5F, (float) z);
    GL11.glNormal3f(0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-event.getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(event.getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
    GlStateManager.scale(-f1, -f1, f1);
    GlStateManager.disableLighting();
    GlStateManager.depthMask(false);
    GlStateManager.disableDepth();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
    Tessellator tessellator = Tessellator.getInstance();
    WorldRenderer worldrenderer = tessellator.getWorldRenderer();
    int i = 0;

    int j = fontrenderer.getStringWidth(tag.getString()) / 2;
    GlStateManager.disableTexture2D();
    worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
    worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
    tessellator.draw();
    GlStateManager.enableTexture2D();

    renderString(fontrenderer, tag);

    GlStateManager.enableLighting();
    GlStateManager.disableBlend();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.popMatrix();
}
 
Example #28
Source Project: Hyperium   Author: HyperiumClient   File: MemoryDisplay.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void draw(int x, double y, boolean config) {
    int mbDiv = 1048576;
    long maxMemory = Runtime.getRuntime().maxMemory() / mbDiv;
    long totalMemory = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / mbDiv;

    String displayString = totalMemory + " / " + (maxMemory == Long.MAX_VALUE ? "No limit" : maxMemory) + "MB";
    ElementRenderer.draw(x, y, displayString);
    FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;

    height = fr.FONT_HEIGHT * ElementRenderer.getCurrentScale();
    width = fr.getStringWidth(displayString) * ElementRenderer.getCurrentScale();
}
 
Example #29
Source Project: Hyperium   Author: HyperiumClient   File: ElementRenderer.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void drawChromaString(String text, int xIn, int y) {
    FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
    int x = xIn;

    for (char c : text.toCharArray()) {
        long dif = (x * 10) - (y * 10);
        if (current.isStaticChroma()) dif = 0;
        long l = System.currentTimeMillis() - dif;
        float ff = current.isStaticChroma() ? 1000.0F : 2000.0F;
        int i = Color.HSBtoRGB((float) (l % (int) ff) / ff, 0.8F, 0.8F);
        String tmp = String.valueOf(c);
        renderer.drawString(tmp, (float) ((double) x / currentScale), (float) ((double) y / currentScale), i, current.isShadow());
        x += (double) renderer.getCharWidth(c) * currentScale;
    }
}
 
Example #30
Source Project: Hyperium   Author: HyperiumClient   File: MixinGuiOverlayDebug.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void renderOldDebugInfoLeft() {
    FontRenderer fontRendererObj = mc.fontRendererObj;

    fontRendererObj.drawStringWithShadow("Minecraft 1.8.9 (" + Minecraft.getDebugFPS() + " fps, " +
        RenderChunk.renderChunksUpdated + " chunk updates)", 2, 2, -1);
    fontRendererObj.drawStringWithShadow(mc.renderGlobal.getDebugInfoRenders(), 2, 12, -1);
    fontRendererObj.drawStringWithShadow(mc.renderGlobal.getDebugInfoEntities(), 2, 22, -1);
    fontRendererObj.drawStringWithShadow("P: " + mc.effectRenderer.getStatistics() + ". T: " + mc.theWorld.getDebugLoadedEntities(), 2, 32, -1);
    fontRendererObj.drawStringWithShadow(mc.theWorld.getProviderName(), 2, 42, -1);

    int posX = MathHelper.floor_double(mc.thePlayer.posX);
    int posY = MathHelper.floor_double(mc.thePlayer.posY);
    int posZ = MathHelper.floor_double(mc.thePlayer.posZ);
    fontRendererObj.drawStringWithShadow(String.format("x: %.5f (%d) // c: %d (%d)", mc.thePlayer.posX, posX, posX >> 4, posX & 15), 2, 64, -1);
    fontRendererObj.drawStringWithShadow(String.format("y: %.3f (feet pos, %.3f eyes pos)",
        mc.thePlayer.getEntityBoundingBox().minY, mc.thePlayer.posY), 2, 72, -1);
    Entity entity = mc.getRenderViewEntity();
    EnumFacing enumfacing = entity.getHorizontalFacing();
    fontRendererObj.drawStringWithShadow(String.format("z: %.5f (%d) // c: %d (%d)", mc.thePlayer.posZ, posZ, posZ >> 4, posZ & 15), 2, 80, -1);
    int yaw = MathHelper.floor_double((double) (mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
    fontRendererObj.drawStringWithShadow("f: " + yaw + " (" + enumfacing + ") / " +
        MathHelper.wrapAngleTo180_float(mc.thePlayer.rotationYaw), 2, 88, -1);
    if (mc.theWorld != null && !mc.theWorld.isAirBlock(new BlockPos(posX, posY, posZ))) {
        Chunk chunk = mc.theWorld.getChunkFromBlockCoords(new BlockPos(posX, posY, posZ));
        fontRendererObj.drawStringWithShadow("lc: " + (chunk.getTopFilledSegment() + 15) + " b: " +
                chunk.getBiome(new BlockPos(posX & 15, 64, posZ & 15), mc.theWorld.getWorldChunkManager()).biomeName + " bl: "
                + chunk.getBlockLightOpacity(new BlockPos(posX & 15, posY, posZ & 15)) + " sl: " + chunk.getBlockLightOpacity(
            new BlockPos(posX & 15, posY, posZ & 15)) + " rl: " + chunk.getBlockLightOpacity(new BlockPos(posX & 15, posY, posZ & 15)),
            2, 96, -1);
    }

    fontRendererObj.drawStringWithShadow(String.format("ws: %.3f, fs: %.3f, g: %b, fl: %d", mc.thePlayer.capabilities.getWalkSpeed(),
        mc.thePlayer.capabilities.getFlySpeed(), mc.thePlayer.onGround, mc.theWorld.getHeight()), 2, 104, -1);
    if (mc.entityRenderer != null && mc.entityRenderer.isShaderActive()) {
        fontRendererObj.drawStringWithShadow(String.format("shader: %s", mc.entityRenderer.getShaderGroup().getShaderGroupName()), 2, 112, -1);
    }
}