use of net.minecraft.client.gui.FontRenderer in project Almura by AlmuraDev.
the class CacheTileEntityRenderer method render.
@Override
public void render(SingleSlotTileEntity te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
final ISingleSlotItemHandler itemHandler = (ISingleSlotItemHandler) te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (itemHandler == null) {
return;
}
final ItemStack cache = itemHandler.getStackInSlot(0);
final BlockPos pos = te.getPos();
final World world = te.getWorld();
final IBlockState blockState = world.getBlockState(pos);
if (!(blockState.getBlock() instanceof CacheBlock)) {
return;
}
final CacheBlock block = (CacheBlock) blockState.getBlock();
final int blockX = pos.getX();
final int blockY = pos.getY();
final int blockZ = pos.getZ();
GlStateManager.pushMatrix();
float angle = 0f;
double translatedX = x;
double translatedZ = z;
float brightness = 0f;
switch(blockState.getValue(BlockHorizontal.FACING)) {
case SOUTH:
angle = 0f;
translatedX += 0.5;
translatedZ += 1.025;
brightness = blockState.getPackedLightmapCoords(world, new BlockPos(blockX, blockY, blockZ + 1));
break;
case WEST:
angle = -90f;
translatedX -= 0.025;
translatedZ += 0.5;
brightness = blockState.getPackedLightmapCoords(world, new BlockPos(blockX - 1, blockY, blockZ));
break;
case NORTH:
angle = 180f;
translatedX += 0.5;
translatedZ -= 0.025;
brightness = blockState.getPackedLightmapCoords(world, new BlockPos(blockX, blockY, blockZ - 1));
break;
case EAST:
angle = 90f;
translatedX += 1.025;
translatedZ += 0.5;
brightness = blockState.getPackedLightmapCoords(world, new BlockPos(blockX + 1, blockY, blockZ));
break;
}
// Move the matrix to the front face, in the center
GlStateManager.translate(translatedX, y + 0.525f, translatedZ);
GlStateManager.rotate(angle, 0f, 1f, 0f);
// Set lightmap coordinates to the skylight value of the block in front of the cache item model
float j = brightness % 65536;
float k = brightness / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j / 1.0F, k / 1.0F);
GlStateManager.color(1f, 1f, 1f, 1f);
// Rotate cache item model to fit default Vanilla cache icon look. We do not support rotating the item model
GlStateManager.rotate(180f, 0.0F, 1f, 0f);
GlStateManager.scale(0.5F, 0.5F, 0.5F);
// FIXED is meant for ItemFrame rendering which we are mimicing
this.client.getRenderItem().renderItem(cache, ItemCameraTransforms.TransformType.FIXED);
// Revert lightmap texture coordinates to world values pre-render tick
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, OpenGlHelper.lastBrightnessX, OpenGlHelper.lastBrightnessY);
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
// Translate to face the cache item model is on but at the bottom edge
GlStateManager.translate(translatedX, y, translatedZ);
// Rotate on the y-axis by the angle
GlStateManager.rotate(angle, 0f, 1f, 0f);
// Scale the matrix by a scale factor (to make writing legible but not too big on block)
final float scaleFactor = 0.6666667F * 0.016666668F;
GlStateManager.scale(scaleFactor, -scaleFactor, scaleFactor);
final FontRenderer fontRenderer = this.client.fontRenderer;
String displayName;
String cacheQuantity = ZERO_QUANTITY;
boolean empty = cache.isEmpty();
if (empty) {
displayName = block.getLocalizedName();
} else {
cacheQuantity = CacheFeature.format.format(cache.getCount());
displayName = cache.getDisplayName();
}
final String cacheMaxQuantity = CacheFeature.format.format(itemHandler.getSlotLimit(0));
// Check if we can fit the displayname on the first line, if not then split it to two lines at most
if (fontRenderer.getStringWidth(displayName) > MAX_LINE_WIDTH) {
int firstLineLength = displayName.length();
while (fontRenderer.getStringWidth(displayName.substring(0, firstLineLength)) > MAX_LINE_WIDTH) {
firstLineLength--;
}
final String firstLine = displayName.substring(0, firstLineLength);
final String secondLine = displayName.substring(firstLineLength, displayName.length());
fontRenderer.drawString(firstLine, -fontRenderer.getStringWidth(firstLine) / 2, (int) y - 80, 0);
fontRenderer.drawString(secondLine, -fontRenderer.getStringWidth(secondLine) / 2, (int) y - 70, 0);
} else {
fontRenderer.drawString(displayName, -fontRenderer.getStringWidth(displayName) / 2, (int) y - 80, 0);
}
final int lineWidth = fontRenderer.getStringWidth(cacheMaxQuantity) / 2;
fontRenderer.drawString(cacheQuantity, -fontRenderer.getStringWidth(cacheQuantity) / 2, (int) y - 24, 0);
Gui.drawRect(-lineWidth, (int) y - 16, lineWidth, (int) y - 15, 0xFF000000);
fontRenderer.drawString(cacheMaxQuantity, -fontRenderer.getStringWidth(cacheMaxQuantity) / 2, (int) y - 14, 0);
GlStateManager.popMatrix();
}
use of net.minecraft.client.gui.FontRenderer in project Charset by CharsetMC.
the class ProjectorHandlerBook method render.
@Override
@SideOnly(Side.CLIENT)
public void render(ItemStack stack, IProjector projector, IProjectorSurface surface) {
// oh boy! text!
if (stack.hasTagCompound()) {
GlStateManager.pushMatrix();
GlStateManager.translate(((surface.getCornerStart().x + surface.getCornerEnd().x) / 2) + surface.getScreenFacing().getFrontOffsetX() * 0.001f, ((surface.getCornerStart().y + surface.getCornerEnd().y) / 2) + surface.getScreenFacing().getFrontOffsetY() * 0.001f, ((surface.getCornerStart().z + surface.getCornerEnd().z) / 2) + surface.getScreenFacing().getFrontOffsetZ() * 0.001f);
Orientation orientation = ProjectorHelper.INSTANCE.getOrientation(surface);
Quaternion.fromOrientation(orientation).glRotate();
GlStateManager.rotate(270.0f, 0, 0, 1);
GlStateManager.rotate(270.0f, 0, 1, 0);
GlStateManager.translate(0, 0, -ProjectorHelper.OFFSET);
float scaleVal = 2f * surface.getWidth() / 146f;
GlStateManager.scale(scaleVal, scaleVal, scaleVal);
FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
NBTTagList pages = stack.getTagCompound().getTagList("pages", Constants.NBT.TAG_STRING);
if (pages.tagCount() > projector.getPage()) {
String pageCount = I18n.format("book.pageIndicator", projector.getPage() + 1, pages.tagCount());
renderer.drawString(pageCount, -73 + 129 - renderer.getStringWidth(pageCount), -90 + 15, 0xFF000000);
String page = ((NBTTagString) pages.get(projector.getPage())).getString();
ITextComponent fullComponent = ITextComponent.Serializer.jsonToComponent(page);
if (fullComponent != null) {
List<ITextComponent> components = GuiUtilRenderComponents.splitText(fullComponent, 116, renderer, true, true);
for (int i = 0; i < components.size(); i++) {
renderer.drawString(components.get(i).getUnformattedText(), -73 + 16, -90 + 30 + i * renderer.FONT_HEIGHT, 0xFF000000);
}
}
}
GlStateManager.popMatrix();
surface.restoreGLColor();
}
Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/book.png"));
ProjectorHelper.INSTANCE.renderTexture(surface, 20, 20 + 146, 1, 1 + 180);
}
use of net.minecraft.client.gui.FontRenderer in project Charset by CharsetMC.
the class NotifyProxyClient method renderMessage.
private void renderMessage(ClientMessage m, float partial, float opacity, Vec3d c) {
int width = 0;
String[] lines = m.msgRendered.split("\n");
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldrenderer = tessellator.getBuffer();
for (String line : lines) {
width = Math.max(width, fr.getStringWidth(line));
}
width += 2;
int halfWidth = width / 2;
float scaling = 1.6F / 60F;
scaling *= 2F / 3F;
GlStateManager.pushMatrix();
int lineCount = lines.length;
float centeringOffset = 0;
if (m.show_item) {
if (lineCount == 1) {
centeringOffset = 5F;
}
lineCount = Math.max(2, lineCount);
}
Vec3d vec = m.getPosition(partial);
float x = (float) vec.x;
float y = (float) vec.y;
float z = (float) vec.z;
if (m.style.contains(NoticeStyle.SCALE_SIZE)) {
double dx = x - c.x;
double dy = y - c.y;
double dz = z - c.z;
double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
scaling *= Math.sqrt(dist);
}
NotificationCoord co = m.asCoord();
if (co != null && !m.position_important) {
BlockPos pos = co.getPos();
IBlockState bs = co.getWorld().getBlockState(pos);
AxisAlignedBB bb = bs.getCollisionBoundingBox(co.getWorld(), pos);
if (bb != null) {
y = (float) Math.max(y, pos.getY() + bb.maxY);
} else {
y = (float) Math.max(y, pos.getY() + 0.5f);
}
}
GlStateManager.translate(x + 0.5F, y, z + 0.5F);
Minecraft mc = Minecraft.getMinecraft();
float pvx = mc.getRenderManager().playerViewX;
float pvy = -mc.getRenderManager().playerViewY;
if (mc.gameSettings.thirdPersonView == 2) {
pvx = -pvx;
}
GlStateManager.rotate(pvy, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(pvx, 1.0F, 0.0F, 0.0F);
GlStateManager.scale(-scaling, -scaling, scaling);
GlStateManager.translate(0, -10 * lineCount, 0);
{
int lineHeight = (lineCount - 1) * 10;
double item_add = 0;
if (m.show_item) {
item_add += 24;
}
float col = 0.0F;
GlStateManager.disableTexture2D();
GlStateManager.color(col, col, col, Math.min(opacity, 0.2F));
double Z = 0.001D;
// TODO: Use 2 tessellator + 2 draw calls to do all notice rendering
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
worldrenderer.pos(-halfWidth - 1, -1, Z).endVertex();
worldrenderer.pos(-halfWidth - 1, 8 + lineHeight, Z).endVertex();
worldrenderer.pos(halfWidth + 1 + item_add, 8 + lineHeight, Z).endVertex();
worldrenderer.pos(halfWidth + 1 + item_add, -1, Z).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
}
{
int i = 0;
int B = (int) (0xFF * Math.min(1, 0.5F + opacity));
int color = (B << 16) + (B << 8) + B + ((int) (0xFF * opacity) << 24);
GlStateManager.translate(0, centeringOffset, 0);
for (String line : lines) {
fr.drawString(line, -fr.getStringWidth(line) / 2, 10 * i, color);
i++;
}
}
{
if (m.show_item) {
// TODO: Add transparency support
GlStateManager.translate(0, -centeringOffset, 0);
GlStateManager.translate((float) (halfWidth + 4), -lineCount / 2, 0);
// Undoes the effects of setupGuiTransform
renderItem.zLevel -= 100;
renderItem.renderItemIntoGUI(m.item, 0, 0);
renderItem.zLevel += 100;
}
}
GlStateManager.popMatrix();
}
use of net.minecraft.client.gui.FontRenderer in project ForestryMC by ForestryMC.
the class WidgetDatabaseScreen method update.
private void update() {
// reset list and layout helper
scrollable.clear();
scrollBar.setVisible(false);
scrollable.updateVisibleElements(0);
layoutHelper = new GuiElementHelper(scrollable);
if (state == DatabaseScreenLogic.ScreenState.SUCCESS) {
IDatabaseTab selectedTab = logic.selectedTab;
selectedTab.createElements(layoutHelper, logic.individual, logic.itemStack);
int invisibleElements = scrollable.getInvisibleElementCount();
if (invisibleElements > 0) {
scrollBar.setParameters(this, 0, invisibleElements, 1);
scrollBar.setVisible(true);
// scrollBar.setValue(0);
} else {
scrollBar.setValue(0);
}
scrollable.updateVisibleElements(scrollBar.getValue());
} else {
GuiElementHelper layoutHelper = new GuiElementHelper(scrollable);
FontRenderer fontRenderer = manager.gui.getFontRenderer();
String key = "for.gui.portablealyzer.help";
if (state == DatabaseScreenLogic.ScreenState.NO_PLUGIN) {
key = "for.gui.database.support";
}
List<String> lines = fontRenderer.listFormattedStringToWidth(Translator.translateToLocal(key), width - 10);
for (String text : lines) {
layoutHelper.addText(2, text, -1);
}
scrollable.updateVisibleElements(0);
}
}
use of net.minecraft.client.gui.FontRenderer in project ForestryMC by ForestryMC.
the class WidgetClimatePanel method draw.
@Override
public void draw(int startX, int startY) {
GlStateManager.color(1.0f, 1.0f, 1.0f);
Minecraft mc = Minecraft.getMinecraft();
mc.getTextureManager().bindTexture(gui.textureFile);
gui.drawTexturedModalRect(startX + textField.x - 2, startY + textField.y - 2, 196, 50, 52, 12);
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
String title = Translator.translateToLocal("for.gui." + type.getName());
fontRenderer.drawString(title, xPos + startX + width / 2 - fontRenderer.getStringWidth(title) / 2, startY + yPos + 2, ColourProperties.INSTANCE.get("gui.greenhouse." + type.getName() + ".header"));
GlStateManager.color(1.0f, 1.0f, 1.0f);
textField.drawTextBox();
String modifiersTitle = Translator.translateToLocal("for.gui.modifier.title");
fontRenderer.drawStringWithShadow(TextFormatting.UNDERLINE + modifiersTitle, xPos + startX + width / 2 - fontRenderer.getStringWidth(modifiersTitle) / 2, yPos + startY + (height - WidgetClimateModifier.HEIGHT * 4), ColourProperties.INSTANCE.get("gui.greenhouse.modifiers.subheader"));
for (WidgetClimateModifier modifier : modifiers) {
modifier.draw(startX, startY);
}
}
Aggregations